Skip to main content

SEA.certify()

Create cryptographic certificates that grant specific permissions to other users. Certificates allow delegated access control in distributed systems.
SEA.certify() is an early experimental feature. The API may change in future versions. Use with caution in production.

Syntax

Parameters

  • certificants (string|array|object): Who receives permissions
    • String: Single public key
    • Array: Multiple public keys or user objects
    • Object with pub property: Single user
    • '*': Grant to everyone (wildcard)
  • policy (string|object|array): What permissions to grant
    • String: Path/property name (e.g., 'inbox')
    • Object: Read/write policies { read: ..., write: ... }
    • Array: Multiple paths
    • RAD/LEX pattern matching object
  • authority (object): Certificate authority’s key pair
    • Must have pub and priv properties
    • Signs the certificate
  • callback (function, optional): Called with certificate
  • options (object, optional):
    • expiry: Timestamp when certificate expires
    • block: Blacklist/blocklist for denying access
    • raw: Return raw object (default: false)

Returns

A Promise that resolves to a signed certificate:

Basic Usage

Grant Write Permission

Grant to Multiple Users

Grant to Everyone (Wildcard)

Certificate Structure

Reference: ~/workspace/source/sea/certify.js:50-63

Reserved Keys

  • c: Certificants (who gets the permission)
  • w: Write policy (what they can write)
  • r: Read policy (what they can read)
  • e: Expiry (when certificate becomes invalid)
  • rb: Read block (who is explicitly denied read)
  • wb: Write block (who is explicitly denied write)

Policy Types

Simple String Policy

Read/Write Policies

Array of Paths

RAD/LEX Pattern Matching

Use Gun’s RAD (Reference, Atomic, and Delta) and LEX (Lexical) patterns:

Dynamic Certificant Matching

Force key to equal certificant’s public key:

Expiry

Set when a certificate becomes invalid:

Blocklists

Explicitly deny access to specific users:

Read and Write Blocks

Use Cases

Collaborative Document Editing

Forum Moderation

Inbox Management

Time-limited Access

Certificate Validation

SEA and GUN automatically validate certificates when:
  1. Signature: Verifies authority signed the certificate
  2. Expiry: Checks if certificate is still valid
  3. Policy: Matches requested path against policy patterns
  4. Blocklist: Ensures user is not blocked

Security Considerations

Certificate Authority Trust

Certificates are only as trustworthy as their authority. Anyone can create a certificate, but it only grants access to data controlled by that authority.

Certificate Storage

Certificates should be stored in a discoverable location:

Revocation

To revoke a certificate:

Advanced Patterns

Delegation Chain

Conditional Permissions

Multi-level Access

Integration with GUN

Using Certificates

When writing data, pass the certificate:
GUN automatically:
  1. Validates the certificate signature
  2. Checks expiry
  3. Matches the path against the policy
  4. Allows or denies the operation

Certificate Discovery

Applications should implement certificate discovery:

Troubleshooting

Certificate Not Working

  1. Verify signature: Ensure authority signed it
  2. Check expiry: Certificate may have expired
  3. Match policy: Path must match the policy pattern
  4. Check blocklist: User may be blocked
  5. Authority control: Authority must own the data

Common Errors