## Replit Identity
**Supports TypeScript**

Create and verify Replit Identity tokens.

[![NPM Version][npm-version-image]][npm-url]
[![NPM Install Size][npm-install-size-image]][npm-install-size-url]
[![NPM Downloads][npm-downloads-image]][npm-downloads-url]
```js
const { create, verify } = require('replit-identity');

const audience = 'target-repl-id';
const token = await create(audience);

const info = await verify(token, audience);
console.log(info);
```
### Installation
```bash
npm install replit-identity
```
**Important:** This package can only be used within a Replit environment.
### API
The `replit-identity` module exports the following functions:

**create**

Creates a new identity token.
* **param:** `audience` (string): The target audience for the token.
* **returns:** A Promise resolving to the string token, or null on error.

**verify**

Verifies an existing identity token.
* **param:** `token` (string): The token to verify.
* **param:** `audience` (string): The audience to verify against.
* **returns:** A Promise resolving to an object containing token information, or null if the token is invalid.

Example return value:
```js
const info = {
  slug: "repl-name", 
  replId: "unique-repl-id",
  audience: "target-repl-id", 
  username: "jane_doe" ,
  userId: 12345,
  runtime: {
    // Based on Replit environment:
    interactive: {
      cluster: 'example-cluster',
      subcluster: 'example-subcluster'
    },
    // Or:
    hosting: {
      cluster: 'example-cluster',
      subcluster: 'example-subcluster'
    },
    // Or (if in deployment):
    deployment: true,
  }
}
```

[npm-downloads-image]: https://badgen.net/npm/dm/replit-identity
[npm-downloads-url]: https://npmcharts.com/compare/replit-identity?minimal=true
[npm-install-size-image]: https://badgen.net/packagephobia/install/replit-identity
[npm-install-size-url]: https://packagephobia.com/result?p=replit-identity
[npm-url]: https://npmjs.org/package/replit-identity
[npm-version-image]: https://badgen.net/npm/v/replit-identity
