Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion backend/tools/MultiSigPaymentTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Asset,
BASE_FEE,
Memo,
StrKey,
xdr,
} from "@stellar/stellar-sdk";
import { z } from "zod";
Expand All @@ -29,7 +30,12 @@ export const MultiSigInputSchema = z.object({
.string()
.refine((v) => Buffer.byteLength(v, "utf8") <= 28, "Memo must be at most 28 bytes")
.optional(),
additionalSigners: z.array(z.string().length(56, "Invalid signer public key")),
additionalSigners: z.array(
z
.string()
.length(56, "Invalid signer public key")
.refine((value) => StrKey.isValidEd25519PublicKey(value), "Invalid signer public key")
),
minSignatures: z.number().int().min(1),
signatures: z.array(z.string()).optional(),
});
Expand Down
21 changes: 17 additions & 4 deletions tests/multisig_payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
import { MultiSigPaymentTool } from "../backend/tools/MultiSigPaymentTool";
import * as rpcClient from "../backend/rpc_client";

const { Keypair } = require("@stellar/stellar-sdk");
const TEST_SECRET = Keypair.random().secret();

vi.mock("../backend/rpc_client", () => ({
loadAccount: vi.fn(),
submitTransaction: vi.fn(),
Expand All @@ -18,9 +21,7 @@ vi.mock("../backend/rpc_client", () => ({
}));

vi.mock("../backend/config", () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { Keypair } = require("@stellar/stellar-sdk");
const secret = "process.env.AGENT_SECRET_KEY";
const secret = TEST_SECRET;
return {
config: {
STELLAR_NETWORK: "testnet",
Expand All @@ -37,7 +38,6 @@ vi.mock("../backend/config", () => {
};
});

const TEST_SECRET = "process.env.AGENT_SECRET_KEY";
const DEST = "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";
const SIGNER2 = "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGZUK9AI4WDCBAHD9HTPFE7";
const ISSUER = "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN";
Expand Down Expand Up @@ -84,6 +84,19 @@ describe("MultiSigPaymentTool", () => {
expect(result.txHash).toBeUndefined();
});

it("rejects invalid additional signers before any network call", async () => {
await expect(
tool.execute({
destination: DEST,
amount: "100",
assetCode: "XLM",
additionalSigners: ["A".repeat(56)],
minSignatures: 2,
})
).rejects.toThrow(/Invalid signer public key/);
expect(rpcClient.loadAccount).not.toHaveBeenCalled();
});

it("unsigned XDR is valid base64-encoded XDR (non-empty)", async () => {
const result = await tool.execute({
destination: DEST,
Expand Down
Loading