run402-mcp
Version:
MCP server for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.
35 lines • 1.66 kB
JavaScript
import { LocalError } from "../../errors.js";
import { kmsAccount } from "./kms.js";
export { adoptKmsKey, kmsAccount, kmsError } from "./kms.js";
/** How a wallet signs, without loading anything. */
export function walletSignerKind(wallet) {
return wallet.signer ? wallet.signer.kind : "local";
}
/** True when the wallet can sign at all (a key or a signer reference). */
export function walletCanSign(wallet) {
return Boolean(wallet && (wallet.signer || wallet.privateKey));
}
/** The viem account that signs as `wallet`. */
export async function resolveWalletAccount(wallet, opts = {}) {
if (wallet.privateKey && wallet.signer) {
throw new LocalError("This wallet has both a private key and a signer; a wallet is backed by exactly one.", "resolving the wallet signer", {
code: "BAD_WALLET_FILE",
});
}
if (wallet.signer)
return kmsAccount(wallet.signer, wallet.address, opts);
if (wallet.privateKey) {
const toAccount = opts.privateKeyToAccount ?? (await import("viem/accounts")).privateKeyToAccount;
return toAccount(wallet.privateKey);
}
throw new LocalError("This wallet has neither a private key nor a signer.", "resolving the wallet signer", {
code: "BAD_WALLET_FILE",
next_actions: [{ type: "initialize_wallet", command: "run402 init" }],
});
}
/** An EIP-191 personal-message signer for `wallet` (SIWX, identity links). */
export async function personalMessageSignerFor(wallet, opts = {}) {
const account = await resolveWalletAccount(wallet, opts);
return (message) => account.signMessage({ message });
}
//# sourceMappingURL=index.js.map