fix(agentstack): reject malformed CoinPay DIDs (#83)

This commit is contained in:
RissRIce 2026-06-22 06:24:46 -06:00 committed by GitHub
parent 895bb9989e
commit 2f07f74126
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 12 deletions

View file

@ -29,6 +29,7 @@ describe("DID helpers", () => {
it("rejects non-CoinPay DIDs", () => {
expect(parseDid("did:web:example.com")).toBeNull();
expect(parseDid("did:coinpay:bot:abc")).toBeNull();
expect(parseDid("did:coinpay:user:abc:extra")).toBeNull();
});
});

View file

@ -25,7 +25,9 @@ export const agentDid = (id: string) => makeDid("agent", id);
export function parseDid(did: string): { kind: DidKind; id: string } | null {
const prefix = `${DID_METHOD}:`;
if (!did.startsWith(prefix)) return null;
const [kind, id] = did.slice(prefix.length).split(":");
const parts = did.slice(prefix.length).split(":");
if (parts.length !== 2) return null;
const [kind, id] = parts;
if ((kind !== "user" && kind !== "agent") || !id) return null;
return { kind, id };
}