# Authorization

A system for obtaining and managing increased API rate limits through request authorization.

### Initialization

```typescript
const afSdk = new Aftermath("MAINNET");
await afSdk.init(); // initialize provider

const auth = afSdk.Auth();
```

### Rate Limits

Default rate limit: 1000 requests per 10 seconds.

To request increased limits:

1. Visit [Aftermath Discord](https://discord.com/invite/KvVCAauXk5)
2. Open a ticket with:

```
sui-address: <your-sui-address>
rate-limit-requests: [<sdk-call>: <desired-rate-limit>]
```

### Methods

#### Initialize with Private Key

```typescript
const keypair = Helpers.keypairFromPrivateKey("your-private-key");

const stopAuth = await auth.init({
	signMessageCallback: async ({ message }) => {
		const { signature } = await keypair.signPersonalMessage(message);
		return { signature };
	},
	walletAddress: keypair.toSuiAddress(),
});

// Make authorized requests
const pools = await afSdk.Pools().getAllPools();

// Stop authorization
stopAuth();
```

### Types

```typescript
interface AuthInitOptions {
	signMessageCallback: (args: { message: Uint8Array }) => Promise<{
		signature: string;
	}>;
	walletAddress: string;
}
```

### Example Usage

```typescript
const afSdk = new Aftermath("MAINNET");
await afSdk.init();

// Initialize with private key
const keypair = Helpers.keypairFromPrivateKey("your-private-key");
const stopAuth = await afSdk.Auth().init({
	signMessageCallback: async ({ message }) => {
		const { signature } = await keypair.signPersonalMessage(message);
		return { signature };
	},
	walletAddress: keypair.toSuiAddress(),
});

// Make authorized requests
const pools = await afSdk.Pools().getAllPools();
const prices = await afSdk.Prices().getCoinPrice({
	coin: "0x2::sui::SUI",
});

// Clean up
stopAuth();
```
