@alchemy/wallet-apis 0.0.0-alpha.18 → 0.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions/formatSign.d.ts +12 -10
- package/dist/esm/actions/formatSign.js +18 -12
- package/dist/esm/actions/formatSign.js.map +1 -1
- package/dist/esm/actions/getCapabilities.d.ts +27 -0
- package/dist/esm/actions/getCapabilities.js +49 -0
- package/dist/esm/actions/getCapabilities.js.map +1 -0
- package/dist/esm/actions/grantPermissions.d.ts +12 -14
- package/dist/esm/actions/grantPermissions.js +22 -18
- package/dist/esm/actions/grantPermissions.js.map +1 -1
- package/dist/esm/actions/listAccounts.d.ts +7 -9
- package/dist/esm/actions/listAccounts.js +11 -7
- package/dist/esm/actions/listAccounts.js.map +1 -1
- package/dist/esm/actions/prepareCalls.d.ts +27 -13
- package/dist/esm/actions/prepareCalls.js +39 -22
- package/dist/esm/actions/prepareCalls.js.map +1 -1
- package/dist/esm/actions/prepareSign.d.ts +12 -11
- package/dist/esm/actions/prepareSign.js +18 -17
- package/dist/esm/actions/prepareSign.js.map +1 -1
- package/dist/esm/actions/requestAccount.d.ts +7 -12
- package/dist/esm/actions/requestAccount.js +10 -2
- package/dist/esm/actions/requestAccount.js.map +1 -1
- package/dist/esm/actions/sendCalls.d.ts +10 -8
- package/dist/esm/actions/sendCalls.js +11 -9
- package/dist/esm/actions/sendCalls.js.map +1 -1
- package/dist/esm/actions/sendPreparedCalls.d.ts +13 -12
- package/dist/esm/actions/sendPreparedCalls.js +21 -15
- package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signMessage.d.ts +4 -3
- package/dist/esm/actions/signMessage.js +7 -4
- package/dist/esm/actions/signMessage.js.map +1 -1
- package/dist/esm/actions/signPreparedCalls.d.ts +18 -2
- package/dist/esm/actions/signPreparedCalls.js +1 -1
- package/dist/esm/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signSignatureRequest.d.ts +3 -2
- package/dist/esm/actions/signSignatureRequest.js +4 -9
- package/dist/esm/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/actions/signTypedData.d.ts +3 -2
- package/dist/esm/actions/signTypedData.js +6 -3
- package/dist/esm/actions/signTypedData.js.map +1 -1
- package/dist/esm/client.d.ts +1 -1
- package/dist/esm/client.js +1 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/decorators/smartWalletActions.d.ts +3 -2
- package/dist/esm/decorators/smartWalletActions.js +4 -3
- package/dist/esm/decorators/smartWalletActions.js.map +1 -1
- package/dist/esm/experimental/actions/requestQuoteV0.d.ts +17 -14
- package/dist/esm/experimental/actions/requestQuoteV0.js +25 -22
- package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
- package/dist/esm/exports/index.d.ts +2 -0
- package/dist/esm/exports/index.js +1 -0
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/types.d.ts +3 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/capabilities.d.ts +48 -2
- package/dist/esm/utils/capabilities.js +58 -11
- package/dist/esm/utils/capabilities.js.map +1 -1
- package/dist/esm/utils/resolve.d.ts +7 -0
- package/dist/esm/utils/resolve.js +4 -0
- package/dist/esm/utils/resolve.js.map +1 -0
- package/dist/esm/utils/schema.d.ts +24 -0
- package/dist/esm/utils/schema.js +7 -0
- package/dist/esm/utils/schema.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/actions/formatSign.d.ts +12 -10
- package/dist/types/actions/formatSign.d.ts.map +1 -1
- package/dist/types/actions/getCapabilities.d.ts +28 -0
- package/dist/types/actions/getCapabilities.d.ts.map +1 -0
- package/dist/types/actions/grantPermissions.d.ts +12 -14
- package/dist/types/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/actions/listAccounts.d.ts +7 -9
- package/dist/types/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/actions/prepareCalls.d.ts +27 -13
- package/dist/types/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/actions/prepareSign.d.ts +12 -11
- package/dist/types/actions/prepareSign.d.ts.map +1 -1
- package/dist/types/actions/requestAccount.d.ts +7 -12
- package/dist/types/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/actions/sendCalls.d.ts +10 -8
- package/dist/types/actions/sendCalls.d.ts.map +1 -1
- package/dist/types/actions/sendPreparedCalls.d.ts +13 -12
- package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/actions/signMessage.d.ts +4 -3
- package/dist/types/actions/signMessage.d.ts.map +1 -1
- package/dist/types/actions/signPreparedCalls.d.ts +18 -2
- package/dist/types/actions/signPreparedCalls.d.ts.map +1 -1
- package/dist/types/actions/signSignatureRequest.d.ts +3 -2
- package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/actions/signTypedData.d.ts +3 -2
- package/dist/types/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client.d.ts +1 -1
- package/dist/types/decorators/smartWalletActions.d.ts +3 -2
- package/dist/types/decorators/smartWalletActions.d.ts.map +1 -1
- package/dist/types/experimental/actions/requestQuoteV0.d.ts +17 -14
- package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +2 -0
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/capabilities.d.ts +48 -2
- package/dist/types/utils/capabilities.d.ts.map +1 -1
- package/dist/types/utils/resolve.d.ts +8 -0
- package/dist/types/utils/resolve.d.ts.map +1 -0
- package/dist/types/utils/schema.d.ts +25 -0
- package/dist/types/utils/schema.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -5
- package/src/actions/formatSign.ts +34 -28
- package/src/actions/getCapabilities.ts +64 -0
- package/src/actions/grantPermissions.ts +38 -31
- package/src/actions/listAccounts.ts +27 -20
- package/src/actions/prepareCalls.ts +82 -38
- package/src/actions/prepareSign.ts +36 -35
- package/src/actions/requestAccount.ts +21 -16
- package/src/actions/sendCalls.ts +18 -12
- package/src/actions/sendPreparedCalls.ts +48 -27
- package/src/actions/signMessage.ts +9 -11
- package/src/actions/signPreparedCalls.ts +32 -12
- package/src/actions/signSignatureRequest.ts +9 -14
- package/src/actions/signTypedData.ts +8 -10
- package/src/client.ts +1 -1
- package/src/decorators/smartWalletActions.ts +9 -7
- package/src/experimental/actions/requestQuoteV0.ts +51 -39
- package/src/exports/index.ts +2 -0
- package/src/types.ts +6 -2
- package/src/utils/capabilities.ts +118 -17
- package/src/utils/resolve.ts +11 -0
- package/src/utils/schema.ts +32 -0
- package/src/version.ts +1 -1
- package/dist/esm/utils/viemDecode.d.ts +0 -8
- package/dist/esm/utils/viemDecode.js +0 -231
- package/dist/esm/utils/viemDecode.js.map +0 -1
- package/dist/esm/utils/viemEncode.d.ts +0 -40
- package/dist/esm/utils/viemEncode.js +0 -216
- package/dist/esm/utils/viemEncode.js.map +0 -1
- package/dist/types/utils/viemDecode.d.ts +0 -9
- package/dist/types/utils/viemDecode.d.ts.map +0 -1
- package/dist/types/utils/viemEncode.d.ts +0 -41
- package/dist/types/utils/viemEncode.d.ts.map +0 -1
- package/src/utils/viemDecode.ts +0 -313
- package/src/utils/viemEncode.ts +0 -345
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
2
|
+
import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
3
|
+
import { type AccountParam } from "../utils/resolve.js";
|
|
4
|
+
import { type MethodParams, type MethodResponse } from "../utils/schema.js";
|
|
5
|
+
type BasePrepareSignParams = MethodParams<typeof MethodSchema>;
|
|
6
|
+
type PrepareSignResponse = MethodResponse<typeof MethodSchema>;
|
|
7
|
+
export type PrepareSignParams = DistributiveOmit<BasePrepareSignParams, "from" | "chainId"> & {
|
|
8
|
+
account?: AccountParam;
|
|
9
|
+
chainId?: number;
|
|
10
|
+
};
|
|
11
|
+
export type PrepareSignResult = PrepareSignResponse;
|
|
11
12
|
/**
|
|
12
13
|
* Prepares a signature request for signing messages or transactions.
|
|
13
14
|
*
|
|
@@ -19,7 +20,7 @@ export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
|
|
|
19
20
|
* ```ts
|
|
20
21
|
* // Prepare a message to be signed
|
|
21
22
|
* const result = await client.prepareSign({
|
|
22
|
-
*
|
|
23
|
+
* account: "0x1234...",
|
|
23
24
|
* type: "personal_sign",
|
|
24
25
|
* data: "Hello, world!",
|
|
25
26
|
* });
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AccountNotFoundError } from "@alchemy/common";
|
|
1
|
+
import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
3
2
|
import { LOGGER } from "../logger.js";
|
|
3
|
+
import { resolveAddress } from "../utils/resolve.js";
|
|
4
|
+
import { Value } from "typebox/value";
|
|
5
|
+
import { methodSchema, } from "../utils/schema.js";
|
|
6
|
+
const schema = methodSchema(MethodSchema);
|
|
4
7
|
/**
|
|
5
8
|
* Prepares a signature request for signing messages or transactions.
|
|
6
9
|
*
|
|
@@ -12,30 +15,28 @@ import { LOGGER } from "../logger.js";
|
|
|
12
15
|
* ```ts
|
|
13
16
|
* // Prepare a message to be signed
|
|
14
17
|
* const result = await client.prepareSign({
|
|
15
|
-
*
|
|
18
|
+
* account: "0x1234...",
|
|
16
19
|
* type: "personal_sign",
|
|
17
20
|
* data: "Hello, world!",
|
|
18
21
|
* });
|
|
19
22
|
* ```
|
|
20
23
|
*/
|
|
21
24
|
export async function prepareSign(client, params) {
|
|
22
|
-
const from = params.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
throw new AccountNotFoundError();
|
|
26
|
-
}
|
|
25
|
+
const from = params.account
|
|
26
|
+
? resolveAddress(params.account)
|
|
27
|
+
: client.account.address;
|
|
27
28
|
LOGGER.debug("prepareSign:start", { type: params.signatureRequest.type });
|
|
28
|
-
const
|
|
29
|
+
const { account: _, chainId: __, ...rest } = params;
|
|
30
|
+
const rpcParams = Value.Encode(schema.request, {
|
|
31
|
+
...rest,
|
|
32
|
+
from,
|
|
33
|
+
chainId: params.chainId ?? client.chain.id,
|
|
34
|
+
});
|
|
35
|
+
const rpcResp = await client.request({
|
|
29
36
|
method: "wallet_prepareSign",
|
|
30
|
-
params: [
|
|
31
|
-
{
|
|
32
|
-
...params,
|
|
33
|
-
from,
|
|
34
|
-
chainId: params.chainId ?? toHex(client.chain.id),
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
+
params: [rpcParams],
|
|
37
38
|
});
|
|
38
39
|
LOGGER.debug("prepareSign:done");
|
|
39
|
-
return
|
|
40
|
+
return Value.Decode(schema.response, rpcResp);
|
|
40
41
|
}
|
|
41
42
|
//# sourceMappingURL=prepareSign.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"
|
|
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,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,YAAY,GAGb,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,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7C,GAAG,IAAI;QACP,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;KACX,CAAC,CAAC;IAEnC,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,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAChD,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 { Value } from \"typebox/value\";\nimport {\n methodSchema,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BasePrepareSignParams = MethodParams<typeof MethodSchema>;\ntype PrepareSignResponse = MethodResponse<typeof MethodSchema>;\n\nexport type PrepareSignParams = DistributiveOmit<\n BasePrepareSignParams,\n \"from\" | \"chainId\"\n> & {\n account?: AccountParam;\n chainId?: number;\n};\n\nexport type PrepareSignResult = PrepareSignResponse;\n\n/**\n * Prepares a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareSignParams} params - Parameters for preparing the signature request\n * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request\n *\n * @example\n * ```ts\n * // Prepare a message to be signed\n * const result = await client.prepareSign({\n * account: \"0x1234...\",\n * type: \"personal_sign\",\n * data: \"Hello, world!\",\n * });\n * ```\n */\nexport async function prepareSign(\n client: InnerWalletApiClient,\n params: PrepareSignParams,\n): Promise<PrepareSignResult> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n LOGGER.debug(\"prepareSign:start\", { type: params.signatureRequest.type });\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = Value.Encode(schema.request, {\n ...rest,\n from,\n chainId: params.chainId ?? client.chain.id,\n } satisfies BasePrepareSignParams);\n\n const rpcResp = await client.request({\n method: \"wallet_prepareSign\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"prepareSign:done\");\n return Value.Decode(schema.response, rpcResp);\n}\n"]}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import type { Address } from "abitype";
|
|
2
|
-
import { type Prettify } from "viem";
|
|
3
|
-
import
|
|
4
|
-
import type { InnerWalletApiClient } from "../types";
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
}>;
|
|
10
|
-
export type RequestAccountParams = Prettify<Omit<Extract<RpcSchema["Request"]["params"][0], {
|
|
2
|
+
import { type JsonRpcAccount, type Prettify } from "viem";
|
|
3
|
+
import { wallet_requestAccount as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types";
|
|
5
|
+
import { type MethodParams } from "../utils/schema.js";
|
|
6
|
+
type BaseRequestAccountParams = MethodParams<typeof MethodSchema>;
|
|
7
|
+
export type RequestAccountParams = Prettify<DistributiveOmit<Extract<BaseRequestAccountParams, {
|
|
11
8
|
signerAddress: Address;
|
|
12
9
|
}>, "signerAddress" | "includeCounterfactualInfo"> & ({
|
|
13
10
|
signerAddress?: Address;
|
|
@@ -16,9 +13,7 @@ export type RequestAccountParams = Prettify<Omit<Extract<RpcSchema["Request"]["p
|
|
|
16
13
|
signerAddress?: never;
|
|
17
14
|
accountAddress: Address;
|
|
18
15
|
})>;
|
|
19
|
-
export type RequestAccountResult =
|
|
20
|
-
address: Address;
|
|
21
|
-
}>;
|
|
16
|
+
export type RequestAccountResult = JsonRpcAccount<Address>;
|
|
22
17
|
/**
|
|
23
18
|
* Requests a smart account address for the provided signer using the wallet API client.
|
|
24
19
|
*
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { isAddressEqual } from "viem";
|
|
2
|
+
import { wallet_requestAccount as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
2
3
|
import deepEqual from "deep-equal";
|
|
3
4
|
import { LOGGER } from "../logger.js";
|
|
4
5
|
import { isLocalAccount } from "../utils/assertions.js";
|
|
6
|
+
import { Value } from "typebox/value";
|
|
7
|
+
import { methodSchema } from "../utils/schema.js";
|
|
8
|
+
const schema = methodSchema(MethodSchema);
|
|
5
9
|
/**
|
|
6
10
|
* Requests a smart account address for the provided signer using the wallet API client.
|
|
7
11
|
*
|
|
@@ -53,12 +57,15 @@ export async function requestAccount(client, params) {
|
|
|
53
57
|
});
|
|
54
58
|
return {
|
|
55
59
|
address: cachedAccount.address,
|
|
60
|
+
type: "json-rpc",
|
|
56
61
|
};
|
|
57
62
|
}
|
|
58
|
-
const
|
|
63
|
+
const rpcParams = Value.Encode(schema.request, args);
|
|
64
|
+
const rpcResp = await client.request({
|
|
59
65
|
method: "wallet_requestAccount",
|
|
60
|
-
params: [
|
|
66
|
+
params: [rpcParams],
|
|
61
67
|
});
|
|
68
|
+
const resp = Value.Decode(schema.response, rpcResp);
|
|
62
69
|
client.internal?.setAccount({
|
|
63
70
|
address: resp.accountAddress,
|
|
64
71
|
requestParams: args,
|
|
@@ -66,6 +73,7 @@ export async function requestAccount(client, params) {
|
|
|
66
73
|
LOGGER.debug("requestAccount:done", { address: resp.accountAddress });
|
|
67
74
|
return {
|
|
68
75
|
address: resp.accountAddress,
|
|
76
|
+
type: "json-rpc",
|
|
69
77
|
};
|
|
70
78
|
}
|
|
71
79
|
//# sourceMappingURL=requestAccount.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,
|
|
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,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAErE,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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AM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEpD,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IAEtE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC","sourcesContent":["import type { Address } from \"abitype\";\nimport { isAddressEqual, type JsonRpcAccount, type Prettify } from \"viem\";\nimport { wallet_requestAccount as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport deepEqual from \"deep-equal\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types\";\nimport { LOGGER } from \"../logger.js\";\nimport { isLocalAccount } from \"../utils/assertions.js\";\nimport { Value } from \"typebox/value\";\nimport { methodSchema, type MethodParams } from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseRequestAccountParams = MethodParams<typeof MethodSchema>;\n\nexport type RequestAccountParams = Prettify<\n DistributiveOmit<\n Extract<BaseRequestAccountParams, { signerAddress: Address }>,\n \"signerAddress\" | \"includeCounterfactualInfo\"\n > &\n (\n | { signerAddress?: Address; accountAddress?: never }\n | { signerAddress?: never; accountAddress: Address }\n )\n>;\n\nexport type RequestAccountResult = JsonRpcAccount<Address>;\n\n/**\n * Requests a smart account address for the provided signer using the wallet API client.\n *\n * Note: This is only needed for non-EIP-7702 accounts. The client defaults to using\n * EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`\n * directly without first calling `requestAccount`.\n *\n * If an account already exists for the signer, it will always return that account unless a new ID is specified.\n * If an account already exists, the creationHint will be ignored.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account\n * @param {string} [params.id] - Optional identifier for the account. If specified, a new account with this ID will be created even if one already exists for the signer\n * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists\n * @returns {Promise<RequestAccountResult>} A Promise that resolves to an object containing a smart account address\n *\n * @example\n * ```ts\n * // Request a non-7702 smart account\n * const account = await client.requestAccount();\n * ```\n */\nexport async function requestAccount(\n client: InnerWalletApiClient,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n LOGGER.debug(\"requestAccount:start\", {\n hasParams: !!params,\n hasAccountOnClient: !!client.account,\n });\n\n const signerAddress =\n (params && \"signerAddress\" in params ? params.signerAddress : undefined) ??\n (isLocalAccount(client.owner)\n ? client.owner.address\n : client.owner.account.address);\n\n const args =\n params && \"accountAddress\" in params && params.accountAddress\n ? {\n accountAddress: params.accountAddress,\n includeCounterfactualInfo: true,\n }\n : {\n ...params,\n signerAddress,\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal?.getAccount();\n\n if (\n cachedAccount &&\n ((args.accountAddress &&\n isAddressEqual(cachedAccount.address, args.accountAddress)) ||\n deepEqual(cachedAccount.requestParams, args, { strict: true }))\n ) {\n LOGGER.debug(\"requestAccount:cache-hit\", {\n address: cachedAccount.address,\n });\n return {\n address: cachedAccount.address,\n type: \"json-rpc\",\n };\n }\n\n const rpcParams = Value.Encode(\n schema.request,\n args satisfies BaseRequestAccountParams,\n );\n\n const rpcResp = await client.request({\n method: \"wallet_requestAccount\",\n params: [rpcParams],\n });\n\n const resp = Value.Decode(schema.response, rpcResp);\n\n client.internal?.setAccount({\n address: resp.accountAddress,\n requestParams: args,\n });\n\n LOGGER.debug(\"requestAccount:done\", { address: resp.accountAddress });\n\n return {\n address: resp.accountAddress,\n type: \"json-rpc\",\n };\n}\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { Prettify } from "viem";
|
|
2
|
-
import type { InnerWalletApiClient } from "../types.js";
|
|
1
|
+
import type { Chain, Prettify } from "viem";
|
|
2
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types.js";
|
|
3
3
|
import { type PrepareCallsParams } from "./prepareCalls.js";
|
|
4
4
|
import { type SendPreparedCallsResult } from "./sendPreparedCalls.js";
|
|
5
|
-
export type SendCallsParams = Prettify<PrepareCallsParams
|
|
5
|
+
export type SendCallsParams = Prettify<DistributiveOmit<PrepareCallsParams, "chainId"> & {
|
|
6
|
+
chain?: Pick<Chain, "id">;
|
|
7
|
+
}>;
|
|
6
8
|
export type SendCallsResult = Prettify<SendPreparedCallsResult>;
|
|
7
9
|
/**
|
|
8
10
|
* Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.
|
|
@@ -11,9 +13,9 @@ export type SendCallsResult = Prettify<SendPreparedCallsResult>;
|
|
|
11
13
|
* this directly without first calling `requestAccount`.
|
|
12
14
|
*
|
|
13
15
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {Array<{to: Address, data?: Hex, value?:
|
|
16
|
-
* @param {
|
|
16
|
+
* @param {SendCallsParams} params - Parameters for sending calls
|
|
17
|
+
* @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
|
|
18
|
+
* @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
|
|
17
19
|
* @param {object} [params.capabilities] - Optional capabilities to include with the request.
|
|
18
20
|
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.
|
|
19
21
|
*
|
|
@@ -24,10 +26,10 @@ export type SendCallsResult = Prettify<SendPreparedCallsResult>;
|
|
|
24
26
|
* calls: [{
|
|
25
27
|
* to: "0x1234...",
|
|
26
28
|
* data: "0xabcdef...",
|
|
27
|
-
* value:
|
|
29
|
+
* value: 0n
|
|
28
30
|
* }],
|
|
29
31
|
* capabilities: {
|
|
30
|
-
*
|
|
32
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
31
33
|
* }
|
|
32
34
|
* });
|
|
33
35
|
*
|
|
@@ -11,9 +11,9 @@ import { extractCapabilitiesForSending } from "../utils/capabilities.js";
|
|
|
11
11
|
* this directly without first calling `requestAccount`.
|
|
12
12
|
*
|
|
13
13
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {Array<{to: Address, data?: Hex, value?:
|
|
16
|
-
* @param {
|
|
14
|
+
* @param {SendCallsParams} params - Parameters for sending calls
|
|
15
|
+
* @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
|
|
16
|
+
* @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
|
|
17
17
|
* @param {object} [params.capabilities] - Optional capabilities to include with the request.
|
|
18
18
|
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.
|
|
19
19
|
*
|
|
@@ -24,10 +24,10 @@ import { extractCapabilitiesForSending } from "../utils/capabilities.js";
|
|
|
24
24
|
* calls: [{
|
|
25
25
|
* to: "0x1234...",
|
|
26
26
|
* data: "0xabcdef...",
|
|
27
|
-
* value:
|
|
27
|
+
* value: 0n
|
|
28
28
|
* }],
|
|
29
29
|
* capabilities: {
|
|
30
|
-
*
|
|
30
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
31
31
|
* }
|
|
32
32
|
* });
|
|
33
33
|
*
|
|
@@ -44,13 +44,15 @@ export async function sendCalls(client, params) {
|
|
|
44
44
|
calls: params.calls?.length,
|
|
45
45
|
hasCapabilities: !!params.capabilities,
|
|
46
46
|
});
|
|
47
|
-
|
|
47
|
+
const { chain, ...prepareCallsParams } = params;
|
|
48
|
+
let calls = await prepareCalls(client, {
|
|
49
|
+
...prepareCallsParams,
|
|
50
|
+
...(chain != null ? { chainId: chain.id } : {}),
|
|
51
|
+
});
|
|
48
52
|
if (calls.type === "paymaster-permit") {
|
|
49
53
|
const signature = await signSignatureRequest(client, calls.signatureRequest);
|
|
50
54
|
const secondCallParams = {
|
|
51
|
-
|
|
52
|
-
calls: calls.modifiedRequest.calls,
|
|
53
|
-
capabilities: calls.modifiedRequest.capabilities,
|
|
55
|
+
...calls.modifiedRequest,
|
|
54
56
|
// WebAuthn signatures are not supported for paymaster permits (throws above).
|
|
55
57
|
paymasterPermitSignature: signature,
|
|
56
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendCalls.js","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"sendCalls.js","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0B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AAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { Chain, Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.js\";\nimport { prepareCalls, type PrepareCallsParams } from \"./prepareCalls.js\";\nimport { signPreparedCalls } from \"./signPreparedCalls.js\";\nimport {\n sendPreparedCalls,\n type SendPreparedCallsResult,\n} from \"./sendPreparedCalls.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { extractCapabilitiesForSending } from \"../utils/capabilities.js\";\n\nexport type SendCallsParams = Prettify<\n DistributiveOmit<PrepareCallsParams, \"chainId\"> & {\n chain?: Pick<Chain, \"id\">;\n }\n>;\n\nexport type SendCallsResult = Prettify<SendPreparedCallsResult>;\n\n/**\n * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.\n *\n * The client defaults to using EIP-7702 with the signer's address, so you can call\n * this directly without first calling `requestAccount`.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SendCallsParams} params - Parameters for sending calls\n * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute\n * @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).\n * @param {object} [params.capabilities] - Optional capabilities to include with the request.\n * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.\n *\n * @example\n * ```ts\n * // Send calls (uses signer address via EIP-7702 by default)\n * const result = await client.sendCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: 0n\n * }],\n * capabilities: {\n * paymaster: { policyId: \"your-policy-id\" }\n * }\n * });\n *\n * // The result contains the call ID\n * console.log(result.id);\n * ```\n * <Note>\n * If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden\n * from the user. It is recommended to use the `prepareCalls` action instead to manually handle the permit signature.\n * </Note>\n */\nexport async function sendCalls(\n client: InnerWalletApiClient,\n params: SendCallsParams,\n): Promise<SendCallsResult> {\n LOGGER.info(\"sendCalls:start\", {\n calls: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n const { chain, ...prepareCallsParams } = params;\n let calls = await prepareCalls(client, {\n ...prepareCallsParams,\n ...(chain != null ? { chainId: chain.id } : {}),\n });\n\n if (calls.type === \"paymaster-permit\") {\n const signature = await signSignatureRequest(\n client,\n calls.signatureRequest,\n );\n\n const secondCallParams = {\n ...calls.modifiedRequest,\n // WebAuthn signatures are not supported for paymaster permits (throws above).\n paymasterPermitSignature: signature as Exclude<\n typeof signature,\n { type: \"webauthn-p256\" }\n >,\n };\n\n calls = await prepareCalls(client, secondCallParams);\n }\n\n const signedCalls = await signPreparedCalls(client, calls);\n\n const sendPreparedCallsCapabilities = extractCapabilitiesForSending(\n params.capabilities,\n );\n\n const res = await sendPreparedCalls(client, {\n ...signedCalls,\n ...(sendPreparedCallsCapabilities != null\n ? { capabilities: sendPreparedCallsCapabilities }\n : {}),\n });\n LOGGER.info(\"sendCalls:done\");\n return res;\n}\n"]}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { Prettify } from "viem";
|
|
2
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
3
|
+
import { type WithCapabilities } from "../utils/capabilities.js";
|
|
4
|
+
import { wallet_sendPreparedCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
|
+
import { type MethodParams, type MethodResponse } from "../utils/schema.js";
|
|
6
|
+
type BaseSendPreparedCallsParams = MethodParams<typeof MethodSchema>;
|
|
7
|
+
type SendPreparedCallsResponse = MethodResponse<typeof MethodSchema>;
|
|
8
|
+
export type SendPreparedCallsParams = Prettify<WithCapabilities<DistributiveOmit<BaseSendPreparedCallsParams, "chainId"> & {
|
|
9
|
+
chainId?: number;
|
|
10
|
+
}>>;
|
|
11
|
+
export type SendPreparedCallsResult = SendPreparedCallsResponse;
|
|
11
12
|
/**
|
|
12
13
|
* Sends prepared calls by submitting a signed user operation.
|
|
13
14
|
* This method is used after signing the signature request returned from prepareCalls.
|
|
@@ -23,10 +24,10 @@ export type SendPreparedCallsResult = Prettify<RpcSchema["ReturnType"]>;
|
|
|
23
24
|
* calls: [{
|
|
24
25
|
* to: "0x1234...",
|
|
25
26
|
* data: "0xabcdef...",
|
|
26
|
-
* value:
|
|
27
|
+
* value: 0n
|
|
27
28
|
* }],
|
|
28
29
|
* capabilities: {
|
|
29
|
-
*
|
|
30
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
30
31
|
* }
|
|
31
32
|
* });
|
|
32
33
|
*
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { toHex } from "viem";
|
|
2
1
|
import { LOGGER } from "../logger.js";
|
|
3
|
-
import { mergeClientCapabilities } from "../utils/capabilities.js";
|
|
2
|
+
import { mergeClientCapabilities, toRpcCapabilities, } from "../utils/capabilities.js";
|
|
3
|
+
import { wallet_sendPreparedCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
+
import { Value } from "typebox/value";
|
|
5
|
+
import { methodSchema, } from "../utils/schema.js";
|
|
6
|
+
const schema = methodSchema(MethodSchema);
|
|
4
7
|
/**
|
|
5
8
|
* Sends prepared calls by submitting a signed user operation.
|
|
6
9
|
* This method is used after signing the signature request returned from prepareCalls.
|
|
@@ -16,10 +19,10 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
|
|
|
16
19
|
* calls: [{
|
|
17
20
|
* to: "0x1234...",
|
|
18
21
|
* data: "0xabcdef...",
|
|
19
|
-
* value:
|
|
22
|
+
* value: 0n
|
|
20
23
|
* }],
|
|
21
24
|
* capabilities: {
|
|
22
|
-
*
|
|
25
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
23
26
|
* }
|
|
24
27
|
* });
|
|
25
28
|
*
|
|
@@ -33,20 +36,23 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
|
|
|
33
36
|
* ```
|
|
34
37
|
*/
|
|
35
38
|
export async function sendPreparedCalls(client, params) {
|
|
36
|
-
|
|
39
|
+
const capabilities = mergeClientCapabilities(client, params.capabilities);
|
|
37
40
|
LOGGER.debug("sendPreparedCalls:start", { type: params.type });
|
|
38
|
-
const
|
|
41
|
+
const { chainId: rawChainId, ...restParams } = params;
|
|
42
|
+
const chainId = rawChainId ?? client.chain.id;
|
|
43
|
+
const fullParams = restParams.type === "array"
|
|
44
|
+
? { ...restParams, capabilities: toRpcCapabilities(capabilities) }
|
|
45
|
+
: {
|
|
46
|
+
...restParams,
|
|
47
|
+
chainId,
|
|
48
|
+
capabilities: toRpcCapabilities(capabilities),
|
|
49
|
+
};
|
|
50
|
+
const rpcParams = Value.Encode(schema.request, fullParams);
|
|
51
|
+
const rpcResp = await client.request({
|
|
39
52
|
method: "wallet_sendPreparedCalls",
|
|
40
|
-
params: [
|
|
41
|
-
params.type === "array"
|
|
42
|
-
? params
|
|
43
|
-
: {
|
|
44
|
-
...params,
|
|
45
|
-
chainId: params.chainId ?? toHex(client.chain.id),
|
|
46
|
-
},
|
|
47
|
-
],
|
|
53
|
+
params: [rpcParams],
|
|
48
54
|
});
|
|
49
55
|
LOGGER.debug("sendPreparedCalls:done");
|
|
50
|
-
return
|
|
56
|
+
return Value.Decode(schema.response, rpcResp);
|
|
51
57
|
}
|
|
52
58
|
//# sourceMappingURL=sendPreparedCalls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../src/actions/sendPreparedCalls.ts"],"names":[],"mappings":"
|
|
1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AAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,0BAA0B;QAClC,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACvC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport {\n mergeClientCapabilities,\n toRpcCapabilities,\n type WithCapabilities,\n} from \"../utils/capabilities.js\";\nimport { wallet_sendPreparedCalls as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { Value } from \"typebox/value\";\nimport {\n methodSchema,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype 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 = Value.Encode(\n schema.request,\n fullParams satisfies BaseSendPreparedCallsParams,\n );\n\n const rpcResp = await client.request({\n method: \"wallet_sendPreparedCalls\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"sendPreparedCalls:done\");\n return Value.Decode(schema.response, rpcResp);\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Hex, type Prettify, type SignableMessage } from "viem";
|
|
2
2
|
import type { InnerWalletApiClient } from "../types.js";
|
|
3
|
+
import { type AccountParam } from "../utils/resolve.js";
|
|
3
4
|
export type SignMessageParams = Prettify<{
|
|
4
5
|
message: SignableMessage;
|
|
5
|
-
account?:
|
|
6
|
+
account?: AccountParam;
|
|
6
7
|
}>;
|
|
7
8
|
export type SignMessageResult = Prettify<Hex>;
|
|
8
9
|
/**
|
|
@@ -12,7 +13,7 @@ export type SignMessageResult = Prettify<Hex>;
|
|
|
12
13
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
13
14
|
* @param {SignMessageParams} params - Parameters for signing the message
|
|
14
15
|
* @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.
|
|
15
|
-
* @param {
|
|
16
|
+
* @param {AccountParam} [params.account] - Optional account to use for signing. Can be an address string or an object with an `address` property. If not provided, uses the client's current account.
|
|
16
17
|
* @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
|
|
17
18
|
*
|
|
18
19
|
* @example
|
|
@@ -4,6 +4,7 @@ import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
|
4
4
|
import { formatSign } from "./formatSign.js";
|
|
5
5
|
import { signableMessageToJsonSafe } from "../utils/format.js";
|
|
6
6
|
import { LOGGER } from "../logger.js";
|
|
7
|
+
import { resolveAddress } from "../utils/resolve.js";
|
|
7
8
|
/**
|
|
8
9
|
* Signs a message using the smart account.
|
|
9
10
|
* This method requests the account associated with the signer and uses it to sign the message.
|
|
@@ -11,7 +12,7 @@ import { LOGGER } from "../logger.js";
|
|
|
11
12
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
12
13
|
* @param {SignMessageParams} params - Parameters for signing the message
|
|
13
14
|
* @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.
|
|
14
|
-
* @param {
|
|
15
|
+
* @param {AccountParam} [params.account] - Optional account to use for signing. Can be an address string or an object with an `address` property. If not provided, uses the client's current account.
|
|
15
16
|
* @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
|
|
16
17
|
*
|
|
17
18
|
* @example
|
|
@@ -24,12 +25,14 @@ import { LOGGER } from "../logger.js";
|
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
export async function signMessage(client, params) {
|
|
27
|
-
const accountAddress = params.account
|
|
28
|
+
const accountAddress = params.account
|
|
29
|
+
? resolveAddress(params.account)
|
|
30
|
+
: client.account.address;
|
|
28
31
|
LOGGER.debug("signMessage:start", {
|
|
29
32
|
hasExplicitAccount: params.account != null,
|
|
30
33
|
});
|
|
31
34
|
const prepared = await prepareSign(client, {
|
|
32
|
-
|
|
35
|
+
account: accountAddress,
|
|
33
36
|
signatureRequest: {
|
|
34
37
|
type: "personal_sign",
|
|
35
38
|
data: signableMessageToJsonSafe(params.message),
|
|
@@ -37,7 +40,7 @@ export async function signMessage(client, params) {
|
|
|
37
40
|
});
|
|
38
41
|
const signed = await signSignatureRequest(client, prepared.signatureRequest);
|
|
39
42
|
const formatted = await formatSign(client, {
|
|
40
|
-
|
|
43
|
+
account: accountAddress,
|
|
41
44
|
signature: {
|
|
42
45
|
type: "ecdsa",
|
|
43
46
|
data: signed.data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../../src/actions/signMessage.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../../src/actions/signMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,MAAM,MAAM,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AASxE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAAyB;IAEzB,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO;QACnC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAC3B,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE;QAChC,kBAAkB,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;KAC3C,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE;QACzC,OAAO,EAAE,cAAc;QACvB,gBAAgB,EAAE;YAChB,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,yBAAyB,CAAC,MAAM,CAAC,OAAO,CAAC;SAChD;KACF,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAE7E,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE;QACzC,OAAO,EAAE,cAAc;QACvB,SAAS,EAAE;YACT,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;IAC3D,OAAO,SAAS,CAAC,SAAS,CAAC;AAC7B,CAAC","sourcesContent":["import { type Hex, type Prettify, type SignableMessage } from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { prepareSign } from \"./prepareSign.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { formatSign } from \"./formatSign.js\";\nimport { signableMessageToJsonSafe } from \"../utils/format.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\n\nexport type SignMessageParams = Prettify<{\n message: SignableMessage;\n account?: AccountParam;\n}>;\n\nexport type SignMessageResult = Prettify<Hex>;\n\n/**\n * Signs a message using the smart account.\n * This method requests the account associated with the signer and uses it to sign the message.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SignMessageParams} params - Parameters for signing the message\n * @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.\n * @param {AccountParam} [params.account] - Optional account to use for signing. Can be an address string or an object with an `address` property. If not provided, uses the client's current account.\n * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string\n *\n * @example\n * ```ts\n * // Sign a simple text message\n * const signature = await client.signMessage(\"Hello, world!\");\n *\n * // Sign a raw hex message\n * const signature = await client.signMessage({ raw: \"0x48656c6c6f2c20776f726c6421\" });\n * ```\n */\nexport async function signMessage(\n client: InnerWalletApiClient,\n params: SignMessageParams,\n): Promise<SignMessageResult> {\n const accountAddress = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n LOGGER.debug(\"signMessage:start\", {\n hasExplicitAccount: params.account != null,\n });\n\n const prepared = await prepareSign(client, {\n account: accountAddress,\n signatureRequest: {\n type: \"personal_sign\",\n data: signableMessageToJsonSafe(params.message),\n },\n });\n\n const signed = await signSignatureRequest(client, prepared.signatureRequest);\n\n const formatted = await formatSign(client, {\n account: accountAddress,\n signature: {\n type: \"ecdsa\",\n data: signed.data,\n },\n });\n LOGGER.debug(\"signMessage:done\", { from: accountAddress });\n return formatted.signature;\n}\n"]}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import type { PrepareCallsResult } from "./prepareCalls.ts";
|
|
2
|
+
import { type SignSignatureRequestResult } from "./signSignatureRequest.js";
|
|
2
3
|
import type { Prettify } from "viem";
|
|
3
4
|
import type { InnerWalletApiClient } from "../types.js";
|
|
4
|
-
import type { SendPreparedCallsParams } from "./sendPreparedCalls.js";
|
|
5
5
|
export type SignPreparedCallsParams = Prettify<PrepareCallsResult>;
|
|
6
|
-
|
|
6
|
+
/** Replace signatureRequest/feePayment with the actual signature produced by signPreparedCalls. */
|
|
7
|
+
type Signed<T> = T extends {
|
|
8
|
+
signatureRequest?: unknown;
|
|
9
|
+
} ? Prettify<Omit<T, "signatureRequest" | "feePayment"> & {
|
|
10
|
+
signature: SignSignatureRequestResult;
|
|
11
|
+
}> : never;
|
|
12
|
+
export type SignPreparedCallsResult = {
|
|
13
|
+
type: "array";
|
|
14
|
+
data: Signed<Extract<PrepareCallsResult, {
|
|
15
|
+
type: "array";
|
|
16
|
+
}>["data"][number]>[];
|
|
17
|
+
} | Signed<Extract<PrepareCallsResult, {
|
|
18
|
+
type: "user-operation-v060";
|
|
19
|
+
}>> | Signed<Extract<PrepareCallsResult, {
|
|
20
|
+
type: "user-operation-v070";
|
|
21
|
+
}>>;
|
|
7
22
|
/**
|
|
8
23
|
* Signs prepared calls using the provided signer.
|
|
9
24
|
*
|
|
@@ -30,3 +45,4 @@ export type SignPreparedCallsResult = SendPreparedCallsParams;
|
|
|
30
45
|
* ```
|
|
31
46
|
*/
|
|
32
47
|
export declare function signPreparedCalls(client: InnerWalletApiClient, params: SignPreparedCallsParams): Promise<SignPreparedCallsResult>;
|
|
48
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertNever, BaseError } from "@alchemy/common";
|
|
2
|
-
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
2
|
+
import { signSignatureRequest, } from "./signSignatureRequest.js";
|
|
3
3
|
import { LOGGER } from "../logger.js";
|
|
4
4
|
/**
|
|
5
5
|
* Signs prepared calls using the provided signer.
|