@alchemy/wallet-apis 0.0.0-alpha.16 → 0.0.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions/formatSign.d.ts +4 -8
- package/dist/esm/actions/formatSign.js.map +1 -1
- package/dist/esm/actions/grantPermissions.d.ts +5 -7
- package/dist/esm/actions/grantPermissions.js +4 -11
- package/dist/esm/actions/grantPermissions.js.map +1 -1
- package/dist/esm/actions/listAccounts.d.ts +2 -9
- package/dist/esm/actions/listAccounts.js +6 -23
- package/dist/esm/actions/listAccounts.js.map +1 -1
- package/dist/esm/actions/prepareCalls.d.ts +11 -12
- package/dist/esm/actions/prepareCalls.js +7 -4
- package/dist/esm/actions/prepareCalls.js.map +1 -1
- package/dist/esm/actions/prepareSign.d.ts +4 -8
- package/dist/esm/actions/prepareSign.js.map +1 -1
- package/dist/esm/actions/requestAccount.d.ts +14 -9
- package/dist/esm/actions/requestAccount.js +20 -44
- package/dist/esm/actions/requestAccount.js.map +1 -1
- package/dist/esm/actions/sendCalls.d.ts +12 -8
- package/dist/esm/actions/sendCalls.js +9 -10
- package/dist/esm/actions/sendCalls.js.map +1 -1
- package/dist/esm/actions/sendPreparedCalls.d.ts +1 -1
- package/dist/esm/actions/sendPreparedCalls.js +1 -1
- package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signMessage.js +5 -11
- package/dist/esm/actions/signMessage.js.map +1 -1
- package/dist/esm/actions/signPreparedCalls.js +1 -6
- package/dist/esm/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signSignatureRequest.d.ts +0 -7
- package/dist/esm/actions/signSignatureRequest.js +1 -27
- package/dist/esm/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/actions/signTypedData.js +5 -11
- package/dist/esm/actions/signTypedData.js.map +1 -1
- package/dist/esm/client.d.ts +18 -23
- package/dist/esm/client.js +20 -31
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/decorators/smartWalletActions.d.ts +7 -7
- package/dist/esm/decorators/smartWalletActions.js +1 -1
- package/dist/esm/decorators/smartWalletActions.js.map +1 -1
- package/dist/esm/experimental/actions/requestQuoteV0.d.ts +6 -10
- package/dist/esm/experimental/actions/requestQuoteV0.js +3 -3
- package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
- package/dist/esm/experimental/swapActionsDecorator.d.ts +4 -5
- package/dist/esm/experimental/swapActionsDecorator.js +1 -1
- package/dist/esm/experimental/swapActionsDecorator.js.map +1 -1
- package/dist/esm/exports/index.d.ts +4 -4
- package/dist/esm/exports/index.js +2 -2
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/internal.d.ts +0 -4
- package/dist/esm/exports/internal.js +0 -2
- package/dist/esm/exports/internal.js.map +1 -1
- package/dist/esm/transport.d.ts +3 -0
- package/dist/esm/transport.js +8 -0
- package/dist/esm/transport.js.map +1 -0
- package/dist/esm/types.d.ts +9 -9
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/assertions.d.ts +2 -4
- package/dist/esm/utils/assertions.js +0 -3
- package/dist/esm/utils/assertions.js.map +1 -1
- package/dist/esm/utils/format.d.ts +1 -3
- package/dist/esm/utils/format.js +1 -11
- package/dist/esm/utils/format.js.map +1 -1
- package/dist/esm/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 +4 -8
- package/dist/types/actions/formatSign.d.ts.map +1 -1
- package/dist/types/actions/grantPermissions.d.ts +5 -7
- package/dist/types/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/actions/listAccounts.d.ts +2 -9
- package/dist/types/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/actions/prepareCalls.d.ts +11 -12
- package/dist/types/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/actions/prepareSign.d.ts +4 -8
- package/dist/types/actions/prepareSign.d.ts.map +1 -1
- package/dist/types/actions/requestAccount.d.ts +14 -9
- package/dist/types/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/actions/sendCalls.d.ts +12 -8
- package/dist/types/actions/sendCalls.d.ts.map +1 -1
- package/dist/types/actions/sendPreparedCalls.d.ts +1 -1
- package/dist/types/actions/signMessage.d.ts.map +1 -1
- package/dist/types/actions/signPreparedCalls.d.ts.map +1 -1
- package/dist/types/actions/signSignatureRequest.d.ts +0 -7
- package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client.d.ts +18 -23
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/decorators/smartWalletActions.d.ts +7 -7
- package/dist/types/decorators/smartWalletActions.d.ts.map +1 -1
- package/dist/types/experimental/actions/requestQuoteV0.d.ts +6 -10
- package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
- package/dist/types/experimental/swapActionsDecorator.d.ts +4 -5
- package/dist/types/experimental/swapActionsDecorator.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +4 -4
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/internal.d.ts +0 -4
- package/dist/types/exports/internal.d.ts.map +1 -1
- package/dist/types/transport.d.ts +4 -0
- package/dist/types/transport.d.ts.map +1 -0
- package/dist/types/types.d.ts +9 -9
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/assertions.d.ts +2 -4
- package/dist/types/utils/assertions.d.ts.map +1 -1
- package/dist/types/utils/format.d.ts +1 -3
- package/dist/types/utils/format.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -6
- package/src/actions/formatSign.ts +10 -11
- package/src/actions/grantPermissions.ts +10 -32
- package/src/actions/listAccounts.ts +14 -37
- package/src/actions/prepareCalls.ts +17 -15
- package/src/actions/prepareSign.ts +10 -11
- package/src/actions/requestAccount.ts +30 -64
- package/src/actions/sendCalls.ts +13 -20
- package/src/actions/sendPreparedCalls.ts +1 -1
- package/src/actions/signMessage.ts +4 -18
- package/src/actions/signPreparedCalls.ts +1 -12
- package/src/actions/signSignatureRequest.ts +5 -64
- package/src/actions/signTypedData.ts +4 -17
- package/src/client.ts +34 -60
- package/src/decorators/smartWalletActions.ts +8 -14
- package/src/experimental/actions/requestQuoteV0.ts +13 -20
- package/src/experimental/swapActionsDecorator.ts +6 -11
- package/src/exports/index.ts +5 -7
- package/src/exports/internal.ts +0 -6
- package/src/transport.ts +16 -0
- package/src/types.ts +7 -16
- package/src/utils/assertions.ts +2 -9
- package/src/utils/format.ts +1 -20
- package/src/version.ts +1 -1
- package/dist/esm/provider.d.ts +0 -26
- package/dist/esm/provider.js +0 -191
- package/dist/esm/provider.js.map +0 -1
- package/dist/esm/testSetup.d.ts +0 -3
- package/dist/esm/testSetup.js +0 -18
- package/dist/esm/testSetup.js.map +0 -1
- package/dist/esm/utils/signer.d.ts +0 -10
- package/dist/esm/utils/signer.js +0 -28
- package/dist/esm/utils/signer.js.map +0 -1
- package/dist/types/provider.d.ts +0 -27
- package/dist/types/provider.d.ts.map +0 -1
- package/dist/types/testSetup.d.ts +0 -4
- package/dist/types/testSetup.d.ts.map +0 -1
- package/dist/types/utils/signer.d.ts +0 -11
- package/dist/types/utils/signer.d.ts.map +0 -1
- package/src/provider.ts +0 -261
- package/src/testSetup.ts +0 -24
- package/src/utils/signer.ts +0 -36
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
|
|
2
|
-
import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
|
|
3
|
-
import { type
|
|
2
|
+
import type { InnerWalletApiClient, OptionalChainId, OptionalFrom } from "../types.ts";
|
|
3
|
+
import { type Prettify } from "viem";
|
|
4
4
|
type RpcSchema = Extract<WalletServerRpcSchemaType, {
|
|
5
5
|
Request: {
|
|
6
6
|
method: "wallet_formatSign";
|
|
7
7
|
};
|
|
8
8
|
}>;
|
|
9
|
-
export type FormatSignParams
|
|
10
|
-
from: Address;
|
|
11
|
-
} : {
|
|
12
|
-
from?: never;
|
|
13
|
-
})>;
|
|
9
|
+
export type FormatSignParams = Prettify<OptionalFrom<OptionalChainId<RpcSchema["Request"]["params"][0]>>>;
|
|
14
10
|
export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
|
|
15
11
|
/**
|
|
16
12
|
* Formats a signature request for signing messages or transactions.
|
|
@@ -31,5 +27,5 @@ export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
|
|
|
31
27
|
* });
|
|
32
28
|
* ```
|
|
33
29
|
*/
|
|
34
|
-
export declare function formatSign
|
|
30
|
+
export declare function formatSign(client: InnerWalletApiClient, params: FormatSignParams): Promise<FormatSignResult>;
|
|
35
31
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAiB,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAA4B,EAC5B,MAAwB;IAExB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE;YACN,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;SACvE;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport type {\n InnerWalletApiClient,\n OptionalChainId,\n OptionalFrom,\n} from \"../types.ts\";\nimport { toHex, type Prettify } from \"viem\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_formatSign\";\n };\n }\n>;\n\nexport type FormatSignParams = Prettify<\n OptionalFrom<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>>\n>;\n\nexport type FormatSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\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 * from: \"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.from ?? client.account?.address;\n if (!from) {\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"formatSign:start\");\n const res = await client.request({\n method: \"wallet_formatSign\",\n params: [\n { ...params, from, chainId: params.chainId ?? toHex(client.chain.id) },\n ],\n });\n LOGGER.debug(\"formatSign:done\");\n return res;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Address, type Hex, type
|
|
1
|
+
import { type Address, type Hex, type Prettify } from "viem";
|
|
2
2
|
import type { InnerWalletApiClient } from "../types.ts";
|
|
3
3
|
import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
|
|
4
4
|
import type { OptionalChainId } from "../types.ts";
|
|
@@ -7,11 +7,9 @@ type RpcSchema = Extract<WalletServerRpcSchemaType, {
|
|
|
7
7
|
method: "wallet_createSession";
|
|
8
8
|
};
|
|
9
9
|
}>;
|
|
10
|
-
export type GrantPermissionsParams
|
|
11
|
-
account
|
|
12
|
-
}
|
|
13
|
-
account?: never;
|
|
14
|
-
})>;
|
|
10
|
+
export type GrantPermissionsParams = Prettify<OptionalChainId<Omit<RpcSchema["Request"]["params"][0], "account">> & {
|
|
11
|
+
account?: Address;
|
|
12
|
+
}>;
|
|
15
13
|
export type GrantPermissionsResult = Prettify<{
|
|
16
14
|
context: Hex;
|
|
17
15
|
}>;
|
|
@@ -69,5 +67,5 @@ export type GrantPermissionsResult = Prettify<{
|
|
|
69
67
|
* });
|
|
70
68
|
* ```
|
|
71
69
|
*/
|
|
72
|
-
export declare function grantPermissions
|
|
70
|
+
export declare function grantPermissions(client: InnerWalletApiClient, params: GrantPermissionsParams): Promise<GrantPermissionsResult>;
|
|
73
71
|
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { toHex, concatHex
|
|
1
|
+
import { toHex, concatHex } from "viem";
|
|
2
2
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
3
|
-
import { AccountNotFoundError
|
|
3
|
+
import { AccountNotFoundError } from "@alchemy/common";
|
|
4
4
|
import { LOGGER } from "../logger.js";
|
|
5
|
-
import { isWebAuthnAccount } from "../utils/assertions.js";
|
|
6
5
|
/**
|
|
7
6
|
* Grants permissions to a smart account by creating a session.
|
|
8
7
|
* This allows another key to perform operations on behalf of the account.
|
|
@@ -58,15 +57,11 @@ import { isWebAuthnAccount } from "../utils/assertions.js";
|
|
|
58
57
|
* ```
|
|
59
58
|
*/
|
|
60
59
|
export async function grantPermissions(client, params) {
|
|
61
|
-
const account = params.account ?? client.account
|
|
60
|
+
const account = params.account ?? client.account.address;
|
|
62
61
|
if (!account) {
|
|
63
62
|
LOGGER.warn("grantPermissions:no-account");
|
|
64
63
|
throw new AccountNotFoundError();
|
|
65
64
|
}
|
|
66
|
-
if (isWebAuthnAccount(client.owner)) {
|
|
67
|
-
LOGGER.warn("grantPermissions:unsupported-account");
|
|
68
|
-
throw new BaseError("WebAuthn signer is not currently supported for grantPermissions");
|
|
69
|
-
}
|
|
70
65
|
LOGGER.debug("grantPermissions:start", { expirySec: params.expirySec });
|
|
71
66
|
const { sessionId, signatureRequest } = await client.request({
|
|
72
67
|
method: "wallet_createSession",
|
|
@@ -83,9 +78,7 @@ export async function grantPermissions(client, params) {
|
|
|
83
78
|
context: concatHex([
|
|
84
79
|
"0x00", // Remote mode.
|
|
85
80
|
sessionId,
|
|
86
|
-
signature.
|
|
87
|
-
? signature.data.signature
|
|
88
|
-
: signature.data,
|
|
81
|
+
signature.data,
|
|
89
82
|
]),
|
|
90
83
|
};
|
|
91
84
|
LOGGER.debug("grantPermissions:done");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAyC,SAAS,EAAE,MAAM,MAAM,CAAC;AAG/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAsBtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAA4B,EAC5B,MAA8B;IAE9B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IACzD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC3C,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IACxE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC3D,MAAM,EAAE,sBAAsB;QAC9B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,OAAO;gBACP,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;aAClD;SACF;KACF,CAAC,CAAC;IAEH,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 { toHex, type Address, type Hex, type Prettify, concatHex } from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport type { OptionalChainId } from \"../types.ts\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_createSession\";\n };\n }\n>;\n\nexport type GrantPermissionsParams = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"account\">> & {\n account?: Address;\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 {Address} [params.account] - The account address (required if client was not initialized with an account)\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: \"0x0\" }],\n * from: account.address,\n * capabilities: {\n * paymasterService: {\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 ?? client.account.address;\n if (!account) {\n LOGGER.warn(\"grantPermissions:no-account\");\n throw new AccountNotFoundError();\n }\n LOGGER.debug(\"grantPermissions:start\", { expirySec: params.expirySec });\n const { sessionId, signatureRequest } = await client.request({\n method: \"wallet_createSession\",\n params: [\n {\n ...params,\n account,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n\n const signature = await signSignatureRequest(client, signatureRequest);\n\n const res = {\n context: concatHex([\n \"0x00\", // Remote mode.\n sessionId,\n signature.data,\n ]),\n } as const;\n LOGGER.debug(\"grantPermissions:done\");\n return res;\n}\n"]}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import type { InnerWalletApiClient } from "../types.ts";
|
|
2
2
|
import type { Address, Prettify } from "viem";
|
|
3
3
|
import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
-
import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
|
|
5
4
|
type RpcSchema = Extract<WalletServerRpcSchemaType, {
|
|
6
5
|
Request: {
|
|
7
6
|
method: "wallet_listAccounts";
|
|
8
7
|
};
|
|
9
8
|
}>;
|
|
10
|
-
export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress"> &
|
|
9
|
+
export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress" | "signerPublicKey"> & {
|
|
11
10
|
signerAddress?: Address;
|
|
12
11
|
signerPublicKey?: never;
|
|
13
|
-
}
|
|
14
|
-
signerPublicKey: WebAuthnPublicKey;
|
|
15
|
-
signerAddress?: never;
|
|
16
|
-
} | {
|
|
17
|
-
signerAddress?: never;
|
|
18
|
-
signerPublicKey?: never;
|
|
19
|
-
})>;
|
|
12
|
+
}>;
|
|
20
13
|
export type ListAccountsResult = Prettify<RpcSchema["ReturnType"]>;
|
|
21
14
|
/**
|
|
22
15
|
* Lists all smart accounts for a given signer using the wallet API client.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LOGGER } from "../logger.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isLocalAccount } from "../utils/assertions.js";
|
|
3
3
|
/**
|
|
4
4
|
* Lists all smart accounts for a given signer using the wallet API client.
|
|
5
5
|
*
|
|
@@ -27,34 +27,17 @@ import { getSignerAddressOrPublicKey } from "../utils/signer.js";
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
export async function listAccounts(client, params) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const signerParam = params.signerAddress
|
|
35
|
-
? { signerAddress: params.signerAddress }
|
|
36
|
-
: params.signerPublicKey
|
|
37
|
-
? {
|
|
38
|
-
signerPublicKey: {
|
|
39
|
-
type: "webauthn-p256",
|
|
40
|
-
...params.signerPublicKey,
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
: owner.type === "webauthn-p256"
|
|
44
|
-
? {
|
|
45
|
-
signerPublicKey: {
|
|
46
|
-
type: "webauthn-p256",
|
|
47
|
-
...owner.publicKey,
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
: { signerAddress: owner.address };
|
|
30
|
+
const signerAddress = params.signerAddress ??
|
|
31
|
+
(isLocalAccount(client.owner)
|
|
32
|
+
? client.owner.address
|
|
33
|
+
: client.owner.account.address);
|
|
51
34
|
LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
|
|
52
35
|
const res = await client.request({
|
|
53
36
|
method: "wallet_listAccounts",
|
|
54
37
|
params: [
|
|
55
38
|
{
|
|
56
39
|
...params,
|
|
57
|
-
|
|
40
|
+
signerAddress,
|
|
58
41
|
},
|
|
59
42
|
],
|
|
60
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listAccounts.js","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"listAccounts.js","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAuBxD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,aAAa,GACjB,MAAM,CAAC,aAAa;QACpB,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC;YAC3B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO;YACtB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACjE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,aAAa;aACd;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAElE,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport type { Address, Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { isLocalAccount } from \"../utils/assertions.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_listAccounts\";\n };\n }\n>;\n\nexport type ListAccountsParams = Prettify<\n Omit<\n RpcSchema[\"Request\"][\"params\"][0],\n \"signerAddress\" | \"signerPublicKey\"\n > & {\n signerAddress?: Address;\n signerPublicKey?: never;\n }\n>;\n\nexport type ListAccountsResult = Prettify<RpcSchema[\"ReturnType\"]>;\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 const res = await client.request({\n method: \"wallet_listAccounts\",\n params: [\n {\n ...params,\n signerAddress,\n },\n ],\n });\n LOGGER.debug(\"listAccounts:done\", { count: res.accounts.length });\n\n return res;\n}\n"]}
|
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
|
|
1
|
+
import { type Prettify } from "viem";
|
|
2
|
+
import type { InnerWalletApiClient, OptionalChainId, OptionalFrom } from "../types.ts";
|
|
3
3
|
import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
|
|
4
4
|
type RpcSchema = Extract<WalletServerRpcSchemaType, {
|
|
5
5
|
Request: {
|
|
6
6
|
method: "wallet_prepareCalls";
|
|
7
7
|
};
|
|
8
8
|
}>;
|
|
9
|
-
export type PrepareCallsParams
|
|
10
|
-
from: Address;
|
|
11
|
-
} : {
|
|
12
|
-
from?: never;
|
|
13
|
-
})>;
|
|
9
|
+
export type PrepareCallsParams = Prettify<OptionalFrom<OptionalChainId<RpcSchema["Request"]["params"][0]>>>;
|
|
14
10
|
export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
|
|
15
11
|
/**
|
|
16
12
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
17
13
|
* Returns the built user operation and a signature request that needs to be signed
|
|
18
14
|
* before submitting to sendPreparedCalls.
|
|
19
15
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
16
|
+
* The client defaults to using EIP-7702 with the signer's address, so you can call
|
|
17
|
+
* this directly without first calling `requestAccount`.
|
|
18
|
+
*
|
|
19
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
20
|
+
* @param {PrepareCallsParams} params - Parameters for preparing calls
|
|
22
21
|
* @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
|
|
23
|
-
* @param {Address} [params.from] - The address to execute the calls from
|
|
22
|
+
* @param {Address} [params.from] - The address to execute the calls from. Defaults to the client's account (signer address via EIP-7702).
|
|
24
23
|
* @param {object} [params.capabilities] - Optional capabilities to include with the request
|
|
25
24
|
* @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
|
|
26
25
|
* the user operation data and signature request
|
|
27
26
|
*
|
|
28
27
|
* @example
|
|
29
28
|
* ```ts
|
|
30
|
-
* // Prepare a sponsored user operation call
|
|
29
|
+
* // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)
|
|
31
30
|
* const result = await client.prepareCalls({
|
|
32
31
|
* calls: [{
|
|
33
32
|
* to: "0x1234...",
|
|
@@ -40,5 +39,5 @@ export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
|
|
|
40
39
|
* });
|
|
41
40
|
* ```
|
|
42
41
|
*/
|
|
43
|
-
export declare function prepareCalls
|
|
42
|
+
export declare function prepareCalls(client: InnerWalletApiClient, params: PrepareCallsParams): Promise<PrepareCallsResult>;
|
|
44
43
|
export {};
|
|
@@ -7,17 +7,20 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
|
|
|
7
7
|
* Returns the built user operation and a signature request that needs to be signed
|
|
8
8
|
* before submitting to sendPreparedCalls.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* The client defaults to using EIP-7702 with the signer's address, so you can call
|
|
11
|
+
* this directly without first calling `requestAccount`.
|
|
12
|
+
*
|
|
13
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
14
|
+
* @param {PrepareCallsParams} params - Parameters for preparing calls
|
|
12
15
|
* @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
|
|
13
|
-
* @param {Address} [params.from] - The address to execute the calls from
|
|
16
|
+
* @param {Address} [params.from] - The address to execute the calls from. Defaults to the client's account (signer address via EIP-7702).
|
|
14
17
|
* @param {object} [params.capabilities] - Optional capabilities to include with the request
|
|
15
18
|
* @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
|
|
16
19
|
* the user operation data and signature request
|
|
17
20
|
*
|
|
18
21
|
* @example
|
|
19
22
|
* ```ts
|
|
20
|
-
* // Prepare a sponsored user operation call
|
|
23
|
+
* // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)
|
|
21
24
|
* const result = await client.prepareCalls({
|
|
22
25
|
* calls: [{
|
|
23
26
|
* to: "0x1234...",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiB,MAAM,MAAM,CAAC;AAM5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAkBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAE1E,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAChC,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjD,IAAI;gBACJ,YAAY;aACb;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAClC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { toHex, type Prettify } from \"viem\";\nimport type {\n InnerWalletApiClient,\n OptionalChainId,\n OptionalFrom,\n} from \"../types.ts\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport { mergeClientCapabilities } from \"../utils/capabilities.js\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareCalls\";\n };\n }\n>;\n\nexport type PrepareCallsParams = Prettify<\n OptionalFrom<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>>\n>;\n\nexport type PrepareCallsResult = Prettify<RpcSchema[\"ReturnType\"]>;\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?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from. 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: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { 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.from ?? client.account?.address;\n if (!from) {\n LOGGER.warn(\"prepareCalls:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\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 const res = await client.request({\n method: \"wallet_prepareCalls\",\n params: [\n {\n ...params,\n chainId: params.chainId ?? toHex(client.chain.id),\n from,\n capabilities,\n },\n ],\n });\n LOGGER.debug(\"prepareCalls:done\");\n return res;\n}\n"]}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
|
|
2
|
-
import { type
|
|
1
|
+
import type { InnerWalletApiClient, OptionalChainId, OptionalFrom } from "../types.ts";
|
|
2
|
+
import { type Prettify } from "viem";
|
|
3
3
|
import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
|
|
4
4
|
type RpcSchema = Extract<WalletServerRpcSchemaType, {
|
|
5
5
|
Request: {
|
|
6
6
|
method: "wallet_prepareSign";
|
|
7
7
|
};
|
|
8
8
|
}>;
|
|
9
|
-
export type PrepareSignParams
|
|
10
|
-
from: Address;
|
|
11
|
-
} : {
|
|
12
|
-
from?: never;
|
|
13
|
-
})>;
|
|
9
|
+
export type PrepareSignParams = Prettify<OptionalFrom<OptionalChainId<RpcSchema["Request"]["params"][0]>>>;
|
|
14
10
|
export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
|
|
15
11
|
/**
|
|
16
12
|
* Prepares a signature request for signing messages or transactions.
|
|
@@ -29,5 +25,5 @@ export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
|
|
|
29
25
|
* });
|
|
30
26
|
* ```
|
|
31
27
|
*/
|
|
32
|
-
export declare function prepareSign
|
|
28
|
+
export declare function prepareSign(client: InnerWalletApiClient, params: PrepareSignParams): Promise<PrepareSignResult>;
|
|
33
29
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAiB,MAAM,MAAM,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAAyB;IAEzB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1E,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,IAAI;gBACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;aAClD;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type {\n InnerWalletApiClient,\n OptionalChainId,\n OptionalFrom,\n} from \"../types.ts\";\nimport { toHex, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareSign\";\n };\n }\n>;\n\nexport type PrepareSignParams = Prettify<\n OptionalFrom<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>>\n>;\n\nexport type PrepareSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\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 * from: \"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.from ?? client.account?.address;\n if (!from) {\n LOGGER.warn(\"prepareSign:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"prepareSign:start\", { type: params.signatureRequest.type });\n const res = await client.request({\n method: \"wallet_prepareSign\",\n params: [\n {\n ...params,\n from,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n LOGGER.debug(\"prepareSign:done\");\n return res;\n}\n"]}
|
|
@@ -2,7 +2,6 @@ import type { Address } from "abitype";
|
|
|
2
2
|
import { type Prettify } from "viem";
|
|
3
3
|
import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
|
|
4
4
|
import type { InnerWalletApiClient } from "../types";
|
|
5
|
-
import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
|
|
6
5
|
type RpcSchema = Extract<WalletServerRpcSchemaType, {
|
|
7
6
|
Request: {
|
|
8
7
|
method: "wallet_requestAccount";
|
|
@@ -10,16 +9,23 @@ type RpcSchema = Extract<WalletServerRpcSchemaType, {
|
|
|
10
9
|
}>;
|
|
11
10
|
export type RequestAccountParams = Prettify<Omit<Extract<RpcSchema["Request"]["params"][0], {
|
|
12
11
|
signerAddress: Address;
|
|
12
|
+
}>, "signerAddress" | "includeCounterfactualInfo"> & ({
|
|
13
|
+
signerAddress?: Address;
|
|
14
|
+
accountAddress?: never;
|
|
13
15
|
} | {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}>;
|
|
16
|
+
signerAddress?: never;
|
|
17
|
+
accountAddress: Address;
|
|
18
|
+
})>;
|
|
18
19
|
export type RequestAccountResult = Prettify<{
|
|
19
20
|
address: Address;
|
|
20
21
|
}>;
|
|
21
22
|
/**
|
|
22
|
-
* Requests
|
|
23
|
+
* Requests a smart account address for the provided signer using the wallet API client.
|
|
24
|
+
*
|
|
25
|
+
* Note: This is only needed for non-EIP-7702 accounts. The client defaults to using
|
|
26
|
+
* EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`
|
|
27
|
+
* directly without first calling `requestAccount`.
|
|
28
|
+
*
|
|
23
29
|
* If an account already exists for the signer, it will always return that account unless a new ID is specified.
|
|
24
30
|
* If an account already exists, the creationHint will be ignored.
|
|
25
31
|
*
|
|
@@ -31,9 +37,8 @@ export type RequestAccountResult = Prettify<{
|
|
|
31
37
|
*
|
|
32
38
|
* @example
|
|
33
39
|
* ```ts
|
|
34
|
-
* // Request
|
|
35
|
-
* const
|
|
36
|
-
* const account = await client.requestAccount(signer);
|
|
40
|
+
* // Request a non-7702 smart account
|
|
41
|
+
* const account = await client.requestAccount();
|
|
37
42
|
* ```
|
|
38
43
|
*/
|
|
39
44
|
export declare function requestAccount(client: InnerWalletApiClient, params?: RequestAccountParams): Promise<RequestAccountResult>;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isAddressEqual } from "viem";
|
|
2
2
|
import deepEqual from "deep-equal";
|
|
3
3
|
import { LOGGER } from "../logger.js";
|
|
4
|
-
import {
|
|
5
|
-
import { getSignerAddressOrPublicKey } from "../utils/signer.js";
|
|
4
|
+
import { isLocalAccount } from "../utils/assertions.js";
|
|
6
5
|
/**
|
|
7
|
-
* Requests
|
|
6
|
+
* Requests a smart account address for the provided signer using the wallet API client.
|
|
7
|
+
*
|
|
8
|
+
* Note: This is only needed for non-EIP-7702 accounts. The client defaults to using
|
|
9
|
+
* EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`
|
|
10
|
+
* directly without first calling `requestAccount`.
|
|
11
|
+
*
|
|
8
12
|
* If an account already exists for the signer, it will always return that account unless a new ID is specified.
|
|
9
13
|
* If an account already exists, the creationHint will be ignored.
|
|
10
14
|
*
|
|
@@ -16,9 +20,8 @@ import { getSignerAddressOrPublicKey } from "../utils/signer.js";
|
|
|
16
20
|
*
|
|
17
21
|
* @example
|
|
18
22
|
* ```ts
|
|
19
|
-
* // Request
|
|
20
|
-
* const
|
|
21
|
-
* const account = await client.requestAccount(signer);
|
|
23
|
+
* // Request a non-7702 smart account
|
|
24
|
+
* const account = await client.requestAccount();
|
|
22
25
|
* ```
|
|
23
26
|
*/
|
|
24
27
|
export async function requestAccount(client, params) {
|
|
@@ -26,51 +29,24 @@ export async function requestAccount(client, params) {
|
|
|
26
29
|
hasParams: !!params,
|
|
27
30
|
hasAccountOnClient: !!client.account,
|
|
28
31
|
});
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
// Non-webauthn signers do not support the "mav2-webauthn" account type.
|
|
38
|
-
if (creationHint.accountType === "mav2-webauthn") {
|
|
39
|
-
throw new BaseError("ECDSA (secp256k1) signers are not supported with mav2-webauthn account type");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const owner = getSignerAddressOrPublicKey(client.owner);
|
|
43
|
-
const args = (client.account && !params) || params?.accountAddress
|
|
32
|
+
const signerAddress = (params && "signerAddress" in params ? params.signerAddress : undefined) ??
|
|
33
|
+
(isLocalAccount(client.owner)
|
|
34
|
+
? client.owner.address
|
|
35
|
+
: client.owner.account.address);
|
|
36
|
+
const args = params && "accountAddress" in params && params.accountAddress
|
|
44
37
|
? {
|
|
45
|
-
accountAddress: params
|
|
38
|
+
accountAddress: params.accountAddress,
|
|
46
39
|
includeCounterfactualInfo: true,
|
|
47
40
|
}
|
|
48
41
|
: {
|
|
49
|
-
...
|
|
50
|
-
|
|
51
|
-
signerPublicKey: {
|
|
52
|
-
...owner.publicKey,
|
|
53
|
-
type: "webauthn-p256",
|
|
54
|
-
},
|
|
55
|
-
// Casts here are safe due to our checks above.
|
|
56
|
-
...(creationHint
|
|
57
|
-
? { creationHint: creationHint }
|
|
58
|
-
: {}),
|
|
59
|
-
}
|
|
60
|
-
: {
|
|
61
|
-
signerAddress: owner.address,
|
|
62
|
-
...(creationHint
|
|
63
|
-
? {
|
|
64
|
-
creationHint: creationHint,
|
|
65
|
-
}
|
|
66
|
-
: {}),
|
|
67
|
-
}),
|
|
42
|
+
...params,
|
|
43
|
+
signerAddress,
|
|
68
44
|
includeCounterfactualInfo: true,
|
|
69
45
|
};
|
|
70
46
|
const cachedAccount = client.internal?.getAccount();
|
|
71
47
|
if (cachedAccount &&
|
|
72
|
-
((
|
|
73
|
-
cachedAccount.address
|
|
48
|
+
((args.accountAddress &&
|
|
49
|
+
isAddressEqual(cachedAccount.address, args.accountAddress)) ||
|
|
74
50
|
deepEqual(cachedAccount.requestParams, args, { strict: true }))) {
|
|
75
51
|
LOGGER.debug("requestAccount:cache-hit", {
|
|
76
52
|
address: cachedAccount.address,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAiB,MAAM,MAAM,CAAC;AAErD,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAwBxD;;;;;;;;;;;;;;;;;;;;;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,GACjB,CAAC,MAAM,IAAI,eAAe,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC;YAC3B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO;YACtB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,IAAI,GACR,MAAM,IAAI,gBAAgB,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc;QAC3D,CAAC,CAAC;YACE,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,yBAAyB,EAAE,IAAI;SAChC;QACH,CAAC,CAAC;YACE,GAAG,MAAM;YACT,aAAa;YACb,yBAAyB,EAAE,IAAI;SAChC,CAAC;IAER,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;IAEpD,IACE,aAAa;QACb,CAAC,CAAC,IAAI,CAAC,cAAc;YACnB,cAAc,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YAC3D,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACjE,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;YACvC,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAChC,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,IAAI,CAAC;KACf,CAAC,CAAC;IAEH,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;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["import type { Address } from \"abitype\";\nimport { isAddressEqual, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport deepEqual from \"deep-equal\";\nimport type { InnerWalletApiClient } from \"../types\";\nimport { LOGGER } from \"../logger.js\";\nimport { isLocalAccount } from \"../utils/assertions.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_requestAccount\";\n };\n }\n>;\n\nexport type RequestAccountParams = Prettify<\n Omit<\n Extract<RpcSchema[\"Request\"][\"params\"][0], { signerAddress: Address }>,\n \"signerAddress\" | \"includeCounterfactualInfo\"\n > &\n (\n | { signerAddress?: Address; accountAddress?: never }\n | { signerAddress?: never; accountAddress: Address }\n )\n>;\n\nexport type RequestAccountResult = Prettify<{ address: 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 };\n }\n\n const resp = await client.request({\n method: \"wallet_requestAccount\",\n params: [args],\n });\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 };\n}\n"]}
|