@account-kit/wallet-client 0.1.0-alpha.1 → 0.1.0-alpha.2
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/capabilities/permissions/mav2.d.ts +2 -2
- package/dist/esm/capabilities/permissions/mav2.js.map +1 -1
- package/dist/esm/client/actions/createAccount.d.ts +27 -2
- package/dist/esm/client/actions/createAccount.js +25 -0
- package/dist/esm/client/actions/createAccount.js.map +1 -1
- package/dist/esm/client/actions/getCallsStatus.d.ts +21 -2
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +60 -2
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/listAccounts.d.ts +26 -2
- package/dist/esm/client/actions/listAccounts.js +24 -0
- package/dist/esm/client/actions/listAccounts.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +28 -2
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/requestAccount.d.ts +21 -2
- package/dist/esm/client/actions/requestAccount.js +14 -3
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +39 -2
- package/dist/esm/client/actions/sendPreparedCalls.js +37 -0
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +22 -2
- package/dist/esm/client/actions/signMessage.js +4 -2
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +31 -0
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +35 -2
- package/dist/esm/client/actions/signTypedData.js +3 -1
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +99 -11
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +7 -5
- package/dist/esm/client/decorator.js +1 -1
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +4 -4
- package/dist/esm/client/index.js +29 -3
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/exports/index.d.ts +1 -0
- package/dist/esm/exports/index.js +1 -0
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/internal.d.ts +1 -1
- package/dist/esm/exports/internal.js.map +1 -1
- package/dist/esm/internal/decorator.d.ts +2 -0
- package/dist/esm/internal/decorator.js +10 -0
- package/dist/esm/internal/decorator.js.map +1 -0
- package/dist/esm/local/client.d.ts +1 -1
- package/dist/esm/local/client.js +8 -1
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.d.ts +1 -1
- package/dist/esm/remote/client.js +6 -1
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/rpc/schema.d.ts +1 -1
- package/dist/esm/types.d.ts +15 -4
- package/dist/esm/types.js.map +1 -1
- package/dist/types/capabilities/permissions/mav2.d.ts +2 -2
- package/dist/types/capabilities/permissions/mav2.d.ts.map +1 -1
- package/dist/types/client/actions/createAccount.d.ts +27 -2
- package/dist/types/client/actions/createAccount.d.ts.map +1 -1
- package/dist/types/client/actions/getCallsStatus.d.ts +21 -2
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +60 -2
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/listAccounts.d.ts +26 -2
- package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +28 -2
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/requestAccount.d.ts +21 -2
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +39 -2
- package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +22 -2
- package/dist/types/client/actions/signMessage.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +31 -0
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +35 -2
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +7 -5
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +4 -4
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +1 -0
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/internal.d.ts +1 -1
- package/dist/types/exports/internal.d.ts.map +1 -1
- package/dist/types/internal/decorator.d.ts +3 -0
- package/dist/types/internal/decorator.d.ts.map +1 -0
- package/dist/types/local/client.d.ts +1 -1
- package/dist/types/local/client.d.ts.map +1 -1
- package/dist/types/remote/client.d.ts +1 -1
- package/dist/types/remote/client.d.ts.map +1 -1
- package/dist/types/rpc/schema.d.ts +1 -1
- package/dist/types/types.d.ts +15 -4
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/capabilities/permissions/mav2.ts +2 -2
- package/src/client/actions/createAccount.ts +27 -2
- package/src/client/actions/getCallsStatus.ts +21 -2
- package/src/client/actions/grantPermissions.ts +60 -2
- package/src/client/actions/listAccounts.ts +26 -2
- package/src/client/actions/prepareCalls.ts +28 -2
- package/src/client/actions/requestAccount.ts +40 -5
- package/src/client/actions/sendPreparedCalls.ts +39 -2
- package/src/client/actions/signMessage.ts +24 -4
- package/src/client/actions/signSignatureRequest.ts +31 -0
- package/src/client/actions/signTypedData.ts +39 -3
- package/src/client/client.e2e-test.ts +120 -11
- package/src/client/decorator.ts +10 -12
- package/src/client/index.ts +41 -10
- package/src/exports/index.ts +1 -0
- package/src/exports/internal.ts +1 -1
- package/src/internal/decorator.ts +12 -0
- package/src/local/client.ts +52 -42
- package/src/remote/client.ts +10 -5
- package/src/types.ts +18 -4
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type SmartAccountSigner,
|
|
3
|
+
type SmartContractAccount,
|
|
4
|
+
} from "@aa-sdk/core";
|
|
2
5
|
import type { Static } from "@sinclair/typebox";
|
|
3
6
|
import { Value } from "@sinclair/typebox/value";
|
|
4
7
|
import type { Address } from "abitype";
|
|
8
|
+
import deepEqual from "deep-equal";
|
|
5
9
|
import { custom, type IsUndefined, type JsonRpcAccount } from "viem";
|
|
6
10
|
import { createAccount } from "../../isomorphic/utils/createAccount.js";
|
|
7
11
|
import type { wallet_requestAccount } from "../../rpc/request.js";
|
|
@@ -20,12 +24,29 @@ export type RequestAccountParams<
|
|
|
20
24
|
{ signerAddress: Address }
|
|
21
25
|
>,
|
|
22
26
|
"signerAddress" | "includeCounterfactualInfo"
|
|
23
|
-
>
|
|
27
|
+
> & { accountAddress?: Address }
|
|
24
28
|
: never;
|
|
25
29
|
|
|
26
30
|
// TODO: this could be more specific potentially :shrug:
|
|
27
31
|
export type RequestAccountResult = SmartContractAccount;
|
|
28
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Requests an account for the provided signer using the wallet API client.
|
|
35
|
+
* If an account already exists for the signer, it will always return that account unless a new ID is specified.
|
|
36
|
+
* If an account already exists, the creationHint will be ignored.
|
|
37
|
+
*
|
|
38
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
39
|
+
* @param {SmartAccountSigner} signer - The signer that will be associated with the account
|
|
40
|
+
* @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account
|
|
41
|
+
* @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
|
|
42
|
+
* @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists
|
|
43
|
+
* @returns {Promise<RequestAccountResult>} A Promise that resolves to a SmartContractAccount instance
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // Request an account with default parameters using a local signer
|
|
47
|
+
* const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
|
|
48
|
+
* const account = await client.requestAccount(signer);
|
|
49
|
+
*/
|
|
29
50
|
export function requestAccount<
|
|
30
51
|
TAccount extends JsonRpcAccount<Address> | undefined =
|
|
31
52
|
| JsonRpcAccount<Address>
|
|
@@ -42,9 +63,9 @@ export async function requestAccount(
|
|
|
42
63
|
params?: RequestAccountParams,
|
|
43
64
|
): Promise<RequestAccountResult> {
|
|
44
65
|
const args =
|
|
45
|
-
client.account && !params
|
|
66
|
+
(client.account && !params) || params?.accountAddress
|
|
46
67
|
? {
|
|
47
|
-
accountAddress: client.account
|
|
68
|
+
accountAddress: params?.accountAddress ?? client.account!.address,
|
|
48
69
|
includeCounterfactualInfo: true,
|
|
49
70
|
}
|
|
50
71
|
: {
|
|
@@ -53,12 +74,22 @@ export async function requestAccount(
|
|
|
53
74
|
includeCounterfactualInfo: true,
|
|
54
75
|
};
|
|
55
76
|
|
|
77
|
+
const cachedAccount = client.internal.getAccount();
|
|
78
|
+
if (
|
|
79
|
+
cachedAccount &&
|
|
80
|
+
((args.accountAddress &&
|
|
81
|
+
cachedAccount.account.address === args.accountAddress) ||
|
|
82
|
+
deepEqual(cachedAccount.requestParams, args, { strict: true }))
|
|
83
|
+
) {
|
|
84
|
+
return cachedAccount.account;
|
|
85
|
+
}
|
|
86
|
+
|
|
56
87
|
const { counterfactualInfo, accountAddress } = await client.request({
|
|
57
88
|
method: "wallet_requestAccount",
|
|
58
89
|
params: [args],
|
|
59
90
|
});
|
|
60
91
|
|
|
61
|
-
|
|
92
|
+
const account = await createAccount({
|
|
62
93
|
accountAddress: accountAddress,
|
|
63
94
|
counterfactualInfo: Value.Parse(
|
|
64
95
|
TypeSerializedInitcode,
|
|
@@ -68,4 +99,8 @@ export async function requestAccount(
|
|
|
68
99
|
transport: custom(client.transport),
|
|
69
100
|
signer,
|
|
70
101
|
});
|
|
102
|
+
|
|
103
|
+
client.internal.setAccount({ account, requestParams: args });
|
|
104
|
+
|
|
105
|
+
return account;
|
|
71
106
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Static, StaticDecode } from "@sinclair/typebox";
|
|
2
2
|
import { toHex } from "viem";
|
|
3
|
-
import type { wallet_sendPreparedCalls } from "../../rpc/request";
|
|
4
|
-
import type { InnerWalletApiClient } from "../../types";
|
|
3
|
+
import type { wallet_sendPreparedCalls } from "../../rpc/request.ts";
|
|
4
|
+
import type { InnerWalletApiClient } from "../../types.ts";
|
|
5
5
|
|
|
6
6
|
export type SendPreparedCallsParams = Omit<
|
|
7
7
|
StaticDecode<typeof wallet_sendPreparedCalls>["Request"]["params"][0],
|
|
@@ -12,6 +12,43 @@ export type SendPreparedCallsResult = Static<
|
|
|
12
12
|
typeof wallet_sendPreparedCalls
|
|
13
13
|
>["ReturnType"];
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Sends prepared calls by submitting a signed user operation.
|
|
17
|
+
* This method is used after signing the signature request returned from prepareCalls.
|
|
18
|
+
*
|
|
19
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
20
|
+
* @param {SendPreparedCallsParams} params - Parameters for sending prepared calls
|
|
21
|
+
* @param {string} params.type - The user operation type ('user-operation-v060' or 'user-operation-v070')
|
|
22
|
+
* @param {object} params.data - The user operation data without signature
|
|
23
|
+
* @param {string} params.chainId - The chain ID in hex format
|
|
24
|
+
* @param {object} params.signature - The signature object
|
|
25
|
+
* @param {string} params.signature.type - The signature type (must be 'ecdsa')
|
|
26
|
+
* @param {string} params.signature.signature - The hex-encoded signature value
|
|
27
|
+
* @param {object} [params.capabilities] - Optional capabilities to include with the request
|
|
28
|
+
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // First prepare the calls
|
|
32
|
+
* const preparedCalls = await client.prepareCalls({
|
|
33
|
+
* calls: [{
|
|
34
|
+
* to: "0x1234...",
|
|
35
|
+
* data: "0xabcdef...",
|
|
36
|
+
* value: "0x0"
|
|
37
|
+
* }],
|
|
38
|
+
* capabilities: {
|
|
39
|
+
* paymasterService: { policyId: "your-policy-id" }
|
|
40
|
+
* }
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Sign the signature request using signSignatureRequest with your signer
|
|
44
|
+
* const signedRequest = await client.signSignatureRequest(preparedCalls.signatureRequest);
|
|
45
|
+
*
|
|
46
|
+
* // Then send the prepared calls with the signature
|
|
47
|
+
* const result = await client.sendPreparedCalls({
|
|
48
|
+
* ...preparedCalls,
|
|
49
|
+
* signature: signedRequest.signature,
|
|
50
|
+
* });
|
|
51
|
+
*/
|
|
15
52
|
export async function sendPreparedCalls(
|
|
16
53
|
client: InnerWalletApiClient,
|
|
17
54
|
params: SendPreparedCallsParams,
|
|
@@ -5,13 +5,30 @@ import {
|
|
|
5
5
|
type JsonRpcAccount,
|
|
6
6
|
type SignableMessage,
|
|
7
7
|
} from "viem";
|
|
8
|
-
import type { InnerWalletApiClient } from "../../types";
|
|
8
|
+
import type { InnerWalletApiClient } from "../../types.ts";
|
|
9
9
|
import { requestAccount } from "./requestAccount.js";
|
|
10
10
|
|
|
11
|
-
export type SignMessageParams = SignableMessage;
|
|
11
|
+
export type SignMessageParams = { message: SignableMessage; account?: Address };
|
|
12
12
|
|
|
13
13
|
export type SignMessageResult = Hex;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Signs a message using the smart account.
|
|
17
|
+
* This method requests the account associated with the signer and uses it to sign the message.
|
|
18
|
+
*
|
|
19
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
20
|
+
* @param {SmartAccountSigner} signer - The signer of the smart account
|
|
21
|
+
* @param {SignableMessage} message - The message to sign
|
|
22
|
+
* @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Sign a simple text message
|
|
26
|
+
* const signature = await client.signMessage("Hello, world!");
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Sign a raw hex message
|
|
30
|
+
* const signature = await client.signMessage({ raw: "0x48656c6c6f2c20776f726c6421" });
|
|
31
|
+
*/
|
|
15
32
|
export async function signMessage<
|
|
16
33
|
TAccount extends JsonRpcAccount<Address> | undefined =
|
|
17
34
|
| JsonRpcAccount<Address>
|
|
@@ -27,6 +44,9 @@ export async function signMessage(
|
|
|
27
44
|
signer: SmartAccountSigner,
|
|
28
45
|
params: SignMessageParams,
|
|
29
46
|
): Promise<SignMessageResult> {
|
|
30
|
-
const account = await requestAccount(client, signer
|
|
31
|
-
|
|
47
|
+
const account = await requestAccount(client, signer, {
|
|
48
|
+
accountAddress: params.account ?? client.account?.address,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return account.signMessageWith6492({ message: params.message });
|
|
32
52
|
}
|
|
@@ -11,6 +11,37 @@ export type SignSignatureRequestResult = {
|
|
|
11
11
|
signature: Hex;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Signs a signature request using the provided signer.
|
|
16
|
+
* This method handles different types of signature requests including personal_sign and eth_signTypedData_v4.
|
|
17
|
+
*
|
|
18
|
+
* @param {SmartAccountSigner} signer - The signer to use for signing the request
|
|
19
|
+
* @param {SignSignatureRequestParams} params - The signature request parameters
|
|
20
|
+
* @param {string} params.type - The type of signature request ('personal_sign' or 'eth_signTypedData_v4')
|
|
21
|
+
* @param {any} params.data - The data to sign, format depends on the signature type
|
|
22
|
+
* @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result
|
|
23
|
+
* @returns {string} result.type - The signature type (currently only 'ecdsa' is supported)
|
|
24
|
+
* @returns {Hex} result.signature - The hex-encoded signature
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Sign a personal message
|
|
28
|
+
* const result = await client.signSignatureRequest({
|
|
29
|
+
* type: 'personal_sign',
|
|
30
|
+
* data: 'Hello, world!'
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Sign typed data (EIP-712)
|
|
35
|
+
* const result = await client.signSignatureRequest({
|
|
36
|
+
* type: 'eth_signTypedData_v4',
|
|
37
|
+
* data: {
|
|
38
|
+
* domain: { ... },
|
|
39
|
+
* types: { ... },
|
|
40
|
+
* primaryType: '...',
|
|
41
|
+
* message: { ... }
|
|
42
|
+
* }
|
|
43
|
+
* });
|
|
44
|
+
*/
|
|
14
45
|
export function signSignatureRequest(
|
|
15
46
|
signer: SmartAccountSigner,
|
|
16
47
|
params: SignSignatureRequestParams,
|
|
@@ -5,13 +5,46 @@ import {
|
|
|
5
5
|
type JsonRpcAccount,
|
|
6
6
|
type TypedDataDefinition,
|
|
7
7
|
} from "viem";
|
|
8
|
-
import type { InnerWalletApiClient } from "../../types";
|
|
8
|
+
import type { InnerWalletApiClient } from "../../types.ts";
|
|
9
9
|
import { requestAccount } from "./requestAccount.js";
|
|
10
10
|
|
|
11
|
-
export type SignTypedDataParams = TypedDataDefinition
|
|
11
|
+
export type SignTypedDataParams = TypedDataDefinition & {
|
|
12
|
+
account?: Address;
|
|
13
|
+
};
|
|
12
14
|
|
|
13
15
|
export type SignTypedDataResult = Hex;
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Signs typed data (EIP-712) using the smart account.
|
|
19
|
+
* This method requests the account associated with the signer and uses it to sign the typed data.
|
|
20
|
+
*
|
|
21
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
22
|
+
* @param {SmartAccountSigner} signer - The signer of the smart account
|
|
23
|
+
* @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format
|
|
24
|
+
* @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Sign typed data
|
|
28
|
+
* const signature = await client.signTypedData({
|
|
29
|
+
* domain: {
|
|
30
|
+
* name: 'Example DApp',
|
|
31
|
+
* version: '1',
|
|
32
|
+
* chainId: 1,
|
|
33
|
+
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
|
|
34
|
+
* },
|
|
35
|
+
* types: {
|
|
36
|
+
* Person: [
|
|
37
|
+
* { name: 'name', type: 'string' },
|
|
38
|
+
* { name: 'wallet', type: 'address' }
|
|
39
|
+
* ]
|
|
40
|
+
* },
|
|
41
|
+
* primaryType: 'Person',
|
|
42
|
+
* message: {
|
|
43
|
+
* name: 'John Doe',
|
|
44
|
+
* wallet: '0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa'
|
|
45
|
+
* }
|
|
46
|
+
* });
|
|
47
|
+
*/
|
|
15
48
|
export async function signTypedData<
|
|
16
49
|
TAccount extends JsonRpcAccount<Address> | undefined =
|
|
17
50
|
| JsonRpcAccount<Address>
|
|
@@ -27,6 +60,9 @@ export async function signTypedData(
|
|
|
27
60
|
signer: SmartAccountSigner,
|
|
28
61
|
params: SignTypedDataParams,
|
|
29
62
|
): Promise<SignTypedDataResult> {
|
|
30
|
-
const account = await requestAccount(client, signer
|
|
63
|
+
const account = await requestAccount(client, signer, {
|
|
64
|
+
accountAddress: params.account ?? client.account?.address,
|
|
65
|
+
});
|
|
66
|
+
|
|
31
67
|
return account.signTypedDataWith6492(params);
|
|
32
68
|
}
|
|
@@ -32,6 +32,27 @@ describe("Client E2E Tests", () => {
|
|
|
32
32
|
transport,
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
it("should successfully request account with different salt", async () => {
|
|
36
|
+
const account = await client.requestAccount({
|
|
37
|
+
id: "2d00c64e-2e55-4925-832e-e288dbf1139e",
|
|
38
|
+
creationHint: { salt: "0x1" },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(account.address).toMatchInlineSnapshot(
|
|
42
|
+
`"0x569bCECaC47Ef9706c4b2370f2891bccd4cdE30c"`,
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should not cache account if different inputs provided", async () => {
|
|
47
|
+
const account = await client.requestAccount();
|
|
48
|
+
const account2 = await client.requestAccount({
|
|
49
|
+
id: "2d00c64e-2e55-4925-832e-e288dbf1139e",
|
|
50
|
+
creationHint: { salt: "0x1" },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(account.address).not.toEqual(account2.address);
|
|
54
|
+
});
|
|
55
|
+
|
|
35
56
|
it("should successfully get a counterfactual address", async () => {
|
|
36
57
|
const account = await client.requestAccount();
|
|
37
58
|
expect(account.address).toMatchInlineSnapshot(
|
|
@@ -42,14 +63,10 @@ describe("Client E2E Tests", () => {
|
|
|
42
63
|
it("can correctly sign a message", async () => {
|
|
43
64
|
const account = await client.requestAccount();
|
|
44
65
|
const message = "hello world";
|
|
45
|
-
const signature = await client.signMessage(message);
|
|
46
|
-
const publicClient = createPublicClient({
|
|
47
|
-
chain: arbitrumSepolia,
|
|
48
|
-
transport,
|
|
49
|
-
});
|
|
66
|
+
const signature = await client.signMessage({ message });
|
|
50
67
|
const isValid = await publicClient.verifyMessage({
|
|
51
68
|
address: account.address,
|
|
52
|
-
message
|
|
69
|
+
message,
|
|
53
70
|
signature,
|
|
54
71
|
});
|
|
55
72
|
expect(isValid).toBeTrue();
|
|
@@ -66,6 +83,43 @@ describe("Client E2E Tests", () => {
|
|
|
66
83
|
expect(isValid).toBeTrue();
|
|
67
84
|
});
|
|
68
85
|
|
|
86
|
+
it("can correctly sign a message with a different account", async () => {
|
|
87
|
+
const account = await client.requestAccount({
|
|
88
|
+
id: "2d00c64e-2e55-4925-832e-e288dbf1139e",
|
|
89
|
+
creationHint: { salt: "0x1" },
|
|
90
|
+
});
|
|
91
|
+
const message = "hello world";
|
|
92
|
+
|
|
93
|
+
const signature = await client.signMessage({
|
|
94
|
+
message,
|
|
95
|
+
account: account.address,
|
|
96
|
+
});
|
|
97
|
+
const isValid = await publicClient.verifyMessage({
|
|
98
|
+
address: account.address,
|
|
99
|
+
message,
|
|
100
|
+
signature,
|
|
101
|
+
});
|
|
102
|
+
expect(isValid).toBeTrue();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("can correctly sign typed data with a different account", async () => {
|
|
106
|
+
const account = await client.requestAccount({
|
|
107
|
+
id: "2d00c64e-2e55-4925-832e-e288dbf1139e",
|
|
108
|
+
creationHint: { salt: "0x1" },
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const signature = await client.signTypedData({
|
|
112
|
+
...givenTypedData,
|
|
113
|
+
account: account.address,
|
|
114
|
+
});
|
|
115
|
+
const isValid = await publicClient.verifyTypedData({
|
|
116
|
+
...givenTypedData,
|
|
117
|
+
signature,
|
|
118
|
+
address: account.address,
|
|
119
|
+
});
|
|
120
|
+
expect(isValid).toBeTrue();
|
|
121
|
+
});
|
|
122
|
+
|
|
69
123
|
it("should successfully send a UO with paymaster", async () => {
|
|
70
124
|
const account = await client.requestAccount();
|
|
71
125
|
const preparedUO = await client.prepareCalls({
|
|
@@ -164,14 +218,31 @@ describe("Client E2E Tests", () => {
|
|
|
164
218
|
);
|
|
165
219
|
});
|
|
166
220
|
|
|
221
|
+
it("should successfully request account with different salt", async () => {
|
|
222
|
+
const account = await client.requestAccount({
|
|
223
|
+
id: "8670d2d8-2781-49e9-a75c-1eb980271ca9",
|
|
224
|
+
creationHint: { salt: "0x1" },
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
expect(account.address).toMatchInlineSnapshot(
|
|
228
|
+
`"0xC9B8271E44f14be83CecfDE1dDb325e9fa15e9Ff"`,
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("should not cache account if different inputs provided", async () => {
|
|
233
|
+
const account = await client.requestAccount();
|
|
234
|
+
const account2 = await client.requestAccount({
|
|
235
|
+
id: "8670d2d8-2781-49e9-a75c-1eb980271ca9",
|
|
236
|
+
creationHint: { salt: "0x1" },
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
expect(account.address).not.toEqual(account2.address);
|
|
240
|
+
});
|
|
241
|
+
|
|
167
242
|
it("can correctly sign a message", async () => {
|
|
168
243
|
const account = await client.requestAccount();
|
|
169
244
|
const message = "hello world";
|
|
170
|
-
const signature = await client.signMessage(message);
|
|
171
|
-
const publicClient = createPublicClient({
|
|
172
|
-
chain: arbitrumSepolia,
|
|
173
|
-
transport,
|
|
174
|
-
});
|
|
245
|
+
const signature = await client.signMessage({ message });
|
|
175
246
|
const isValid = await publicClient.verifyMessage({
|
|
176
247
|
address: account.address,
|
|
177
248
|
message: "hello world",
|
|
@@ -191,6 +262,44 @@ describe("Client E2E Tests", () => {
|
|
|
191
262
|
expect(isValid).toBeTrue();
|
|
192
263
|
});
|
|
193
264
|
|
|
265
|
+
it("can correctly sign a message with a different account", async () => {
|
|
266
|
+
const account = await client.requestAccount({
|
|
267
|
+
id: "8670d2d8-2781-49e9-a75c-1eb980271ca9",
|
|
268
|
+
creationHint: { salt: "0x1" },
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const message = "hello world";
|
|
272
|
+
const signature = await client.signMessage({
|
|
273
|
+
message,
|
|
274
|
+
account: account.address,
|
|
275
|
+
});
|
|
276
|
+
const isValid = await publicClient.verifyMessage({
|
|
277
|
+
address: account.address,
|
|
278
|
+
message: "hello world",
|
|
279
|
+
signature,
|
|
280
|
+
});
|
|
281
|
+
expect(isValid).toBeTrue();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("can correctly sign typed data with a different account", async () => {
|
|
285
|
+
const account = await client.requestAccount({
|
|
286
|
+
id: "8670d2d8-2781-49e9-a75c-1eb980271ca9",
|
|
287
|
+
creationHint: { salt: "0x1" },
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
const signature = await client.signTypedData({
|
|
291
|
+
...givenTypedData,
|
|
292
|
+
account: account.address,
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const isValid = await publicClient.verifyTypedData({
|
|
296
|
+
...givenTypedData,
|
|
297
|
+
signature,
|
|
298
|
+
address: account.address,
|
|
299
|
+
});
|
|
300
|
+
expect(isValid).toBeTrue();
|
|
301
|
+
});
|
|
302
|
+
|
|
194
303
|
it("should successfully send a UO with paymaster", async () => {
|
|
195
304
|
const account = await client.requestAccount();
|
|
196
305
|
const preparedUO = await client.prepareCalls({
|
package/src/client/decorator.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
-
import type {
|
|
3
|
-
Hex,
|
|
4
|
-
JsonRpcAccount,
|
|
5
|
-
SignableMessage,
|
|
6
|
-
TypedDataDefinition,
|
|
7
|
-
} from "viem";
|
|
2
|
+
import type { Hex, JsonRpcAccount } from "viem";
|
|
8
3
|
import type {
|
|
9
4
|
SendPreparedCallsParams,
|
|
10
5
|
SendPreparedCallsResult,
|
|
11
|
-
} from "../isomorphic/actions/sendPreparedCalls";
|
|
12
|
-
import type { InnerWalletApiClient } from "../types";
|
|
6
|
+
} from "../isomorphic/actions/sendPreparedCalls.ts";
|
|
7
|
+
import type { InnerWalletApiClient } from "../types.ts";
|
|
13
8
|
import {
|
|
14
9
|
createAccount,
|
|
15
10
|
type CreateAccountParams,
|
|
@@ -41,13 +36,16 @@ import {
|
|
|
41
36
|
type RequestAccountResult,
|
|
42
37
|
} from "./actions/requestAccount.js";
|
|
43
38
|
import { sendPreparedCalls } from "./actions/sendPreparedCalls.js";
|
|
44
|
-
import { signMessage } from "./actions/signMessage.js";
|
|
39
|
+
import { signMessage, type SignMessageParams } from "./actions/signMessage.js";
|
|
45
40
|
import {
|
|
46
41
|
signSignatureRequest,
|
|
47
42
|
type SignSignatureRequestParams,
|
|
48
43
|
type SignSignatureRequestResult,
|
|
49
44
|
} from "./actions/signSignatureRequest.js";
|
|
50
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
signTypedData,
|
|
47
|
+
type SignTypedDataParams,
|
|
48
|
+
} from "./actions/signTypedData.js";
|
|
51
49
|
|
|
52
50
|
export type SmartWalletActions<
|
|
53
51
|
TAccount extends JsonRpcAccount | undefined = JsonRpcAccount | undefined,
|
|
@@ -69,8 +67,8 @@ export type SmartWalletActions<
|
|
|
69
67
|
signSignatureRequest: (
|
|
70
68
|
params: SignSignatureRequestParams,
|
|
71
69
|
) => Promise<SignSignatureRequestResult>;
|
|
72
|
-
signMessage: (params:
|
|
73
|
-
signTypedData: (params:
|
|
70
|
+
signMessage: (params: SignMessageParams) => Promise<Hex>;
|
|
71
|
+
signTypedData: (params: SignTypedDataParams) => Promise<Hex>;
|
|
74
72
|
grantPermissions: (
|
|
75
73
|
params: GrantPermissionsParams<TAccount>,
|
|
76
74
|
) => Promise<GrantPermissionsResult>;
|
package/src/client/index.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type Prettify,
|
|
1
|
+
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
+
import type {
|
|
3
|
+
Address,
|
|
4
|
+
Chain,
|
|
5
|
+
IsUndefined,
|
|
6
|
+
JsonRpcAccount,
|
|
7
|
+
Prettify,
|
|
9
8
|
} from "viem";
|
|
10
9
|
import { createLocalClient } from "../local/client.js";
|
|
11
10
|
import { createRemoteClient } from "../remote/client.js";
|
|
12
|
-
import type { InnerWalletApiClient } from "../types";
|
|
11
|
+
import type { InnerWalletApiClient } from "../types.ts";
|
|
13
12
|
import {
|
|
14
13
|
smartWalletClientActions,
|
|
15
14
|
type SmartWalletActions,
|
|
16
15
|
} from "./decorator.js";
|
|
16
|
+
import type { AlchemyTransport } from "@account-kit/infra";
|
|
17
17
|
|
|
18
18
|
export type SmartWalletClientParams<
|
|
19
19
|
TAccount extends JsonRpcAccount<Address> | undefined =
|
|
@@ -49,7 +49,38 @@ export function createSmartWalletClient<
|
|
|
49
49
|
params: SmartWalletClientParams<TAccount>,
|
|
50
50
|
): InnerWalletApiClient<TAccount> & SmartWalletActions<TAccount>;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Creates a smart wallet client that can be used to interact with a smart account.
|
|
54
|
+
*
|
|
55
|
+
* @param {SmartWalletClientParams} params - The parameters for creating the smart wallet client
|
|
56
|
+
* @param {AlchemyTransport} params.transport - The Alchemy transport to use
|
|
57
|
+
* @param {Chain} params.chain - The chain to use
|
|
58
|
+
* @param {SmartAccountSigner} params.signer - The signer to use for the smart account
|
|
59
|
+
* @param {"local" | "remote"} params.mode - The client's mode (local or remote).
|
|
60
|
+
* @param {string} [params.policyId] - The policy ID for gas sponsorship (optional)
|
|
61
|
+
* @param {Address} [params.account] - The smart account address to use (optional)
|
|
62
|
+
* @returns {InnerWalletApiClient & SmartWalletActions} - A viem-compatible client
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* import { LocalAccountSigner } from "@aa-sdk/core";
|
|
66
|
+
* import { alchemy, arbitrumSepolia } from "@account-kit/infra";
|
|
67
|
+
* import { generatePrivateKey } from "viem/accounts";
|
|
68
|
+
* import { createSmartWalletClient } from "@account-kit/wallet-apis"; // TODO(jh): update this if we change the pkg name to `@account-kit/wallet-client`
|
|
69
|
+
*
|
|
70
|
+
* const signer = LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey());
|
|
71
|
+
* const transport = alchemy({
|
|
72
|
+
* apiKey: "your-alchemy-api-key",
|
|
73
|
+
* });
|
|
74
|
+
* const client = createSmartWalletClient({
|
|
75
|
+
* transport,
|
|
76
|
+
* chain: arbitrumSepolia,
|
|
77
|
+
* mode: "remote",
|
|
78
|
+
* signer,
|
|
79
|
+
* });
|
|
80
|
+
*/
|
|
81
|
+
export function createSmartWalletClient(
|
|
82
|
+
params: SmartWalletClientParams,
|
|
83
|
+
): InnerWalletApiClient & SmartWalletActions {
|
|
53
84
|
const { transport, chain, policyId, mode, account, signer } = params;
|
|
54
85
|
|
|
55
86
|
const innerClient =
|
package/src/exports/index.ts
CHANGED
|
@@ -30,3 +30,4 @@ export { requestAccount } from "../client/actions/requestAccount.js";
|
|
|
30
30
|
export { signMessage } from "../client/actions/signMessage.js";
|
|
31
31
|
export { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
|
|
32
32
|
export { signTypedData } from "../client/actions/signTypedData.js";
|
|
33
|
+
export { grantPermissions } from "../client/actions/grantPermissions.js";
|
package/src/exports/internal.ts
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CachedAccount, InternalState } from "../types.ts";
|
|
2
|
+
|
|
3
|
+
export function internalStateDecorator(): InternalState {
|
|
4
|
+
let account: CachedAccount | undefined = undefined;
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
setAccount: (newAccount: CachedAccount) => {
|
|
8
|
+
account = newAccount;
|
|
9
|
+
},
|
|
10
|
+
getAccount: () => account,
|
|
11
|
+
};
|
|
12
|
+
}
|