@alchemy/wallet-apis 0.0.0-alpha.19 → 0.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions/formatSign.js +3 -4
- package/dist/esm/actions/formatSign.js.map +1 -1
- package/dist/esm/actions/grantPermissions.js +3 -4
- package/dist/esm/actions/grantPermissions.js.map +1 -1
- package/dist/esm/actions/listAccounts.js +3 -4
- package/dist/esm/actions/listAccounts.js.map +1 -1
- package/dist/esm/actions/prepareCalls.d.ts +14 -3
- package/dist/esm/actions/prepareCalls.js +19 -5
- package/dist/esm/actions/prepareCalls.js.map +1 -1
- package/dist/esm/actions/prepareSign.js +3 -4
- package/dist/esm/actions/prepareSign.js.map +1 -1
- package/dist/esm/actions/requestAccount.js +3 -4
- package/dist/esm/actions/requestAccount.js.map +1 -1
- package/dist/esm/actions/sendCalls.js +2 -5
- package/dist/esm/actions/sendCalls.js.map +1 -1
- package/dist/esm/actions/sendPreparedCalls.js +3 -4
- package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/experimental/actions/requestQuoteV0.js +3 -4
- package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
- package/dist/esm/utils/capabilities.d.ts +14 -7
- package/dist/esm/utils/capabilities.js +3 -2
- package/dist/esm/utils/capabilities.js.map +1 -1
- package/dist/esm/utils/schema.d.ts +3 -1
- package/dist/esm/utils/schema.js +58 -0
- package/dist/esm/utils/schema.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/actions/formatSign.d.ts.map +1 -1
- package/dist/types/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/actions/prepareCalls.d.ts +14 -3
- package/dist/types/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/actions/prepareSign.d.ts.map +1 -1
- package/dist/types/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/actions/sendCalls.d.ts.map +1 -1
- package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
- package/dist/types/utils/capabilities.d.ts +14 -7
- package/dist/types/utils/capabilities.d.ts.map +1 -1
- package/dist/types/utils/schema.d.ts +3 -1
- package/dist/types/utils/schema.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/actions/formatSign.ts +5 -4
- package/src/actions/grantPermissions.ts +9 -11
- package/src/actions/listAccounts.ts +5 -7
- package/src/actions/prepareCalls.ts +42 -6
- package/src/actions/prepareSign.ts +5 -4
- package/src/actions/requestAccount.ts +8 -7
- package/src/actions/sendCalls.ts +2 -8
- package/src/actions/sendPreparedCalls.ts +4 -6
- package/src/experimental/actions/requestQuoteV0.ts +5 -4
- package/src/utils/capabilities.ts +23 -11
- package/src/utils/schema.ts +79 -1
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../src/utils/capabilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../src/utils/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,IAAI,8BAA8B,EAC1D,6BAA6B,IAAI,mCAAmC,GACrE,MAAM,wCAAwC,CAAC;AA6ChD,SAAS,mBAAmB,CAC1B,KAAa;IAEb,OAAO,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,0BAA0B,CACjC,KAAa;IAEb,OAAO,CAAC,CAAC,kBAAkB,IAAI,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,YAGa;IAEb,IAAI,CAAC,YAAY;QAAE,OAAO,SAAS,CAAC;IACpC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,YAAY,CAAC;IAC5C,MAAM,MAAM,GACV,SAAS,KAAK,SAAS;QACrB,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE;QAC1C,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC;IAClB,IAAI,mBAAmB,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC/C,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,YAGa;IAEb,IAAI,CAAC,YAAY;QAAE,OAAO,SAAS,CAAC;IACpC,IAAI,kBAAkB,IAAI,YAAY,EAAE,CAAC;QACvC,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,YAAY,CAAC;QACnD,MAAM,MAAM,GACV,gBAAgB,KAAK,SAAS;YAC5B,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE;YAC1C,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC;QAClB,IAAI,0BAA0B,CAAC,MAAM,CAAC;YAAE,OAAO,MAAM,CAAC;QACtD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,0BAA0B,CAAC,YAAY,CAAC;QAAE,OAAO,YAAY,CAAC;IAClE,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAGrC,MAA4B,EAC5B,YAA2B,EACZ,EAAE;IACjB,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,IAAI,YAAY,EAAE,SAAS,EAAE,CAAC;QACzD,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,OAAO;QACL,GAAG,YAAY;QACf,SAAS,EACP,MAAM,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YAC3B,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;YACnC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE;KACjC,CAAC;AACT,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,YAAkD,EACP,EAAE;IAC7C,IAAI,YAAY,EAAE,WAAW,IAAI,IAAI,IAAI,YAAY,EAAE,SAAS,IAAI,IAAI,EAAE,CAAC;QACzE,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;IAEzC,OAAO;QACL,WAAW,EAAE,YAAY,CAAC,WAAW;QACrC,SAAS,EACP,SAAS,IAAI,IAAI;YACf,CAAC,CAAC;gBACE,GAAG,CAAC,UAAU,IAAI,SAAS;oBACzB,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE;oBAClC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC;gBACvC,WAAW,EAAE,SAAS,CAAC,WAAW;aACnC;YACH,CAAC,CAAC,SAAS;KAChB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n PrepareCallsCapabilities as PrepareCallsCapabilitiesSchema,\n SendPreparedCallsCapabilities as SendPreparedCallsCapabilitiesSchema,\n} from \"@alchemy/wallet-api-types/capabilities\";\nimport type { StaticDecode } from \"typebox\";\nimport type { InnerWalletApiClient } from \"../types.js\";\n\n/**\n * Decoded capabilities matching the schema shape (uses `paymasterService` key).\n * `ResolveCapabilities` renames this to `paymaster` for client-facing types.\n */\ntype DecodedPrepareCallsCaps = StaticDecode<\n typeof PrepareCallsCapabilitiesSchema\n>;\ntype DecodedSendPreparedCallsCaps = StaticDecode<\n typeof SendPreparedCallsCapabilitiesSchema\n>;\n\n/**\n * Renames `paymasterService` (RPC) to `paymaster` in a capabilities type. This\n * is because our RPC schema's paymasterService capability does not exactly match\n * the shape of the new spec, so we want to use a different name in our client\n * types to avoid confusion and be compatible with Viem's types.\n */\ntype ResolveCapabilities<T> = T extends {\n paymasterService?: infer P;\n}\n ? Omit<T, \"paymasterService\"> & { paymaster?: P }\n : T;\n\nexport type PrepareCallsCapabilities =\n ResolveCapabilities<DecodedPrepareCallsCaps>;\n\nexport type SendPreparedCallsCapabilities =\n ResolveCapabilities<DecodedSendPreparedCallsCaps>;\n\n/**\n * Transforms a type so that any `capabilities` field uses `paymaster`\n * instead of `paymasterService` (RPC).\n */\nexport type WithCapabilities<T> = T extends {\n capabilities?: infer C;\n}\n ? Omit<T, \"capabilities\"> & {\n capabilities?: ResolveCapabilities<NonNullable<C>>;\n }\n : T;\n\nfunction hasNoPaymasterField(\n value: object,\n): value is DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps {\n return !(\"paymaster\" in value);\n}\n\nfunction hasNoPaymasterServiceField(\n value: object,\n): value is PrepareCallsCapabilities | SendPreparedCallsCapabilities {\n return !(\"paymasterService\" in value);\n}\n\n/**\n * Converts capabilities (with `paymaster`) to RPC capabilities (with `paymasterService`)\n * for use with Value.Encode before sending to the RPC.\n *\n * @param {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} capabilities - Capabilities object containing a `paymaster` field\n * @returns {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} RPC capabilities with `paymasterService`, or undefined if input is undefined\n */\nexport function toRpcCapabilities(\n capabilities:\n | PrepareCallsCapabilities\n | SendPreparedCallsCapabilities\n | undefined,\n): DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined {\n if (!capabilities) return undefined;\n const { paymaster, ...rest } = capabilities;\n const result =\n paymaster !== undefined\n ? { ...rest, paymasterService: paymaster }\n : { ...rest };\n if (hasNoPaymasterField(result)) return result;\n return undefined;\n}\n\n/**\n * Converts RPC capabilities (with `paymasterService`) from Value.Decode\n * to capabilities (with `paymaster`).\n *\n * @param {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} capabilities - RPC capabilities object containing a `paymasterService` field\n * @returns {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} Capabilities with `paymaster`, or undefined if input is undefined\n */\nexport function fromRpcCapabilities(\n capabilities:\n | DecodedPrepareCallsCaps\n | DecodedSendPreparedCallsCaps\n | undefined,\n): PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined {\n if (!capabilities) return undefined;\n if (\"paymasterService\" in capabilities) {\n const { paymasterService, ...rest } = capabilities;\n const result =\n paymasterService !== undefined\n ? { ...rest, paymaster: paymasterService }\n : { ...rest };\n if (hasNoPaymasterServiceField(result)) return result;\n return undefined;\n }\n if (hasNoPaymasterServiceField(capabilities)) return capabilities;\n return undefined;\n}\n\n/**\n * Merges client capabilities with capabilities from the request.\n * Uses policyId (singular) when there's one policy, policyIds (array) when multiple.\n *\n * @param {InnerWalletApiClient} client - The inner wallet API client (potentially including global capabilities like policy IDs)\n * @param {T | undefined} capabilities - Request capabilities to merge with, if any\n * @returns {T | undefined} The merged capabilities object, or original capabilities if no capability configuration exists on the client\n */\nexport const mergeClientCapabilities = <\n T extends PrepareCallsCapabilities | SendPreparedCallsCapabilities,\n>(\n client: InnerWalletApiClient,\n capabilities: T | undefined,\n): T | undefined => {\n if (!client.policyIds?.length || capabilities?.paymaster) {\n return capabilities;\n }\n\n return {\n ...capabilities,\n paymaster:\n client.policyIds.length === 1\n ? { policyId: client.policyIds[0] }\n : { policyIds: client.policyIds },\n } as T;\n};\n\n/**\n * Extracts capabilities from prepareCalls that are usable for sendPreparedCalls.\n * Only permissions and paymaster (policyId/policyIds & webhookData) are supported.\n *\n * @param {PrepareCallsCapabilities | undefined} capabilities - The prepareCalls capabilities\n * @returns {SendPreparedCallsCapabilities | undefined} The sendPreparedCalls capabilities, or undefined if no relevant capabilities exist\n */\nexport const extractCapabilitiesForSending = (\n capabilities: PrepareCallsCapabilities | undefined,\n): SendPreparedCallsCapabilities | undefined => {\n if (capabilities?.permissions == null && capabilities?.paymaster == null) {\n return undefined;\n }\n\n const paymaster = capabilities.paymaster;\n\n return {\n permissions: capabilities.permissions,\n paymaster:\n paymaster != null\n ? {\n ...(\"policyId\" in paymaster\n ? { policyId: paymaster.policyId }\n : { policyIds: paymaster.policyIds }),\n webhookData: paymaster.webhookData,\n }\n : undefined,\n };\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TObject, TSchema, TTuple, StaticDecode } from "typebox";
|
|
1
|
+
import type { TObject, TSchema, TTuple, StaticDecode, StaticEncode } from "typebox";
|
|
2
2
|
/** Constraint for RPC method schemas from `@alchemy/wallet-api-types/rpc`. */
|
|
3
3
|
type RpcMethodSchema = TObject<{
|
|
4
4
|
Request: TObject<{
|
|
@@ -21,4 +21,6 @@ export declare function methodSchema<TReq extends TSchema, TRes extends TSchema>
|
|
|
21
21
|
export type MethodParams<T extends RpcMethodSchema> = StaticDecode<T["properties"]["Request"]["properties"]["params"]["items"][0]>;
|
|
22
22
|
/** Extracts the decoded response type from a method schema. */
|
|
23
23
|
export type MethodResponse<T extends RpcMethodSchema> = StaticDecode<T["properties"]["ReturnType"]>;
|
|
24
|
+
export declare function encode<const T extends TSchema>(schema: T, value: StaticDecode<T>): StaticEncode<T>;
|
|
25
|
+
export declare function decode<const T extends TSchema>(schema: T, value: StaticEncode<T>): StaticDecode<T>;
|
|
24
26
|
export {};
|
package/dist/esm/utils/schema.js
CHANGED
|
@@ -1,7 +1,65 @@
|
|
|
1
|
+
import { Value, EncodeError, DecodeError, Pointer } from "typebox/value";
|
|
2
|
+
import { BaseError } from "@alchemy/common";
|
|
1
3
|
export function methodSchema(schema) {
|
|
2
4
|
return {
|
|
3
5
|
request: schema.properties.Request.properties.params.items[0],
|
|
4
6
|
response: schema.properties.ReturnType,
|
|
5
7
|
};
|
|
6
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Formats an {@link EncodeError} or {@link DecodeError} into a human-readable
|
|
11
|
+
* string describing what went wrong, including the JSON path and the schema's
|
|
12
|
+
* custom error message (if any).
|
|
13
|
+
*
|
|
14
|
+
* @param {TSchema} schema - The TypeBox schema that validation was run against.
|
|
15
|
+
* @param {EncodeError | DecodeError} error - The error thrown by {@link Value.Encode} or {@link Value.Decode}.
|
|
16
|
+
* @returns {string} A formatted error string prefixed with `"Invalid params"`.
|
|
17
|
+
*/
|
|
18
|
+
function formatCodecError(schema, error) {
|
|
19
|
+
// Use only the first error — it's the most specific. Subsequent errors are
|
|
20
|
+
// typically cascade noise from union/anyOf branches.
|
|
21
|
+
const causeError = error.cause.errors[0];
|
|
22
|
+
// errors is typed as an open array — guard against the (practically
|
|
23
|
+
// impossible) empty case.
|
|
24
|
+
if (!causeError)
|
|
25
|
+
return "Invalid params";
|
|
26
|
+
const path = causeError.instancePath || "(root)";
|
|
27
|
+
// Prefer the schema's custom errorMessage annotation over the generic locale message.
|
|
28
|
+
let message = causeError.message;
|
|
29
|
+
const schemaPointer = causeError.schemaPath.replace(/^#/, "");
|
|
30
|
+
if (schemaPointer) {
|
|
31
|
+
const schemaNode = Pointer.Get(schema, schemaPointer);
|
|
32
|
+
if (schemaNode &&
|
|
33
|
+
typeof schemaNode === "object" &&
|
|
34
|
+
"errorMessage" in schemaNode &&
|
|
35
|
+
typeof schemaNode.errorMessage === "string") {
|
|
36
|
+
message = schemaNode.errorMessage;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return `Invalid params: ${path}: ${message}`;
|
|
40
|
+
}
|
|
41
|
+
// Type-safe wrapper around `Value.Encode` with human-readable errors.
|
|
42
|
+
export function encode(schema, value) {
|
|
43
|
+
try {
|
|
44
|
+
return Value.Encode(schema, value);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof EncodeError) {
|
|
48
|
+
throw new BaseError(formatCodecError(schema, error), { cause: error });
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Type-safe wrapper around `Value.Decode` with human-readable errors.
|
|
54
|
+
export function decode(schema, value) {
|
|
55
|
+
try {
|
|
56
|
+
return Value.Decode(schema, value);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof DecodeError) {
|
|
60
|
+
throw new BaseError(formatCodecError(schema, error), { cause: error });
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
7
65
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,UAAU,YAAY,CAC1B,MAGE;IAEF,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7D,QAAQ,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU;KACvC,CAAC;AACJ,CAAC;AAYD;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CACvB,MAAe,EACf,KAAgC;IAEhC,2EAA2E;IAC3E,qDAAqD;IACrD,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACzC,oEAAoE;IACpE,0BAA0B;IAC1B,IAAI,CAAC,UAAU;QAAE,OAAO,gBAAgB,CAAC;IAEzC,MAAM,IAAI,GAAG,UAAU,CAAC,YAAY,IAAI,QAAQ,CAAC;IAEjD,sFAAsF;IACtF,IAAI,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IACjC,MAAM,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9D,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QACtD,IACE,UAAU;YACV,OAAO,UAAU,KAAK,QAAQ;YAC9B,cAAc,IAAI,UAAU;YAC5B,OAAQ,UAAsC,CAAC,YAAY,KAAK,QAAQ,EACxE,CAAC;YACD,OAAO,GAAI,UAAsC,CAAC,YAAsB,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,OAAO,mBAAmB,IAAI,KAAK,OAAO,EAAE,CAAC;AAC/C,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,MAAM,CACpB,MAAS,EACT,KAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,MAAM,CACpB,MAAS,EACT,KAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type {\n TObject,\n TSchema,\n TTuple,\n StaticDecode,\n StaticEncode,\n} from \"typebox\";\nimport { Value, EncodeError, DecodeError, Pointer } from \"typebox/value\";\nimport { BaseError } from \"@alchemy/common\";\n\n/** Constraint for RPC method schemas from `@alchemy/wallet-api-types/rpc`. */\ntype RpcMethodSchema = TObject<{\n Request: TObject<{\n method: TSchema;\n params: TTuple<[TSchema, ...TSchema[]]>;\n }>;\n ReturnType: TSchema;\n}>;\n\nexport function methodSchema<TReq extends TSchema, TRes extends TSchema>(\n schema: TObject<{\n Request: TObject<{ method: TSchema; params: TTuple<[TReq, ...TSchema[]]> }>;\n ReturnType: TRes;\n }>,\n): { request: TReq; response: TRes } {\n return {\n request: schema.properties.Request.properties.params.items[0],\n response: schema.properties.ReturnType,\n };\n}\n\n/** Extracts the decoded params type from a method schema. */\nexport type MethodParams<T extends RpcMethodSchema> = StaticDecode<\n T[\"properties\"][\"Request\"][\"properties\"][\"params\"][\"items\"][0]\n>;\n\n/** Extracts the decoded response type from a method schema. */\nexport type MethodResponse<T extends RpcMethodSchema> = StaticDecode<\n T[\"properties\"][\"ReturnType\"]\n>;\n\n/**\n * Formats an {@link EncodeError} or {@link DecodeError} into a human-readable\n * string describing what went wrong, including the JSON path and the schema's\n * custom error message (if any).\n *\n * @param {TSchema} schema - The TypeBox schema that validation was run against.\n * @param {EncodeError | DecodeError} error - The error thrown by {@link Value.Encode} or {@link Value.Decode}.\n * @returns {string} A formatted error string prefixed with `\"Invalid params\"`.\n */\nfunction formatCodecError(\n schema: TSchema,\n error: EncodeError | DecodeError,\n): string {\n // Use only the first error — it's the most specific. Subsequent errors are\n // typically cascade noise from union/anyOf branches.\n const causeError = error.cause.errors[0];\n // errors is typed as an open array — guard against the (practically\n // impossible) empty case.\n if (!causeError) return \"Invalid params\";\n\n const path = causeError.instancePath || \"(root)\";\n\n // Prefer the schema's custom errorMessage annotation over the generic locale message.\n let message = causeError.message;\n const schemaPointer = causeError.schemaPath.replace(/^#/, \"\");\n if (schemaPointer) {\n const schemaNode = Pointer.Get(schema, schemaPointer);\n if (\n schemaNode &&\n typeof schemaNode === \"object\" &&\n \"errorMessage\" in schemaNode &&\n typeof (schemaNode as Record<string, unknown>).errorMessage === \"string\"\n ) {\n message = (schemaNode as Record<string, unknown>).errorMessage as string;\n }\n }\n\n return `Invalid params: ${path}: ${message}`;\n}\n\n// Type-safe wrapper around `Value.Encode` with human-readable errors.\nexport function encode<const T extends TSchema>(\n schema: T,\n value: StaticDecode<T>,\n): StaticEncode<T> {\n try {\n return Value.Encode(schema, value);\n } catch (error) {\n if (error instanceof EncodeError) {\n throw new BaseError(formatCodecError(schema, error), { cause: error });\n }\n throw error;\n }\n}\n\n// Type-safe wrapper around `Value.Decode` with human-readable errors.\nexport function decode<const T extends TSchema>(\n schema: T,\n value: StaticEncode<T>,\n): StaticDecode<T> {\n try {\n return Value.Decode(schema, value);\n } catch (error) {\n if (error instanceof DecodeError) {\n throw new BaseError(formatCodecError(schema, error), { cause: error });\n }\n throw error;\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.20";
|
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.20\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatSign.d.ts","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"formatSign.d.ts","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,oBAAoB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAC9D,KAAK,kBAAkB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAE9D,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CACrC,gBAAgB,CAAC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG;IAC3D,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CACF,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAqB3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grantPermissions.d.ts","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAa,MAAM,MAAM,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"grantPermissions.d.ts","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAa,MAAM,MAAM,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAGrF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,uBAAuB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAEjE,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAC3C,gBAAgB,CAAC,uBAAuB,EAAE,SAAS,GAAG,SAAS,CAAC,GAAG;IACjE,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CACF,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,OAAO,EAAE,GAAG,CAAC;CACd,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,sBAAsB,CAAC,CAkCjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listAccounts.d.ts","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"listAccounts.d.ts","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEpF,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,sBAAsB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAChE,KAAK,oBAAoB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAEhE,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CACvC,gBAAgB,CACd,sBAAsB,EACtB,eAAe,GAAG,iBAAiB,CACpC,GAAG;IACF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,KAAK,CAAC;CACzB,CACF,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAuB7B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Prettify } from "viem";
|
|
1
|
+
import type { Address, Prettify } from "viem";
|
|
2
2
|
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
3
|
-
import { type WithCapabilities } from "../utils/capabilities.js";
|
|
3
|
+
import { type PrepareCallsCapabilities, type WithCapabilities } from "../utils/capabilities.js";
|
|
4
4
|
import { type AccountParam } from "../utils/resolve.js";
|
|
5
5
|
import { wallet_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
6
6
|
import { type MethodParams, type MethodResponse } from "../utils/schema.js";
|
|
@@ -10,7 +10,18 @@ export type PrepareCallsParams = Prettify<WithCapabilities<DistributiveOmit<Base
|
|
|
10
10
|
account?: AccountParam;
|
|
11
11
|
chainId?: number;
|
|
12
12
|
}>>;
|
|
13
|
-
|
|
13
|
+
/** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */
|
|
14
|
+
type ClientModifiedRequest = Prettify<Omit<BasePrepareCallsParams, "from" | "capabilities"> & {
|
|
15
|
+
account: Address;
|
|
16
|
+
capabilities?: PrepareCallsCapabilities;
|
|
17
|
+
}>;
|
|
18
|
+
export type PrepareCallsResult = Exclude<PrepareCallsResponse, {
|
|
19
|
+
type: "paymaster-permit";
|
|
20
|
+
}> | (Omit<Extract<PrepareCallsResponse, {
|
|
21
|
+
type: "paymaster-permit";
|
|
22
|
+
}>, "modifiedRequest"> & {
|
|
23
|
+
modifiedRequest: ClientModifiedRequest;
|
|
24
|
+
});
|
|
14
25
|
/**
|
|
15
26
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
16
27
|
* Returns the built user operation and a signature request that needs to be signed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"prepareCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EAIL,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,sBAAsB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAChE,KAAK,oBAAoB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAEhE,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CACvC,gBAAgB,CACd,gBAAgB,CAAC,sBAAsB,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG;IAC7D,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CACF,CACF,CAAC;AAEF,2FAA2F;AAC3F,KAAK,qBAAqB,GAAG,QAAQ,CACnC,IAAI,CAAC,sBAAsB,EAAE,MAAM,GAAG,cAAc,CAAC,GAAG;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,wBAAwB,CAAC;CACzC,CACF,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC1B,OAAO,CAAC,oBAAoB,EAAE;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC,GAC3D,CAAC,IAAI,CACH,OAAO,CAAC,oBAAoB,EAAE;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC,EAC3D,iBAAiB,CAClB,GAAG;IACF,eAAe,EAAE,qBAAqB,CAAC;CACxC,CAAC,CAAC;AAEP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CA+C7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareSign.d.ts","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,kBAAkB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEnF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"prepareSign.d.ts","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,kBAAkB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEnF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,qBAAqB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAC/D,KAAK,mBAAmB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAE/D,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,CAC9C,qBAAqB,EACrB,MAAM,GAAG,SAAS,CACnB,GAAG;IACF,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAqB5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestAccount.d.ts","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAkB,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,qBAAqB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"requestAccount.d.ts","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAkB,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,qBAAqB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGvE,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,wBAAwB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAElE,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CACzC,gBAAgB,CACd,OAAO,CAAC,wBAAwB,EAAE;IAAE,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,EAC7D,eAAe,GAAG,2BAA2B,CAC9C,GACC,CACI;IAAE,aAAa,CAAC,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,KAAK,CAAA;CAAE,GACnD;IAAE,aAAa,CAAC,EAAE,KAAK,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAE,CACrD,CACJ,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,CAAC,EAAE,oBAAoB,GAC5B,OAAO,CAAC,oBAAoB,CAAC,CA6D/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"sendCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,wBAAwB,CAAC;AAKhC,MAAM,MAAM,eAAe,GAAG,QAAQ,CACpC,gBAAgB,CAAC,kBAAkB,EAAE,SAAS,CAAC,GAAG;IAChD,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;CAC3B,CACF,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,uBAAuB,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,eAAe,CAAC,CA2C1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendPreparedCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"sendPreparedCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,2BAA2B,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AACrE,KAAK,yBAAyB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAErE,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,gBAAgB,CACd,gBAAgB,CAAC,2BAA2B,EAAE,SAAS,CAAC,GAAG;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CACF,CACF,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,uBAAuB,CAAC,CA0BlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestQuoteV0.d.ts","sourceRoot":"","sources":["../../../../src/experimental/actions/requestQuoteV0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"requestQuoteV0.d.ts","sourceRoot":"","sources":["../../../../src/experimental/actions/requestQuoteV0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAG/B,KAAK,wBAAwB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;AAClE,KAAK,sBAAsB,GAAG,cAAc,CAAC,OAAO,YAAY,CAAC,CAAC;AAElE,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CACzC,gBAAgB,CACd,gBAAgB,CAAC,wBAAwB,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG;IAC/D,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CACF,CACF,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CA2B/B"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PrepareCallsCapabilities as PrepareCallsCapabilitiesSchema, SendPreparedCallsCapabilities as SendPreparedCallsCapabilitiesSchema } from "@alchemy/wallet-api-types/capabilities";
|
|
2
|
+
import type { StaticDecode } from "typebox";
|
|
2
3
|
import type { InnerWalletApiClient } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Decoded capabilities matching the schema shape (uses `paymasterService` key).
|
|
6
|
+
* `ResolveCapabilities` renames this to `paymaster` for client-facing types.
|
|
7
|
+
*/
|
|
8
|
+
type DecodedPrepareCallsCaps = StaticDecode<typeof PrepareCallsCapabilitiesSchema>;
|
|
9
|
+
type DecodedSendPreparedCallsCaps = StaticDecode<typeof SendPreparedCallsCapabilitiesSchema>;
|
|
3
10
|
/**
|
|
4
11
|
* Renames `paymasterService` (RPC) to `paymaster` in a capabilities type. This
|
|
5
12
|
* is because our RPC schema's paymasterService capability does not exactly match
|
|
@@ -11,8 +18,8 @@ type ResolveCapabilities<T> = T extends {
|
|
|
11
18
|
} ? Omit<T, "paymasterService"> & {
|
|
12
19
|
paymaster?: P;
|
|
13
20
|
} : T;
|
|
14
|
-
export type PrepareCallsCapabilities = ResolveCapabilities<
|
|
15
|
-
export type SendPreparedCallsCapabilities = ResolveCapabilities<
|
|
21
|
+
export type PrepareCallsCapabilities = ResolveCapabilities<DecodedPrepareCallsCaps>;
|
|
22
|
+
export type SendPreparedCallsCapabilities = ResolveCapabilities<DecodedSendPreparedCallsCaps>;
|
|
16
23
|
/**
|
|
17
24
|
* Transforms a type so that any `capabilities` field uses `paymaster`
|
|
18
25
|
* instead of `paymasterService` (RPC).
|
|
@@ -27,17 +34,17 @@ export type WithCapabilities<T> = T extends {
|
|
|
27
34
|
* for use with Value.Encode before sending to the RPC.
|
|
28
35
|
*
|
|
29
36
|
* @param {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} capabilities - Capabilities object containing a `paymaster` field
|
|
30
|
-
* @returns {
|
|
37
|
+
* @returns {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} RPC capabilities with `paymasterService`, or undefined if input is undefined
|
|
31
38
|
*/
|
|
32
|
-
export declare function toRpcCapabilities(capabilities: PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined):
|
|
39
|
+
export declare function toRpcCapabilities(capabilities: PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined): DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined;
|
|
33
40
|
/**
|
|
34
41
|
* Converts RPC capabilities (with `paymasterService`) from Value.Decode
|
|
35
42
|
* to capabilities (with `paymaster`).
|
|
36
43
|
*
|
|
37
|
-
* @param {
|
|
44
|
+
* @param {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} capabilities - RPC capabilities object containing a `paymasterService` field
|
|
38
45
|
* @returns {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} Capabilities with `paymaster`, or undefined if input is undefined
|
|
39
46
|
*/
|
|
40
|
-
export declare function fromRpcCapabilities(capabilities:
|
|
47
|
+
export declare function fromRpcCapabilities(capabilities: DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined): PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined;
|
|
41
48
|
/**
|
|
42
49
|
* Merges client capabilities with capabilities from the request.
|
|
43
50
|
* Uses policyId (singular) when there's one policy, policyIds (array) when multiple.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/utils/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/utils/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,IAAI,8BAA8B,EAC1D,6BAA6B,IAAI,mCAAmC,EACrE,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD;;;GAGG;AACH,KAAK,uBAAuB,GAAG,YAAY,CACzC,OAAO,8BAA8B,CACtC,CAAC;AACF,KAAK,4BAA4B,GAAG,YAAY,CAC9C,OAAO,mCAAmC,CAC3C,CAAC;AAEF;;;;;GAKG;AACH,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC,CAAC;CAC5B,GACG,IAAI,CAAC,CAAC,EAAE,kBAAkB,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,CAAC,CAAA;CAAE,GAC/C,CAAC,CAAC;AAEN,MAAM,MAAM,wBAAwB,GAClC,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;AAE/C,MAAM,MAAM,6BAA6B,GACvC,mBAAmB,CAAC,4BAA4B,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC,CAAC;CACxB,GACG,IAAI,CAAC,CAAC,EAAE,cAAc,CAAC,GAAG;IACxB,YAAY,CAAC,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;CACpD,GACD,CAAC,CAAC;AAcN;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EACR,wBAAwB,GACxB,6BAA6B,GAC7B,SAAS,GACZ,uBAAuB,GAAG,4BAA4B,GAAG,SAAS,CASpE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EACR,uBAAuB,GACvB,4BAA4B,GAC5B,SAAS,GACZ,wBAAwB,GAAG,6BAA6B,GAAG,SAAS,CAatE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAClC,CAAC,SAAS,wBAAwB,GAAG,6BAA6B,EAElE,QAAQ,oBAAoB,EAC5B,cAAc,CAAC,GAAG,SAAS,KAC1B,CAAC,GAAG,SAYN,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,GACxC,cAAc,wBAAwB,GAAG,SAAS,KACjD,6BAA6B,GAAG,SAmBlC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TObject, TSchema, TTuple, StaticDecode } from "typebox";
|
|
1
|
+
import type { TObject, TSchema, TTuple, StaticDecode, StaticEncode } from "typebox";
|
|
2
2
|
/** Constraint for RPC method schemas from `@alchemy/wallet-api-types/rpc`. */
|
|
3
3
|
type RpcMethodSchema = TObject<{
|
|
4
4
|
Request: TObject<{
|
|
@@ -21,5 +21,7 @@ export declare function methodSchema<TReq extends TSchema, TRes extends TSchema>
|
|
|
21
21
|
export type MethodParams<T extends RpcMethodSchema> = StaticDecode<T["properties"]["Request"]["properties"]["params"]["items"][0]>;
|
|
22
22
|
/** Extracts the decoded response type from a method schema. */
|
|
23
23
|
export type MethodResponse<T extends RpcMethodSchema> = StaticDecode<T["properties"]["ReturnType"]>;
|
|
24
|
+
export declare function encode<const T extends TSchema>(schema: T, value: StaticDecode<T>): StaticEncode<T>;
|
|
25
|
+
export declare function decode<const T extends TSchema>(schema: T, value: StaticEncode<T>): StaticDecode<T>;
|
|
24
26
|
export {};
|
|
25
27
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,MAAM,EACN,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAC;AAIjB,8EAA8E;AAC9E,KAAK,eAAe,GAAG,OAAO,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;QACf,MAAM,EAAE,OAAO,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC;KACzC,CAAC,CAAC;IACH,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC,CAAC;AAEH,wBAAgB,YAAY,CAAC,IAAI,SAAS,OAAO,EAAE,IAAI,SAAS,OAAO,EACrE,MAAM,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAA;KAAE,CAAC,CAAC;IAC5E,UAAU,EAAE,IAAI,CAAC;CAClB,CAAC,GACD;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAA;CAAE,CAKnC;AAED,6DAA6D;AAC7D,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,eAAe,IAAI,YAAY,CAChE,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAC/D,CAAC;AAEF,+DAA+D;AAC/D,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,eAAe,IAAI,YAAY,CAClE,CAAC,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,CAC9B,CAAC;AA2CF,wBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,OAAO,EAC5C,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GACrB,YAAY,CAAC,CAAC,CAAC,CASjB;AAGD,wBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,OAAO,EAC5C,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GACrB,YAAY,CAAC,CAAC,CAAC,CASjB"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.0.0-alpha.20";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alchemy/wallet-apis",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.21",
|
|
4
4
|
"description": "Alchemy Wallet APIs",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"typescript-template": "*"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@alchemy/common": "^0.0.0-alpha.
|
|
57
|
-
"@alchemy/wallet-api-types": "0.1.0-alpha.
|
|
56
|
+
"@alchemy/common": "^0.0.0-alpha.21",
|
|
57
|
+
"@alchemy/wallet-api-types": "0.1.0-alpha.25",
|
|
58
58
|
"deep-equal": "^2.2.3",
|
|
59
59
|
"ox": "^0.11.1",
|
|
60
60
|
"typebox": "^1.0.81",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
73
73
|
},
|
|
74
74
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "b253d0ee34fcb723a72d594d56b484188ac6867b"
|
|
76
76
|
}
|
|
@@ -3,9 +3,10 @@ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
|
3
3
|
import { wallet_formatSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
4
|
import { LOGGER } from "../logger.js";
|
|
5
5
|
import { resolveAddress, type AccountParam } from "../utils/resolve.js";
|
|
6
|
-
import { Value } from "typebox/value";
|
|
7
6
|
import {
|
|
8
7
|
methodSchema,
|
|
8
|
+
encode,
|
|
9
|
+
decode,
|
|
9
10
|
type MethodParams,
|
|
10
11
|
type MethodResponse,
|
|
11
12
|
} from "../utils/schema.js";
|
|
@@ -53,11 +54,11 @@ export async function formatSign(
|
|
|
53
54
|
LOGGER.debug("formatSign:start");
|
|
54
55
|
|
|
55
56
|
const { account: _, chainId: __, ...rest } = params;
|
|
56
|
-
const rpcParams =
|
|
57
|
+
const rpcParams = encode(schema.request, {
|
|
57
58
|
...rest,
|
|
58
59
|
from,
|
|
59
60
|
chainId: params.chainId ?? client.chain.id,
|
|
60
|
-
}
|
|
61
|
+
});
|
|
61
62
|
|
|
62
63
|
const rpcResp = await client.request({
|
|
63
64
|
method: "wallet_formatSign",
|
|
@@ -65,5 +66,5 @@ export async function formatSign(
|
|
|
65
66
|
});
|
|
66
67
|
|
|
67
68
|
LOGGER.debug("formatSign:done");
|
|
68
|
-
return
|
|
69
|
+
return decode(schema.response, rpcResp);
|
|
69
70
|
}
|
|
@@ -3,9 +3,13 @@ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
|
3
3
|
import { wallet_createSession as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
4
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
5
5
|
import { LOGGER } from "../logger.js";
|
|
6
|
-
import { Value } from "typebox/value";
|
|
7
6
|
import { resolveAddress, type AccountParam } from "../utils/resolve.js";
|
|
8
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
methodSchema,
|
|
9
|
+
encode,
|
|
10
|
+
decode,
|
|
11
|
+
type MethodParams,
|
|
12
|
+
} from "../utils/schema.js";
|
|
9
13
|
|
|
10
14
|
const schema = methodSchema(MethodSchema);
|
|
11
15
|
type BaseCreateSessionParams = MethodParams<typeof MethodSchema>;
|
|
@@ -88,24 +92,18 @@ export async function grantPermissions(
|
|
|
88
92
|
const chainId = params.chainId ?? client.chain.id;
|
|
89
93
|
|
|
90
94
|
const { account: _, chainId: __, ...rest } = params;
|
|
91
|
-
const rpcParams =
|
|
95
|
+
const rpcParams = encode(schema.request, {
|
|
92
96
|
...rest,
|
|
93
97
|
account,
|
|
94
98
|
chainId,
|
|
95
|
-
}
|
|
99
|
+
});
|
|
96
100
|
|
|
97
101
|
const rpcResp = await client.request({
|
|
98
102
|
method: "wallet_createSession",
|
|
99
103
|
params: [rpcParams],
|
|
100
104
|
});
|
|
101
105
|
|
|
102
|
-
const { sessionId, signatureRequest } =
|
|
103
|
-
schema.response,
|
|
104
|
-
rpcResp,
|
|
105
|
-
) satisfies {
|
|
106
|
-
sessionId: Hex;
|
|
107
|
-
signatureRequest: Parameters<typeof signSignatureRequest>[1];
|
|
108
|
-
};
|
|
106
|
+
const { sessionId, signatureRequest } = decode(schema.response, rpcResp);
|
|
109
107
|
|
|
110
108
|
const signature = await signSignatureRequest(client, signatureRequest);
|
|
111
109
|
|
|
@@ -3,9 +3,10 @@ import { LOGGER } from "../logger.js";
|
|
|
3
3
|
import type { Address, Prettify } from "viem";
|
|
4
4
|
import { wallet_listAccounts as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
5
|
import { isLocalAccount } from "../utils/assertions.js";
|
|
6
|
-
import { Value } from "typebox/value";
|
|
7
6
|
import {
|
|
8
7
|
methodSchema,
|
|
8
|
+
encode,
|
|
9
|
+
decode,
|
|
9
10
|
type MethodParams,
|
|
10
11
|
type MethodResponse,
|
|
11
12
|
} from "../utils/schema.js";
|
|
@@ -64,20 +65,17 @@ export async function listAccounts(
|
|
|
64
65
|
|
|
65
66
|
LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
|
|
66
67
|
|
|
67
|
-
const rpcParams =
|
|
68
|
+
const rpcParams = encode(schema.request, {
|
|
68
69
|
...params,
|
|
69
70
|
signerAddress,
|
|
70
|
-
}
|
|
71
|
+
});
|
|
71
72
|
|
|
72
73
|
const rpcResp = await client.request({
|
|
73
74
|
method: "wallet_listAccounts",
|
|
74
75
|
params: [rpcParams],
|
|
75
76
|
});
|
|
76
77
|
|
|
77
|
-
const res =
|
|
78
|
-
schema.response,
|
|
79
|
-
rpcResp,
|
|
80
|
-
) satisfies ListAccountsResult;
|
|
78
|
+
const res = decode(schema.response, rpcResp);
|
|
81
79
|
LOGGER.debug("listAccounts:done", { count: res.accounts.length });
|
|
82
80
|
|
|
83
81
|
return res;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import type { Prettify } from "viem";
|
|
1
|
+
import type { Address, Prettify } from "viem";
|
|
2
2
|
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
3
3
|
import { LOGGER } from "../logger.js";
|
|
4
4
|
import {
|
|
5
|
+
fromRpcCapabilities,
|
|
5
6
|
mergeClientCapabilities,
|
|
6
7
|
toRpcCapabilities,
|
|
8
|
+
type PrepareCallsCapabilities,
|
|
7
9
|
type WithCapabilities,
|
|
8
10
|
} from "../utils/capabilities.js";
|
|
9
11
|
import { resolveAddress, type AccountParam } from "../utils/resolve.js";
|
|
10
12
|
import { wallet_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
11
|
-
import { Value } from "typebox/value";
|
|
12
13
|
import {
|
|
13
14
|
methodSchema,
|
|
15
|
+
encode,
|
|
16
|
+
decode,
|
|
14
17
|
type MethodParams,
|
|
15
18
|
type MethodResponse,
|
|
16
19
|
} from "../utils/schema.js";
|
|
@@ -28,7 +31,22 @@ export type PrepareCallsParams = Prettify<
|
|
|
28
31
|
>
|
|
29
32
|
>;
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
/** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */
|
|
35
|
+
type ClientModifiedRequest = Prettify<
|
|
36
|
+
Omit<BasePrepareCallsParams, "from" | "capabilities"> & {
|
|
37
|
+
account: Address;
|
|
38
|
+
capabilities?: PrepareCallsCapabilities;
|
|
39
|
+
}
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
export type PrepareCallsResult =
|
|
43
|
+
| Exclude<PrepareCallsResponse, { type: "paymaster-permit" }>
|
|
44
|
+
| (Omit<
|
|
45
|
+
Extract<PrepareCallsResponse, { type: "paymaster-permit" }>,
|
|
46
|
+
"modifiedRequest"
|
|
47
|
+
> & {
|
|
48
|
+
modifiedRequest: ClientModifiedRequest;
|
|
49
|
+
});
|
|
32
50
|
|
|
33
51
|
/**
|
|
34
52
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
@@ -79,12 +97,12 @@ export async function prepareCalls(
|
|
|
79
97
|
});
|
|
80
98
|
|
|
81
99
|
const { account: _, chainId: __, ...rest } = params;
|
|
82
|
-
const rpcParams =
|
|
100
|
+
const rpcParams = encode(schema.request, {
|
|
83
101
|
...rest,
|
|
84
102
|
chainId,
|
|
85
103
|
from,
|
|
86
104
|
capabilities: toRpcCapabilities(capabilities),
|
|
87
|
-
}
|
|
105
|
+
});
|
|
88
106
|
|
|
89
107
|
const rpcResp = await client.request({
|
|
90
108
|
method: "wallet_prepareCalls",
|
|
@@ -92,5 +110,23 @@ export async function prepareCalls(
|
|
|
92
110
|
});
|
|
93
111
|
|
|
94
112
|
LOGGER.debug("prepareCalls:done");
|
|
95
|
-
|
|
113
|
+
const decoded = decode(schema.response, rpcResp);
|
|
114
|
+
|
|
115
|
+
// Transform paymaster-permit modifiedRequest from RPC format to client format:
|
|
116
|
+
// - `from` (RPC) → `account` (client)
|
|
117
|
+
// - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)
|
|
118
|
+
if (decoded.type === "paymaster-permit") {
|
|
119
|
+
const { from, capabilities, ...restModifiedRequest } =
|
|
120
|
+
decoded.modifiedRequest;
|
|
121
|
+
return {
|
|
122
|
+
...decoded,
|
|
123
|
+
modifiedRequest: {
|
|
124
|
+
...restModifiedRequest,
|
|
125
|
+
account: from,
|
|
126
|
+
capabilities: fromRpcCapabilities(capabilities),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return decoded;
|
|
96
132
|
}
|
|
@@ -2,9 +2,10 @@ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
|
2
2
|
import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
3
3
|
import { LOGGER } from "../logger.js";
|
|
4
4
|
import { resolveAddress, type AccountParam } from "../utils/resolve.js";
|
|
5
|
-
import { Value } from "typebox/value";
|
|
6
5
|
import {
|
|
7
6
|
methodSchema,
|
|
7
|
+
encode,
|
|
8
|
+
decode,
|
|
8
9
|
type MethodParams,
|
|
9
10
|
type MethodResponse,
|
|
10
11
|
} from "../utils/schema.js";
|
|
@@ -51,11 +52,11 @@ export async function prepareSign(
|
|
|
51
52
|
LOGGER.debug("prepareSign:start", { type: params.signatureRequest.type });
|
|
52
53
|
|
|
53
54
|
const { account: _, chainId: __, ...rest } = params;
|
|
54
|
-
const rpcParams =
|
|
55
|
+
const rpcParams = encode(schema.request, {
|
|
55
56
|
...rest,
|
|
56
57
|
from,
|
|
57
58
|
chainId: params.chainId ?? client.chain.id,
|
|
58
|
-
}
|
|
59
|
+
});
|
|
59
60
|
|
|
60
61
|
const rpcResp = await client.request({
|
|
61
62
|
method: "wallet_prepareSign",
|
|
@@ -63,5 +64,5 @@ export async function prepareSign(
|
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
LOGGER.debug("prepareSign:done");
|
|
66
|
-
return
|
|
67
|
+
return decode(schema.response, rpcResp);
|
|
67
68
|
}
|