# SubscriptionManager

## Overview

The Secret AI [Subscription Manager Contract](https://github.com/scrtlabs/claive-contracts/blob/master/subscription-manager/src/contract.rs) is designed for subscription-based use cases, where an admin manages subscribers using their public keys. The contract keeps track of registered subscribers and API keys, ensuring that only authorized admins can manage them.

## Contract State

The contract stores:

* **Admin Address**: The account that has permission to register or remove subscribers, manage API keys, and change admin rights.
* **Subscribers**: A mapping from a public key to the subscriber's status (active or inactive).
* **API Keys**: A mapping of hashed API keys used for external access control. The API keys are stored as SHA-256 hashes to enhance security.

## Messages (ExecuteMsg)

**Note**: All `ExecuteMsg` messages can only be called by the **admin** of the contract.

### `RegisterSubscriber`&#x20;

* **Action**: Registers a new subscriber in the contract's state.
* **Parameters**:
  * `public_key` (String): The public key of the subscriber.

### `RemoveSubscriber`

* **Action**: Removes a subscriber from the contract's state.
* **Parameters**:
  * `public_key` (String): The public key of the subscriber.

### `SetAdmin`

* **Action**: Updates the admin of the contract.
* **Parameters**:
  * `public_key` (String): The public key of the new admin.

### `AddApiKey`

* **Action**: Adds a new API key (its `SHA-256` hash) to the contract's state.
* **Parameters**:
  * `api_key` (String): The plaintext API key.

### **`RevokeApiKey`**

* **Action**: Revokes an existing API key by removing its hash.
* **Parameters**:
  * `api_key` (String): The plaintext API key.

## Queries (QueryMsg)

### `SubscriberStatus`

* **Action**: Verifies whether a subscriber is active by checking if their public key is stored in the contract.
* **Parameters**:
  * `public_key` (String): The public key of the subscriber.
* **Response**:
  * `active` (bool): Returns `true` if the subscriber is active, otherwise `false`.

### `ApiKeysWithPermit`

* **Action**: Returns the list of all stored API keys.
* **Parameters**:
  * `permit` (Permit): A valid admin-signed permit.
* **Response**:
  * `api_keys` (Vec\<ApiKey>): A list of hashed API keys.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.scrt.network/secret-network-documentation/secret-ai/smart-contract-reference/subscriptionmanager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
