@alchemy/wallet-apis 0.0.0-alpha.20 → 0.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions/formatSign.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/experimental/actions/requestQuoteV0.js +3 -4
- 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/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/experimental/actions/requestQuoteV0.ts +5 -4
- package/src/utils/schema.ts +79 -1
- package/src/version.ts +1 -1
|
@@ -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;AAClF,OAAO,EAA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AAC,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,EAAE,MAAM,EAAE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AAO,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":["../../../src/actions/listAcc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ributiveOmit, 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,MAAM,cAAc,CAA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AM,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,MAAM,aAAa,GAC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;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,EAAE,MAAM,+BAA+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../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"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { 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,6 @@ export async function requestQuoteV0(client, params) {
|
|
|
60
59
|
method: "wallet_requestQuote_v0",
|
|
61
60
|
params: [rpcParams],
|
|
62
61
|
});
|
|
63
|
-
return
|
|
62
|
+
return decode(schema.response, rpcResp);
|
|
64
63
|
}
|
|
65
64
|
//# sourceMappingURL=requestQuoteV0.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestQuoteV0.js","sourceRoot":"","sources":["../../../../src/experimental/actions/requestQuoteV0.ts"],"names":[],"mappings":"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AAM,CAAC,MAAM,CAAC,OAAO,EAAE;QACvC,GAAG,IAAI;QACP,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;QAC1C,IAAI;QACJ,GAAG,CAAC,YAAY,IAAI,EAAE,YAAY,EAAE,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC;KACvE,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,wBAAwB;QAChC,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,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 {\n mergeClientCapabilities,\n toRpcCapabilities,\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\nexport type RequestQuoteV0Result = RequestQuoteV0Response;\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 return decode(schema.response, rpcResp);\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 {};
|
package/dist/esm/utils/schema.js
CHANGED
|
@@ -1,7 +1,65 @@
|
|
|
1
|
+
import { Value, EncodeError, DecodeError, Pointer } from "typebox/value";
|
|
2
|
+
import { BaseError } from "@alchemy/common";
|
|
1
3
|
export function methodSchema(schema) {
|
|
2
4
|
return {
|
|
3
5
|
request: schema.properties.Request.properties.params.items[0],
|
|
4
6
|
response: schema.properties.ReturnType,
|
|
5
7
|
};
|
|
6
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Formats an {@link EncodeError} or {@link DecodeError} into a human-readable
|
|
11
|
+
* string describing what went wrong, including the JSON path and the schema's
|
|
12
|
+
* custom error message (if any).
|
|
13
|
+
*
|
|
14
|
+
* @param {TSchema} schema - The TypeBox schema that validation was run against.
|
|
15
|
+
* @param {EncodeError | DecodeError} error - The error thrown by {@link Value.Encode} or {@link Value.Decode}.
|
|
16
|
+
* @returns {string} A formatted error string prefixed with `"Invalid params"`.
|
|
17
|
+
*/
|
|
18
|
+
function formatCodecError(schema, error) {
|
|
19
|
+
// Use only the first error — it's the most specific. Subsequent errors are
|
|
20
|
+
// typically cascade noise from union/anyOf branches.
|
|
21
|
+
const causeError = error.cause.errors[0];
|
|
22
|
+
// errors is typed as an open array — guard against the (practically
|
|
23
|
+
// impossible) empty case.
|
|
24
|
+
if (!causeError)
|
|
25
|
+
return "Invalid params";
|
|
26
|
+
const path = causeError.instancePath || "(root)";
|
|
27
|
+
// Prefer the schema's custom errorMessage annotation over the generic locale message.
|
|
28
|
+
let message = causeError.message;
|
|
29
|
+
const schemaPointer = causeError.schemaPath.replace(/^#/, "");
|
|
30
|
+
if (schemaPointer) {
|
|
31
|
+
const schemaNode = Pointer.Get(schema, schemaPointer);
|
|
32
|
+
if (schemaNode &&
|
|
33
|
+
typeof schemaNode === "object" &&
|
|
34
|
+
"errorMessage" in schemaNode &&
|
|
35
|
+
typeof schemaNode.errorMessage === "string") {
|
|
36
|
+
message = schemaNode.errorMessage;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return `Invalid params: ${path}: ${message}`;
|
|
40
|
+
}
|
|
41
|
+
// Type-safe wrapper around `Value.Encode` with human-readable errors.
|
|
42
|
+
export function encode(schema, value) {
|
|
43
|
+
try {
|
|
44
|
+
return Value.Encode(schema, value);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof EncodeError) {
|
|
48
|
+
throw new BaseError(formatCodecError(schema, error), { cause: error });
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Type-safe wrapper around `Value.Decode` with human-readable errors.
|
|
54
|
+
export function decode(schema, value) {
|
|
55
|
+
try {
|
|
56
|
+
return Value.Decode(schema, value);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof DecodeError) {
|
|
60
|
+
throw new BaseError(formatCodecError(schema, error), { cause: error });
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
7
65
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,UAAU,YAAY,CAC1B,MAGE;IAEF,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7D,QAAQ,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU;KACvC,CAAC;AACJ,CAAC;AAYD;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CACvB,MAAe,EACf,KAAgC;IAEhC,2EAA2E;IAC3E,qDAAqD;IACrD,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACzC,oEAAoE;IACpE,0BAA0B;IAC1B,IAAI,CAAC,UAAU;QAAE,OAAO,gBAAgB,CAAC;IAEzC,MAAM,IAAI,GAAG,UAAU,CAAC,YAAY,IAAI,QAAQ,CAAC;IAEjD,sFAAsF;IACtF,IAAI,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IACjC,MAAM,aAAa,GAAG,U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,CAAC","sourcesContent":["import type {\n TObject,\n TSchema,\n TTuple,\n StaticDecode,\n StaticEncode,\n} from \"typebox\";\nimport { Value, EncodeError, DecodeError, Pointer } from \"typebox/value\";\nimport { BaseError } from \"@alchemy/common\";\n\n/** Constraint for RPC method schemas from `@alchemy/wallet-api-types/rpc`. */\ntype RpcMethodSchema = TObject<{\n Request: TObject<{\n method: TSchema;\n params: TTuple<[TSchema, ...TSchema[]]>;\n }>;\n ReturnType: TSchema;\n}>;\n\nexport function methodSchema<TReq extends TSchema, TRes extends TSchema>(\n schema: TObject<{\n Request: TObject<{ method: TSchema; params: TTuple<[TReq, ...TSchema[]]> }>;\n ReturnType: TRes;\n }>,\n): { request: TReq; response: TRes } {\n return {\n request: schema.properties.Request.properties.params.items[0],\n response: schema.properties.ReturnType,\n };\n}\n\n/** Extracts the decoded params type from a method schema. */\nexport type MethodParams<T extends RpcMethodSchema> = StaticDecode<\n T[\"properties\"][\"Request\"][\"properties\"][\"params\"][\"items\"][0]\n>;\n\n/** Extracts the decoded response type from a method schema. */\nexport type MethodResponse<T extends RpcMethodSchema> = StaticDecode<\n T[\"properties\"][\"ReturnType\"]\n>;\n\n/**\n * Formats an {@link EncodeError} or {@link DecodeError} into a human-readable\n * string describing what went wrong, including the JSON path and the schema's\n * custom error message (if any).\n *\n * @param {TSchema} schema - The TypeBox schema that validation was run against.\n * @param {EncodeError | DecodeError} error - The error thrown by {@link Value.Encode} or {@link Value.Decode}.\n * @returns {string} A formatted error string prefixed with `\"Invalid params\"`.\n */\nfunction formatCodecError(\n schema: TSchema,\n error: EncodeError | DecodeError,\n): string {\n // Use only the first error — it's the most specific. Subsequent errors are\n // typically cascade noise from union/anyOf branches.\n const causeError = error.cause.errors[0];\n // errors is typed as an open array — guard against the (practically\n // impossible) empty case.\n if (!causeError) return \"Invalid params\";\n\n const path = causeError.instancePath || \"(root)\";\n\n // Prefer the schema's custom errorMessage annotation over the generic locale message.\n let message = causeError.message;\n const schemaPointer = causeError.schemaPath.replace(/^#/, \"\");\n if (schemaPointer) {\n const schemaNode = Pointer.Get(schema, schemaPointer);\n if (\n schemaNode &&\n typeof schemaNode === \"object\" &&\n \"errorMessage\" in schemaNode &&\n typeof (schemaNode as Record<string, unknown>).errorMessage === \"string\"\n ) {\n message = (schemaNode as Record<string, unknown>).errorMessage as string;\n }\n }\n\n return `Invalid params: ${path}: ${message}`;\n}\n\n// Type-safe wrapper around `Value.Encode` with human-readable errors.\nexport function encode<const T extends TSchema>(\n schema: T,\n value: StaticDecode<T>,\n): StaticEncode<T> {\n try {\n return Value.Encode(schema, value);\n } catch (error) {\n if (error instanceof EncodeError) {\n throw new BaseError(formatCodecError(schema, error), { cause: error });\n }\n throw error;\n }\n}\n\n// Type-safe wrapper around `Value.Decode` with human-readable errors.\nexport function decode<const T extends TSchema>(\n schema: T,\n value: StaticEncode<T>,\n): StaticDecode<T> {\n try {\n return Value.Decode(schema, value);\n } catch (error) {\n if (error instanceof DecodeError) {\n throw new BaseError(formatCodecError(schema, error), { cause: error });\n }\n throw error;\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.20";
|
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.20\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatSign.d.ts","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"formatSign.d.ts","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,oBAAoB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAC9D,KAAK,kBAAkB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAE9D,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CACrC,gBAAgB,CAAC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG;IAC3D,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CACF,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAqB3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grantPermissions.d.ts","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAa,MAAM,MAAM,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"grantPermissions.d.ts","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAa,MAAM,MAAM,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAGrF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,uBAAuB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAEjE,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAC3C,gBAAgB,CAAC,uBAAuB,EAAE,SAAS,GAAG,SAAS,CAAC,GAAG;IACjE,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CACF,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,OAAO,EAAE,GAAG,CAAC;CACd,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,sBAAsB,CAAC,CAkCjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listAccounts.d.ts","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"listAccounts.d.ts","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEpF,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,sBAAsB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAChE,KAAK,oBAAoB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAEhE,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CACvC,gBAAgB,CACd,sBAAsB,EACtB,eAAe,GAAG,iBAAiB,CACpC,GAAG;IACF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,KAAK,CAAC;CACzB,CACF,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAuB7B"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AACpF,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,sBAAsB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAChE,KAAK,oBAA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areSign.d.ts","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,kBAAkB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEnF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,qBAAqB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAC/D,KAAK,mBAAmB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAE/D,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,CAC9C,qBAAqB,EACrB,MAAM,GAAG,SAAS,CACnB,GAAG;IACF,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAqB5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestAccount.d.ts","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAkB,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,qBAAqB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"requestAccount.d.ts","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAkB,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,qBAAqB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGvE,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,wBAAwB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAElE,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CACzC,gBAAgB,CACd,OAAO,CAAC,wBAAwB,EAAE;IAAE,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,EAC7D,eAAe,GAAG,2BAA2B,CAC9C,GACC,CACI;IAAE,aAAa,CAAC,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,KAAK,CAAA;CAAE,GACnD;IAAE,aAAa,CAAC,EAAE,KAAK,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAE,CACrD,CACJ,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,CAAC,EAAE,oBAAoB,GAC5B,OAAO,CAAC,oBAAoB,CAAC,CA6D/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendPreparedCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"sendPreparedCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,2BAA2B,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AACrE,KAAK,yBAAyB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAErE,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,gBAAgB,CACd,gBAAgB,CAAC,2BAA2B,EAAE,SAAS,CAAC,GAAG;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CACF,CACF,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,uBAAuB,CAAC,CA0BlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestQuoteV0.d.ts","sourceRoot":"","sources":["../../../../src/experimental/actions/requestQuoteV0.ts"],"names":[],"mappings":"AAAA,OAAO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CG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CA2B/B"}
|
|
@@ -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,5 +21,7 @@ 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 {};
|
|
25
27
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,MAAM,EACN,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAC;AAIjB,8EAA8E;AAC9E,KAAK,eAAe,GAAG,OAAO,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;QACf,MAAM,EAAE,OAAO,CAAC;QAChB,MAAM,EAAE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
|
|
1
|
-
export declare const VERSION = "0.0.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.0.0-alpha.20";
|
|
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.21",
|
|
4
4
|
"description": "Alchemy Wallet APIs",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"typescript-template": "*"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@alchemy/common": "^0.0.0-alpha.
|
|
56
|
+
"@alchemy/common": "^0.0.0-alpha.21",
|
|
57
57
|
"@alchemy/wallet-api-types": "0.1.0-alpha.25",
|
|
58
58
|
"deep-equal": "^2.2.3",
|
|
59
59
|
"ox": "^0.11.1",
|
|
@@ -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": "b253d0ee34fcb723a72d594d56b484188ac6867b"
|
|
76
76
|
}
|
|
@@ -3,9 +3,10 @@ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
|
3
3
|
import { wallet_formatSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
4
|
import { LOGGER } from "../logger.js";
|
|
5
5
|
import { resolveAddress, type AccountParam } from "../utils/resolve.js";
|
|
6
|
-
import { Value } from "typebox/value";
|
|
7
6
|
import {
|
|
8
7
|
methodSchema,
|
|
8
|
+
encode,
|
|
9
|
+
decode,
|
|
9
10
|
type MethodParams,
|
|
10
11
|
type MethodResponse,
|
|
11
12
|
} from "../utils/schema.js";
|
|
@@ -53,11 +54,11 @@ export async function formatSign(
|
|
|
53
54
|
LOGGER.debug("formatSign:start");
|
|
54
55
|
|
|
55
56
|
const { account: _, chainId: __, ...rest } = params;
|
|
56
|
-
const rpcParams =
|
|
57
|
+
const rpcParams = encode(schema.request, {
|
|
57
58
|
...rest,
|
|
58
59
|
from,
|
|
59
60
|
chainId: params.chainId ?? client.chain.id,
|
|
60
|
-
}
|
|
61
|
+
});
|
|
61
62
|
|
|
62
63
|
const rpcResp = await client.request({
|
|
63
64
|
method: "wallet_formatSign",
|
|
@@ -65,5 +66,5 @@ export async function formatSign(
|
|
|
65
66
|
});
|
|
66
67
|
|
|
67
68
|
LOGGER.debug("formatSign:done");
|
|
68
|
-
return
|
|
69
|
+
return decode(schema.response, rpcResp);
|
|
69
70
|
}
|
|
@@ -3,9 +3,13 @@ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
|
3
3
|
import { wallet_createSession as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
4
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
5
5
|
import { LOGGER } from "../logger.js";
|
|
6
|
-
import { Value } from "typebox/value";
|
|
7
6
|
import { resolveAddress, type AccountParam } from "../utils/resolve.js";
|
|
8
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
methodSchema,
|
|
9
|
+
encode,
|
|
10
|
+
decode,
|
|
11
|
+
type MethodParams,
|
|
12
|
+
} from "../utils/schema.js";
|
|
9
13
|
|
|
10
14
|
const schema = methodSchema(MethodSchema);
|
|
11
15
|
type BaseCreateSessionParams = MethodParams<typeof MethodSchema>;
|
|
@@ -88,24 +92,18 @@ export async function grantPermissions(
|
|
|
88
92
|
const chainId = params.chainId ?? client.chain.id;
|
|
89
93
|
|
|
90
94
|
const { account: _, chainId: __, ...rest } = params;
|
|
91
|
-
const rpcParams =
|
|
95
|
+
const rpcParams = encode(schema.request, {
|
|
92
96
|
...rest,
|
|
93
97
|
account,
|
|
94
98
|
chainId,
|
|
95
|
-
}
|
|
99
|
+
});
|
|
96
100
|
|
|
97
101
|
const rpcResp = await client.request({
|
|
98
102
|
method: "wallet_createSession",
|
|
99
103
|
params: [rpcParams],
|
|
100
104
|
});
|
|
101
105
|
|
|
102
|
-
const { sessionId, signatureRequest } =
|
|
103
|
-
schema.response,
|
|
104
|
-
rpcResp,
|
|
105
|
-
) satisfies {
|
|
106
|
-
sessionId: Hex;
|
|
107
|
-
signatureRequest: Parameters<typeof signSignatureRequest>[1];
|
|
108
|
-
};
|
|
106
|
+
const { sessionId, signatureRequest } = decode(schema.response, rpcResp);
|
|
109
107
|
|
|
110
108
|
const signature = await signSignatureRequest(client, signatureRequest);
|
|
111
109
|
|
|
@@ -3,9 +3,10 @@ import { LOGGER } from "../logger.js";
|
|
|
3
3
|
import type { Address, Prettify } from "viem";
|
|
4
4
|
import { wallet_listAccounts as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
5
|
import { isLocalAccount } from "../utils/assertions.js";
|
|
6
|
-
import { Value } from "typebox/value";
|
|
7
6
|
import {
|
|
8
7
|
methodSchema,
|
|
8
|
+
encode,
|
|
9
|
+
decode,
|
|
9
10
|
type MethodParams,
|
|
10
11
|
type MethodResponse,
|
|
11
12
|
} from "../utils/schema.js";
|
|
@@ -64,20 +65,17 @@ export async function listAccounts(
|
|
|
64
65
|
|
|
65
66
|
LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
|
|
66
67
|
|
|
67
|
-
const rpcParams =
|
|
68
|
+
const rpcParams = encode(schema.request, {
|
|
68
69
|
...params,
|
|
69
70
|
signerAddress,
|
|
70
|
-
}
|
|
71
|
+
});
|
|
71
72
|
|
|
72
73
|
const rpcResp = await client.request({
|
|
73
74
|
method: "wallet_listAccounts",
|
|
74
75
|
params: [rpcParams],
|
|
75
76
|
});
|
|
76
77
|
|
|
77
|
-
const res =
|
|
78
|
-
schema.response,
|
|
79
|
-
rpcResp,
|
|
80
|
-
) satisfies ListAccountsResult;
|
|
78
|
+
const res = decode(schema.response, rpcResp);
|
|
81
79
|
LOGGER.debug("listAccounts:done", { count: res.accounts.length });
|
|
82
80
|
|
|
83
81
|
return res;
|
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
} from "../utils/capabilities.js";
|
|
11
11
|
import { resolveAddress, type AccountParam } from "../utils/resolve.js";
|
|
12
12
|
import { wallet_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
13
|
-
import { Value } from "typebox/value";
|
|
14
13
|
import {
|
|
15
14
|
methodSchema,
|
|
15
|
+
encode,
|
|
16
|
+
decode,
|
|
16
17
|
type MethodParams,
|
|
17
18
|
type MethodResponse,
|
|
18
19
|
} from "../utils/schema.js";
|
|
@@ -96,12 +97,12 @@ export async function prepareCalls(
|
|
|
96
97
|
});
|
|
97
98
|
|
|
98
99
|
const { account: _, chainId: __, ...rest } = params;
|
|
99
|
-
const rpcParams =
|
|
100
|
+
const rpcParams = encode(schema.request, {
|
|
100
101
|
...rest,
|
|
101
102
|
chainId,
|
|
102
103
|
from,
|
|
103
104
|
capabilities: toRpcCapabilities(capabilities),
|
|
104
|
-
}
|
|
105
|
+
});
|
|
105
106
|
|
|
106
107
|
const rpcResp = await client.request({
|
|
107
108
|
method: "wallet_prepareCalls",
|
|
@@ -109,7 +110,7 @@ export async function prepareCalls(
|
|
|
109
110
|
});
|
|
110
111
|
|
|
111
112
|
LOGGER.debug("prepareCalls:done");
|
|
112
|
-
const decoded =
|
|
113
|
+
const decoded = decode(schema.response, rpcResp);
|
|
113
114
|
|
|
114
115
|
// Transform paymaster-permit modifiedRequest from RPC format to client format:
|
|
115
116
|
// - `from` (RPC) → `account` (client)
|
|
@@ -2,9 +2,10 @@ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
|
2
2
|
import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
3
3
|
import { LOGGER } from "../logger.js";
|
|
4
4
|
import { resolveAddress, type AccountParam } from "../utils/resolve.js";
|
|
5
|
-
import { Value } from "typebox/value";
|
|
6
5
|
import {
|
|
7
6
|
methodSchema,
|
|
7
|
+
encode,
|
|
8
|
+
decode,
|
|
8
9
|
type MethodParams,
|
|
9
10
|
type MethodResponse,
|
|
10
11
|
} from "../utils/schema.js";
|
|
@@ -51,11 +52,11 @@ export async function prepareSign(
|
|
|
51
52
|
LOGGER.debug("prepareSign:start", { type: params.signatureRequest.type });
|
|
52
53
|
|
|
53
54
|
const { account: _, chainId: __, ...rest } = params;
|
|
54
|
-
const rpcParams =
|
|
55
|
+
const rpcParams = encode(schema.request, {
|
|
55
56
|
...rest,
|
|
56
57
|
from,
|
|
57
58
|
chainId: params.chainId ?? client.chain.id,
|
|
58
|
-
}
|
|
59
|
+
});
|
|
59
60
|
|
|
60
61
|
const rpcResp = await client.request({
|
|
61
62
|
method: "wallet_prepareSign",
|
|
@@ -63,5 +64,5 @@ export async function prepareSign(
|
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
LOGGER.debug("prepareSign:done");
|
|
66
|
-
return
|
|
67
|
+
return decode(schema.response, rpcResp);
|
|
67
68
|
}
|
|
@@ -5,8 +5,12 @@ import deepEqual from "deep-equal";
|
|
|
5
5
|
import type { DistributiveOmit, InnerWalletApiClient } from "../types";
|
|
6
6
|
import { LOGGER } from "../logger.js";
|
|
7
7
|
import { isLocalAccount } from "../utils/assertions.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
methodSchema,
|
|
10
|
+
encode,
|
|
11
|
+
decode,
|
|
12
|
+
type MethodParams,
|
|
13
|
+
} from "../utils/schema.js";
|
|
10
14
|
|
|
11
15
|
const schema = methodSchema(MethodSchema);
|
|
12
16
|
type BaseRequestAccountParams = MethodParams<typeof MethodSchema>;
|
|
@@ -90,17 +94,14 @@ export async function requestAccount(
|
|
|
90
94
|
};
|
|
91
95
|
}
|
|
92
96
|
|
|
93
|
-
const rpcParams =
|
|
94
|
-
schema.request,
|
|
95
|
-
args satisfies BaseRequestAccountParams,
|
|
96
|
-
);
|
|
97
|
+
const rpcParams = encode(schema.request, args);
|
|
97
98
|
|
|
98
99
|
const rpcResp = await client.request({
|
|
99
100
|
method: "wallet_requestAccount",
|
|
100
101
|
params: [rpcParams],
|
|
101
102
|
});
|
|
102
103
|
|
|
103
|
-
const resp =
|
|
104
|
+
const resp = decode(schema.response, rpcResp);
|
|
104
105
|
|
|
105
106
|
client.internal?.setAccount({
|
|
106
107
|
address: resp.accountAddress,
|
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
type WithCapabilities,
|
|
8
8
|
} from "../utils/capabilities.js";
|
|
9
9
|
import { wallet_sendPreparedCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
10
|
-
import { Value } from "typebox/value";
|
|
11
10
|
import {
|
|
12
11
|
methodSchema,
|
|
12
|
+
encode,
|
|
13
|
+
decode,
|
|
13
14
|
type MethodParams,
|
|
14
15
|
type MethodResponse,
|
|
15
16
|
} from "../utils/schema.js";
|
|
@@ -79,10 +80,7 @@ export async function sendPreparedCalls(
|
|
|
79
80
|
capabilities: toRpcCapabilities(capabilities),
|
|
80
81
|
};
|
|
81
82
|
|
|
82
|
-
const rpcParams =
|
|
83
|
-
schema.request,
|
|
84
|
-
fullParams satisfies BaseSendPreparedCallsParams,
|
|
85
|
-
);
|
|
83
|
+
const rpcParams = encode(schema.request, fullParams);
|
|
86
84
|
|
|
87
85
|
const rpcResp = await client.request({
|
|
88
86
|
method: "wallet_sendPreparedCalls",
|
|
@@ -90,5 +88,5 @@ export async function sendPreparedCalls(
|
|
|
90
88
|
});
|
|
91
89
|
|
|
92
90
|
LOGGER.debug("sendPreparedCalls:done");
|
|
93
|
-
return
|
|
91
|
+
return decode(schema.response, rpcResp);
|
|
94
92
|
}
|
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
} from "../../utils/capabilities.js";
|
|
8
8
|
import { resolveAddress, type AccountParam } from "../../utils/resolve.js";
|
|
9
9
|
import { wallet_requestQuote_v0 as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
10
|
-
import { Value } from "typebox/value";
|
|
11
10
|
import {
|
|
12
11
|
methodSchema,
|
|
12
|
+
encode,
|
|
13
|
+
decode,
|
|
13
14
|
type MethodParams,
|
|
14
15
|
type MethodResponse,
|
|
15
16
|
} from "../../utils/schema.js";
|
|
@@ -84,17 +85,17 @@ export async function requestQuoteV0(
|
|
|
84
85
|
);
|
|
85
86
|
|
|
86
87
|
const { account: _, chainId: __, ...rest } = params;
|
|
87
|
-
const rpcParams =
|
|
88
|
+
const rpcParams = encode(schema.request, {
|
|
88
89
|
...rest,
|
|
89
90
|
chainId: params.chainId ?? client.chain.id,
|
|
90
91
|
from,
|
|
91
92
|
...(capabilities && { capabilities: toRpcCapabilities(capabilities) }),
|
|
92
|
-
}
|
|
93
|
+
});
|
|
93
94
|
|
|
94
95
|
const rpcResp = await client.request({
|
|
95
96
|
method: "wallet_requestQuote_v0",
|
|
96
97
|
params: [rpcParams],
|
|
97
98
|
});
|
|
98
99
|
|
|
99
|
-
return
|
|
100
|
+
return decode(schema.response, rpcResp);
|
|
100
101
|
}
|
package/src/utils/schema.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
TObject,
|
|
3
|
+
TSchema,
|
|
4
|
+
TTuple,
|
|
5
|
+
StaticDecode,
|
|
6
|
+
StaticEncode,
|
|
7
|
+
} from "typebox";
|
|
8
|
+
import { Value, EncodeError, DecodeError, Pointer } from "typebox/value";
|
|
9
|
+
import { BaseError } from "@alchemy/common";
|
|
2
10
|
|
|
3
11
|
/** Constraint for RPC method schemas from `@alchemy/wallet-api-types/rpc`. */
|
|
4
12
|
type RpcMethodSchema = TObject<{
|
|
@@ -30,3 +38,73 @@ export type MethodParams<T extends RpcMethodSchema> = StaticDecode<
|
|
|
30
38
|
export type MethodResponse<T extends RpcMethodSchema> = StaticDecode<
|
|
31
39
|
T["properties"]["ReturnType"]
|
|
32
40
|
>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Formats an {@link EncodeError} or {@link DecodeError} into a human-readable
|
|
44
|
+
* string describing what went wrong, including the JSON path and the schema's
|
|
45
|
+
* custom error message (if any).
|
|
46
|
+
*
|
|
47
|
+
* @param {TSchema} schema - The TypeBox schema that validation was run against.
|
|
48
|
+
* @param {EncodeError | DecodeError} error - The error thrown by {@link Value.Encode} or {@link Value.Decode}.
|
|
49
|
+
* @returns {string} A formatted error string prefixed with `"Invalid params"`.
|
|
50
|
+
*/
|
|
51
|
+
function formatCodecError(
|
|
52
|
+
schema: TSchema,
|
|
53
|
+
error: EncodeError | DecodeError,
|
|
54
|
+
): string {
|
|
55
|
+
// Use only the first error — it's the most specific. Subsequent errors are
|
|
56
|
+
// typically cascade noise from union/anyOf branches.
|
|
57
|
+
const causeError = error.cause.errors[0];
|
|
58
|
+
// errors is typed as an open array — guard against the (practically
|
|
59
|
+
// impossible) empty case.
|
|
60
|
+
if (!causeError) return "Invalid params";
|
|
61
|
+
|
|
62
|
+
const path = causeError.instancePath || "(root)";
|
|
63
|
+
|
|
64
|
+
// Prefer the schema's custom errorMessage annotation over the generic locale message.
|
|
65
|
+
let message = causeError.message;
|
|
66
|
+
const schemaPointer = causeError.schemaPath.replace(/^#/, "");
|
|
67
|
+
if (schemaPointer) {
|
|
68
|
+
const schemaNode = Pointer.Get(schema, schemaPointer);
|
|
69
|
+
if (
|
|
70
|
+
schemaNode &&
|
|
71
|
+
typeof schemaNode === "object" &&
|
|
72
|
+
"errorMessage" in schemaNode &&
|
|
73
|
+
typeof (schemaNode as Record<string, unknown>).errorMessage === "string"
|
|
74
|
+
) {
|
|
75
|
+
message = (schemaNode as Record<string, unknown>).errorMessage as string;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return `Invalid params: ${path}: ${message}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Type-safe wrapper around `Value.Encode` with human-readable errors.
|
|
83
|
+
export function encode<const T extends TSchema>(
|
|
84
|
+
schema: T,
|
|
85
|
+
value: StaticDecode<T>,
|
|
86
|
+
): StaticEncode<T> {
|
|
87
|
+
try {
|
|
88
|
+
return Value.Encode(schema, value);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (error instanceof EncodeError) {
|
|
91
|
+
throw new BaseError(formatCodecError(schema, error), { cause: error });
|
|
92
|
+
}
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Type-safe wrapper around `Value.Decode` with human-readable errors.
|
|
98
|
+
export function decode<const T extends TSchema>(
|
|
99
|
+
schema: T,
|
|
100
|
+
value: StaticEncode<T>,
|
|
101
|
+
): StaticDecode<T> {
|
|
102
|
+
try {
|
|
103
|
+
return Value.Decode(schema, value);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (error instanceof DecodeError) {
|
|
106
|
+
throw new BaseError(formatCodecError(schema, error), { cause: error });
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/version.ts
CHANGED