@alchemy/wallet-apis 5.0.0-beta.28 → 5.0.0-beta.29
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/prepareCalls.d.ts +8 -3
- package/dist/esm/actions/prepareCalls.js +8 -0
- package/dist/esm/actions/prepareCalls.js.map +1 -1
- package/dist/esm/actions/requestAccount.d.ts +4 -3
- package/dist/esm/actions/requestAccount.js.map +1 -1
- package/dist/esm/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signPreparedCalls.js +1 -1
- package/dist/esm/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signSignatureRequest.d.ts +4 -4
- package/dist/esm/actions/signSignatureRequest.js +1 -1
- package/dist/esm/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/actions/signTypedData.d.ts +14 -4
- package/dist/esm/actions/signTypedData.js.map +1 -1
- package/dist/esm/actions/solana/getCallsStatus.d.ts +24 -0
- package/dist/esm/actions/solana/getCallsStatus.js +44 -0
- package/dist/esm/actions/solana/getCallsStatus.js.map +1 -0
- package/dist/esm/actions/solana/prepareCalls.d.ts +46 -0
- package/dist/esm/actions/solana/prepareCalls.js +70 -0
- package/dist/esm/actions/solana/prepareCalls.js.map +1 -0
- package/dist/esm/actions/solana/sendCalls.d.ts +34 -0
- package/dist/esm/actions/solana/sendCalls.js +44 -0
- package/dist/esm/actions/solana/sendCalls.js.map +1 -0
- package/dist/esm/actions/solana/sendPreparedCalls.d.ts +24 -0
- package/dist/esm/actions/solana/sendPreparedCalls.js +32 -0
- package/dist/esm/actions/solana/sendPreparedCalls.js.map +1 -0
- package/dist/esm/actions/solana/signPreparedCalls.d.ts +23 -0
- package/dist/esm/actions/solana/signPreparedCalls.js +24 -0
- package/dist/esm/actions/solana/signPreparedCalls.js.map +1 -0
- package/dist/esm/actions/solana/signSignatureRequest.d.ts +10 -0
- package/dist/esm/actions/solana/signSignatureRequest.js +33 -0
- package/dist/esm/actions/solana/signSignatureRequest.js.map +1 -0
- package/dist/esm/actions/solana/waitForCallsStatus.d.ts +24 -0
- package/dist/esm/actions/solana/waitForCallsStatus.js +46 -0
- package/dist/esm/actions/solana/waitForCallsStatus.js.map +1 -0
- package/dist/esm/adapters/SolanaSignerError.d.ts +4 -0
- package/dist/esm/adapters/SolanaSignerError.js +13 -0
- package/dist/esm/adapters/SolanaSignerError.js.map +1 -0
- package/dist/esm/adapters/fromKeypair.d.ts +21 -0
- package/dist/esm/adapters/fromKeypair.js +46 -0
- package/dist/esm/adapters/fromKeypair.js.map +1 -0
- package/dist/esm/adapters/fromKitSigner.d.ts +21 -0
- package/dist/esm/adapters/fromKitSigner.js +61 -0
- package/dist/esm/adapters/fromKitSigner.js.map +1 -0
- package/dist/esm/adapters/fromWalletAdapter.d.ts +26 -0
- package/dist/esm/adapters/fromWalletAdapter.js +45 -0
- package/dist/esm/adapters/fromWalletAdapter.js.map +1 -0
- package/dist/esm/adapters/fromWalletStandard.d.ts +31 -0
- package/dist/esm/adapters/fromWalletStandard.js +53 -0
- package/dist/esm/adapters/fromWalletStandard.js.map +1 -0
- package/dist/esm/adapters/resolveSignerSlot.d.ts +10 -0
- package/dist/esm/adapters/resolveSignerSlot.js +39 -0
- package/dist/esm/adapters/resolveSignerSlot.js.map +1 -0
- package/dist/esm/client.d.ts +29 -14
- package/dist/esm/client.js +63 -19
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/decorators/smartWalletActions.js +2 -2
- package/dist/esm/decorators/smartWalletActions.js.map +1 -1
- package/dist/esm/decorators/solanaSmartWalletActions.d.ts +16 -0
- package/dist/esm/decorators/solanaSmartWalletActions.js +16 -0
- package/dist/esm/decorators/solanaSmartWalletActions.js.map +1 -0
- package/dist/esm/experimental/actions/requestQuoteV0.d.ts +34 -7
- package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
- package/dist/esm/exports/index.d.ts +3 -3
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/solana.d.ts +24 -0
- package/dist/esm/exports/solana.js +15 -0
- package/dist/esm/exports/solana.js.map +1 -0
- package/dist/esm/types.d.ts +28 -4
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/assertions.d.ts +4 -2
- package/dist/esm/utils/assertions.js +6 -0
- package/dist/esm/utils/assertions.js.map +1 -1
- package/dist/esm/utils/capabilities.d.ts +22 -6
- package/dist/esm/utils/capabilities.js +19 -2
- package/dist/esm/utils/capabilities.js.map +1 -1
- package/dist/esm/utils/format.js +1 -1
- package/dist/esm/utils/format.js.map +1 -1
- package/dist/esm/utils/schema.d.ts +14 -14
- package/dist/esm/utils/schema.js +35 -39
- 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/prepareCalls.d.ts +8 -3
- package/dist/types/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/actions/requestAccount.d.ts +4 -3
- package/dist/types/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/actions/signSignatureRequest.d.ts +4 -4
- package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/actions/signTypedData.d.ts +14 -4
- package/dist/types/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/actions/solana/getCallsStatus.d.ts +25 -0
- package/dist/types/actions/solana/getCallsStatus.d.ts.map +1 -0
- package/dist/types/actions/solana/prepareCalls.d.ts +47 -0
- package/dist/types/actions/solana/prepareCalls.d.ts.map +1 -0
- package/dist/types/actions/solana/sendCalls.d.ts +35 -0
- package/dist/types/actions/solana/sendCalls.d.ts.map +1 -0
- package/dist/types/actions/solana/sendPreparedCalls.d.ts +25 -0
- package/dist/types/actions/solana/sendPreparedCalls.d.ts.map +1 -0
- package/dist/types/actions/solana/signPreparedCalls.d.ts +24 -0
- package/dist/types/actions/solana/signPreparedCalls.d.ts.map +1 -0
- package/dist/types/actions/solana/signSignatureRequest.d.ts +11 -0
- package/dist/types/actions/solana/signSignatureRequest.d.ts.map +1 -0
- package/dist/types/actions/solana/waitForCallsStatus.d.ts +25 -0
- package/dist/types/actions/solana/waitForCallsStatus.d.ts.map +1 -0
- package/dist/types/adapters/SolanaSignerError.d.ts +5 -0
- package/dist/types/adapters/SolanaSignerError.d.ts.map +1 -0
- package/dist/types/adapters/fromKeypair.d.ts +22 -0
- package/dist/types/adapters/fromKeypair.d.ts.map +1 -0
- package/dist/types/adapters/fromKitSigner.d.ts +22 -0
- package/dist/types/adapters/fromKitSigner.d.ts.map +1 -0
- package/dist/types/adapters/fromWalletAdapter.d.ts +27 -0
- package/dist/types/adapters/fromWalletAdapter.d.ts.map +1 -0
- package/dist/types/adapters/fromWalletStandard.d.ts +32 -0
- package/dist/types/adapters/fromWalletStandard.d.ts.map +1 -0
- package/dist/types/adapters/resolveSignerSlot.d.ts +11 -0
- package/dist/types/adapters/resolveSignerSlot.d.ts.map +1 -0
- package/dist/types/client.d.ts +29 -14
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/decorators/solanaSmartWalletActions.d.ts +17 -0
- package/dist/types/decorators/solanaSmartWalletActions.d.ts.map +1 -0
- package/dist/types/experimental/actions/requestQuoteV0.d.ts +34 -7
- package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +3 -3
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/solana.d.ts +25 -0
- package/dist/types/exports/solana.d.ts.map +1 -0
- package/dist/types/types.d.ts +28 -4
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/assertions.d.ts +4 -2
- package/dist/types/utils/assertions.d.ts.map +1 -1
- package/dist/types/utils/capabilities.d.ts +22 -6
- package/dist/types/utils/capabilities.d.ts.map +1 -1
- package/dist/types/utils/schema.d.ts +14 -14
- package/dist/types/utils/schema.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +26 -9
- package/src/actions/prepareCalls.ts +21 -3
- package/src/actions/requestAccount.ts +7 -5
- package/src/actions/sendPreparedCalls.ts +4 -1
- package/src/actions/signPreparedCalls.ts +1 -1
- package/src/actions/signSignatureRequest.ts +8 -8
- package/src/actions/signTypedData.ts +15 -12
- package/src/actions/solana/getCallsStatus.ts +79 -0
- package/src/actions/solana/prepareCalls.ts +120 -0
- package/src/actions/solana/sendCalls.ts +66 -0
- package/src/actions/solana/sendPreparedCalls.ts +65 -0
- package/src/actions/solana/signPreparedCalls.ts +50 -0
- package/src/actions/solana/signSignatureRequest.ts +63 -0
- package/src/actions/solana/waitForCallsStatus.ts +84 -0
- package/src/adapters/SolanaSignerError.ts +5 -0
- package/src/adapters/fromKeypair.ts +58 -0
- package/src/adapters/fromKitSigner.ts +82 -0
- package/src/adapters/fromWalletAdapter.ts +58 -0
- package/src/adapters/fromWalletStandard.ts +100 -0
- package/src/adapters/resolveSignerSlot.ts +46 -0
- package/src/client.ts +131 -18
- package/src/decorators/smartWalletActions.ts +2 -2
- package/src/decorators/solanaSmartWalletActions.ts +62 -0
- package/src/experimental/actions/requestQuoteV0.ts +26 -11
- package/src/exports/index.ts +8 -4
- package/src/exports/solana.ts +36 -0
- package/src/types.ts +38 -7
- package/src/utils/assertions.ts +17 -2
- package/src/utils/capabilities.ts +40 -8
- package/src/utils/format.ts +1 -1
- package/src/utils/schema.ts +58 -69
- package/src/version.ts +1 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { prepareCalls } from "./prepareCalls.js";
|
|
2
|
+
import { signPreparedCalls } from "./signPreparedCalls.js";
|
|
3
|
+
import { sendPreparedCalls, } from "./sendPreparedCalls.js";
|
|
4
|
+
import { LOGGER } from "../../logger.js";
|
|
5
|
+
/**
|
|
6
|
+
* Prepares, signs, and submits Solana instructions in a single call.
|
|
7
|
+
* Internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.
|
|
8
|
+
*
|
|
9
|
+
* @param {InnerSolanaWalletApiClient} client - The Solana wallet API client
|
|
10
|
+
* @param {SolanaSendCallsParams} params - Parameters for sending Solana calls
|
|
11
|
+
* @param {Array<{programId: string, accounts?: Array, data: Hex}>} params.calls - Array of Solana instructions
|
|
12
|
+
* @param {string} [params.account] - The Solana address to execute from. Defaults to the signer's address.
|
|
13
|
+
* @param {object} [params.capabilities] - Optional capabilities (e.g. paymaster sponsorship)
|
|
14
|
+
* @returns {Promise<SolanaSendCallsResult>} The result containing the call ID
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const result = await client.sendCalls({
|
|
19
|
+
* calls: [{
|
|
20
|
+
* programId: "11111111111111111111111111111111",
|
|
21
|
+
* data: "0x...",
|
|
22
|
+
* }],
|
|
23
|
+
* capabilities: {
|
|
24
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
25
|
+
* }
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export async function sendCalls(client, params) {
|
|
30
|
+
LOGGER.info("solana:sendCalls:start", {
|
|
31
|
+
calls: params.calls?.length,
|
|
32
|
+
hasCapabilities: !!params.capabilities,
|
|
33
|
+
});
|
|
34
|
+
const { chainId, ...rest } = params;
|
|
35
|
+
const prepared = await prepareCalls(client, {
|
|
36
|
+
...rest,
|
|
37
|
+
...(chainId != null ? { chainId } : {}),
|
|
38
|
+
});
|
|
39
|
+
const signed = await signPreparedCalls(client, prepared);
|
|
40
|
+
const res = await sendPreparedCalls(client, signed);
|
|
41
|
+
LOGGER.info("solana:sendCalls:done");
|
|
42
|
+
return res;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=sendCalls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendCalls.js","sourceRoot":"","sources":["../../../../src/actions/solana/sendCalls.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAiC,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAUzC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,MAAkC,EAClC,MAA6B;IAE7B,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE;QACpC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAC3B,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IAEH,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE;QAC1C,GAAG,IAAI;QACP,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACzD,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpD,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACrC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { Prettify } from \"viem\";\nimport type {\n DistributiveOmit,\n InnerSolanaWalletApiClient,\n} from \"../../types.js\";\nimport type { SolanaChainId } from \"@alchemy/wallet-api-types\";\nimport { prepareCalls, type SolanaPrepareCallsParams } from \"./prepareCalls.js\";\nimport { signPreparedCalls } from \"./signPreparedCalls.js\";\nimport {\n sendPreparedCalls,\n type SolanaSendPreparedCallsResult,\n} from \"./sendPreparedCalls.js\";\nimport { LOGGER } from \"../../logger.js\";\n\nexport type SolanaSendCallsParams = Prettify<\n DistributiveOmit<SolanaPrepareCallsParams, \"chainId\"> & {\n chainId?: SolanaChainId;\n }\n>;\n\nexport type SolanaSendCallsResult = Prettify<SolanaSendPreparedCallsResult>;\n\n/**\n * Prepares, signs, and submits Solana instructions in a single call.\n * Internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.\n *\n * @param {InnerSolanaWalletApiClient} client - The Solana wallet API client\n * @param {SolanaSendCallsParams} params - Parameters for sending Solana calls\n * @param {Array<{programId: string, accounts?: Array, data: Hex}>} params.calls - Array of Solana instructions\n * @param {string} [params.account] - The Solana address to execute from. Defaults to the signer's address.\n * @param {object} [params.capabilities] - Optional capabilities (e.g. paymaster sponsorship)\n * @returns {Promise<SolanaSendCallsResult>} The result containing the call ID\n *\n * @example\n * ```ts\n * const result = await client.sendCalls({\n * calls: [{\n * programId: \"11111111111111111111111111111111\",\n * data: \"0x...\",\n * }],\n * capabilities: {\n * paymaster: { policyId: \"your-policy-id\" }\n * }\n * });\n * ```\n */\nexport async function sendCalls(\n client: InnerSolanaWalletApiClient,\n params: SolanaSendCallsParams,\n): Promise<SolanaSendCallsResult> {\n LOGGER.info(\"solana:sendCalls:start\", {\n calls: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n\n const { chainId, ...rest } = params;\n const prepared = await prepareCalls(client, {\n ...rest,\n ...(chainId != null ? { chainId } : {}),\n });\n\n const signed = await signPreparedCalls(client, prepared);\n const res = await sendPreparedCalls(client, signed);\n LOGGER.info(\"solana:sendCalls:done\");\n return res;\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Prettify } from "viem";
|
|
2
|
+
import type { InnerSolanaWalletApiClient } from "../../types.js";
|
|
3
|
+
import { PreparedCall_SolanaV0_Signed as PreparedCall_SolanaV0_SignedSchema } from "@alchemy/wallet-api-types";
|
|
4
|
+
import type { z } from "zod";
|
|
5
|
+
import { wallet_sendPreparedCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
6
|
+
import { type MethodResponse } from "../../utils/schema.js";
|
|
7
|
+
type SendPreparedCallsResponse = MethodResponse<typeof MethodSchema>;
|
|
8
|
+
export type SolanaSendPreparedCallsParams = Prettify<z.output<typeof PreparedCall_SolanaV0_SignedSchema>>;
|
|
9
|
+
type SolanaSendPreparedCallsResponse = Extract<SendPreparedCallsResponse, {
|
|
10
|
+
details: {
|
|
11
|
+
type: "solana-transaction-v0";
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
export type SolanaSendPreparedCallsResult = SolanaSendPreparedCallsResponse;
|
|
15
|
+
/**
|
|
16
|
+
* Sends a signed Solana transaction.
|
|
17
|
+
* This method is used after signing the signature request returned from prepareCalls.
|
|
18
|
+
*
|
|
19
|
+
* @param {InnerSolanaWalletApiClient} client - The Solana wallet API client
|
|
20
|
+
* @param {SolanaSendPreparedCallsParams} params - The signed Solana transaction
|
|
21
|
+
* @returns {Promise<SolanaSendPreparedCallsResult>} The result containing the call ID
|
|
22
|
+
*/
|
|
23
|
+
export declare function sendPreparedCalls(client: InnerSolanaWalletApiClient, params: SolanaSendPreparedCallsParams): Promise<SolanaSendPreparedCallsResult>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PreparedCall_SolanaV0_Signed as PreparedCall_SolanaV0_SignedSchema } from "@alchemy/wallet-api-types";
|
|
2
|
+
import { BaseError } from "@alchemy/common";
|
|
3
|
+
import { LOGGER } from "../../logger.js";
|
|
4
|
+
import { wallet_sendPreparedCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
|
+
import { methodSchema, encode, decode, } from "../../utils/schema.js";
|
|
6
|
+
const schema = methodSchema(MethodSchema);
|
|
7
|
+
function isSolanaResponse(response) {
|
|
8
|
+
return response.details.type === "solana-transaction-v0";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Sends a signed Solana transaction.
|
|
12
|
+
* This method is used after signing the signature request returned from prepareCalls.
|
|
13
|
+
*
|
|
14
|
+
* @param {InnerSolanaWalletApiClient} client - The Solana wallet API client
|
|
15
|
+
* @param {SolanaSendPreparedCallsParams} params - The signed Solana transaction
|
|
16
|
+
* @returns {Promise<SolanaSendPreparedCallsResult>} The result containing the call ID
|
|
17
|
+
*/
|
|
18
|
+
export async function sendPreparedCalls(client, params) {
|
|
19
|
+
LOGGER.debug("solana:sendPreparedCalls:start", { type: params.type });
|
|
20
|
+
const rpcParams = encode(PreparedCall_SolanaV0_SignedSchema, params);
|
|
21
|
+
const rpcResp = await client.request({
|
|
22
|
+
method: "wallet_sendPreparedCalls",
|
|
23
|
+
params: [rpcParams],
|
|
24
|
+
});
|
|
25
|
+
LOGGER.debug("solana:sendPreparedCalls:done");
|
|
26
|
+
const decoded = decode(schema.response, rpcResp);
|
|
27
|
+
if (!isSolanaResponse(decoded)) {
|
|
28
|
+
throw new BaseError(`Unexpected EVM response from Solana sendPreparedCalls: ${decoded.details.type}`);
|
|
29
|
+
}
|
|
30
|
+
return decoded;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=sendPreparedCalls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/actions/solana/sendPreparedCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,IAAI,kCAAkC,EAAE,MAAM,2BAA2B,CAAC;AAE/G,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,wBAAwB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EACL,YAAY,EACZ,MAAM,EACN,MAAM,GAEP,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAc1C,SAAS,gBAAgB,CACvB,QAAmC;IAEnC,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,uBAAuB,CAAC;AAC3D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAkC,EAClC,MAAqC;IAErC,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAEtE,MAAM,SAAS,GAAG,MAAM,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAC;IACrE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,0BAA0B;QAClC,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEjD,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CACjB,0DAA0D,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CACjF,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Prettify } from \"viem\";\nimport type { InnerSolanaWalletApiClient } from \"../../types.js\";\nimport { PreparedCall_SolanaV0_Signed as PreparedCall_SolanaV0_SignedSchema } from \"@alchemy/wallet-api-types\";\nimport type { z } from \"zod\";\nimport { BaseError } from \"@alchemy/common\";\nimport { LOGGER } from \"../../logger.js\";\nimport { wallet_sendPreparedCalls as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport {\n methodSchema,\n encode,\n decode,\n type MethodResponse,\n} from \"../../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype SendPreparedCallsResponse = MethodResponse<typeof MethodSchema>;\n\nexport type SolanaSendPreparedCallsParams = Prettify<\n z.output<typeof PreparedCall_SolanaV0_SignedSchema>\n>;\n\ntype SolanaSendPreparedCallsResponse = Extract<\n SendPreparedCallsResponse,\n { details: { type: \"solana-transaction-v0\" } }\n>;\n\nexport type SolanaSendPreparedCallsResult = SolanaSendPreparedCallsResponse;\n\nfunction isSolanaResponse(\n response: SendPreparedCallsResponse,\n): response is SolanaSendPreparedCallsResult {\n return response.details.type === \"solana-transaction-v0\";\n}\n\n/**\n * Sends a signed Solana transaction.\n * This method is used after signing the signature request returned from prepareCalls.\n *\n * @param {InnerSolanaWalletApiClient} client - The Solana wallet API client\n * @param {SolanaSendPreparedCallsParams} params - The signed Solana transaction\n * @returns {Promise<SolanaSendPreparedCallsResult>} The result containing the call ID\n */\nexport async function sendPreparedCalls(\n client: InnerSolanaWalletApiClient,\n params: SolanaSendPreparedCallsParams,\n): Promise<SolanaSendPreparedCallsResult> {\n LOGGER.debug(\"solana:sendPreparedCalls:start\", { type: params.type });\n\n const rpcParams = encode(PreparedCall_SolanaV0_SignedSchema, params);\n const rpcResp = await client.request({\n method: \"wallet_sendPreparedCalls\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"solana:sendPreparedCalls:done\");\n const decoded = decode(schema.response, rpcResp);\n\n if (!isSolanaResponse(decoded)) {\n throw new BaseError(\n `Unexpected EVM response from Solana sendPreparedCalls: ${decoded.details.type}`,\n );\n }\n\n return decoded;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Prettify } from "viem";
|
|
2
|
+
import type { InnerSolanaWalletApiClient } from "../../types.js";
|
|
3
|
+
import { type SolanaSignatureResult } from "./signSignatureRequest.js";
|
|
4
|
+
import type { SolanaPrepareCallsResult } from "./prepareCalls.js";
|
|
5
|
+
export type SolanaSignPreparedCallsParams = Prettify<SolanaPrepareCallsResult>;
|
|
6
|
+
export type SolanaSignPreparedCallsResult = Prettify<Omit<SolanaPrepareCallsResult, "signatureRequest" | "feePayment" | "details"> & {
|
|
7
|
+
signature: SolanaSignatureResult;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Signs a prepared Solana transaction using the client's Ed25519 signer.
|
|
11
|
+
*
|
|
12
|
+
* @param {InnerSolanaWalletApiClient} client - The Solana wallet client
|
|
13
|
+
* @param {SolanaSignPreparedCallsParams} params - The prepared Solana transaction with signature request
|
|
14
|
+
* @returns {Promise<SolanaSignPreparedCallsResult>} The signed Solana transaction
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const prepared = await client.prepareCalls({ ... });
|
|
19
|
+
* const signed = await client.signPreparedCalls(prepared);
|
|
20
|
+
* const result = await client.sendPreparedCalls(signed);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function signPreparedCalls(client: InnerSolanaWalletApiClient, params: SolanaSignPreparedCallsParams): Promise<SolanaSignPreparedCallsResult>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { signSolanaSignatureRequest, } from "./signSignatureRequest.js";
|
|
2
|
+
import { LOGGER } from "../../logger.js";
|
|
3
|
+
/**
|
|
4
|
+
* Signs a prepared Solana transaction using the client's Ed25519 signer.
|
|
5
|
+
*
|
|
6
|
+
* @param {InnerSolanaWalletApiClient} client - The Solana wallet client
|
|
7
|
+
* @param {SolanaSignPreparedCallsParams} params - The prepared Solana transaction with signature request
|
|
8
|
+
* @returns {Promise<SolanaSignPreparedCallsResult>} The signed Solana transaction
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const prepared = await client.prepareCalls({ ... });
|
|
13
|
+
* const signed = await client.signPreparedCalls(prepared);
|
|
14
|
+
* const result = await client.sendPreparedCalls(signed);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export async function signPreparedCalls(client, params) {
|
|
18
|
+
LOGGER.debug("solana:signPreparedCalls:start");
|
|
19
|
+
const signature = await signSolanaSignatureRequest(client.owner, params.signatureRequest);
|
|
20
|
+
const { signatureRequest: _, feePayment: __, details: ___, ...rest } = params;
|
|
21
|
+
LOGGER.debug("solana:signPreparedCalls:done");
|
|
22
|
+
return { ...rest, signature };
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=signPreparedCalls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signPreparedCalls.js","sourceRoot":"","sources":["../../../../src/actions/solana/signPreparedCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,GAE3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAazC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAkC,EAClC,MAAqC;IAErC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAE/C,MAAM,SAAS,GAAG,MAAM,0BAA0B,CAChD,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,gBAAgB,CACxB,CAAC;IAEF,MAAM,EAAE,gBAAgB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IAE9E,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAC9C,OAAO,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC","sourcesContent":["import type { Prettify } from \"viem\";\nimport type { InnerSolanaWalletApiClient } from \"../../types.js\";\nimport {\n signSolanaSignatureRequest,\n type SolanaSignatureResult,\n} from \"./signSignatureRequest.js\";\nimport type { SolanaPrepareCallsResult } from \"./prepareCalls.js\";\nimport { LOGGER } from \"../../logger.js\";\n\nexport type SolanaSignPreparedCallsParams = Prettify<SolanaPrepareCallsResult>;\n\nexport type SolanaSignPreparedCallsResult = Prettify<\n Omit<\n SolanaPrepareCallsResult,\n \"signatureRequest\" | \"feePayment\" | \"details\"\n > & {\n signature: SolanaSignatureResult;\n }\n>;\n\n/**\n * Signs a prepared Solana transaction using the client's Ed25519 signer.\n *\n * @param {InnerSolanaWalletApiClient} client - The Solana wallet client\n * @param {SolanaSignPreparedCallsParams} params - The prepared Solana transaction with signature request\n * @returns {Promise<SolanaSignPreparedCallsResult>} The signed Solana transaction\n *\n * @example\n * ```ts\n * const prepared = await client.prepareCalls({ ... });\n * const signed = await client.signPreparedCalls(prepared);\n * const result = await client.sendPreparedCalls(signed);\n * ```\n */\nexport async function signPreparedCalls(\n client: InnerSolanaWalletApiClient,\n params: SolanaSignPreparedCallsParams,\n): Promise<SolanaSignPreparedCallsResult> {\n LOGGER.debug(\"solana:signPreparedCalls:start\");\n\n const signature = await signSolanaSignatureRequest(\n client.owner,\n params.signatureRequest,\n );\n\n const { signatureRequest: _, feePayment: __, details: ___, ...rest } = params;\n\n LOGGER.debug(\"solana:signPreparedCalls:done\");\n return { ...rest, signature };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SolanaSigner } from "../../types.js";
|
|
2
|
+
export type SolanaSignatureRequestParams = {
|
|
3
|
+
type: "solana_signTransaction";
|
|
4
|
+
data: `0x${string}`;
|
|
5
|
+
};
|
|
6
|
+
export type SolanaSignatureResult = {
|
|
7
|
+
type: "ed25519";
|
|
8
|
+
data: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function signSolanaSignatureRequest(signer: SolanaSigner, signatureRequest: SolanaSignatureRequestParams): Promise<SolanaSignatureResult>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LOGGER } from "../../logger.js";
|
|
2
|
+
import { hexToBytes } from "viem";
|
|
3
|
+
import { Base58 } from "ox";
|
|
4
|
+
import { findSignerSlot } from "../../adapters/resolveSignerSlot.js";
|
|
5
|
+
import { SolanaSignerError } from "../../adapters/SolanaSignerError.js";
|
|
6
|
+
export async function signSolanaSignatureRequest(signer, signatureRequest) {
|
|
7
|
+
const txBytes = hexToBytes(signatureRequest.data);
|
|
8
|
+
const slotIndex = await findSignerSlot(txBytes, signer.address);
|
|
9
|
+
if (slotIndex < 0) {
|
|
10
|
+
throw new SolanaSignerError(`Signer ${signer.address} is not a required signer in this transaction`);
|
|
11
|
+
}
|
|
12
|
+
LOGGER.debug("signSolanaSignatureRequest:signing");
|
|
13
|
+
const { signedTransaction } = await signer.signTransaction({
|
|
14
|
+
transaction: txBytes,
|
|
15
|
+
});
|
|
16
|
+
if (signedTransaction[0] !== txBytes[0]) {
|
|
17
|
+
throw new SolanaSignerError(`Signer returned a transaction with a different signature count (expected ${txBytes[0]}, got ${signedTransaction[0]})`);
|
|
18
|
+
}
|
|
19
|
+
const offset = 1 + slotIndex * 64;
|
|
20
|
+
const rawSignature = signedTransaction.slice(offset, offset + 64);
|
|
21
|
+
if (rawSignature.length !== 64) {
|
|
22
|
+
throw new SolanaSignerError(`Signed transaction too short to contain signature at slot ${slotIndex}`);
|
|
23
|
+
}
|
|
24
|
+
if (rawSignature.every((b) => b === 0)) {
|
|
25
|
+
throw new SolanaSignerError(`Signer ${signer.address} did not produce a signature at slot ${slotIndex}`);
|
|
26
|
+
}
|
|
27
|
+
LOGGER.debug("signSolanaSignatureRequest:ok");
|
|
28
|
+
return {
|
|
29
|
+
type: "ed25519",
|
|
30
|
+
data: Base58.fromBytes(rawSignature),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=signSignatureRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../../src/actions/solana/signSignatureRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAYxE,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,MAAoB,EACpB,gBAA8C;IAE9C,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAElD,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAChE,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,iBAAiB,CACzB,UAAU,MAAM,CAAC,OAAO,+CAA+C,CACxE,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAEnD,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC;QACzD,WAAW,EAAE,OAAO;KACrB,CAAC,CAAC;IAEH,IAAI,iBAAiB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,iBAAiB,CACzB,4EAA4E,OAAO,CAAC,CAAC,CAAC,SAAS,iBAAiB,CAAC,CAAC,CAAC,GAAG,CACvH,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,CAAC,GAAG,SAAS,GAAG,EAAE,CAAC;IAClC,MAAM,YAAY,GAAG,iBAAiB,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,CAAC,CAAC;IAElE,IAAI,YAAY,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,iBAAiB,CACzB,6DAA6D,SAAS,EAAE,CACzE,CAAC;IACJ,CAAC;IAED,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,iBAAiB,CACzB,UAAU,MAAM,CAAC,OAAO,wCAAwC,SAAS,EAAE,CAC5E,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAC9C,OAAO;QACL,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC;KACrC,CAAC;AACJ,CAAC","sourcesContent":["import type { SolanaSigner } from \"../../types.js\";\nimport { LOGGER } from \"../../logger.js\";\nimport { hexToBytes } from \"viem\";\nimport { Base58 } from \"ox\";\nimport { findSignerSlot } from \"../../adapters/resolveSignerSlot.js\";\nimport { SolanaSignerError } from \"../../adapters/SolanaSignerError.js\";\n\nexport type SolanaSignatureRequestParams = {\n type: \"solana_signTransaction\";\n data: `0x${string}`;\n};\n\nexport type SolanaSignatureResult = {\n type: \"ed25519\";\n data: string;\n};\n\nexport async function signSolanaSignatureRequest(\n signer: SolanaSigner,\n signatureRequest: SolanaSignatureRequestParams,\n): Promise<SolanaSignatureResult> {\n const txBytes = hexToBytes(signatureRequest.data);\n\n const slotIndex = await findSignerSlot(txBytes, signer.address);\n if (slotIndex < 0) {\n throw new SolanaSignerError(\n `Signer ${signer.address} is not a required signer in this transaction`,\n );\n }\n\n LOGGER.debug(\"signSolanaSignatureRequest:signing\");\n\n const { signedTransaction } = await signer.signTransaction({\n transaction: txBytes,\n });\n\n if (signedTransaction[0] !== txBytes[0]) {\n throw new SolanaSignerError(\n `Signer returned a transaction with a different signature count (expected ${txBytes[0]}, got ${signedTransaction[0]})`,\n );\n }\n\n const offset = 1 + slotIndex * 64;\n const rawSignature = signedTransaction.slice(offset, offset + 64);\n\n if (rawSignature.length !== 64) {\n throw new SolanaSignerError(\n `Signed transaction too short to contain signature at slot ${slotIndex}`,\n );\n }\n\n if (rawSignature.every((b) => b === 0)) {\n throw new SolanaSignerError(\n `Signer ${signer.address} did not produce a signature at slot ${slotIndex}`,\n );\n }\n\n LOGGER.debug(\"signSolanaSignatureRequest:ok\");\n return {\n type: \"ed25519\",\n data: Base58.fromBytes(rawSignature),\n };\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InnerSolanaWalletApiClient } from "../../types.js";
|
|
2
|
+
import { type SolanaGetCallsStatusResult } from "./getCallsStatus.js";
|
|
3
|
+
export type SolanaWaitForCallsStatusParams = {
|
|
4
|
+
id: `0x${string}`;
|
|
5
|
+
pollingInterval?: number;
|
|
6
|
+
retryCount?: number;
|
|
7
|
+
retryDelay?: (opts: {
|
|
8
|
+
count: number;
|
|
9
|
+
}) => number;
|
|
10
|
+
status?: (result: SolanaGetCallsStatusResult) => boolean;
|
|
11
|
+
throwOnFailure?: boolean;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
};
|
|
14
|
+
export type SolanaWaitForCallsStatusResult = SolanaGetCallsStatusResult;
|
|
15
|
+
/**
|
|
16
|
+
* Polls getCallsStatus until the call reaches a terminal state.
|
|
17
|
+
* Similar API to viem's waitForCallsStatus with retry, exponential backoff,
|
|
18
|
+
* configurable status predicate, throwOnFailure, and timeout.
|
|
19
|
+
*
|
|
20
|
+
* @param {InnerSolanaWalletApiClient} client - The Solana wallet API client
|
|
21
|
+
* @param {SolanaWaitForCallsStatusParams} params - The call ID and optional polling config
|
|
22
|
+
* @returns {Promise<SolanaWaitForCallsStatusResult>} The final status
|
|
23
|
+
*/
|
|
24
|
+
export declare function waitForCallsStatus(client: InnerSolanaWalletApiClient, params: SolanaWaitForCallsStatusParams): Promise<SolanaWaitForCallsStatusResult>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getCallsStatus, } from "./getCallsStatus.js";
|
|
2
|
+
import { BaseError } from "@alchemy/common";
|
|
3
|
+
import { LOGGER } from "../../logger.js";
|
|
4
|
+
/**
|
|
5
|
+
* Polls getCallsStatus until the call reaches a terminal state.
|
|
6
|
+
* Similar API to viem's waitForCallsStatus with retry, exponential backoff,
|
|
7
|
+
* configurable status predicate, throwOnFailure, and timeout.
|
|
8
|
+
*
|
|
9
|
+
* @param {InnerSolanaWalletApiClient} client - The Solana wallet API client
|
|
10
|
+
* @param {SolanaWaitForCallsStatusParams} params - The call ID and optional polling config
|
|
11
|
+
* @returns {Promise<SolanaWaitForCallsStatusResult>} The final status
|
|
12
|
+
*/
|
|
13
|
+
export async function waitForCallsStatus(client, params) {
|
|
14
|
+
const { id, pollingInterval = client.pollingInterval, retryCount = 4, retryDelay = ({ count }) => ~~(1 << count) * 200, status: isReady = ({ statusCode }) => statusCode === 200 || statusCode >= 300, throwOnFailure = false, timeout = 60000, } = params;
|
|
15
|
+
LOGGER.debug("solana:waitForCallsStatus:start", { id });
|
|
16
|
+
const start = Date.now();
|
|
17
|
+
while (Date.now() - start < timeout) {
|
|
18
|
+
let result;
|
|
19
|
+
for (let attempt = 0; attempt <= retryCount; attempt++) {
|
|
20
|
+
try {
|
|
21
|
+
result = await getCallsStatus(client, { id });
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (attempt >= retryCount)
|
|
26
|
+
throw error;
|
|
27
|
+
await new Promise((r) => setTimeout(r, retryDelay({ count: attempt })));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!result)
|
|
31
|
+
throw new BaseError("Unexpected: no result after retries");
|
|
32
|
+
if (throwOnFailure && result.status === "failure") {
|
|
33
|
+
throw new BaseError(`Solana call bundle failed with status code ${result.statusCode}`);
|
|
34
|
+
}
|
|
35
|
+
if (isReady(result)) {
|
|
36
|
+
LOGGER.debug("solana:waitForCallsStatus:done", {
|
|
37
|
+
status: result.status,
|
|
38
|
+
statusCode: result.statusCode,
|
|
39
|
+
});
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
await new Promise((r) => setTimeout(r, pollingInterval));
|
|
43
|
+
}
|
|
44
|
+
throw new BaseError(`Timed out while waiting for call bundle with id "${id}" to be confirmed.`);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=waitForCallsStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitForCallsStatus.js","sourceRoot":"","sources":["../../../../src/actions/solana/waitForCallsStatus.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,GAEf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAczC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAkC,EAClC,MAAsC;IAEtC,MAAM,EACJ,EAAE,EACF,eAAe,GAAG,MAAM,CAAC,eAAe,EACxC,UAAU,GAAG,CAAC,EACd,UAAU,GAAG,CAAC,EAAE,KAAK,EAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,GAAG,EACnE,MAAM,EAAE,OAAO,GAAG,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CACnC,UAAU,KAAK,GAAG,IAAI,UAAU,IAAI,GAAG,EACzC,cAAc,GAAG,KAAK,EACtB,OAAO,GAAG,KAAM,GACjB,GAAG,MAAM,CAAC;IAEX,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAExD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEzB,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,OAAO,EAAE,CAAC;QACpC,IAAI,MAA8C,CAAC;QAEnD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;YACvD,IAAI,CAAC;gBACH,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC9C,MAAM;YACR,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,OAAO,IAAI,UAAU;oBAAE,MAAM,KAAK,CAAC;gBACvC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;QAED,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC,CAAC;QAExE,IAAI,cAAc,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAClD,MAAM,IAAI,SAAS,CACjB,8CAA8C,MAAM,CAAC,UAAU,EAAE,CAClE,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE;gBAC7C,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,UAAU,EAAE,MAAM,CAAC,UAAU;aAC9B,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,IAAI,SAAS,CACjB,oDAAoD,EAAE,oBAAoB,CAC3E,CAAC;AACJ,CAAC","sourcesContent":["import type { InnerSolanaWalletApiClient } from \"../../types.js\";\nimport {\n getCallsStatus,\n type SolanaGetCallsStatusResult,\n} from \"./getCallsStatus.js\";\nimport { BaseError } from \"@alchemy/common\";\nimport { LOGGER } from \"../../logger.js\";\n\nexport type SolanaWaitForCallsStatusParams = {\n id: `0x${string}`;\n pollingInterval?: number;\n retryCount?: number;\n retryDelay?: (opts: { count: number }) => number;\n status?: (result: SolanaGetCallsStatusResult) => boolean;\n throwOnFailure?: boolean;\n timeout?: number;\n};\n\nexport type SolanaWaitForCallsStatusResult = SolanaGetCallsStatusResult;\n\n/**\n * Polls getCallsStatus until the call reaches a terminal state.\n * Similar API to viem's waitForCallsStatus with retry, exponential backoff,\n * configurable status predicate, throwOnFailure, and timeout.\n *\n * @param {InnerSolanaWalletApiClient} client - The Solana wallet API client\n * @param {SolanaWaitForCallsStatusParams} params - The call ID and optional polling config\n * @returns {Promise<SolanaWaitForCallsStatusResult>} The final status\n */\nexport async function waitForCallsStatus(\n client: InnerSolanaWalletApiClient,\n params: SolanaWaitForCallsStatusParams,\n): Promise<SolanaWaitForCallsStatusResult> {\n const {\n id,\n pollingInterval = client.pollingInterval,\n retryCount = 4,\n retryDelay = ({ count }: { count: number }) => ~~(1 << count) * 200,\n status: isReady = ({ statusCode }) =>\n statusCode === 200 || statusCode >= 300,\n throwOnFailure = false,\n timeout = 60_000,\n } = params;\n\n LOGGER.debug(\"solana:waitForCallsStatus:start\", { id });\n\n const start = Date.now();\n\n while (Date.now() - start < timeout) {\n let result: SolanaGetCallsStatusResult | undefined;\n\n for (let attempt = 0; attempt <= retryCount; attempt++) {\n try {\n result = await getCallsStatus(client, { id });\n break;\n } catch (error) {\n if (attempt >= retryCount) throw error;\n await new Promise((r) => setTimeout(r, retryDelay({ count: attempt })));\n }\n }\n\n if (!result) throw new BaseError(\"Unexpected: no result after retries\");\n\n if (throwOnFailure && result.status === \"failure\") {\n throw new BaseError(\n `Solana call bundle failed with status code ${result.statusCode}`,\n );\n }\n\n if (isReady(result)) {\n LOGGER.debug(\"solana:waitForCallsStatus:done\", {\n status: result.status,\n statusCode: result.statusCode,\n });\n return result;\n }\n\n await new Promise((r) => setTimeout(r, pollingInterval));\n }\n\n throw new BaseError(\n `Timed out while waiting for call bundle with id \"${id}\" to be confirmed.`,\n );\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseError } from "@alchemy/common";
|
|
2
|
+
export class SolanaSignerError extends BaseError {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
Object.defineProperty(this, "name", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: "SolanaSignerError"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=SolanaSignerError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SolanaSignerError.js","sourceRoot":"","sources":["../../../src/adapters/SolanaSignerError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAAhD;;QACW;;;;mBAAO,mBAAmB;WAAC;IACtC,CAAC;CAAA","sourcesContent":["import { BaseError } from \"@alchemy/common\";\n\nexport class SolanaSignerError extends BaseError {\n override name = \"SolanaSignerError\";\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SolanaSigner } from "../types.js";
|
|
2
|
+
/** Raw Ed25519 keypair signer (e.g. `Keypair` from `@solana/web3.js` v1 or a bare Ed25519 key). */
|
|
3
|
+
export interface SolanaKeypairSigner {
|
|
4
|
+
address: string;
|
|
5
|
+
signMessage(message: Uint8Array): Promise<Uint8Array>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Adapts a raw Ed25519 keypair signer into a {@link SolanaSigner}.
|
|
9
|
+
*
|
|
10
|
+
* Use this for legacy `@solana/web3.js` v1 `Keypair` signers or any signer
|
|
11
|
+
* that exposes a `signMessage(bytes) => signature` interface. For
|
|
12
|
+
* `@solana/kit` signers, use {@link fromKitSigner}. For browser wallets
|
|
13
|
+
* (wallet adapter, Phantom, etc.), use {@link fromWalletAdapter}. For
|
|
14
|
+
* wallet-standard wallets, use {@link fromWalletStandard}.
|
|
15
|
+
*
|
|
16
|
+
* Requires `@solana/kit` or `@solana/web3.js` as a peer dependency.
|
|
17
|
+
*
|
|
18
|
+
* @param {SolanaKeypairSigner} signer - The raw Ed25519 keypair signer to adapt
|
|
19
|
+
* @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`
|
|
20
|
+
*/
|
|
21
|
+
export declare function fromKeypair(signer: SolanaKeypairSigner): SolanaSigner;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SolanaSignerError } from "./SolanaSignerError.js";
|
|
2
|
+
import { findSignerSlot } from "./resolveSignerSlot.js";
|
|
3
|
+
/**
|
|
4
|
+
* Adapts a raw Ed25519 keypair signer into a {@link SolanaSigner}.
|
|
5
|
+
*
|
|
6
|
+
* Use this for legacy `@solana/web3.js` v1 `Keypair` signers or any signer
|
|
7
|
+
* that exposes a `signMessage(bytes) => signature` interface. For
|
|
8
|
+
* `@solana/kit` signers, use {@link fromKitSigner}. For browser wallets
|
|
9
|
+
* (wallet adapter, Phantom, etc.), use {@link fromWalletAdapter}. For
|
|
10
|
+
* wallet-standard wallets, use {@link fromWalletStandard}.
|
|
11
|
+
*
|
|
12
|
+
* Requires `@solana/kit` or `@solana/web3.js` as a peer dependency.
|
|
13
|
+
*
|
|
14
|
+
* @param {SolanaKeypairSigner} signer - The raw Ed25519 keypair signer to adapt
|
|
15
|
+
* @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`
|
|
16
|
+
*/
|
|
17
|
+
export function fromKeypair(signer) {
|
|
18
|
+
return {
|
|
19
|
+
address: signer.address,
|
|
20
|
+
async signTransaction({ transaction }) {
|
|
21
|
+
const numSigs = transaction[0];
|
|
22
|
+
const messageStart = 1 + numSigs * 64;
|
|
23
|
+
const messageBytes = transaction.slice(messageStart);
|
|
24
|
+
let sig;
|
|
25
|
+
try {
|
|
26
|
+
sig = await signer.signMessage(messageBytes);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw new SolanaSignerError("Keypair signer failed to sign message", {
|
|
30
|
+
cause: e,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (sig.length !== 64) {
|
|
34
|
+
throw new SolanaSignerError(`Expected a 64-byte Ed25519 signature but received ${sig.length} bytes`);
|
|
35
|
+
}
|
|
36
|
+
const slotIndex = await findSignerSlot(transaction, signer.address);
|
|
37
|
+
if (slotIndex < 0) {
|
|
38
|
+
throw new SolanaSignerError(`Signer ${signer.address} is not a required signer in this transaction`);
|
|
39
|
+
}
|
|
40
|
+
const signedTx = new Uint8Array(transaction);
|
|
41
|
+
signedTx.set(sig, 1 + slotIndex * 64);
|
|
42
|
+
return { signedTransaction: signedTx };
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=fromKeypair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromKeypair.js","sourceRoot":"","sources":["../../../src/adapters/fromKeypair.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAQxD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,MAA2B;IACrD,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,KAAK,CAAC,eAAe,CAAC,EAAE,WAAW,EAAE;YACnC,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;YAC/B,MAAM,YAAY,GAAG,CAAC,GAAG,OAAO,GAAG,EAAE,CAAC;YACtC,MAAM,YAAY,GAAG,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACrD,IAAI,GAAe,CAAC;YACpB,IAAI,CAAC;gBACH,GAAG,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;YAC/C,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,iBAAiB,CAAC,uCAAuC,EAAE;oBACnE,KAAK,EAAE,CAAU;iBAClB,CAAC,CAAC;YACL,CAAC;YACD,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;gBACtB,MAAM,IAAI,iBAAiB,CACzB,qDAAqD,GAAG,CAAC,MAAM,QAAQ,CACxE,CAAC;YACJ,CAAC;YAED,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;YACpE,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;gBAClB,MAAM,IAAI,iBAAiB,CACzB,UAAU,MAAM,CAAC,OAAO,+CAA+C,CACxE,CAAC;YACJ,CAAC;YAED,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;YAC7C,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,SAAS,GAAG,EAAE,CAAC,CAAC;YACtC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { SolanaSigner } from \"../types.js\";\nimport { SolanaSignerError } from \"./SolanaSignerError.js\";\nimport { findSignerSlot } from \"./resolveSignerSlot.js\";\n\n/** Raw Ed25519 keypair signer (e.g. `Keypair` from `@solana/web3.js` v1 or a bare Ed25519 key). */\nexport interface SolanaKeypairSigner {\n address: string;\n signMessage(message: Uint8Array): Promise<Uint8Array>;\n}\n\n/**\n * Adapts a raw Ed25519 keypair signer into a {@link SolanaSigner}.\n *\n * Use this for legacy `@solana/web3.js` v1 `Keypair` signers or any signer\n * that exposes a `signMessage(bytes) => signature` interface. For\n * `@solana/kit` signers, use {@link fromKitSigner}. For browser wallets\n * (wallet adapter, Phantom, etc.), use {@link fromWalletAdapter}. For\n * wallet-standard wallets, use {@link fromWalletStandard}.\n *\n * Requires `@solana/kit` or `@solana/web3.js` as a peer dependency.\n *\n * @param {SolanaKeypairSigner} signer - The raw Ed25519 keypair signer to adapt\n * @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`\n */\nexport function fromKeypair(signer: SolanaKeypairSigner): SolanaSigner {\n return {\n address: signer.address,\n async signTransaction({ transaction }) {\n const numSigs = transaction[0];\n const messageStart = 1 + numSigs * 64;\n const messageBytes = transaction.slice(messageStart);\n let sig: Uint8Array;\n try {\n sig = await signer.signMessage(messageBytes);\n } catch (e) {\n throw new SolanaSignerError(\"Keypair signer failed to sign message\", {\n cause: e as Error,\n });\n }\n if (sig.length !== 64) {\n throw new SolanaSignerError(\n `Expected a 64-byte Ed25519 signature but received ${sig.length} bytes`,\n );\n }\n\n const slotIndex = await findSignerSlot(transaction, signer.address);\n if (slotIndex < 0) {\n throw new SolanaSignerError(\n `Signer ${signer.address} is not a required signer in this transaction`,\n );\n }\n\n const signedTx = new Uint8Array(transaction);\n signedTx.set(sig, 1 + slotIndex * 64);\n return { signedTransaction: signedTx };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SolanaSigner } from "../types.js";
|
|
2
|
+
/** Any {@link https://solanakit.com @solana/kit} signer that implements `signTransactions` (e.g. `TransactionPartialSigner`, `KeyPairSigner`). */
|
|
3
|
+
export interface SolanaTransactionPartialSigner {
|
|
4
|
+
address: string;
|
|
5
|
+
signTransactions(transactions: readonly unknown[]): Promise<readonly Record<string, Uint8Array>[]>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Adapts an {@link https://solanakit.com @solana/kit} signer into a {@link SolanaSigner}.
|
|
9
|
+
*
|
|
10
|
+
* Accepts any signer that implements `signTransactions`, including
|
|
11
|
+
* `KeyPairSigner`, `TransactionPartialSigner`, and `NoopSigner`. For raw
|
|
12
|
+
* Ed25519 keypairs, use {@link fromKeypair}. For browser wallets (wallet
|
|
13
|
+
* adapter, Phantom, etc.), use {@link fromWalletAdapter}. For
|
|
14
|
+
* wallet-standard wallets, use {@link fromWalletStandard}.
|
|
15
|
+
*
|
|
16
|
+
* Requires `@solana/kit` as a peer dependency.
|
|
17
|
+
*
|
|
18
|
+
* @param {SolanaTransactionPartialSigner} signer - The @solana/kit signer to adapt
|
|
19
|
+
* @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`
|
|
20
|
+
*/
|
|
21
|
+
export declare function fromKitSigner(signer: SolanaTransactionPartialSigner): SolanaSigner;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { SolanaSignerError } from "./SolanaSignerError.js";
|
|
2
|
+
import { findSignerSlot } from "./resolveSignerSlot.js";
|
|
3
|
+
/**
|
|
4
|
+
* Adapts an {@link https://solanakit.com @solana/kit} signer into a {@link SolanaSigner}.
|
|
5
|
+
*
|
|
6
|
+
* Accepts any signer that implements `signTransactions`, including
|
|
7
|
+
* `KeyPairSigner`, `TransactionPartialSigner`, and `NoopSigner`. For raw
|
|
8
|
+
* Ed25519 keypairs, use {@link fromKeypair}. For browser wallets (wallet
|
|
9
|
+
* adapter, Phantom, etc.), use {@link fromWalletAdapter}. For
|
|
10
|
+
* wallet-standard wallets, use {@link fromWalletStandard}.
|
|
11
|
+
*
|
|
12
|
+
* Requires `@solana/kit` as a peer dependency.
|
|
13
|
+
*
|
|
14
|
+
* @param {SolanaTransactionPartialSigner} signer - The @solana/kit signer to adapt
|
|
15
|
+
* @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`
|
|
16
|
+
*/
|
|
17
|
+
export function fromKitSigner(signer) {
|
|
18
|
+
return {
|
|
19
|
+
address: signer.address,
|
|
20
|
+
async signTransaction({ transaction }) {
|
|
21
|
+
let tx;
|
|
22
|
+
try {
|
|
23
|
+
const { getTransactionCodec } = await import("@solana/kit");
|
|
24
|
+
const codec = getTransactionCodec();
|
|
25
|
+
tx = codec.decode(transaction);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
throw new SolanaSignerError("Failed to decode transaction", {
|
|
29
|
+
cause: e,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
let sigDict;
|
|
33
|
+
try {
|
|
34
|
+
[sigDict] = await signer.signTransactions([tx]);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw new SolanaSignerError("Kit signer failed to sign transaction", {
|
|
38
|
+
cause: e,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (!sigDict) {
|
|
42
|
+
throw new SolanaSignerError("TransactionPartialSigner returned no signatures");
|
|
43
|
+
}
|
|
44
|
+
const sig = sigDict[signer.address];
|
|
45
|
+
if (!sig) {
|
|
46
|
+
throw new SolanaSignerError(`TransactionPartialSigner did not produce a signature for ${signer.address}`);
|
|
47
|
+
}
|
|
48
|
+
if (sig.length !== 64) {
|
|
49
|
+
throw new SolanaSignerError(`Expected a 64-byte Ed25519 signature but received ${sig.length} bytes`);
|
|
50
|
+
}
|
|
51
|
+
const slotIndex = await findSignerSlot(transaction, signer.address);
|
|
52
|
+
if (slotIndex < 0) {
|
|
53
|
+
throw new SolanaSignerError(`Signer ${signer.address} is not a required signer in this transaction`);
|
|
54
|
+
}
|
|
55
|
+
const signedTx = new Uint8Array(transaction);
|
|
56
|
+
signedTx.set(sig, 1 + slotIndex * 64);
|
|
57
|
+
return { signedTransaction: signedTx };
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=fromKitSigner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromKitSigner.js","sourceRoot":"","sources":["../../../src/adapters/fromKitSigner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAUxD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAsC;IAEtC,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,KAAK,CAAC,eAAe,CAAC,EAAE,WAAW,EAAE;YACnC,IAAI,EAAW,CAAC;YAChB,IAAI,CAAC;gBACH,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;gBAC5D,MAAM,KAAK,GAAG,mBAAmB,EAAE,CAAC;gBACpC,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACjC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,iBAAiB,CAAC,8BAA8B,EAAE;oBAC1D,KAAK,EAAE,CAAU;iBAClB,CAAC,CAAC;YACL,CAAC;YAED,IAAI,OAA+C,CAAC;YACpD,IAAI,CAAC;gBACH,CAAC,OAAO,CAAC,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAClD,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,iBAAiB,CAAC,uCAAuC,EAAE;oBACnE,KAAK,EAAE,CAAU;iBAClB,CAAC,CAAC;YACL,CAAC;YACD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,iBAAiB,CACzB,iDAAiD,CAClD,CAAC;YACJ,CAAC;YAED,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACpC,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,iBAAiB,CACzB,4DAA4D,MAAM,CAAC,OAAO,EAAE,CAC7E,CAAC;YACJ,CAAC;YACD,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;gBACtB,MAAM,IAAI,iBAAiB,CACzB,qDAAqD,GAAG,CAAC,MAAM,QAAQ,CACxE,CAAC;YACJ,CAAC;YAED,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;YACpE,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;gBAClB,MAAM,IAAI,iBAAiB,CACzB,UAAU,MAAM,CAAC,OAAO,+CAA+C,CACxE,CAAC;YACJ,CAAC;YAED,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;YAC7C,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,SAAS,GAAG,EAAE,CAAC,CAAC;YACtC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { SolanaSigner } from \"../types.js\";\nimport { SolanaSignerError } from \"./SolanaSignerError.js\";\nimport { findSignerSlot } from \"./resolveSignerSlot.js\";\n\n/** Any {@link https://solanakit.com @solana/kit} signer that implements `signTransactions` (e.g. `TransactionPartialSigner`, `KeyPairSigner`). */\nexport interface SolanaTransactionPartialSigner {\n address: string;\n signTransactions(\n transactions: readonly unknown[],\n ): Promise<readonly Record<string, Uint8Array>[]>;\n}\n\n/**\n * Adapts an {@link https://solanakit.com @solana/kit} signer into a {@link SolanaSigner}.\n *\n * Accepts any signer that implements `signTransactions`, including\n * `KeyPairSigner`, `TransactionPartialSigner`, and `NoopSigner`. For raw\n * Ed25519 keypairs, use {@link fromKeypair}. For browser wallets (wallet\n * adapter, Phantom, etc.), use {@link fromWalletAdapter}. For\n * wallet-standard wallets, use {@link fromWalletStandard}.\n *\n * Requires `@solana/kit` as a peer dependency.\n *\n * @param {SolanaTransactionPartialSigner} signer - The @solana/kit signer to adapt\n * @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`\n */\nexport function fromKitSigner(\n signer: SolanaTransactionPartialSigner,\n): SolanaSigner {\n return {\n address: signer.address,\n async signTransaction({ transaction }) {\n let tx: unknown;\n try {\n const { getTransactionCodec } = await import(\"@solana/kit\");\n const codec = getTransactionCodec();\n tx = codec.decode(transaction);\n } catch (e) {\n throw new SolanaSignerError(\"Failed to decode transaction\", {\n cause: e as Error,\n });\n }\n\n let sigDict: Record<string, Uint8Array> | undefined;\n try {\n [sigDict] = await signer.signTransactions([tx]);\n } catch (e) {\n throw new SolanaSignerError(\"Kit signer failed to sign transaction\", {\n cause: e as Error,\n });\n }\n if (!sigDict) {\n throw new SolanaSignerError(\n \"TransactionPartialSigner returned no signatures\",\n );\n }\n\n const sig = sigDict[signer.address];\n if (!sig) {\n throw new SolanaSignerError(\n `TransactionPartialSigner did not produce a signature for ${signer.address}`,\n );\n }\n if (sig.length !== 64) {\n throw new SolanaSignerError(\n `Expected a 64-byte Ed25519 signature but received ${sig.length} bytes`,\n );\n }\n\n const slotIndex = await findSignerSlot(transaction, signer.address);\n if (slotIndex < 0) {\n throw new SolanaSignerError(\n `Signer ${signer.address} is not a required signer in this transaction`,\n );\n }\n\n const signedTx = new Uint8Array(transaction);\n signedTx.set(sig, 1 + slotIndex * 64);\n return { signedTransaction: signedTx };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SolanaSigner } from "../types.js";
|
|
2
|
+
import type { VersionedTransaction } from "@solana/web3.js";
|
|
3
|
+
/** Any signer with a `publicKey` and `signTransaction(VersionedTransaction)` method — matches `useWallet()` from `@solana/wallet-adapter-react` and injected wallet providers like `window.phantom.solana`. */
|
|
4
|
+
export interface WalletAdapterSigner {
|
|
5
|
+
publicKey: {
|
|
6
|
+
toBase58(): string;
|
|
7
|
+
};
|
|
8
|
+
signTransaction: <T extends VersionedTransaction>(transaction: T) => Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Adapts a wallet that signs `VersionedTransaction` objects into a {@link SolanaSigner}.
|
|
12
|
+
*
|
|
13
|
+
* Works with `useWallet()` from `@solana/wallet-adapter-react` and injected
|
|
14
|
+
* browser wallet providers (e.g. `window.phantom.solana`). Handles the
|
|
15
|
+
* `Uint8Array` ↔ `VersionedTransaction` conversion internally.
|
|
16
|
+
*
|
|
17
|
+
* For `@solana/kit` signers, use {@link fromKitSigner}. For raw Ed25519
|
|
18
|
+
* keypairs, use {@link fromKeypair}. For wallet-standard wallets, use
|
|
19
|
+
* {@link fromWalletStandard}.
|
|
20
|
+
*
|
|
21
|
+
* Requires `@solana/web3.js` as a peer dependency.
|
|
22
|
+
*
|
|
23
|
+
* @param {WalletAdapterSigner} signer - The wallet adapter signer
|
|
24
|
+
* @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`
|
|
25
|
+
*/
|
|
26
|
+
export declare function fromWalletAdapter(signer: WalletAdapterSigner): SolanaSigner;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SolanaSignerError } from "./SolanaSignerError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Adapts a wallet that signs `VersionedTransaction` objects into a {@link SolanaSigner}.
|
|
4
|
+
*
|
|
5
|
+
* Works with `useWallet()` from `@solana/wallet-adapter-react` and injected
|
|
6
|
+
* browser wallet providers (e.g. `window.phantom.solana`). Handles the
|
|
7
|
+
* `Uint8Array` ↔ `VersionedTransaction` conversion internally.
|
|
8
|
+
*
|
|
9
|
+
* For `@solana/kit` signers, use {@link fromKitSigner}. For raw Ed25519
|
|
10
|
+
* keypairs, use {@link fromKeypair}. For wallet-standard wallets, use
|
|
11
|
+
* {@link fromWalletStandard}.
|
|
12
|
+
*
|
|
13
|
+
* Requires `@solana/web3.js` as a peer dependency.
|
|
14
|
+
*
|
|
15
|
+
* @param {WalletAdapterSigner} signer - The wallet adapter signer
|
|
16
|
+
* @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`
|
|
17
|
+
*/
|
|
18
|
+
export function fromWalletAdapter(signer) {
|
|
19
|
+
return {
|
|
20
|
+
address: signer.publicKey.toBase58(),
|
|
21
|
+
async signTransaction({ transaction }) {
|
|
22
|
+
let tx;
|
|
23
|
+
try {
|
|
24
|
+
const web3 = await import("@solana/web3.js");
|
|
25
|
+
tx = web3.VersionedTransaction.deserialize(transaction);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
throw new SolanaSignerError("Failed to deserialize transaction", {
|
|
29
|
+
cause: e,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
let signed;
|
|
33
|
+
try {
|
|
34
|
+
signed = await signer.signTransaction(tx);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw new SolanaSignerError("Wallet adapter failed to sign transaction", {
|
|
38
|
+
cause: e,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return { signedTransaction: new Uint8Array(signed.serialize()) };
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=fromWalletAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromWalletAdapter.js","sourceRoot":"","sources":["../../../src/adapters/fromWalletAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAU3D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA2B;IAC3D,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE;QACpC,KAAK,CAAC,eAAe,CAAC,EAAE,WAAW,EAAE;YACnC,IAAI,EAAwB,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;gBAC7C,EAAE,GAAG,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;YAC1D,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,iBAAiB,CAAC,mCAAmC,EAAE;oBAC/D,KAAK,EAAE,CAAU;iBAClB,CAAC,CAAC;YACL,CAAC;YAED,IAAI,MAA4B,CAAC;YACjC,IAAI,CAAC;gBACH,MAAM,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;YAC5C,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,iBAAiB,CACzB,2CAA2C,EAC3C;oBACE,KAAK,EAAE,CAAU;iBAClB,CACF,CAAC;YACJ,CAAC;YAED,OAAO,EAAE,iBAAiB,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC;QACnE,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { SolanaSigner } from \"../types.js\";\nimport type { VersionedTransaction } from \"@solana/web3.js\";\nimport { SolanaSignerError } from \"./SolanaSignerError.js\";\n\n/** Any signer with a `publicKey` and `signTransaction(VersionedTransaction)` method — matches `useWallet()` from `@solana/wallet-adapter-react` and injected wallet providers like `window.phantom.solana`. */\nexport interface WalletAdapterSigner {\n publicKey: { toBase58(): string };\n signTransaction: <T extends VersionedTransaction>(\n transaction: T,\n ) => Promise<T>;\n}\n\n/**\n * Adapts a wallet that signs `VersionedTransaction` objects into a {@link SolanaSigner}.\n *\n * Works with `useWallet()` from `@solana/wallet-adapter-react` and injected\n * browser wallet providers (e.g. `window.phantom.solana`). Handles the\n * `Uint8Array` ↔ `VersionedTransaction` conversion internally.\n *\n * For `@solana/kit` signers, use {@link fromKitSigner}. For raw Ed25519\n * keypairs, use {@link fromKeypair}. For wallet-standard wallets, use\n * {@link fromWalletStandard}.\n *\n * Requires `@solana/web3.js` as a peer dependency.\n *\n * @param {WalletAdapterSigner} signer - The wallet adapter signer\n * @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`\n */\nexport function fromWalletAdapter(signer: WalletAdapterSigner): SolanaSigner {\n return {\n address: signer.publicKey.toBase58(),\n async signTransaction({ transaction }) {\n let tx: VersionedTransaction;\n try {\n const web3 = await import(\"@solana/web3.js\");\n tx = web3.VersionedTransaction.deserialize(transaction);\n } catch (e) {\n throw new SolanaSignerError(\"Failed to deserialize transaction\", {\n cause: e as Error,\n });\n }\n\n let signed: VersionedTransaction;\n try {\n signed = await signer.signTransaction(tx);\n } catch (e) {\n throw new SolanaSignerError(\n \"Wallet adapter failed to sign transaction\",\n {\n cause: e as Error,\n },\n );\n }\n\n return { signedTransaction: new Uint8Array(signed.serialize()) };\n },\n };\n}\n"]}
|