> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript Manage Sessions

> Restore sessions, manage access, and sign out with the TypeScript OMS Wallet SDK.

Use the TypeScript SDK session APIs after authentication to restore wallet state, issue ID tokens, and manage credential access.

## Session Restore

The default storage backend is browser `localStorage` when it is available. Non-browser runtimes use in-memory storage unless you provide a custom `StorageManager`. OIDC redirect state defaults to browser `sessionStorage`.

Browser signing defaults to a non-extractable WebCrypto P-256 credential stored through IndexedDB when available, so raw private key bytes are not written to `localStorage`.

```typescript theme={null}
import { MemoryStorageManager, OMSClient } from '@0xsequence/typescript-sdk'

const oms = new OMSClient({
  publishableKey: 'YOUR_PROJECT_ACCESS_KEY',
  projectId: 'YOUR_PROJECT_ID',
  storage: new MemoryStorageManager(),
  redirectAuthStorage: new MemoryStorageManager(),
})

if (oms.wallet.session.walletAddress) {
  console.log('Restored wallet:', oms.wallet.session.walletAddress)
}
```

**Returns**

`oms.wallet.session` returns `OMSClientSessionState` with `walletAddress`, `expiresAt`, `loginType`, and `sessionEmail`.

## Session Expiry Events

Register an `onSessionExpired` listener when the app should react as soon as the active wallet session expires.

```typescript theme={null}
const unsubscribe = oms.wallet.onSessionExpired((event) => {
  console.log('Session expired at:', event.expiredAt)
  console.log('Expired wallet:', event.session.walletAddress)
})

// Call when the component, route, or service no longer needs updates.
unsubscribe()
```

The SDK replays the latest expired-session event to new listeners until a new auth flow, new wallet session, or sign out clears it. Listener errors are ignored by the SDK so app callbacks do not change wallet operation results.

**Parameters**

| Parameter  | Type                              | Description                                                                      |
| ---------- | --------------------------------- | -------------------------------------------------------------------------------- |
| `listener` | `OMSClientSessionExpiredListener` | Callback that receives `{ session, expiredAt }` when the wallet session expires. |

**Returns**

Returns `() => void`, an unsubscribe function that removes the listener.

## List Wallets

List wallets available to the authenticated credential.

```typescript theme={null}
const wallets = await oms.wallet.listWallets()

for (const wallet of wallets) {
  console.log(wallet.id, wallet.type, wallet.address)
}
```

**Parameters**

Takes no parameters.

**Returns**

Returns `Promise<OmsWallet[]>`.

## Get ID Token

Request an ID token for the active wallet session. Send this token to your backend when using backend wallet verification.

```typescript theme={null}
const idToken = await oms.wallet.getIdToken({
  ttlSeconds: 300,
})
```

**Parameters**

| Parameter      | Type                                   | Description                                     |
| -------------- | -------------------------------------- | ----------------------------------------------- |
| `ttlSeconds`   | `number` or undefined                  | Optional token lifetime in seconds.             |
| `customClaims` | `Record<string, unknown>` or undefined | Optional custom claims to include in the token. |

**Returns**

Returns `Promise<string>`.

## List Access

List credentials that currently have access to the active wallet.

```typescript theme={null}
const grants = await oms.wallet.listAccess()

for (const grant of grants) {
  console.log(grant.credentialId, grant.expiresAt, grant.isCaller)
}
```

**Parameters**

| Parameter  | Type                  | Description                                                 |
| ---------- | --------------------- | ----------------------------------------------------------- |
| `pageSize` | `number` or undefined | Optional page size used while following Wallet API cursors. |

**Returns**

Returns `Promise<AccessGrant[]>`.

## List Access Pages

Use `listAccessPages` when your UI should render credential access one page at a time.

```typescript theme={null}
for await (const page of oms.wallet.listAccessPages({ pageSize: 25 })) {
  for (const grant of page.grants) {
    console.log(grant.credentialId, grant.isCaller)
  }
}
```

**Parameters**

| Parameter  | Type                  | Description                                     |
| ---------- | --------------------- | ----------------------------------------------- |
| `pageSize` | `number` or undefined | Optional page size for each Wallet API request. |

**Returns**

Returns `AsyncIterable<AccessGrantPage>`.

## Revoke Access

Revoke another credential's access to the active wallet.

```typescript theme={null}
await oms.wallet.revokeAccess({
  targetCredentialId: 'credential-id',
})
```

**Parameters**

| Parameter            | Type     | Description                             |
| -------------------- | -------- | --------------------------------------- |
| `targetCredentialId` | `string` | Credential ID returned by `listAccess`. |

**Returns**

Returns `Promise<void>`.

## Sign Out

```typescript theme={null}
await oms.wallet.signOut()
```

Signing out clears wallet metadata from storage, pending OIDC redirect auth state, and the configured credential signer when supported.

**Parameters**

Takes no parameters.

**Returns**

Returns `Promise<void>`.
