# BRC-116: Wallet Permissions and Counterparty Trust - Stephen Thomson (stephen@projectbabbage.com) - Brayden Langley (brayden@projectbabbage.com) - Jackie Lu (jackie@projectbabbage.com) ## Abstract This document fully specifies how BRC-100 wallets handle application permission requests. Its goals are to: - Define, without ambiguity, how permissions are declared, requested, and evaluated - Specify full permission lifecycle behavior: grant, deny, renew, revoke, and persistence - Distinguish **group permissions** from **counterparty trust (PACT)** and define how both are enforced together - Provide an authoritative, implementation-agnostic reference for compliant wallet behavior This document is **normative**: it defines complete expected behavior for compliant wallets and applications, independent of UI or implementation language. --- ## Motivation Wallets act as security boundaries between users and applications. Applications must not be able to: - Spend funds - Access private data - Interact with protocols - Access certificates ...without **explicit user authorization**. The permissions system ensures: - Least-privilege access - Clear user consent - Deterministic enforcement - Predictable developer behavior ## Normative Language The key words **MUST**, **MUST NOT**, **SHOULD**, and **MAY** in this document are to be interpreted as described in RFC 2119 and RFC 8174 when, and only when, they appear in all capitals. --- ## Specification ### 3.0 Terminology The following terms are used consistently throughout this document: - **Wallet**: Software responsible for enforcing permissions and managing user assets and data. - **Application (Originator)**: Software acting as an originator that requests permissions from the wallet. Identified by its domain (e.g. `example.com`). - **User**: The human owner of the wallet who grants or denies permissions. - **Counterparty**: An external entity (identified by a compressed public key) interacting with the user through an application via Level 2 protocols. - **Permission Grant**: A persisted authorization allowing an originator to perform a specific action within defined scope. - **Permission Token**: An on-chain PushDrop output stored in an admin basket that represents a persisted permission grant. Tokens are encrypted so only the wallet owner can read them. See Section 7. - **Security Level**: An integer (0, 1, or 2) that classifies protocol access. **Level 0** is open (no permission required). **Level 1** protocols are application-scoped. **Level 2** protocols are counterparty-specific (a distinct external entity is involved). The [BRC-43](https://brc.dev/43) specification defines how these are applied and used within cryptographic operations. - **Manifest**: A JSON file served at `https://{domain}/manifest.json` providing application metadata. See Section 3.2. - **Trusted Certifier**: An entity the user has chosen to trust, identified by a compressed public key and assigned a trust score (1-10). Used for registry resolution and identity verification. For the purposes of this document, **group permissions** refer to permissions granted by a user to an application originator via the wallet's standard permission system. These are distinct from **PACT** (counterparty trust), which governs trust relationships with external entities (see Section 5). ### 3.1 Originator An **originator** represents the identity of an application requesting permissions, derived from the application's domain. Permissions are always scoped to an originator. Granting permission to one originator does **not** imply permission for another. The wallet resolves originator identity from the request context (typically HTTP headers such as `Origin` or `Originator`) when evaluating permission scope. **Security Note:** The user's wallet, web browser and computer system are expected to coordinate and confirm the authenticity of originators, thereby preventing request forgery. The steps taken to confirm originator authenticity vary depending on wallet deployment context, but this specification assumes wallets will prevent forged requests via IPC, local kernel/substrate-specific authentication, or other means. --- ### 3.2 Manifest Each application SHOULD serve a **manifest** file at `https://{domain}/manifest.json`. The manifest follows the [W3C Web App Manifest](https://www.w3.org/TR/appmanifest/) standard for application metadata (name, icons, display preferences), and extends it with a `metanet` namespace for wallet permission declarations. This keeps the manifest interoperable with standard web tooling while adding Metanet-specific capabilities. The manifest serves three purposes: 1. **Application metadata** - Standard W3C fields (`name`, `short_name`, `description`, `icons`) for display in permission prompts and the wallet dashboard. 2. **Group permission declarations** - Under `metanet.groupPermissions`, applications declare the permissions they need. When grouped permission seeking is enabled, the wallet fetches these declarations and presents them to the user as a single grouped prompt on first interaction, rather than prompting one-by-one as each capability is used. 3. **Counterparty permission declarations** - Under `metanet.counterpartyPermissions`, applications declare the Level 2 protocols they require for peer interaction in that app. When a new (untrusted) counterparty is encountered, the wallet uses this declaration to request trust for those protocols before allowing that peer interaction to proceed. #### Manifest Structure ```json { "name": "My Application", "short_name": "MyApp", "description": "A web application with Metanet permissions.", "start_url": ".", "display": "standalone", "theme_color": "#000000", "background_color": "#ffffff", "icons": [ { "src": "favicon.ico", "sizes": "64x64 32x32 24x24 16x16", "type": "image/x-icon" } ], "metanet": { "schemaVersion": 1, "groupPermissions": { "description": "Permissions needed by this application", "spendingAuthorization": { "amount": 10000, "description": "Monthly spending limit for transactions" }, "protocolPermissions": [ { "protocolID": [2, "myprotocol"], "counterparty": "", "description": "Peer messaging" } ], "basketAccess": [ { "basket": "my-tokens", "description": "Token storage" } ], "certificateAccess": [ { "type": "", "verifierPublicKey": "02...", "fields": ["name", "email"], "description": "Identity verification" } ] }, "counterpartyPermissions": { "description": "Peer trust required by this application", "protocols": [ { "protocolName": "myprotocol", "description": "Peer-to-peer messaging" } ] } } } ``` All fields under `metanet` are optional. New manifests SHOULD include `schemaVersion`. An application that declares no `metanet.groupPermissions` will simply be prompted individually at runtime for each capability it uses. An application that declares no `metanet.counterpartyPermissions` will never trigger a PACT prompt - Level 2 protocol requests will fall through to individual or grouped permission prompts instead. #### Schema Version The `metanet.schemaVersion` field identifies the version of the Metanet permission schema. New manifests SHOULD provide it, and the current version is `1`. For interoperability with current wallet-toolbox behavior: - Wallets SHOULD tolerate manifests that omit `schemaVersion`. - Wallets SHOULD continue to support the legacy `babbage` namespace as described in the Backwards Compatibility section. - Wallets SHOULD handle unknown or unsupported schema versions gracefully (for example by ignoring the unsupported fields or warning the user). #### Group Permissions Declaration Grouped permissions let an application declare multiple permissions required up front so the wallet can request them in one consolidated prompt. Without grouped declarations, permissions are requested individually at runtime when each protected operation is first attempted. The `metanet.groupPermissions` object follows the `GroupedPermissions` interface ([BRC-73](https://brc.dev/73)): | Field | Type | Description | |-------|------|-------------| | `description` | string? | Human-readable description of the permission group | | `spendingAuthorization` | `{ amount, description }` | Monthly spending limit in satoshis | | `protocolPermissions` | array | Protocol access requests (Level 1 or 2). Level 2 entries MUST include a specific `counterparty`; Level 1 entries MAY omit `counterparty`. | | `basketAccess` | array | Basket access requests, each with a `basket` name | | `certificateAccess` | array | Certificate access requests with `type`, `verifierPublicKey`, `fields` | When the wallet encounters a permission-requiring operation, it MUST: 1. Check whether a permission token already exists for this operation. If so, allow the operation. Otherwise, proceed with step 2. 2. Fetch the originator's manifest. 3. Check whether the current operation is covered by the manifest's `groupPermissions`. If it is not, trigger a one-off prompt for the operation. If it is, proceed with step 4. 4. Filter out permissions already granted (by looking up existing on-chain tokens). Remove them from the list before showing the user a prompt. 5. Present all remaining permissions as a single grouped prompt for the user's approval. 6. After the user responds, check whether the specific triggering operation is now satisfied. If yes, allow it to proceed with the operation. If no, trigger an individual one-off prompt. #### Counterparty Permissions Declaration Counterparty permissions let an app declare all the Level 2 protocols it needs when interacting with an untrusted counterparty. The wallet can then request trust for that person in one bundled prompt, instead of showing repeated one-off Level 2 prompts as each operation is attempted. The `metanet.counterpartyPermissions` object declares PACT requirements - the Level 2 protocol set the application requires to interact with a peer in that app: | Field | Type | Description | |-------|------|-------------| | `description` | string? | Human-readable description | | `protocols` | array | Array of `{ protocolName, description }` - required peer-interaction protocols, interpreted as **Level 2 only** | The wallet MUST interpret `counterpartyPermissions` entries as Level 2 protocol declarations. For interoperability with current wallet-toolbox behavior, a declaration MAY identify the protocol either by: - a non-empty `protocolName`, or - a `protocolID` equal to `[2, ""]`. Entries that do not resolve to a Level 2 protocol declaration MUST be ignored. These declarations define required Level 2 protocols, while the concrete counterparty is supplied at request time. Effective permission scope remains per-originator + per-counterparty. Including `counterpartyPermissions` tells the wallet: "when this app encounters a new (untrusted) counterparty, request trust for this declared protocol set before allowing peer interaction to proceed." Without it, each Level 2 protocol permission is requested individually as it's used. #### Manifest Examples **Example 1: Simple app with spending only** An application that only needs to spend satoshis (e.g. a tipping service): ```json { "name": "Tip Jar", "short_name": "TipJar", "description": "Send tips to content creators.", "start_url": ".", "display": "standalone", "icons": [{ "src": "icon.png", "sizes": "192x192", "type": "image/png" }], "metanet": { "schemaVersion": 1, "groupPermissions": { "description": "Spending permission for sending tips", "spendingAuthorization": { "amount": 50000, "description": "Monthly tip budget (50,000 satoshis)" } } } } ``` **Example 2: Data storage app (baskets, no counterparties)** An application that stores encrypted notes in a basket using a Level 1 protocol: ```json { "name": "Secure Notes", "short_name": "Notes", "description": "Encrypted personal notes on the blockchain.", "start_url": ".", "display": "standalone", "icons": [{ "src": "icon.png", "sizes": "192x192", "type": "image/png" }], "metanet": { "schemaVersion": 1, "groupPermissions": { "description": "Storage and encryption permissions", "protocolPermissions": [ { "protocolID": [1, "secure-notes"], "description": "Encrypt and decrypt your notes" } ], "basketAccess": [ { "basket": "encrypted-notes", "description": "Store your encrypted notes" } ] } } } ``` **Example 3: Peer-to-peer messaging (with counterparty permissions)** An application where users exchange messages with specific counterparties. This declares `counterpartyPermissions` so the wallet will prompt the user to establish trust (PACT) when a new counterparty is encountered: ```json { "name": "Peer Messenger", "short_name": "PeerMsg", "description": "End-to-end encrypted messaging.", "start_url": ".", "display": "standalone", "icons": [{ "src": "icon.png", "sizes": "192x192", "type": "image/png" }], "metanet": { "schemaVersion": 1, "groupPermissions": { "description": "Messaging permissions", "protocolPermissions": [], "basketAccess": [ { "basket": "message-inbox", "description": "Store received messages" } ], "spendingAuthorization": { "amount": 5000, "description": "Transaction fees for sending messages" } }, "counterpartyPermissions": { "description": "Trust required to communicate with a peer", "protocols": [ { "protocolName": "peer-messaging", "description": "Allow this person to send you encrypted messages" }, { "protocolName": "peer-presence", "description": "Share your online status with this person" } ] } } } ``` **Example 4: Identity verification app (certificates)** An application that verifies user identity by requesting specific certificate fields: ```json { "name": "KYC Portal", "short_name": "KYC", "description": "Identity verification for regulated services.", "start_url": ".", "display": "standalone", "icons": [{ "src": "icon.png", "sizes": "192x192", "type": "image/png" }], "metanet": { "schemaVersion": 1, "groupPermissions": { "description": "Identity verification permissions", "certificateAccess": [ { "type": "AGbsvkGHSi78y1FR6JL0Ig==", "verifierPublicKey": "0294c479f762f3571c4c36f6a75f04995ddcf200777b704131ca71dab5b0e19bfb", "fields": ["firstName", "lastName", "dateOfBirth"], "description": "Verify your legal name and date of birth" }, { "type": "AGbsvkGHSi78y1FR6JL0Ig==", "verifierPublicKey": "0294c479f762f3571c4c36f6a75f04995ddcf200777b704131ca71dab5b0e19bfb", "fields": ["country", "address"], "description": "Verify your address for compliance" } ] } } } ``` **Example 5: Full-featured application (all permission types + PACT)** ```json { "name": "Decentralized Marketplace", "short_name": "DeMarket", "description": "Buy and sell goods with on-chain escrow.", "start_url": ".", "display": "standalone", "theme_color": "#1a1a2e", "background_color": "#ffffff", "icons": [ { "src": "icon-192.png", "sizes": "192x192", "type": "image/png" }, { "src": "icon-512.png", "sizes": "512x512", "type": "image/png" } ], "metanet": { "schemaVersion": 1, "groupPermissions": { "description": "Marketplace permissions", "spendingAuthorization": { "amount": 1000000, "description": "Monthly purchase and escrow budget" }, "protocolPermissions": [ { "protocolID": [1, "marketplace-listings"], "description": "Create and manage your product listings" }, { "protocolID": [2, "escrow-negotiation"], "counterparty": "02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "description": "Negotiate escrow terms with buyers/sellers" }, { "protocolID": [2, "trade-messaging"], "counterparty": "02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "description": "Exchange messages during a trade" } ], "basketAccess": [ { "basket": "marketplace-listings", "description": "Your active product listings" }, { "basket": "escrow-contracts", "description": "Active escrow agreements" }, { "basket": "trade-receipts", "description": "Completed trade receipts" } ], "certificateAccess": [ { "type": "AGbsvkGHSi78y1FR6JL0Ig==", "verifierPublicKey": "0294c479f762f3571c4c36f6a75f04995ddcf200777b704131ca71dab5b0e19bfb", "fields": ["displayName"], "description": "Display your verified name to trade partners" } ] }, "counterpartyPermissions": { "description": "Trust required to trade with a peer", "protocols": [ { "protocolName": "escrow-negotiation", "description": "Negotiate escrow terms with this trader" }, { "protocolName": "trade-messaging", "description": "Exchange messages with this trader" } ] } } } ``` **Example 6: Minimal manifest (no Metanet permissions)** An application that does not declare any permissions upfront. The wallet will prompt individually as each capability is used: ```json { "name": "Simple App", "short_name": "Simple", "description": "A basic application.", "start_url": ".", "display": "standalone", "icons": [{ "src": "favicon.ico", "sizes": "64x64", "type": "image/x-icon" }] } ``` --- ### 3.3 Permission Categories The system defines four primary permission types: | # | Type | Protocol Acronym | Scope Key | Counterparty-Aware | |---|------|-----------------|-----------|-------------------| | 1 | Protocol Permissions | DPACP (Domain Protocol Access Control Protocol) | `protocolID` (security level + name) | Yes (Level 2) | | 2 | Spending Permissions | DSAP (Domain Spending Authorization Protocol) | Satoshi amount | No | | 3 | Basket Permissions | DBAP (Domain Basket Access Protocol) | Basket name | No | | 4 | Certificate Permissions | DCAP (Domain Certificate Access Protocol) | Certificate type + verifier + fields | No | Each permission type has distinct scope, grant options, and prompting behavior. All four types support a **renewal** flag indicating the permission is being re-requested after a previous grant has expired (when finite expiry is used) or been revoked. ### 3.4 Deterministic Permission Evaluation To remove ambiguity across implementations: - Wallets MUST make allow/deny decisions from canonical permission state: valid, unspent, unexpired on-chain permission tokens, explicit one-time ephemeral grants for the current request, and explicitly approved bounded wallet-session grants as described in Section 7.4.1. - Caches of token lookups are performance optimizations only and MUST NOT be treated as authoritative permission state. A separately recorded explicit session grant is authorization state, not a token-lookup cache. - If a token-lookup cache and on-chain token state disagree, the wallet MUST use on-chain token state. An independent session grant MUST be evaluated within its own approved scope and lifetime. - Revocation, renewal, or token spend events that change permission state MUST invalidate affected cache entries immediately. - Internal function names, callback names, and class names in this document are illustrative unless explicitly defined as protocol surface. --- ## 4. Permission Types ### 4.1 Protocol Permissions Protocol permissions control an application's ability to interact with named protocols for cryptographic and data operations. #### Scope A protocol permission is scoped by two fields: - **`protocolID`**: A tuple of `[securityLevel, protocolName]` - `securityLevel` - integer, `1` or `2` - `protocolName` - string identifier for the protocol - **`counterparty`**: `'self'`, `'anyone'`, or a compressed public key identifying the other party. Empty string is invalid. - For **Level 2**, `counterparty` is REQUIRED and permission scope is per-originator + per-counterparty. - For **Level 1**, any `counterparty` is allowed, and it SHOULD be omitted in manifest declarations. #### Security Levels - **Level 0**: Open usage - no permission check is required. - **Level 1**: Any counterparty is allowed. No counterparty prompt is required. Once granted for an originator, the permission applies across all counterparties for that originator. The wallet SHOULD present the scope as application-only (e.g. "only with this app"). - **Level 2**: Only this specific external counterparty is permitted. The wallet MUST identify the counterparty to the user by displaying the counterparty's compressed public key, and a PACT relationship may be created (see Section 5). The wallet SHOULD present the scope as application-and-counterparty (e.g. "only with this app and counterparty"). #### Grant Options Protocol permission scope is binary (grant or deny), with no amount limit. Wallets MAY offer one-request or bounded session authorization without creating an on-chain token, while preserving existing persistent grants. Wallets SHOULD issue protocol grants as non-expiring (`expiry = 0`). If an implementation supports finite expiry values, it SHOULD require explicit user or administrator intent, because routine expiry creates repeated renewal prompts and degraded UX. --- ### 4.1.1 Action Label grants carried by DPACP An Action Label permission is a resource permission even when represented using DPACP internally. Wallet prompts, permission lists, app access views, details and revocation controls MUST distinguish it from ordinary cryptographic protocol use. Show the exact label and whether access permits applying it to newly created transactions, reading matching history, or both. Reading by label can include matching activity created through other applications; a label does not prove application ownership of every matching transaction. Existing `[1, "action label