ERC-5573 · Draft · ERC · 2021-07-20
ERC-5573: Sign-In with Ethereum Capabilities, ReCaps
ReCaps extend Sign-In with Ethereum so one signed message both logs you in and grants an app scoped, human-readable permissions to act on your behalf at other services, like OAuth on top of SIWE.
What problem does it solve?
ERC-4361 (Sign-In with Ethereum, SIWE) proves to a website that you control an address. That is authentication. But apps often need authorization too: permission to read or write your data at a third-party service, such as a storage provider, on your behalf.
Without a standard, each service invents its own delegation format, and wallets show users opaque blobs. ReCaps add capability-based authorization to the SIWE message, so the user sees exactly what they are granting in plain text and the service can verify it deterministically. The spec compares the pairing to OpenID Connect (SIWE) plus OAuth2 (ReCaps).
How it works
A ReCap is a normal SIWE message with two additions:
- The last entry in
Resourcesis a ReCap URI:urn:recap:followed by the unpadded base64url encoding of a JSON Details Object. - The
statementends with an auto-generated, human-readable sentence describing those permissions.
The Details Object:
att: map of resource URI → map of ability strings (namespace/ability, e.g.crud/update) → array of restriction objects.[{}]means "allowed, no restrictions"; an empty array means unusable. Keys must be sorted lexicographically.prf(optional): CIDs of parent capabilities, when the signer is not the direct controller of the resource.
The SIWE URI field names the relying party receiving the rights; Issued At, Expiration Time and Not Before bound when they are valid.
The translation algorithm turns att into text beginning with I further authorize the stated URI to perform the following actions on my behalf: followed by numbered entries per resource and namespace.
Verification: check the SIWE signature, decode the last resource as a ReCap, regenerate the statement, and confirm the signed statement ends with it. This guarantees the user saw the same permissions that are being enforced.
Sample code
Building a ReCap URI and the matching statement in TypeScript:
type Att = Record<string, Record<string, object[]>>;
function sortKeys<T extends Record<string, any>>(o: T): T {
return Object.fromEntries(Object.keys(o).sort().map(k => [k, o[k]])) as T;
}
export function buildRecap(att: Att) {
const sorted: Att = sortKeys(Object.fromEntries(
Object.entries(att).map(([res, abil]) => [res, sortKeys(abil)]),
));
const json = JSON.stringify({ att: sorted });
const uri = "urn:recap:" + Buffer.from(json).toString("base64url"); // unpadded
let n = 1;
let text = "I further authorize the stated URI to perform the following actions on my behalf:";
for (const [resource, abilities] of Object.entries(sorted)) {
const byNs: Record<string, string[]> = {};
for (const key of Object.keys(abilities)) {
const [ns, name] = key.split("/");
(byNs[ns] ??= []).push(name);
}
for (const [ns, names] of Object.entries(byNs)) {
text += ` (${n++}) '${ns}': ${names.map(x => `'${x}'`).join(", ")} for '${resource}'.`;
}
}
return { uri, statement: text };
}
// buildRecap({ "https://example.com/pictures/": { "crud/update": [{}], "crud/delete": [{}] } })
// statement: "... (1) 'crud': 'delete', 'update' for 'https://example.com/pictures/'."
Place uri as the final Resources entry and append statement to any existing SIWE statement.
Things to know
- Status: Draft. Several sections (implementer's guide, rationale) are still marked TBD.
- A ReCap is not a bearer token. The resource service must still authenticate the relying party separately; how is out of scope.
- What each ability and restriction means is defined by each resource service, not by this standard.
- Ordering rules matter: a differently ordered
attproduces a different URI and statement, and verification will fail.