mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-13 22:37:29 +00:00
fix(agentstack): reject malformed CoinPay DIDs (#83)
This commit is contained in:
parent
895bb9989e
commit
2f07f74126
2 changed files with 15 additions and 12 deletions
|
|
@ -29,6 +29,7 @@ describe("DID helpers", () => {
|
||||||
it("rejects non-CoinPay DIDs", () => {
|
it("rejects non-CoinPay DIDs", () => {
|
||||||
expect(parseDid("did:web:example.com")).toBeNull();
|
expect(parseDid("did:web:example.com")).toBeNull();
|
||||||
expect(parseDid("did:coinpay:bot:abc")).toBeNull();
|
expect(parseDid("did:coinpay:bot:abc")).toBeNull();
|
||||||
|
expect(parseDid("did:coinpay:user:abc:extra")).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ export const agentDid = (id: string) => makeDid("agent", id);
|
||||||
export function parseDid(did: string): { kind: DidKind; id: string } | null {
|
export function parseDid(did: string): { kind: DidKind; id: string } | null {
|
||||||
const prefix = `${DID_METHOD}:`;
|
const prefix = `${DID_METHOD}:`;
|
||||||
if (!did.startsWith(prefix)) return null;
|
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;
|
if ((kind !== "user" && kind !== "agent") || !id) return null;
|
||||||
return { kind, id };
|
return { kind, id };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue