@account-kit/wallet-client 4.76.0 → 4.77.1
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/client/actions/grantPermissions.d.ts +3 -3
- package/dist/esm/client/actions/grantPermissions.js +28 -3
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/listAccounts.d.ts +11 -7
- package/dist/esm/client/actions/listAccounts.js +27 -4
- package/dist/esm/client/actions/listAccounts.js.map +1 -1
- package/dist/esm/client/actions/requestAccount.d.ts +8 -4
- package/dist/esm/client/actions/requestAccount.js +37 -6
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/sendCalls.d.ts +3 -3
- package/dist/esm/client/actions/sendCalls.js +5 -2
- package/dist/esm/client/actions/sendCalls.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +3 -3
- package/dist/esm/client/actions/signMessage.js +1 -2
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.d.ts +3 -3
- package/dist/esm/client/actions/signPreparedCalls.js +5 -2
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +8 -37
- package/dist/esm/client/actions/signSignatureRequest.js +30 -2
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +3 -3
- package/dist/esm/client/actions/signTypedData.js +1 -1
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/actions/waitForCallsStatus.d.ts +1 -1
- package/dist/esm/client/decorator.d.ts +2 -2
- package/dist/esm/client/decorator.js +13 -1
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +9 -2
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/internal/account.d.ts +3 -2
- package/dist/esm/internal/account.js +28 -3
- package/dist/esm/internal/account.js.map +1 -1
- package/dist/esm/utils.d.ts +6 -0
- package/dist/esm/utils.js +14 -1
- package/dist/esm/utils.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/client/actions/grantPermissions.d.ts +3 -3
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/listAccounts.d.ts +11 -7
- package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/client/actions/requestAccount.d.ts +8 -4
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/sendCalls.d.ts +3 -3
- package/dist/types/client/actions/sendCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +3 -3
- package/dist/types/client/actions/signMessage.d.ts.map +1 -1
- package/dist/types/client/actions/signPreparedCalls.d.ts +3 -3
- package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +8 -37
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +3 -3
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/actions/waitForCallsStatus.d.ts +1 -1
- package/dist/types/client/decorator.d.ts +2 -2
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +9 -2
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/internal/account.d.ts +3 -2
- package/dist/types/internal/account.d.ts.map +1 -1
- package/dist/types/utils.d.ts +6 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -5
- package/src/client/actions/grantPermissions.ts +33 -4
- package/src/client/actions/listAccounts.ts +38 -8
- package/src/client/actions/requestAccount.ts +60 -12
- package/src/client/actions/sendCalls.ts +9 -3
- package/src/client/actions/signMessage.ts +3 -3
- package/src/client/actions/signPreparedCalls.ts +10 -4
- package/src/client/actions/signSignatureRequest.ts +75 -8
- package/src/client/actions/signTypedData.ts +3 -3
- package/src/client/decorator.ts +21 -3
- package/src/client/index.ts +11 -2
- package/src/internal/account.ts +38 -5
- package/src/utils.ts +25 -1
- package/src/version.ts +1 -1
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type SmartAccountSigner,
|
|
3
|
-
type SmartContractAccount,
|
|
4
|
-
} from "@aa-sdk/core";
|
|
1
|
+
import { BaseError, type SmartContractAccount } from "@aa-sdk/core";
|
|
5
2
|
import type { Address } from "abitype";
|
|
6
3
|
import deepEqual from "deep-equal";
|
|
7
4
|
import { custom } from "viem";
|
|
8
5
|
import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
|
|
9
6
|
import type { InnerWalletApiClient } from "../../types.js";
|
|
10
7
|
import { createAccount } from "../../internal/account.js";
|
|
8
|
+
import type { SmartWalletSigner } from "../index.js";
|
|
9
|
+
import {
|
|
10
|
+
credentialToWebAuthnPublicKey,
|
|
11
|
+
isWebAuthnSigner,
|
|
12
|
+
} from "../../utils.js";
|
|
13
|
+
import {
|
|
14
|
+
CreationOptionsByPublicKey,
|
|
15
|
+
CreationOptionsBySignerAddress,
|
|
16
|
+
type WebAuthnPublicKey,
|
|
17
|
+
} from "@alchemy/wallet-api-types";
|
|
11
18
|
|
|
12
19
|
type RpcSchema = Extract<
|
|
13
20
|
WalletServerRpcSchemaType,
|
|
@@ -19,8 +26,11 @@ type RpcSchema = Extract<
|
|
|
19
26
|
>;
|
|
20
27
|
|
|
21
28
|
export type RequestAccountParams = Omit<
|
|
22
|
-
Extract<
|
|
23
|
-
|
|
29
|
+
Extract<
|
|
30
|
+
RpcSchema["Request"]["params"][0],
|
|
31
|
+
{ signerAddress: Address } | { signerPublicKey: WebAuthnPublicKey }
|
|
32
|
+
>,
|
|
33
|
+
"signerAddress" | "signerPublicKey" | "includeCounterfactualInfo"
|
|
24
34
|
> & { accountAddress?: Address };
|
|
25
35
|
|
|
26
36
|
export type RequestAccountResult = SmartContractAccount;
|
|
@@ -31,7 +41,7 @@ export type RequestAccountResult = SmartContractAccount;
|
|
|
31
41
|
* If an account already exists, the creationHint will be ignored.
|
|
32
42
|
*
|
|
33
43
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
34
|
-
* @param {SmartAccountSigner} signer - The signer that will be associated with the account
|
|
44
|
+
* @param {SmartAccountSigner | WebAuthnSigner} signer - The signer that will be associated with the account
|
|
35
45
|
* @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account
|
|
36
46
|
* @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
|
|
37
47
|
* @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists
|
|
@@ -46,20 +56,58 @@ export type RequestAccountResult = SmartContractAccount;
|
|
|
46
56
|
*/
|
|
47
57
|
export async function requestAccount(
|
|
48
58
|
client: InnerWalletApiClient,
|
|
49
|
-
signer:
|
|
59
|
+
signer: SmartWalletSigner,
|
|
50
60
|
params?: RequestAccountParams,
|
|
51
61
|
): Promise<RequestAccountResult> {
|
|
52
|
-
const
|
|
62
|
+
const { creationHint = {} } = params ?? {};
|
|
63
|
+
|
|
64
|
+
if (isWebAuthnSigner(signer)) {
|
|
65
|
+
if (
|
|
66
|
+
creationHint.accountType &&
|
|
67
|
+
creationHint.accountType !== "mav2-webauthn"
|
|
68
|
+
) {
|
|
69
|
+
throw new BaseError(
|
|
70
|
+
"WebAuthn signers are only supported with mav2-webauthn account type",
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
// non-webauthn signers do not support the "mav2-webauthn" account type
|
|
75
|
+
if (creationHint.accountType === "mav2-webauthn") {
|
|
76
|
+
throw new BaseError(
|
|
77
|
+
"ECDSA (secp256k1) signers are not supported with mav2-webauthn account type",
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const args = (
|
|
53
83
|
(client.account && !params) || params?.accountAddress
|
|
54
84
|
? {
|
|
55
85
|
accountAddress: params?.accountAddress ?? client.account!.address,
|
|
56
86
|
includeCounterfactualInfo: true,
|
|
57
87
|
}
|
|
58
88
|
: {
|
|
59
|
-
...
|
|
60
|
-
|
|
89
|
+
...(isWebAuthnSigner(signer)
|
|
90
|
+
? {
|
|
91
|
+
signerPublicKey: {
|
|
92
|
+
...credentialToWebAuthnPublicKey(signer.credential),
|
|
93
|
+
type: "webauthn-p256",
|
|
94
|
+
},
|
|
95
|
+
...(creationHint
|
|
96
|
+
? { creationHint: creationHint as CreationOptionsByPublicKey }
|
|
97
|
+
: {}),
|
|
98
|
+
}
|
|
99
|
+
: {
|
|
100
|
+
signerAddress: await signer.getAddress(),
|
|
101
|
+
...(creationHint
|
|
102
|
+
? {
|
|
103
|
+
creationHint:
|
|
104
|
+
creationHint as CreationOptionsBySignerAddress,
|
|
105
|
+
}
|
|
106
|
+
: {}),
|
|
107
|
+
}),
|
|
61
108
|
includeCounterfactualInfo: true,
|
|
62
|
-
}
|
|
109
|
+
}
|
|
110
|
+
) satisfies RpcSchema["Request"]["params"][0];
|
|
63
111
|
|
|
64
112
|
const cachedAccount = client.internal.getAccount();
|
|
65
113
|
|
|
@@ -3,12 +3,13 @@ import type { InnerWalletApiClient } from "../../types.js";
|
|
|
3
3
|
import { prepareCalls, type PrepareCallsParams } from "./prepareCalls.js";
|
|
4
4
|
import { metrics } from "../../metrics.js";
|
|
5
5
|
import { signPreparedCalls } from "./signPreparedCalls.js";
|
|
6
|
-
import { type SmartAccountSigner } from "@aa-sdk/core";
|
|
7
6
|
import {
|
|
8
7
|
sendPreparedCalls,
|
|
9
8
|
type SendPreparedCallsResult,
|
|
10
9
|
} from "./sendPreparedCalls.js";
|
|
11
10
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
11
|
+
import type { SmartWalletSigner } from "../index.js";
|
|
12
|
+
import { isWebAuthnSigner } from "../../utils.js";
|
|
12
13
|
|
|
13
14
|
export type SendCallsParams<
|
|
14
15
|
TAccount extends Address | undefined = Address | undefined,
|
|
@@ -25,7 +26,7 @@ export type SendCallsResult = SendPreparedCallsResult;
|
|
|
25
26
|
* </Note>
|
|
26
27
|
*
|
|
27
28
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
28
|
-
* @param {SmartAccountSigner} signer - The signer to use
|
|
29
|
+
* @param {SmartAccountSigner | WebAuthnSigner} signer - The signer to use
|
|
29
30
|
* @param {PrepareCallsParams<TAccount>} params - Parameters for sending calls
|
|
30
31
|
* @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
|
|
31
32
|
* @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)
|
|
@@ -53,7 +54,7 @@ export async function sendCalls<
|
|
|
53
54
|
TAccount extends Address | undefined = Address | undefined,
|
|
54
55
|
>(
|
|
55
56
|
client: InnerWalletApiClient,
|
|
56
|
-
signer:
|
|
57
|
+
signer: SmartWalletSigner,
|
|
57
58
|
params: SendCallsParams<TAccount>,
|
|
58
59
|
): Promise<SendCallsResult> {
|
|
59
60
|
metrics.trackEvent({
|
|
@@ -63,6 +64,11 @@ export async function sendCalls<
|
|
|
63
64
|
let calls = await prepareCalls(client, params);
|
|
64
65
|
|
|
65
66
|
if (calls.type === "paymaster-permit") {
|
|
67
|
+
if (isWebAuthnSigner(signer)) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
"WebAuthn signer is not currently supported for signing paymaster permit signatures",
|
|
70
|
+
);
|
|
71
|
+
}
|
|
66
72
|
const signature = await signSignatureRequest(
|
|
67
73
|
signer,
|
|
68
74
|
calls.signatureRequest,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type SmartAccountSigner } from "@aa-sdk/core";
|
|
2
1
|
import { type Address, type Hex, type SignableMessage } from "viem";
|
|
3
2
|
import type { InnerWalletApiClient } from "../../types.ts";
|
|
4
3
|
import { requestAccount } from "./requestAccount.js";
|
|
5
4
|
import { metrics } from "../../metrics.js";
|
|
5
|
+
import type { SmartWalletSigner } from "../index.js";
|
|
6
6
|
|
|
7
7
|
export type SignMessageParams = { message: SignableMessage; account?: Address };
|
|
8
8
|
|
|
@@ -13,7 +13,7 @@ export type SignMessageResult = Hex;
|
|
|
13
13
|
* This method requests the account associated with the signer and uses it to sign the message.
|
|
14
14
|
*
|
|
15
15
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
16
|
-
* @param {SmartAccountSigner} signer - The signer of the smart account
|
|
16
|
+
* @param {SmartAccountSigner | WebAuthnSigner} signer - The signer of the smart account
|
|
17
17
|
* @param {SignMessageParams} params - Parameters for signing the message
|
|
18
18
|
* @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.
|
|
19
19
|
* @param {Address} [params.account] - Optional account address to use for signing. If not provided, uses the client's current account.
|
|
@@ -30,7 +30,7 @@ export type SignMessageResult = Hex;
|
|
|
30
30
|
*/
|
|
31
31
|
export async function signMessage(
|
|
32
32
|
client: InnerWalletApiClient,
|
|
33
|
-
signer:
|
|
33
|
+
signer: SmartWalletSigner,
|
|
34
34
|
params: SignMessageParams,
|
|
35
35
|
): Promise<SignMessageResult> {
|
|
36
36
|
metrics.trackEvent({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PrepareCallsResult } from "./prepareCalls.ts";
|
|
2
|
-
import { BaseError
|
|
2
|
+
import { BaseError } from "@aa-sdk/core";
|
|
3
3
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
4
4
|
import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
|
|
5
5
|
import type {
|
|
@@ -8,7 +8,8 @@ import type {
|
|
|
8
8
|
PreparedCall_UserOpV070,
|
|
9
9
|
} from "@alchemy/wallet-api-types";
|
|
10
10
|
import { metrics } from "../../metrics.js";
|
|
11
|
-
import { assertNever } from "../../utils.js";
|
|
11
|
+
import { assertNever, isWebAuthnSigner } from "../../utils.js";
|
|
12
|
+
import type { SmartWalletSigner } from "../index.js";
|
|
12
13
|
|
|
13
14
|
type RpcSchema = Extract<
|
|
14
15
|
WalletServerRpcSchemaType,
|
|
@@ -26,12 +27,12 @@ export type SignPreparedCallsResult = RpcSchema["Request"]["params"][0];
|
|
|
26
27
|
/**
|
|
27
28
|
* Signs prepared calls using the provided signer.
|
|
28
29
|
*
|
|
29
|
-
* @param {SmartAccountSigner} signer - The signer to use
|
|
30
|
+
* @param {SmartAccountSigner | WebAuthnSigner} signer - The signer to use
|
|
30
31
|
* @param {SignPreparedCallsParams} params - The prepared calls with signature requests
|
|
31
32
|
* @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls
|
|
32
33
|
*/
|
|
33
34
|
export async function signPreparedCalls(
|
|
34
|
-
signer:
|
|
35
|
+
signer: SmartWalletSigner,
|
|
35
36
|
params: SignPreparedCallsParams,
|
|
36
37
|
): Promise<SignPreparedCallsResult> {
|
|
37
38
|
metrics.trackEvent({
|
|
@@ -43,6 +44,11 @@ export async function signPreparedCalls(
|
|
|
43
44
|
|
|
44
45
|
const signAuthorizationCall = async (call: PreparedCall_Authorization) => {
|
|
45
46
|
const { signatureRequest: _signatureRequest, ...rest } = call;
|
|
47
|
+
if (isWebAuthnSigner(signer)) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"WebAuthn account cannot sign EIP-7702 authorization requests",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
46
52
|
const signature = await signSignatureRequest(signer, {
|
|
47
53
|
type: "eip7702Auth",
|
|
48
54
|
data: {
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
-
import {
|
|
3
|
-
import { assertNever } from "../../utils.js";
|
|
2
|
+
import { hexToNumber, serializeSignature } from "viem";
|
|
3
|
+
import { assertNever, isWebAuthnSigner } from "../../utils.js";
|
|
4
4
|
import type {
|
|
5
5
|
PersonalSignSignatureRequest,
|
|
6
6
|
TypedDataSignatureRequest,
|
|
7
7
|
AuthorizationSignatureRequest,
|
|
8
8
|
Eip7702UnsignedAuth,
|
|
9
|
+
UserOpSig,
|
|
10
|
+
EcdsaSig,
|
|
11
|
+
WebauthnSig,
|
|
9
12
|
} from "@alchemy/wallet-api-types";
|
|
10
13
|
import { vToYParity } from "ox/Signature";
|
|
11
14
|
import type { WithoutRawPayload } from "../../types.ts";
|
|
12
15
|
import { metrics } from "../../metrics.js";
|
|
16
|
+
import type { SmartWalletSigner, WebAuthnSigner } from "../index.js";
|
|
17
|
+
import { toWebAuthnAccount } from "viem/account-abstraction";
|
|
13
18
|
|
|
14
19
|
export type SignSignatureRequestParams = WithoutRawPayload<
|
|
15
20
|
| PersonalSignSignatureRequest
|
|
@@ -19,16 +24,41 @@ export type SignSignatureRequestParams = WithoutRawPayload<
|
|
|
19
24
|
})
|
|
20
25
|
>;
|
|
21
26
|
|
|
22
|
-
export type SignSignatureRequestResult =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
export type SignSignatureRequestResult = UserOpSig["signature"];
|
|
28
|
+
|
|
29
|
+
// Overload: Always an ECDSA signer, can sign any type of request
|
|
30
|
+
export async function signSignatureRequest(
|
|
31
|
+
signer: SmartAccountSigner,
|
|
32
|
+
params: WithoutRawPayload<
|
|
33
|
+
| PersonalSignSignatureRequest
|
|
34
|
+
| TypedDataSignatureRequest
|
|
35
|
+
| (AuthorizationSignatureRequest & {
|
|
36
|
+
data: Eip7702UnsignedAuth;
|
|
37
|
+
})
|
|
38
|
+
>,
|
|
39
|
+
): Promise<EcdsaSig["signature"]>;
|
|
40
|
+
|
|
41
|
+
// Overload: WebAuthn signer, can only sign personal_sign and eth_signTypedData_v4
|
|
42
|
+
export async function signSignatureRequest(
|
|
43
|
+
signer: WebAuthnSigner,
|
|
44
|
+
params: WithoutRawPayload<
|
|
45
|
+
PersonalSignSignatureRequest | TypedDataSignatureRequest
|
|
46
|
+
>,
|
|
47
|
+
): Promise<WebauthnSig["signature"]>;
|
|
48
|
+
|
|
49
|
+
// Overload: Union type of signer, can only sign personal_sign and eth_signTypedData_v4
|
|
50
|
+
export async function signSignatureRequest(
|
|
51
|
+
signer: SmartAccountSigner | WebAuthnSigner,
|
|
52
|
+
params: WithoutRawPayload<
|
|
53
|
+
PersonalSignSignatureRequest | TypedDataSignatureRequest
|
|
54
|
+
>,
|
|
55
|
+
): Promise<UserOpSig["signature"]>;
|
|
26
56
|
|
|
27
57
|
/**
|
|
28
58
|
* Signs a signature request using the provided signer.
|
|
29
59
|
* This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
|
|
30
60
|
*
|
|
31
|
-
* @param {SmartAccountSigner} signer - The signer to use for signing the request
|
|
61
|
+
* @param {SmartAccountSigner | WebAuthnSigner} signer - The signer to use for signing the request
|
|
32
62
|
* @param {SignSignatureRequestParams} params - The signature request parameters
|
|
33
63
|
* @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
|
|
34
64
|
* @param {SignSignatureRequestParams["data"]} params.data - The data to sign, format depends on the signature type
|
|
@@ -56,7 +86,7 @@ export type SignSignatureRequestResult = {
|
|
|
56
86
|
*/
|
|
57
87
|
|
|
58
88
|
export async function signSignatureRequest(
|
|
59
|
-
signer:
|
|
89
|
+
signer: SmartWalletSigner,
|
|
60
90
|
params: SignSignatureRequestParams,
|
|
61
91
|
): Promise<SignSignatureRequestResult> {
|
|
62
92
|
metrics.trackEvent({
|
|
@@ -68,18 +98,55 @@ export async function signSignatureRequest(
|
|
|
68
98
|
|
|
69
99
|
switch (params.type) {
|
|
70
100
|
case "personal_sign": {
|
|
101
|
+
if (isWebAuthnSigner(signer)) {
|
|
102
|
+
const webAuthnAccount = toWebAuthnAccount({ ...signer });
|
|
103
|
+
|
|
104
|
+
const { signature, webauthn: metadata } =
|
|
105
|
+
await webAuthnAccount.signMessage({
|
|
106
|
+
message: params.data,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
type: "webauthn-p256",
|
|
111
|
+
data: {
|
|
112
|
+
signature,
|
|
113
|
+
metadata,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
71
118
|
return {
|
|
72
119
|
type: "secp256k1",
|
|
73
120
|
data: await signer.signMessage(params.data),
|
|
74
121
|
};
|
|
75
122
|
}
|
|
76
123
|
case "eth_signTypedData_v4": {
|
|
124
|
+
if (isWebAuthnSigner(signer)) {
|
|
125
|
+
const webAuthnAccount = toWebAuthnAccount({ ...signer });
|
|
126
|
+
|
|
127
|
+
const { signature, webauthn: metadata } =
|
|
128
|
+
await webAuthnAccount.signTypedData(params.data);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
type: "webauthn-p256",
|
|
132
|
+
data: {
|
|
133
|
+
signature,
|
|
134
|
+
metadata,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
77
138
|
return {
|
|
78
139
|
type: "secp256k1",
|
|
79
140
|
data: await signer.signTypedData(params.data),
|
|
80
141
|
};
|
|
81
142
|
}
|
|
82
143
|
case "eip7702Auth": {
|
|
144
|
+
if (isWebAuthnSigner(signer)) {
|
|
145
|
+
throw new Error(
|
|
146
|
+
"WebAuthn account cannot sign EIP-7702 authorization requests",
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
83
150
|
if (!signer.signAuthorization) {
|
|
84
151
|
throw new Error("Signer does not implement signAuthorization");
|
|
85
152
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
1
|
import { type Address, type Hex, type TypedDataDefinition } from "viem";
|
|
3
2
|
import type { InnerWalletApiClient } from "../../types.ts";
|
|
4
3
|
import { requestAccount } from "./requestAccount.js";
|
|
5
4
|
import { metrics } from "../../metrics.js";
|
|
5
|
+
import type { SmartWalletSigner } from "../index.js";
|
|
6
6
|
|
|
7
7
|
export type SignTypedDataParams = TypedDataDefinition & {
|
|
8
8
|
account?: Address;
|
|
@@ -15,7 +15,7 @@ export type SignTypedDataResult = Hex;
|
|
|
15
15
|
* This method requests the account associated with the signer and uses it to sign the typed data.
|
|
16
16
|
*
|
|
17
17
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
18
|
-
* @param {SmartAccountSigner} signer - The signer of the smart account
|
|
18
|
+
* @param {SmartAccountSigner | WebAuthnSigner} signer - The signer of the smart account
|
|
19
19
|
* @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format
|
|
20
20
|
* @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
|
|
21
21
|
*
|
|
@@ -45,7 +45,7 @@ export type SignTypedDataResult = Hex;
|
|
|
45
45
|
*/
|
|
46
46
|
export async function signTypedData(
|
|
47
47
|
client: InnerWalletApiClient,
|
|
48
|
-
signer:
|
|
48
|
+
signer: SmartWalletSigner,
|
|
49
49
|
params: SignTypedDataParams,
|
|
50
50
|
): Promise<SignTypedDataResult> {
|
|
51
51
|
metrics.trackEvent({
|
package/src/client/decorator.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
1
|
import type { Address, Hex } from "viem";
|
|
3
2
|
import {
|
|
4
3
|
type WaitForCallsStatusParameters,
|
|
@@ -56,6 +55,25 @@ import {
|
|
|
56
55
|
type SendCallsParams,
|
|
57
56
|
type SendCallsResult,
|
|
58
57
|
} from "./actions/sendCalls.js";
|
|
58
|
+
import type { SmartWalletSigner } from "./index.js";
|
|
59
|
+
import { isWebAuthnSigner } from "../utils.js";
|
|
60
|
+
|
|
61
|
+
async function signSignatureRequestSafe(
|
|
62
|
+
signer: SmartWalletSigner,
|
|
63
|
+
params: SignSignatureRequestParams,
|
|
64
|
+
): Promise<SignSignatureRequestResult> {
|
|
65
|
+
if (params.type === "eip7702Auth") {
|
|
66
|
+
if (isWebAuthnSigner(signer)) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
"WebAuthn signer cannot sign EIP-7702 authorization requests",
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
// We must split up the call to signSignatureRequest across two conditionals for the TS compiler to
|
|
72
|
+
// correctly infer which overload to use.
|
|
73
|
+
return signSignatureRequest(signer, params);
|
|
74
|
+
}
|
|
75
|
+
return signSignatureRequest(signer, params);
|
|
76
|
+
}
|
|
59
77
|
|
|
60
78
|
export type SmartWalletActions<
|
|
61
79
|
TAccount extends Address | undefined = Address | undefined,
|
|
@@ -94,7 +112,7 @@ export function smartWalletClientActions<
|
|
|
94
112
|
TAccount extends Address | undefined = Address | undefined,
|
|
95
113
|
>(
|
|
96
114
|
client: InnerWalletApiClient,
|
|
97
|
-
signer:
|
|
115
|
+
signer: SmartWalletSigner,
|
|
98
116
|
): SmartWalletActions<TAccount> {
|
|
99
117
|
return {
|
|
100
118
|
requestAccount: (params) => requestAccount(client, signer, params),
|
|
@@ -104,7 +122,7 @@ export function smartWalletClientActions<
|
|
|
104
122
|
sendCalls: (params) => sendCalls(client, signer, params),
|
|
105
123
|
getCallsStatus: (params) => getCallsStatus(client, params),
|
|
106
124
|
waitForCallsStatus: (params) => waitForCallsStatus(client, params),
|
|
107
|
-
signSignatureRequest: (params) =>
|
|
125
|
+
signSignatureRequest: (params) => signSignatureRequestSafe(signer, params),
|
|
108
126
|
signPreparedCalls: (params) => signPreparedCalls(signer, params),
|
|
109
127
|
signMessage: (params) => signMessage(client, signer, params),
|
|
110
128
|
signTypedData: (params) => signTypedData(client, signer, params),
|
package/src/client/index.ts
CHANGED
|
@@ -21,6 +21,15 @@ import type {
|
|
|
21
21
|
} from "@alchemy/wallet-api-types/rpc";
|
|
22
22
|
import { internalStateDecorator } from "../internal/decorator.js";
|
|
23
23
|
import { metrics } from "../metrics.js";
|
|
24
|
+
import type { ToWebAuthnAccountParameters } from "viem/account-abstraction";
|
|
25
|
+
|
|
26
|
+
export type WebAuthnSigner = {
|
|
27
|
+
credential: ToWebAuthnAccountParameters["credential"];
|
|
28
|
+
getFn?: ToWebAuthnAccountParameters["getFn"] | undefined;
|
|
29
|
+
rpId?: ToWebAuthnAccountParameters["rpId"] | undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type SmartWalletSigner = SmartAccountSigner<any> | WebAuthnSigner;
|
|
24
33
|
|
|
25
34
|
export type SmartWalletClientParams<
|
|
26
35
|
TAccount extends Address | undefined = Address | undefined,
|
|
@@ -28,7 +37,7 @@ export type SmartWalletClientParams<
|
|
|
28
37
|
{
|
|
29
38
|
transport: AlchemyTransport;
|
|
30
39
|
chain: Chain;
|
|
31
|
-
signer:
|
|
40
|
+
signer: SmartWalletSigner;
|
|
32
41
|
account?: TAccount | Address | undefined;
|
|
33
42
|
} & (
|
|
34
43
|
| { policyId?: string; policyIds?: never }
|
|
@@ -46,7 +55,7 @@ export type SmartWalletClient<
|
|
|
46
55
|
* @param {SmartWalletClientParams} params - The parameters for creating the smart wallet client
|
|
47
56
|
* @param {AlchemyTransport} params.transport - The Alchemy transport to use
|
|
48
57
|
* @param {Chain} params.chain - The chain to use
|
|
49
|
-
* @param {SmartAccountSigner} params.signer - The signer to use for the smart account
|
|
58
|
+
* @param {SmartAccountSigner | WebAuthnSigner} params.signer - The signer to use for the smart account
|
|
50
59
|
* @param {string} [params.policyId] - The policy ID for gas sponsorship (optional)
|
|
51
60
|
* @param {Address} [params.account] - The smart account address to use (optional)
|
|
52
61
|
* @returns {SmartWalletClient} - A viem-compatible client
|
package/src/internal/account.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
InvalidSignerTypeError,
|
|
3
|
+
type SmartContractAccount,
|
|
4
|
+
} from "@aa-sdk/core";
|
|
2
5
|
import {
|
|
3
6
|
createModularAccountV2,
|
|
4
7
|
createLightAccount,
|
|
@@ -14,13 +17,14 @@ import {
|
|
|
14
17
|
} from "viem";
|
|
15
18
|
import type { SerializedInitcode } from "@alchemy/wallet-api-types";
|
|
16
19
|
import { InternalError, InvalidRequestError } from "ox/RpcResponse";
|
|
17
|
-
import { assertNever } from "../utils.js";
|
|
20
|
+
import { assertNever, isWebAuthnSigner } from "../utils.js";
|
|
18
21
|
import { metrics } from "../metrics.js";
|
|
22
|
+
import type { SmartWalletSigner } from "../client/index.js";
|
|
19
23
|
|
|
20
24
|
type CreateAccountParams = {
|
|
21
25
|
chain: Chain;
|
|
22
26
|
transport: Transport;
|
|
23
|
-
signer:
|
|
27
|
+
signer: SmartWalletSigner;
|
|
24
28
|
accountAddress: Address;
|
|
25
29
|
counterfactualInfo?: SerializedInitcode; // undefined for 7702 accounts
|
|
26
30
|
delegation?: Address; // for 7702 accounts
|
|
@@ -48,14 +52,20 @@ type CreateAccountParams = {
|
|
|
48
52
|
export async function createAccount(
|
|
49
53
|
params: CreateAccountParams,
|
|
50
54
|
): Promise<SmartContractAccount> {
|
|
51
|
-
const { counterfactualInfo: ci, ...accountParams } = params;
|
|
55
|
+
const { counterfactualInfo: ci, signer, ...accountParams } = params;
|
|
52
56
|
|
|
53
57
|
if (params.delegation) {
|
|
54
58
|
if (!isAddressEqual(params.delegation, MAV2_7702_DELEGATION_ADDRESS)) {
|
|
55
59
|
throw new Error("7702 mode currently only supports ModularAccountV2");
|
|
56
60
|
}
|
|
61
|
+
|
|
62
|
+
if (isWebAuthnSigner(signer)) {
|
|
63
|
+
throw new InvalidSignerTypeError("WebAuthn");
|
|
64
|
+
}
|
|
65
|
+
|
|
57
66
|
return createModularAccountV2({
|
|
58
67
|
...accountParams,
|
|
68
|
+
signer,
|
|
59
69
|
mode: "7702",
|
|
60
70
|
});
|
|
61
71
|
}
|
|
@@ -82,45 +92,68 @@ export async function createAccount(
|
|
|
82
92
|
},
|
|
83
93
|
});
|
|
84
94
|
|
|
95
|
+
// WebAuthn accounts must use a different signer type, so they are handled separately.
|
|
96
|
+
if (factoryType === "MAv2.0.0-ma-webauthn") {
|
|
97
|
+
if (!isWebAuthnSigner(signer)) {
|
|
98
|
+
throw new InvalidSignerTypeError(signer.signerType);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return createModularAccountV2({
|
|
102
|
+
...commonParams,
|
|
103
|
+
...signer,
|
|
104
|
+
mode: "webauthn",
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (isWebAuthnSigner(signer)) {
|
|
109
|
+
throw new InvalidSignerTypeError("WebAuthn");
|
|
110
|
+
}
|
|
111
|
+
|
|
85
112
|
// Return the account created based on the factory type
|
|
86
113
|
switch (factoryType) {
|
|
87
114
|
case "MAv2.0.0-sma-b":
|
|
88
115
|
return createModularAccountV2({
|
|
89
116
|
...commonParams,
|
|
117
|
+
signer,
|
|
90
118
|
mode: "default",
|
|
91
119
|
});
|
|
92
120
|
case "LightAccountV2.0.0":
|
|
93
121
|
return createLightAccount({
|
|
94
122
|
...commonParams,
|
|
123
|
+
signer,
|
|
95
124
|
version: "v2.0.0",
|
|
96
125
|
});
|
|
97
126
|
case "LightAccountV1.0.1":
|
|
98
127
|
return createLightAccount({
|
|
99
128
|
...commonParams,
|
|
129
|
+
signer,
|
|
100
130
|
version: "v1.0.1",
|
|
101
131
|
});
|
|
102
132
|
case "LightAccountV1.0.2":
|
|
103
133
|
return createLightAccount({
|
|
104
134
|
...commonParams,
|
|
135
|
+
signer,
|
|
105
136
|
version: "v1.0.2",
|
|
106
137
|
});
|
|
107
138
|
case "LightAccountV1.1.0":
|
|
108
139
|
return createLightAccount({
|
|
109
140
|
...commonParams,
|
|
141
|
+
signer,
|
|
110
142
|
version: "v1.1.0",
|
|
111
143
|
});
|
|
112
144
|
case "MAv1.0.0-MultiOwner":
|
|
113
145
|
return createMultiOwnerModularAccount({
|
|
114
146
|
...commonParams,
|
|
147
|
+
signer,
|
|
115
148
|
});
|
|
116
149
|
case "LightAccountV2.0.0-MultiOwner":
|
|
117
150
|
return createMultiOwnerLightAccount({
|
|
118
151
|
...commonParams,
|
|
119
152
|
version: "v2.0.0",
|
|
153
|
+
signer,
|
|
120
154
|
});
|
|
121
155
|
case "MAv1.0.0-MultiSig":
|
|
122
156
|
case "MAv2.0.0-ma-ssv":
|
|
123
|
-
case "MAv2.0.0-ma-webauthn":
|
|
124
157
|
case "unknown":
|
|
125
158
|
case undefined:
|
|
126
159
|
throw new InvalidRequestError({
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { isHex, toHex, type Hex } from "viem";
|
|
1
|
+
import { isHex, sliceHex, toHex, type Hex } from "viem";
|
|
2
|
+
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
3
|
+
import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
|
|
4
|
+
import type { ToWebAuthnAccountParameters } from "viem/account-abstraction";
|
|
5
|
+
import type { WebAuthnSigner } from "./client";
|
|
2
6
|
|
|
3
7
|
export type Expect<T extends true> = T;
|
|
4
8
|
|
|
@@ -25,3 +29,23 @@ export const castToHex = (val: string | number | bigint | Hex): Hex => {
|
|
|
25
29
|
}
|
|
26
30
|
return toHex(val);
|
|
27
31
|
};
|
|
32
|
+
|
|
33
|
+
export function isWebAuthnSigner(
|
|
34
|
+
signer: SmartAccountSigner | WebAuthnSigner,
|
|
35
|
+
): signer is WebAuthnSigner {
|
|
36
|
+
return "credential" in signer;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function credentialToWebAuthnPublicKey(
|
|
40
|
+
credential: ToWebAuthnAccountParameters["credential"],
|
|
41
|
+
): WebAuthnPublicKey {
|
|
42
|
+
const { x, y } = {
|
|
43
|
+
x: sliceHex(credential.publicKey, 0, 32, { strict: true }),
|
|
44
|
+
y: sliceHex(credential.publicKey, 32, 64, { strict: true }),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
x,
|
|
49
|
+
y,
|
|
50
|
+
};
|
|
51
|
+
}
|
package/src/version.ts
CHANGED