@alchemy/wallet-apis 0.0.0-alpha.14 → 0.0.0-alpha.15
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/grantPermissions.js +9 -2
- package/dist/esm/actions/grantPermissions.js.map +1 -1
- package/dist/esm/actions/listAccounts.d.ts +10 -2
- package/dist/esm/actions/listAccounts.js +23 -2
- package/dist/esm/actions/listAccounts.js.map +1 -1
- package/dist/esm/actions/requestAccount.d.ts +10 -3
- package/dist/esm/actions/requestAccount.js +43 -15
- package/dist/esm/actions/requestAccount.js.map +1 -1
- package/dist/esm/actions/sendCalls.d.ts +4 -0
- package/dist/esm/actions/sendCalls.js +22 -1
- package/dist/esm/actions/sendCalls.js.map +1 -1
- package/dist/esm/actions/signMessage.js +5 -1
- package/dist/esm/actions/signMessage.js.map +1 -1
- package/dist/esm/actions/signPreparedCalls.js +6 -1
- package/dist/esm/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signSignatureRequest.d.ts +10 -3
- package/dist/esm/actions/signSignatureRequest.js +93 -42
- package/dist/esm/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/actions/signTypedData.js +5 -1
- package/dist/esm/actions/signTypedData.js.map +1 -1
- package/dist/esm/client.d.ts +4 -4
- package/dist/esm/client.js +3 -13
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/types.d.ts +4 -7
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/assertions.d.ts +6 -2
- package/dist/esm/utils/assertions.js +9 -0
- package/dist/esm/utils/assertions.js.map +1 -1
- package/dist/esm/utils/format.d.ts +3 -1
- package/dist/esm/utils/format.js +11 -1
- package/dist/esm/utils/format.js.map +1 -1
- package/dist/esm/utils/signer.d.ts +10 -0
- package/dist/esm/utils/signer.js +28 -0
- package/dist/esm/utils/signer.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/grantPermissions.d.ts.map +1 -1
- package/dist/types/actions/listAccounts.d.ts +10 -2
- package/dist/types/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/actions/requestAccount.d.ts +10 -3
- package/dist/types/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/actions/sendCalls.d.ts +4 -0
- package/dist/types/actions/sendCalls.d.ts.map +1 -1
- package/dist/types/actions/signMessage.d.ts.map +1 -1
- package/dist/types/actions/signPreparedCalls.d.ts.map +1 -1
- package/dist/types/actions/signSignatureRequest.d.ts +10 -3
- package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client.d.ts +4 -4
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/types.d.ts +4 -7
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/assertions.d.ts +6 -2
- package/dist/types/utils/assertions.d.ts.map +1 -1
- package/dist/types/utils/format.d.ts +3 -1
- package/dist/types/utils/format.d.ts.map +1 -1
- package/dist/types/utils/signer.d.ts +11 -0
- package/dist/types/utils/signer.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -5
- package/src/actions/grantPermissions.ts +13 -2
- package/src/actions/listAccounts.ts +39 -5
- package/src/actions/requestAccount.ts +67 -22
- package/src/actions/sendCalls.ts +33 -1
- package/src/actions/signMessage.ts +8 -0
- package/src/actions/signPreparedCalls.ts +14 -1
- package/src/actions/signSignatureRequest.ts +165 -54
- package/src/actions/signTypedData.ts +8 -0
- package/src/client.ts +5 -23
- package/src/types.ts +5 -5
- package/src/utils/assertions.ts +21 -2
- package/src/utils/format.ts +20 -1
- package/src/utils/signer.ts +36 -0
- package/src/version.ts +1 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { hexToNumber, serializeSignature } from "viem";
|
|
2
2
|
import { vToYParity } from "ox/Signature";
|
|
3
|
-
import { assertNever } from "@alchemy/common";
|
|
3
|
+
import { assertNever, BaseError } from "@alchemy/common";
|
|
4
|
+
import { LOGGER } from "../logger.js";
|
|
5
|
+
import { isLocalAccount, isWebAuthnAccount } from "../utils/assertions.js";
|
|
4
6
|
import { getAction } from "viem/utils";
|
|
5
7
|
import { signAuthorization, signMessage, signTypedData } from "viem/actions";
|
|
6
|
-
import { LOGGER } from "../logger.js";
|
|
7
8
|
/**
|
|
8
9
|
* Signs a signature request using the provided signer.
|
|
9
10
|
* This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
|
|
10
11
|
*
|
|
11
|
-
* @param {
|
|
12
|
+
* @param {InnerWalletApiClient} client - The wallet client to use for signing
|
|
12
13
|
* @param {SignSignatureRequestParams} params - The signature request parameters
|
|
13
14
|
* @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
|
|
14
15
|
* @param {SignSignatureRequestParams["data"]} params.data - The data to sign, format depends on the signature type
|
|
@@ -36,62 +37,112 @@ import { LOGGER } from "../logger.js";
|
|
|
36
37
|
*/
|
|
37
38
|
export async function signSignatureRequest(client, params) {
|
|
38
39
|
LOGGER.debug("signSignatureRequest:start", { type: params.type });
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
if (isWebAuthnAccount(client.owner)) {
|
|
41
|
+
return signWithWebAuthn(client.owner, params);
|
|
42
|
+
}
|
|
43
|
+
if (isLocalAccount(client.owner)) {
|
|
44
|
+
return signWithLocalAccount(client.owner, params);
|
|
45
|
+
}
|
|
46
|
+
return signWithSignerClient(client.owner, params);
|
|
47
|
+
}
|
|
48
|
+
async function signWithWebAuthn(signer, params) {
|
|
44
49
|
switch (params.type) {
|
|
45
50
|
case "personal_sign": {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}),
|
|
52
|
-
};
|
|
53
|
-
LOGGER.debug("signSignatureRequest:personal_sign:ok");
|
|
54
|
-
return res;
|
|
51
|
+
const { signature, webauthn: metadata } = await signer.signMessage({
|
|
52
|
+
message: params.data,
|
|
53
|
+
});
|
|
54
|
+
LOGGER.debug("signSignatureRequest:webauthn:personal_sign:ok");
|
|
55
|
+
return { type: "webauthn-p256", data: { signature, metadata } };
|
|
55
56
|
}
|
|
56
57
|
case "eth_signTypedData_v4": {
|
|
57
|
-
const
|
|
58
|
+
const { signature, webauthn: metadata } = await signer.signTypedData(params.data);
|
|
59
|
+
LOGGER.debug("signSignatureRequest:webauthn:eth_signTypedData_v4:ok");
|
|
60
|
+
return { type: "webauthn-p256", data: { signature, metadata } };
|
|
61
|
+
}
|
|
62
|
+
case "eip7702Auth":
|
|
63
|
+
throw new BaseError("WebAuthn account cannot sign EIP-7702 authorization requests");
|
|
64
|
+
default:
|
|
65
|
+
LOGGER.warn("signSignatureRequest:unknown-type", {
|
|
66
|
+
type: params.type,
|
|
67
|
+
});
|
|
68
|
+
return assertNever(params, "Unexpected signature request type.");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function signWithLocalAccount(signer, params) {
|
|
72
|
+
switch (params.type) {
|
|
73
|
+
case "personal_sign": {
|
|
74
|
+
const data = await signer.signMessage({ message: params.data });
|
|
75
|
+
LOGGER.debug("signSignatureRequest:localAccount:personal_sign:ok");
|
|
76
|
+
return { type: "secp256k1", data };
|
|
77
|
+
}
|
|
78
|
+
case "eth_signTypedData_v4": {
|
|
79
|
+
const data = await signer.signTypedData(params.data);
|
|
80
|
+
LOGGER.debug("signSignatureRequest:localAccount:eth_signTypedData_v4:ok");
|
|
81
|
+
return { type: "secp256k1", data };
|
|
82
|
+
}
|
|
83
|
+
case "eip7702Auth": {
|
|
84
|
+
if (!signer.signAuthorization) {
|
|
85
|
+
throw new BaseError("Current signer does not support signing authorization requests");
|
|
86
|
+
}
|
|
87
|
+
const { r, s, v, yParity: _yParity, } = await signer.signAuthorization({
|
|
88
|
+
address: params.data.address,
|
|
89
|
+
chainId: hexToNumber(params.data.chainId),
|
|
90
|
+
nonce: hexToNumber(params.data.nonce),
|
|
91
|
+
});
|
|
92
|
+
const yParity = _yParity != null ? Number(_yParity) : vToYParity(Number(v));
|
|
93
|
+
LOGGER.debug("signSignatureRequest:localAccount:eip7702Auth:ok");
|
|
94
|
+
return {
|
|
58
95
|
type: "secp256k1",
|
|
59
|
-
data:
|
|
60
|
-
...params.data,
|
|
61
|
-
account: client.owner.account,
|
|
62
|
-
}),
|
|
96
|
+
data: serializeSignature({ r, s, yParity }),
|
|
63
97
|
};
|
|
64
|
-
|
|
65
|
-
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
LOGGER.warn("signSignatureRequest:unknown-type", {
|
|
101
|
+
type: params.type,
|
|
102
|
+
});
|
|
103
|
+
return assertNever(params, "Unexpected signature request type.");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
107
|
+
// SignerClient (WalletClient)
|
|
108
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
109
|
+
async function signWithSignerClient(signer, params) {
|
|
110
|
+
switch (params.type) {
|
|
111
|
+
case "personal_sign": {
|
|
112
|
+
const action = getAction(signer, signMessage, "signMessage");
|
|
113
|
+
const data = await action({
|
|
114
|
+
message: params.data,
|
|
115
|
+
account: signer.account,
|
|
116
|
+
});
|
|
117
|
+
LOGGER.debug("signSignatureRequest:signerClient:personal_sign:ok");
|
|
118
|
+
return { type: "secp256k1", data };
|
|
119
|
+
}
|
|
120
|
+
case "eth_signTypedData_v4": {
|
|
121
|
+
const action = getAction(signer, signTypedData, "signTypedData");
|
|
122
|
+
const data = await action({ ...params.data, account: signer.account });
|
|
123
|
+
LOGGER.debug("signSignatureRequest:signerClient:eth_signTypedData_v4:ok");
|
|
124
|
+
return { type: "secp256k1", data };
|
|
66
125
|
}
|
|
67
126
|
case "eip7702Auth": {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
account: client.owner.account,
|
|
127
|
+
const action = getAction(signer, signAuthorization, "signAuthorization");
|
|
128
|
+
const { r, s, v, yParity: _yParity, } = await action({
|
|
129
|
+
address: params.data.address,
|
|
130
|
+
chainId: hexToNumber(params.data.chainId),
|
|
131
|
+
nonce: hexToNumber(params.data.nonce),
|
|
132
|
+
account: signer.account,
|
|
75
133
|
});
|
|
76
|
-
// yParity *should* already be a number, but some 3rd
|
|
77
|
-
// party signers may mistakenly return it as a bigint.
|
|
78
134
|
const yParity = _yParity != null ? Number(_yParity) : vToYParity(Number(v));
|
|
79
|
-
|
|
135
|
+
LOGGER.debug("signSignatureRequest:signerClient:eip7702Auth:ok");
|
|
136
|
+
return {
|
|
80
137
|
type: "secp256k1",
|
|
81
|
-
data: serializeSignature({
|
|
82
|
-
r,
|
|
83
|
-
s,
|
|
84
|
-
yParity,
|
|
85
|
-
}),
|
|
138
|
+
data: serializeSignature({ r, s, yParity }),
|
|
86
139
|
};
|
|
87
|
-
LOGGER.debug("signSignatureRequest:eip7702Auth:ok");
|
|
88
|
-
return res;
|
|
89
140
|
}
|
|
90
141
|
default:
|
|
91
142
|
LOGGER.warn("signSignatureRequest:unknown-type", {
|
|
92
143
|
type: params.type,
|
|
93
144
|
});
|
|
94
|
-
return assertNever(params,
|
|
145
|
+
return assertNever(params, "Unexpected signature request type.");
|
|
95
146
|
}
|
|
96
147
|
}
|
|
97
148
|
//# sourceMappingURL=signSignatureRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../src/actions/signSignatureRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,WAAW,EAAiB,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAOhF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAA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YACX,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;YAClD,OAAO,GAAG,CAAC;QACb,CAAC;QACD,KAAK,aAAa,CAAC,CAAC,CAAC;YACnB,MAAM,EACJ,CAAC,EACD,CAAC,EACD,CAAC,EACD,OAAO,EAAE,QAAQ,GAClB,GAAG,MAAM,OAAO,CAAC,iBAAiB,CAAC;gBAClC,GAAG;oBACD,GAAG,MAAM,CAAC,IAAI;oBACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;oBACzC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;iBACtC;gBACD,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;aAC9B,CAAC,CAAC;YACH,qDAAqD;YACrD,sDAAsD;YACtD,MAAM,OAAO,GACX,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAE9D,MAAM,GAAG,GAAG;gBACV,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,CAAC;oBACD,CAAC;oBACD,OAAO;iBACR,CAAC;aACM,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;YACpD,OAAO,GAAG,CAAC;QACb,CAAC;QACD;YACE,MAAM,CAAC,IAAI,CAAC,mCAAmC,EAAE;gBAC/C,IAAI,EAAG,MAA6B,CAAC,IAAI;aAC1C,CAAC,CAAC;YACH,OAAO,WAAW,CAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["import { type Hex, hexToNumber, type Prettify, serializeSignature } from \"viem\";\nimport type {\n PersonalSignSignatureRequest,\n TypedDataSignatureRequest,\n AuthorizationSignatureRequest,\n Eip7702UnsignedAuth,\n} from \"@alchemy/wallet-api-types\";\nimport { vToYParity } from \"ox/Signature\";\nimport type { InnerWalletApiClient, WithoutRawPayload } from \"../types\";\nimport { assertNever } from \"@alchemy/common\";\nimport { getAction } from \"viem/utils\";\nimport { signAuthorization, signMessage, signTypedData } from \"viem/actions\";\nimport { LOGGER } from \"../logger.js\";\n\nexport type SignSignatureRequestParams = Prettify<\n WithoutRawPayload<\n | PersonalSignSignatureRequest\n | TypedDataSignatureRequest\n | (AuthorizationSignatureRequest & {\n data: Eip7702UnsignedAuth;\n })\n >\n>;\n\nexport type SignSignatureRequestResult = Prettify<{\n type: \"secp256k1\";\n data: Hex;\n}>;\n\n/**\n * Signs a signature request using the provided signer.\n * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.\n *\n * @param {SmartAccountSigner} signer - The signer to use for signing the request\n * @param {SignSignatureRequestParams} params - The signature request parameters\n * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')\n * @param {SignSignatureRequestParams[\"data\"]} params.data - The data to sign, format depends on the signature type\n * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result\n *\n * @example\n * ```ts\n * // Sign a personal message\n * const result = await client.signSignatureRequest({\n * type: 'personal_sign',\n * data: 'Hello, world!'\n * });\n *\n * // Sign typed data (EIP-712)\n * const result = await client.signSignatureRequest({\n * type: 'eth_signTypedData_v4',\n * data: {\n * domain: { ... },\n * types: { ... },\n * primaryType: '...',\n * message: { ... }\n * }\n * });\n * ```\n */\n\nexport async function signSignatureRequest(\n client: InnerWalletApiClient,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n LOGGER.debug(\"signSignatureRequest:start\", { type: params.type });\n const actions = {\n signMessage: getAction(client.owner, signMessage, \"signMessage\"),\n signTypedData: getAction(client.owner, signTypedData, \"signTypedData\"),\n signAuthorization: getAction(\n client.owner,\n signAuthorization,\n \"signAuthorization\",\n ),\n };\n\n switch (params.type) {\n case \"personal_sign\": {\n const res = {\n type: \"secp256k1\",\n data: await actions.signMessage({\n message: params.data,\n account: client.owner.account,\n }),\n } as const;\n LOGGER.debug(\"signSignatureRequest:personal_sign:ok\");\n return res;\n }\n case \"eth_signTypedData_v4\": {\n const res = {\n type: \"secp256k1\",\n data: await actions.signTypedData({\n ...params.data,\n account: client.owner.account,\n }),\n } as const;\n LOGGER.debug(\"signSignatureRequest:typedData:ok\");\n return res;\n }\n case \"eip7702Auth\": {\n const {\n r,\n s,\n v,\n yParity: _yParity,\n } = await actions.signAuthorization({\n ...{\n ...params.data,\n chainId: hexToNumber(params.data.chainId),\n nonce: hexToNumber(params.data.nonce),\n },\n account: client.owner.account,\n });\n // yParity *should* already be a number, but some 3rd\n // party signers may mistakenly return it as a bigint.\n const yParity =\n _yParity != null ? Number(_yParity) : vToYParity(Number(v));\n\n const res = {\n type: \"secp256k1\",\n data: serializeSignature({\n r,\n s,\n yParity,\n }),\n } as const;\n LOGGER.debug(\"signSignatureRequest:eip7702Auth:ok\");\n return res;\n }\n default:\n LOGGER.warn(\"signSignatureRequest:unknown-type\", {\n type: (params as { type?: unknown }).type,\n });\n return assertNever(params, `Unexpected signature request type.`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../src/actions/signSignatureRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,WAAW,EAAiB,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAOhF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAiC7E;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C,IAAI,EAAG,MAA6B,CAAC,IAAI;aAC1C,CAAC,CAAC;YACH,OAAO,WAAW,CAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["import { type Hex, hexToNumber, type Prettify, serializeSignature } from \"viem\";\nimport type {\n PersonalSignSignatureRequest,\n TypedDataSignatureRequest,\n AuthorizationSignatureRequest,\n Eip7702UnsignedAuth,\n} from \"@alchemy/wallet-api-types\";\nimport { vToYParity } from \"ox/Signature\";\nimport type {\n InnerWalletApiClient,\n SignerClient,\n WithoutRawPayload,\n} from \"../types\";\nimport { assertNever, BaseError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport { isLocalAccount, isWebAuthnAccount } from \"../utils/assertions.js\";\nimport { getAction } from \"viem/utils\";\nimport { signAuthorization, signMessage, signTypedData } from \"viem/actions\";\nimport type {\n WebAuthnSignReturnType,\n WebAuthnAccount,\n} from \"viem/account-abstraction\";\nimport type { LocalAccount } from \"viem\";\n\nexport type SignSignatureRequestParams = Prettify<\n WithoutRawPayload<\n | PersonalSignSignatureRequest\n | TypedDataSignatureRequest\n | (AuthorizationSignatureRequest & {\n data: Eip7702UnsignedAuth;\n })\n >\n>;\n\nexport type SignSignatureRequestResult =\n | {\n type: \"secp256k1\";\n data: Hex;\n }\n | {\n type: \"webauthn-p256\";\n data: {\n signature: Hex;\n metadata: Pick<\n WebAuthnSignReturnType[\"webauthn\"],\n \"clientDataJSON\" | \"authenticatorData\"\n >;\n };\n };\n\n/**\n * Signs a signature request using the provided signer.\n * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.\n *\n * @param {InnerWalletApiClient} client - The wallet client to use for signing\n * @param {SignSignatureRequestParams} params - The signature request parameters\n * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')\n * @param {SignSignatureRequestParams[\"data\"]} params.data - The data to sign, format depends on the signature type\n * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result\n *\n * @example\n * ```ts\n * // Sign a personal message\n * const result = await client.signSignatureRequest({\n * type: 'personal_sign',\n * data: 'Hello, world!'\n * });\n *\n * // Sign typed data (EIP-712)\n * const result = await client.signSignatureRequest({\n * type: 'eth_signTypedData_v4',\n * data: {\n * domain: { ... },\n * types: { ... },\n * primaryType: '...',\n * message: { ... }\n * }\n * });\n * ```\n */\n\nexport async function signSignatureRequest(\n client: InnerWalletApiClient,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n LOGGER.debug(\"signSignatureRequest:start\", { type: params.type });\n\n if (isWebAuthnAccount(client.owner)) {\n return signWithWebAuthn(client.owner, params);\n }\n\n if (isLocalAccount(client.owner)) {\n return signWithLocalAccount(client.owner, params);\n }\n\n return signWithSignerClient(client.owner, params);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// WebAuthn signer\n// ─────────────────────────────────────────────────────────────────────────────\n\ntype WebAuthnResult = Extract<\n SignSignatureRequestResult,\n { type: \"webauthn-p256\" }\n>;\n\nasync function signWithWebAuthn(\n signer: WebAuthnAccount,\n params: SignSignatureRequestParams,\n): Promise<WebAuthnResult> {\n switch (params.type) {\n case \"personal_sign\": {\n const { signature, webauthn: metadata } = await signer.signMessage({\n message: params.data,\n });\n LOGGER.debug(\"signSignatureRequest:webauthn:personal_sign:ok\");\n return { type: \"webauthn-p256\", data: { signature, metadata } };\n }\n case \"eth_signTypedData_v4\": {\n const { signature, webauthn: metadata } = await signer.signTypedData(\n params.data,\n );\n LOGGER.debug(\"signSignatureRequest:webauthn:eth_signTypedData_v4:ok\");\n return { type: \"webauthn-p256\", data: { signature, metadata } };\n }\n case \"eip7702Auth\":\n throw new BaseError(\n \"WebAuthn account cannot sign EIP-7702 authorization requests\",\n );\n default:\n LOGGER.warn(\"signSignatureRequest:unknown-type\", {\n type: (params as { type?: unknown }).type,\n });\n return assertNever(params, \"Unexpected signature request type.\");\n }\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// LocalAccount signer\n// ─────────────────────────────────────────────────────────────────────────────\n\ntype Secp256k1Result = Extract<\n SignSignatureRequestResult,\n { type: \"secp256k1\" }\n>;\n\nasync function signWithLocalAccount(\n signer: LocalAccount,\n params: SignSignatureRequestParams,\n): Promise<Secp256k1Result> {\n switch (params.type) {\n case \"personal_sign\": {\n const data = await signer.signMessage({ message: params.data });\n LOGGER.debug(\"signSignatureRequest:localAccount:personal_sign:ok\");\n return { type: \"secp256k1\", data };\n }\n case \"eth_signTypedData_v4\": {\n const data = await signer.signTypedData(params.data);\n LOGGER.debug(\"signSignatureRequest:localAccount:eth_signTypedData_v4:ok\");\n return { type: \"secp256k1\", data };\n }\n case \"eip7702Auth\": {\n if (!signer.signAuthorization) {\n throw new BaseError(\n \"Current signer does not support signing authorization requests\",\n );\n }\n const {\n r,\n s,\n v,\n yParity: _yParity,\n } = await signer.signAuthorization({\n address: params.data.address,\n chainId: hexToNumber(params.data.chainId),\n nonce: hexToNumber(params.data.nonce),\n });\n const yParity =\n _yParity != null ? Number(_yParity) : vToYParity(Number(v));\n LOGGER.debug(\"signSignatureRequest:localAccount:eip7702Auth:ok\");\n return {\n type: \"secp256k1\",\n data: serializeSignature({ r, s, yParity }),\n };\n }\n default:\n LOGGER.warn(\"signSignatureRequest:unknown-type\", {\n type: (params as { type?: unknown }).type,\n });\n return assertNever(params, \"Unexpected signature request type.\");\n }\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// SignerClient (WalletClient)\n// ─────────────────────────────────────────────────────────────────────────────\n\nasync function signWithSignerClient(\n signer: SignerClient,\n params: SignSignatureRequestParams,\n): Promise<Secp256k1Result> {\n switch (params.type) {\n case \"personal_sign\": {\n const action = getAction(signer, signMessage, \"signMessage\");\n const data = await action({\n message: params.data,\n account: signer.account,\n });\n LOGGER.debug(\"signSignatureRequest:signerClient:personal_sign:ok\");\n return { type: \"secp256k1\", data };\n }\n case \"eth_signTypedData_v4\": {\n const action = getAction(signer, signTypedData, \"signTypedData\");\n const data = await action({ ...params.data, account: signer.account });\n LOGGER.debug(\"signSignatureRequest:signerClient:eth_signTypedData_v4:ok\");\n return { type: \"secp256k1\", data };\n }\n case \"eip7702Auth\": {\n const action = getAction(signer, signAuthorization, \"signAuthorization\");\n const {\n r,\n s,\n v,\n yParity: _yParity,\n } = await action({\n address: params.data.address,\n chainId: hexToNumber(params.data.chainId),\n nonce: hexToNumber(params.data.nonce),\n account: signer.account,\n });\n const yParity =\n _yParity != null ? Number(_yParity) : vToYParity(Number(v));\n LOGGER.debug(\"signSignatureRequest:signerClient:eip7702Auth:ok\");\n return {\n type: \"secp256k1\",\n data: serializeSignature({ r, s, yParity }),\n };\n }\n default:\n LOGGER.warn(\"signSignatureRequest:unknown-type\", {\n type: (params as { type?: unknown }).type,\n });\n return assertNever(params, \"Unexpected signature request type.\");\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {} from "viem";
|
|
1
|
+
import { BaseError, } from "viem";
|
|
2
2
|
import { requestAccount } from "./requestAccount.js";
|
|
3
3
|
import { prepareSign } from "./prepareSign.js";
|
|
4
4
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
@@ -53,6 +53,10 @@ export async function signTypedData(client, params) {
|
|
|
53
53
|
},
|
|
54
54
|
});
|
|
55
55
|
const signed = await signSignatureRequest(client, prepared.signatureRequest);
|
|
56
|
+
// TODO: Wallet server needs to be updated to support webauthn here.
|
|
57
|
+
if (signed.type === "webauthn-p256") {
|
|
58
|
+
throw new BaseError("WebAuthn account is currently unsupported by wallet_formatSign");
|
|
59
|
+
}
|
|
56
60
|
const formatted = await formatSign(client, {
|
|
57
61
|
from: account.address,
|
|
58
62
|
signature: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signTypedData.js","sourceRoot":"","sources":["../../../src/actions/signTypedData.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"signTypedData.js","sourceRoot":"","sources":["../../../src/actions/signTyped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AC;QACpC,MAAM,IAAI,SAAS,CACjB,gEAAgE,CACjE,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE;QACzC,IAAI,EAAE,OAAO,CAAC,OAAO;QACrB,SAAS,EAAE;YACT,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9D,OAAO,SAAS,CAAC,SAAS,CAAC;AAC7B,CAAC","sourcesContent":["import {\n BaseError,\n type Address,\n type Hex,\n type Prettify,\n type TypedDataDefinition,\n} from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport { requestAccount } from \"./requestAccount.js\";\nimport { prepareSign } from \"./prepareSign.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { formatSign } from \"./formatSign.js\";\nimport { typedDataToJsonSafe } from \"../utils/format.js\";\nimport { LOGGER } from \"../logger.js\";\n\nexport type SignTypedDataParams = Prettify<\n TypedDataDefinition & {\n account?: Address;\n }\n>;\n\nexport type SignTypedDataResult = Prettify<Hex>;\n\n/**\n * Signs typed data (EIP-712) using the smart account.\n * This method requests the account associated with the signer and uses it to sign the typed data.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SignerClient} signerClient - The wallet client to use for signing\n * @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format\n * @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string\n *\n * @example\n * ```ts\n * // Sign typed data\n * const signature = await client.signTypedData({\n * domain: {\n * name: 'Example DApp',\n * version: '1',\n * chainId: 1,\n * verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'\n * },\n * types: {\n * Person: [\n * { name: 'name', type: 'string' },\n * { name: 'wallet', type: 'address' }\n * ]\n * },\n * primaryType: 'Person',\n * message: {\n * name: 'John Doe',\n * wallet: '0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa'\n * }\n * });\n * ```\n */\n\nexport async function signTypedData(\n client: InnerWalletApiClient,\n params: SignTypedDataParams,\n): Promise<SignTypedDataResult> {\n LOGGER.debug(\"signTypedData:start\", {\n hasExplicitAccount: params.account != null,\n primaryType: params.primaryType,\n });\n const accountAddress = params.account ?? client.account?.address;\n const account = await requestAccount(\n client,\n accountAddress != null ? { accountAddress } : undefined,\n );\n\n const prepared = await prepareSign(client, {\n from: account.address,\n signatureRequest: {\n type: \"eth_signTypedData_v4\",\n data: typedDataToJsonSafe(params),\n },\n });\n\n const signed = await signSignatureRequest(client, prepared.signatureRequest);\n\n // TODO: Wallet server needs to be updated to support webauthn here.\n if (signed.type === \"webauthn-p256\") {\n throw new BaseError(\n \"WebAuthn account is currently unsupported by wallet_formatSign\",\n );\n }\n\n const formatted = await formatSign(client, {\n from: account.address,\n signature: {\n type: \"ecdsa\",\n data: signed.data,\n },\n });\n LOGGER.debug(\"signTypedData:done\", { from: account.address });\n return formatted.signature;\n}\n"]}
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type Address, type Chain
|
|
1
|
+
import { type Address, type Chain } from "viem";
|
|
2
2
|
import { type AlchemyTransport } from "@alchemy/common";
|
|
3
|
-
import type {
|
|
3
|
+
import type { SmartWalletClient, SmartWalletSigner } from "./types.js";
|
|
4
4
|
import type { CreationOptionsBySignerAddress } from "@alchemy/wallet-api-types";
|
|
5
5
|
export type CreateSmartWalletClientParams<TAccount extends Address | undefined = Address | undefined> = {
|
|
6
|
-
signer:
|
|
6
|
+
signer: SmartWalletSigner;
|
|
7
7
|
transport: AlchemyTransport;
|
|
8
8
|
chain: Chain;
|
|
9
9
|
account?: TAccount;
|
|
@@ -14,7 +14,7 @@ export type CreateSmartWalletClientParams<TAccount extends Address | undefined =
|
|
|
14
14
|
* Creates a smart wallet client with wallet API actions.
|
|
15
15
|
*
|
|
16
16
|
* @param {CreateSmartWalletClientParams} params - Parameters for creating the smart wallet client.
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {SmartWalletSigner} params.account - The account to use for signing.
|
|
18
18
|
* @param {AlchemyTransport} params.transport - The transport to use for RPC calls.
|
|
19
19
|
* @param {Chain} params.chain - The blockchain network to connect to.
|
|
20
20
|
* @param {string[]} params.policyIds - Optional policy IDs for paymaster service.
|
package/dist/esm/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createClient
|
|
1
|
+
import { createClient } from "viem";
|
|
2
2
|
import { smartWalletActions } from "./decorators/smartWalletActions.js";
|
|
3
3
|
import {} from "@alchemy/common";
|
|
4
4
|
import { createInternalState } from "./internal.js";
|
|
@@ -6,7 +6,7 @@ import { createInternalState } from "./internal.js";
|
|
|
6
6
|
* Creates a smart wallet client with wallet API actions.
|
|
7
7
|
*
|
|
8
8
|
* @param {CreateSmartWalletClientParams} params - Parameters for creating the smart wallet client.
|
|
9
|
-
* @param {
|
|
9
|
+
* @param {SmartWalletSigner} params.account - The account to use for signing.
|
|
10
10
|
* @param {AlchemyTransport} params.transport - The transport to use for RPC calls.
|
|
11
11
|
* @param {Chain} params.chain - The blockchain network to connect to.
|
|
12
12
|
* @param {string[]} params.policyIds - Optional policy IDs for paymaster service.
|
|
@@ -14,16 +14,6 @@ import { createInternalState } from "./internal.js";
|
|
|
14
14
|
*/
|
|
15
15
|
export const createSmartWalletClient = ({ account, transport, chain, signer, policyId, policyIds, }) => {
|
|
16
16
|
const _policyIds = [...(policyId ? [policyId] : []), ...(policyIds ?? [])];
|
|
17
|
-
// If the signer is a `LocalAccount` wrap it inside of a client now so
|
|
18
|
-
// downstream actions can just use `getAction` to get signing actions
|
|
19
|
-
// and `signerClient.account.address` to access the address.
|
|
20
|
-
const signerClient = "request" in signer
|
|
21
|
-
? signer
|
|
22
|
-
: createWalletClient({
|
|
23
|
-
account: signer,
|
|
24
|
-
transport,
|
|
25
|
-
chain,
|
|
26
|
-
});
|
|
27
17
|
return createClient({
|
|
28
18
|
account,
|
|
29
19
|
transport,
|
|
@@ -33,7 +23,7 @@ export const createSmartWalletClient = ({ account, transport, chain, signer, pol
|
|
|
33
23
|
.extend(() => ({
|
|
34
24
|
policyIds: _policyIds,
|
|
35
25
|
internal: createInternalState(),
|
|
36
|
-
owner:
|
|
26
|
+
owner: signer,
|
|
37
27
|
}))
|
|
38
28
|
.extend((smartWalletActions));
|
|
39
29
|
};
|
package/dist/esm/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA4B,MAAM,MAAM,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAyB,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAkBpD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAErC,EACA,OAAO,EACP,SAAS,EACT,KAAK,EACL,MAAM,EACN,QAAQ,EACR,SAAS,GAC+B,EAA+B,EAAE;IACzE,MAAM,UAAU,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;IAE3E,OAAO,YAAY,CAAC;QAClB,OAAO;QACP,SAAS;QACT,KAAK;QACL,IAAI,EAAE,0BAA0B;KACjC,CAAC;SACC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QACb,SAAS,EAAE,UAAU;QACrB,QAAQ,EAAE,mBAAmB,EAAE;QAC/B,KAAK,EAAE,MAAM;KACd,CAAC,CAAC;SACF,MAAM,CAAC,CAAA,kBAA4B,CAAA,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAG,KAAK,EAC3D,YAAsD,EACtD,iBAEkC,EAAE,EACC,EAAE;IACvC,MAAM,oBAAoB,GAAG,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAEnE,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,cAAc,CACvD,gBAAgB,IAAI,cAAc;QAChC,CAAC,CAAC;YACE,cAAc,EAAE,cAAc,CAAC,cAAc;SAC9C;QACH,CAAC,CAAC;YACE,YAAY,EAAE,cAAc;SAC7B,CACN,CAAC;IAEF,OAAO,uBAAuB,CAAC;QAC7B,GAAG,YAAY;QACf,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { createClient, type Address, type Chain } from \"viem\";\nimport { smartWalletActions } from \"./decorators/smartWalletActions.js\";\nimport { type AlchemyTransport } from \"@alchemy/common\";\nimport type { SmartWalletClient, SmartWalletSigner } from \"./types.js\";\nimport { createInternalState } from \"./internal.js\";\nimport type { CreationOptionsBySignerAddress } from \"@alchemy/wallet-api-types\";\n\nexport type CreateSmartWalletClientParams<\n TAccount extends Address | undefined = Address | undefined,\n> = {\n signer: SmartWalletSigner;\n transport: AlchemyTransport;\n chain: Chain;\n account?: TAccount;\n // TODO(v5): Reconsider if the client store store the policyIds, especially as\n // new paymaster fields (i.e. for erc-20 support) are introduced. It might make\n // more sense for them to be stored at a higher level like in the wagmi config\n // or hooks.\n policyId?: string;\n policyIds?: string[];\n};\n\n/**\n * Creates a smart wallet client with wallet API actions.\n *\n * @param {CreateSmartWalletClientParams} params - Parameters for creating the smart wallet client.\n * @param {SmartWalletSigner} params.account - The account to use for signing.\n * @param {AlchemyTransport} params.transport - The transport to use for RPC calls.\n * @param {Chain} params.chain - The blockchain network to connect to.\n * @param {string[]} params.policyIds - Optional policy IDs for paymaster service.\n * @returns {WalletClient} A wallet client extended with smart wallet actions.\n */\nexport const createSmartWalletClient = <\n TAccount extends Address | undefined = Address | undefined,\n>({\n account,\n transport,\n chain,\n signer,\n policyId,\n policyIds,\n}: CreateSmartWalletClientParams<TAccount>): SmartWalletClient<TAccount> => {\n const _policyIds = [...(policyId ? [policyId] : []), ...(policyIds ?? [])];\n\n return createClient({\n account,\n transport,\n chain,\n name: \"alchemySmartWalletClient\",\n })\n .extend(() => ({\n policyIds: _policyIds,\n internal: createInternalState(),\n owner: signer,\n }))\n .extend(smartWalletActions<TAccount>);\n};\n\n/**\n * Creates a smart wallet client and requests an account in a single operation.\n * This is a convenience function that combines client creation with account initialization.\n *\n * @param {CreateSmartWalletClientParams<undefined>} clientParams - Parameters for creating the smart wallet client (without an account).\n * @param {CreationOptionsBySignerAddress | { accountAddress: Address }} accountOptions - Options for requesting the account. Can either be creation options for a new account or an object with an existing account address.\n * @returns {Promise<SmartWalletClient<Address>>} A promise that resolves to a smart wallet client with an initialized account.\n */\nexport const createSmartWalletClientAndRequestAccount = async (\n clientParams: CreateSmartWalletClientParams<undefined>,\n accountOptions:\n | CreationOptionsBySignerAddress\n | { accountAddress: Address } = {},\n): Promise<SmartWalletClient<Address>> => {\n const clientWithoutAccount = createSmartWalletClient(clientParams);\n\n const account = await clientWithoutAccount.requestAccount(\n \"accountAddress\" in accountOptions\n ? {\n accountAddress: accountOptions.accountAddress,\n }\n : {\n creationHint: accountOptions,\n },\n );\n\n return createSmartWalletClient({\n ...clientParams,\n account: account.address,\n });\n};\n"]}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
2
|
-
import type { Account, Address, Chain, Client, EIP1193Events, EIP1193RequestFn, Hex, JsonRpcAccount, Prettify, Transport, WalletClient } from "viem";
|
|
2
|
+
import type { Account, Address, Chain, Client, EIP1193Events, EIP1193RequestFn, Hex, JsonRpcAccount, Prettify, Transport, WalletClient, LocalAccount } from "viem";
|
|
3
3
|
import type { InternalState } from "./internal";
|
|
4
4
|
import type { SmartWalletClient1193Methods } from "./provider";
|
|
5
5
|
import type { SmartWalletActions } from "./decorators/smartWalletActions";
|
|
6
|
+
import type { WebAuthnAccount } from "viem/account-abstraction";
|
|
6
7
|
export type BaseWalletClient<TExtend extends {
|
|
7
8
|
[key: string]: unknown;
|
|
8
9
|
} | undefined = {
|
|
@@ -10,10 +11,11 @@ export type BaseWalletClient<TExtend extends {
|
|
|
10
11
|
} | undefined> = Client<Transport<"alchemyHttp">, Chain, JsonRpcAccount<Address> | undefined, WalletServerViemRpcSchema, TExtend>;
|
|
11
12
|
export type InnerWalletApiClient = BaseWalletClient<{
|
|
12
13
|
internal: InternalState | undefined;
|
|
13
|
-
owner:
|
|
14
|
+
owner: SmartWalletSigner;
|
|
14
15
|
policyIds?: string[];
|
|
15
16
|
}>;
|
|
16
17
|
export type SignerClient = WalletClient<Transport, Chain | undefined, Account>;
|
|
18
|
+
export type SmartWalletSigner = LocalAccount | WebAuthnAccount | SignerClient;
|
|
17
19
|
export type SmartWalletClientEip1193Provider = Prettify<EIP1193Events & {
|
|
18
20
|
request: EIP1193RequestFn<SmartWalletClient1193Methods>;
|
|
19
21
|
}>;
|
|
@@ -23,11 +25,6 @@ export type OptionalChainId<T> = T extends {
|
|
|
23
25
|
} ? Omit<T, "chainId"> & {
|
|
24
26
|
chainId?: Hex | undefined;
|
|
25
27
|
} : T;
|
|
26
|
-
export type OptionalSignerAddress<T> = T extends {
|
|
27
|
-
signerAddress: Address;
|
|
28
|
-
} ? Omit<T, "signerAddress"> & {
|
|
29
|
-
signerAddress?: Address | undefined;
|
|
30
|
-
} : T;
|
|
31
28
|
export type WithoutRawPayload<T> = T extends {
|
|
32
29
|
rawPayload: Hex;
|
|
33
30
|
} ? Omit<T, "rawPayload"> : T;
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { WalletServerViemRpcSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport type {\n Account,\n Address,\n Chain,\n Client,\n EIP1193Events,\n EIP1193RequestFn,\n Hex,\n JsonRpcAccount,\n Prettify,\n Transport,\n WalletClient,\n} from \"viem\";\nimport type { InternalState } from \"./internal\";\nimport type { SmartWalletClient1193Methods } from \"./provider\";\nimport type { SmartWalletActions } from \"./decorators/smartWalletActions\";\n\nexport type BaseWalletClient<\n TExtend extends { [key: string]: unknown } | undefined =\n | { [key: string]: unknown }\n | undefined,\n> = Client<\n Transport<\"alchemyHttp\">,\n Chain,\n JsonRpcAccount<Address> | undefined,\n WalletServerViemRpcSchema,\n TExtend\n>;\n\nexport type InnerWalletApiClient = BaseWalletClient<{\n internal: InternalState | undefined; // undefined if you want to skip using an internal cache\n owner:
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { WalletServerViemRpcSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport type {\n Account,\n Address,\n Chain,\n Client,\n EIP1193Events,\n EIP1193RequestFn,\n Hex,\n JsonRpcAccount,\n Prettify,\n Transport,\n WalletClient,\n LocalAccount,\n} from \"viem\";\nimport type { InternalState } from \"./internal\";\nimport type { SmartWalletClient1193Methods } from \"./provider\";\nimport type { SmartWalletActions } from \"./decorators/smartWalletActions\";\nimport type { WebAuthnAccount } from \"viem/account-abstraction\";\n\nexport type BaseWalletClient<\n TExtend extends { [key: string]: unknown } | undefined =\n | { [key: string]: unknown }\n | undefined,\n> = Client<\n Transport<\"alchemyHttp\">,\n Chain,\n JsonRpcAccount<Address> | undefined,\n WalletServerViemRpcSchema,\n TExtend\n>;\n\nexport type InnerWalletApiClient = BaseWalletClient<{\n internal: InternalState | undefined; // undefined if you want to skip using an internal cache\n owner: SmartWalletSigner;\n policyIds?: string[];\n}>;\n\nexport type SignerClient = WalletClient<Transport, Chain | undefined, Account>;\n\nexport type SmartWalletSigner = LocalAccount | WebAuthnAccount | SignerClient;\n\nexport type SmartWalletClientEip1193Provider = Prettify<\n EIP1193Events & {\n request: EIP1193RequestFn<SmartWalletClient1193Methods>;\n }\n>;\n\nexport type SmartWalletClient<\n TAccount extends Address | undefined = Address | undefined,\n> = BaseWalletClient<SmartWalletActions<TAccount>>;\n\nexport type OptionalChainId<T> = T extends { chainId: Hex }\n ? Omit<T, \"chainId\"> & { chainId?: Hex | undefined }\n : T;\n\nexport type WithoutRawPayload<T> = T extends { rawPayload: Hex }\n ? Omit<T, \"rawPayload\">\n : T;\n\nexport type Expect<T extends true> = T;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Client } from "viem";
|
|
2
|
-
import type { InnerWalletApiClient } from "../types.js";
|
|
1
|
+
import type { Client, LocalAccount } from "viem";
|
|
2
|
+
import type { InnerWalletApiClient, SignerClient } from "../types.js";
|
|
3
|
+
import type { WebAuthnAccount } from "viem/account-abstraction";
|
|
3
4
|
/**
|
|
4
5
|
* Type guard function to check if a client is an Alchemy Smart Wallet Client.
|
|
5
6
|
*
|
|
@@ -16,3 +17,6 @@ export declare function isSmartWalletClient(client: Client): client is InnerWall
|
|
|
16
17
|
* @throws {Error} Throws an error if the client is not an Alchemy Smart Wallet Client
|
|
17
18
|
*/
|
|
18
19
|
export declare function assertSmartWalletClient(client: Client, message?: string): asserts client is InnerWalletApiClient;
|
|
20
|
+
export declare function isLocalAccount(signer: LocalAccount | WebAuthnAccount | SignerClient): signer is LocalAccount;
|
|
21
|
+
export declare function isWebAuthnAccount(signer: LocalAccount | WebAuthnAccount | SignerClient): signer is WebAuthnAccount;
|
|
22
|
+
export declare function isSignerClient(signer: LocalAccount | WebAuthnAccount | SignerClient): signer is SignerClient;
|
|
@@ -21,4 +21,13 @@ export function assertSmartWalletClient(client, message = "Expected an Alchemy S
|
|
|
21
21
|
throw new BaseError(message);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
export function isLocalAccount(signer) {
|
|
25
|
+
return signer.type === "local";
|
|
26
|
+
}
|
|
27
|
+
export function isWebAuthnAccount(signer) {
|
|
28
|
+
return signer.type === "webAuthn";
|
|
29
|
+
}
|
|
30
|
+
export function isSignerClient(signer) {
|
|
31
|
+
return "request" in signer;
|
|
32
|
+
}
|
|
24
33
|
//# sourceMappingURL=assertions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertions.js","sourceRoot":"","sources":["../../../src/utils/assertions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"assertions.js","sourceRoot":"","sources":["../../../src/utils/assertions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAc;IAEd,OAAO,MAAM,CAAC,IAAI,KAAK,0BAA0B,IAAI,OAAO,IAAI,MAAM,CAAC;AACzE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAc,EACd,OAAO,GAAG,yCAAyC;IAEnD,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,MAAqD;IAErD,OAAO,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,MAAqD;IAErD,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,MAAqD;IAErD,OAAO,SAAS,IAAI,MAAM,CAAC;AAC7B,CAAC","sourcesContent":["import type { Client, LocalAccount } from \"viem\";\nimport type { InnerWalletApiClient, SignerClient } from \"../types.js\";\nimport { BaseError } from \"@alchemy/common\";\nimport type { WebAuthnAccount } from \"viem/account-abstraction\";\n\n/**\n * Type guard function to check if a client is an Alchemy Smart Wallet Client.\n *\n * @param {Client} client - The client to check\n * @returns {boolean} True if the client is an Alchemy Smart Wallet Client\n */\nexport function isSmartWalletClient(\n client: Client,\n): client is InnerWalletApiClient {\n return client.name === \"alchemySmartWalletClient\" && \"owner\" in client;\n}\n\n/**\n * Assertion function that throws an error if the client is not an Alchemy Smart Wallet Client.\n * After this function returns successfully, TypeScript will narrow the client type.\n *\n * @param {Client} client - The client to assert\n * @param {string} message - Custom error message if assertion fails\n * @throws {Error} Throws an error if the client is not an Alchemy Smart Wallet Client\n */\nexport function assertSmartWalletClient(\n client: Client,\n message = \"Expected an Alchemy Smart Wallet Client\",\n): asserts client is InnerWalletApiClient {\n if (!isSmartWalletClient(client)) {\n throw new BaseError(message);\n }\n}\n\nexport function isLocalAccount(\n signer: LocalAccount | WebAuthnAccount | SignerClient,\n): signer is LocalAccount {\n return signer.type === \"local\";\n}\n\nexport function isWebAuthnAccount(\n signer: LocalAccount | WebAuthnAccount | SignerClient,\n): signer is WebAuthnAccount {\n return signer.type === \"webAuthn\";\n}\n\nexport function isSignerClient(\n signer: LocalAccount | WebAuthnAccount | SignerClient,\n): signer is SignerClient {\n return \"request\" in signer;\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type Hex, type SignableMessage, type TypedDataDefinition } from "viem";
|
|
2
|
-
import type { TypedDataDefinition as WalletServerTypedDataDefinition } from "@alchemy/wallet-api-types";
|
|
2
|
+
import type { TypedDataDefinition as WalletServerTypedDataDefinition, WebAuthnPublicKey } from "@alchemy/wallet-api-types";
|
|
3
|
+
import type { ToWebAuthnAccountParameters } from "viem/account-abstraction";
|
|
3
4
|
export declare const castToHex: (val: string | number | bigint | Hex) => Hex;
|
|
4
5
|
export declare const signableMessageToJsonSafe: (message: SignableMessage) => string | {
|
|
5
6
|
raw: Hex;
|
|
6
7
|
};
|
|
7
8
|
export declare const typedDataToJsonSafe: ({ domain, primaryType, message, types, }: TypedDataDefinition) => WalletServerTypedDataDefinition;
|
|
9
|
+
export declare function credentialToWebAuthnPublicKey(credential: ToWebAuthnAccountParameters["credential"]): WebAuthnPublicKey;
|
package/dist/esm/utils/format.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isHex, toHex, bytesToHex, getTypesForEIP712Domain, } from "viem";
|
|
1
|
+
import { isHex, toHex, bytesToHex, getTypesForEIP712Domain, sliceHex, } from "viem";
|
|
2
2
|
export const castToHex = (val) => {
|
|
3
3
|
if (isHex(val)) {
|
|
4
4
|
return val;
|
|
@@ -34,4 +34,14 @@ export const typedDataToJsonSafe = ({ domain, primaryType, message, types, }) =>
|
|
|
34
34
|
message: JSON.parse(JSON.stringify(message, (_, v) => (typeof v === "bigint" ? toHex(v) : v))),
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
+
export function credentialToWebAuthnPublicKey(credential) {
|
|
38
|
+
const { x, y } = {
|
|
39
|
+
x: sliceHex(credential.publicKey, 0, 32, { strict: true }),
|
|
40
|
+
y: sliceHex(credential.publicKey, 32, 64, { strict: true }),
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
x,
|
|
44
|
+
y,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
37
47
|
//# sourceMappingURL=format.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/utils/format.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EAGL,UAAU,EAEV,uBAAuB,
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/utils/format.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,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BAAuB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;SACvD;QACD,WAAW;QACX,OAAO,EAAE,IAAI,CAAC,KAAK,CACjB,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC1E;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,6BAA6B,CAC3C,UAAqD;IAErD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAC1D,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;KAC5D,CAAC;IAEF,OAAO;QACL,CAAC;QACD,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n isHex,\n toHex,\n type Hex,\n type SignableMessage,\n bytesToHex,\n type TypedDataDefinition,\n getTypesForEIP712Domain,\n sliceHex,\n} from \"viem\";\nimport type {\n TypedDataDefinition as WalletServerTypedDataDefinition,\n WebAuthnPublicKey,\n} from \"@alchemy/wallet-api-types\";\nimport type { ToWebAuthnAccountParameters } from \"viem/account-abstraction\";\n\nexport const castToHex = (val: string | number | bigint | Hex): Hex => {\n if (isHex(val)) {\n return val;\n }\n return toHex(val);\n};\n\nexport const signableMessageToJsonSafe = (\n message: SignableMessage,\n): string | { raw: Hex } => {\n if (typeof message === \"string\") {\n return message;\n }\n return {\n raw:\n typeof message.raw === \"string\" ? message.raw : bytesToHex(message.raw),\n };\n};\n\n// Purposefully not using `formatTypedData` from the wallet server types pkg\n// here, since that would require typebox at runtime (which breaks RN).\nexport const typedDataToJsonSafe = ({\n domain,\n primaryType,\n message,\n types,\n}: TypedDataDefinition): WalletServerTypedDataDefinition => {\n return {\n domain: {\n ...domain,\n chainId:\n typeof domain?.chainId === \"bigint\"\n ? Number(domain.chainId)\n : domain?.chainId,\n },\n types: {\n ...Object.fromEntries(\n Object.entries(types).map(([key, value]) => [\n key,\n value ? [...value] : [],\n ]),\n ),\n EIP712Domain: [...getTypesForEIP712Domain({ domain })],\n },\n primaryType,\n message: JSON.parse(\n JSON.stringify(message, (_, v) => (typeof v === \"bigint\" ? toHex(v) : v)),\n ),\n };\n};\n\nexport function credentialToWebAuthnPublicKey(\n credential: ToWebAuthnAccountParameters[\"credential\"],\n): WebAuthnPublicKey {\n const { x, y } = {\n x: sliceHex(credential.publicKey, 0, 32, { strict: true }),\n y: sliceHex(credential.publicKey, 32, 64, { strict: true }),\n };\n\n return {\n x,\n y,\n };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { SmartWalletSigner } from "../types";
|
|
3
|
+
import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
|
|
4
|
+
export declare function getSignerAddressOrPublicKey(signer: SmartWalletSigner): {
|
|
5
|
+
type: "secp256k1";
|
|
6
|
+
address: Address;
|
|
7
|
+
} | {
|
|
8
|
+
type: "webauthn-p256";
|
|
9
|
+
publicKey: WebAuthnPublicKey;
|
|
10
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { toHex } from "viem";
|
|
2
|
+
import { parsePublicKey } from "webauthn-p256";
|
|
3
|
+
export function getSignerAddressOrPublicKey(signer) {
|
|
4
|
+
// SignerClient.
|
|
5
|
+
if ("request" in signer) {
|
|
6
|
+
return {
|
|
7
|
+
type: "secp256k1",
|
|
8
|
+
address: signer.account.address,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
// LocalAccount.
|
|
12
|
+
if (signer.type === "local") {
|
|
13
|
+
return {
|
|
14
|
+
type: "secp256k1",
|
|
15
|
+
address: signer.address,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
// WebAuthnAccount.
|
|
19
|
+
const key = parsePublicKey(signer.publicKey);
|
|
20
|
+
return {
|
|
21
|
+
type: "webauthn-p256",
|
|
22
|
+
publicKey: {
|
|
23
|
+
x: toHex(key.x),
|
|
24
|
+
y: toHex(key.y),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../src/utils/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgB,MAAM,MAAM,CAAC;AAG3C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,UAAU,2BAA2B,CACzC,MAAyB;IAIzB,gBAAgB;IAChB,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QACxB,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;SAChC,CAAC;IACJ,CAAC;IAED,gBAAgB;IAChB,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC;IACJ,CAAC;IAED,mBAAmB;IACnB,MAAM,GAAG,GAAG,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC7C,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,SAAS,EAAE;YACT,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YACf,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;SAChB;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { toHex, type Address } from \"viem\";\nimport type { SmartWalletSigner } from \"../types\";\nimport type { WebAuthnPublicKey } from \"@alchemy/wallet-api-types\";\nimport { parsePublicKey } from \"webauthn-p256\";\n\nexport function getSignerAddressOrPublicKey(\n signer: SmartWalletSigner,\n):\n | { type: \"secp256k1\"; address: Address }\n | { type: \"webauthn-p256\"; publicKey: WebAuthnPublicKey } {\n // SignerClient.\n if (\"request\" in signer) {\n return {\n type: \"secp256k1\",\n address: signer.account.address,\n };\n }\n\n // LocalAccount.\n if (signer.type === \"local\") {\n return {\n type: \"secp256k1\",\n address: signer.address,\n };\n }\n\n // WebAuthnAccount.\n const key = parsePublicKey(signer.publicKey);\n return {\n type: \"webauthn-p256\",\n publicKey: {\n x: toHex(key.x),\n y: toHex(key.y),\n },\n };\n}\n"]}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.0.0-alpha.14";
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"0.0.0-alpha.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"0.0.0-alpha.14\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grantPermissions.d.ts","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,SAAS,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,EAE1D,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,sBAAsB,CAAC,QAAQ,CAAC,GACvC,OAAO,CAAC,sBAAsB,CAAC,CAsCjC"}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import type { InnerWalletApiClient } from "../types.ts";
|
|
2
2
|
import type { Address, Prettify } from "viem";
|
|
3
3
|
import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
+
import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
|
|
4
5
|
type RpcSchema = Extract<WalletServerRpcSchemaType, {
|
|
5
6
|
Request: {
|
|
6
7
|
method: "wallet_listAccounts";
|
|
7
8
|
};
|
|
8
9
|
}>;
|
|
9
|
-
export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress"> & {
|
|
10
|
+
export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress"> & ({
|
|
10
11
|
signerAddress?: Address;
|
|
11
|
-
|
|
12
|
+
signerPublicKey?: never;
|
|
13
|
+
} | {
|
|
14
|
+
signerPublicKey: WebAuthnPublicKey;
|
|
15
|
+
signerAddress?: never;
|
|
16
|
+
} | {
|
|
17
|
+
signerAddress?: never;
|
|
18
|
+
signerPublicKey?: never;
|
|
19
|
+
})>;
|
|
12
20
|
export type ListAccountsResult = Prettify<RpcSchema["ReturnType"]>;
|
|
13
21
|
/**
|
|
14
22
|
* Lists all smart accounts for a given signer using the wallet API client.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listAccounts.d.ts","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,a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