|
| 1 | +# API Reference |
| 2 | + |
| 3 | +This section lists every exported function from **@thirdweb-dev/vault-sdk** grouped by broad capability. All functions are fully typed – hover in your editor for exact type information. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1. Client utilities |
| 8 | + |
| 9 | +| Function | Description | |
| 10 | +| --- | --- | |
| 11 | +| `createVaultClient({ secretKey })` | Uses your project secret key to establish a connection to your Vault instance and returns a `VaultClient`. Create **one** client per Vault instance and reuse it. | |
| 12 | +| `ping({ client, request })` | Health-check endpoint mainly used in examples and tests. Returns the current server time. | |
| 13 | + |
| 14 | +```ts |
| 15 | +const client = await createVaultClient({ secretKey: "PROJECT_SECRET_KEY" }); |
| 16 | +await ping({ client, request: { message: "pong?" } }); |
| 17 | +``` |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## 2. Service Accounts |
| 22 | + |
| 23 | +| Function | When to use | |
| 24 | +| --- | --- | |
| 25 | +| `createServiceAccount({ request })` | Bootstrap a brand-new Vault. Returns the **admin key** and **rotation code**. _Run once during provisioning_. | |
| 26 | +| `getServiceAccount({ request })` | Retrieve metadata for the current service account. Requires **admin key** or a token with `serviceAccount:read` policy. | |
| 27 | +| `rotateServiceAccount({ request })` | Rotate (invalidate) the admin key **and** all existing access tokens in a single atomic operation. Authenticate with the **rotation code**. | |
| 28 | + |
| 29 | +Example – rotate an account after a key leak: |
| 30 | + |
| 31 | +```ts |
| 32 | +await rotateServiceAccount({ |
| 33 | + client, |
| 34 | + request: { |
| 35 | + auth: { rotationCode: process.env.VAULT_ROTATION_CODE! }, |
| 36 | + }, |
| 37 | +}); |
| 38 | +``` |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## 3. EOAs (Wallets) |
| 43 | + |
| 44 | +| Function | Purpose | |
| 45 | +| --- | --- | |
| 46 | +| `createEoa` | Create a new EOA (wallet) inside the Vault. Optionally attach arbitrary `metadata` for later querying. | |
| 47 | +| `listEoas` | Pagination-aware listing with optional metadata filters. | |
| 48 | +| `signTransaction` | Ask the Vault to sign an EVM transaction (legacy, 2930, 1559, 4844 or 7702). | |
| 49 | +| `signMessage` | Sign a plain string / hex message. | |
| 50 | +| `signTypedData` | Sign EIP-712 typed data with full generic type safety. | |
| 51 | +| `signAuthorization` | Sign an [`Authorization`](#authorization) struct used by some L2s / account-abstraction schemes. | |
| 52 | +| `signStructuredMessage` | Sign EIP-4337 user-operations (v0.6 & v0.7). | |
| 53 | + |
| 54 | +```ts |
| 55 | +// sign a 1559 tx |
| 56 | +import { parseTransaction, signTransaction } from "@thirdweb-dev/vault-sdk"; |
| 57 | + |
| 58 | +const tx = parseTransaction({ |
| 59 | + to: "0x...", |
| 60 | + value: 0n, |
| 61 | + chainId: 1, |
| 62 | + maxFeePerGas: 30n * 10n ** 9n, |
| 63 | + maxPriorityFeePerGas: 1n * 10n ** 9n, |
| 64 | + gasLimit: 21_000, |
| 65 | +}); |
| 66 | + |
| 67 | +await signTransaction({ |
| 68 | + client, |
| 69 | + request: { |
| 70 | + auth: { accessToken: process.env.VAULT_SIG_TOKEN! }, |
| 71 | + options: { from: "0xEoaAddress", transaction: tx }, |
| 72 | + }, |
| 73 | +}); |
| 74 | +``` |
| 75 | + |
| 76 | +> **Note**: `parseTransaction` is a convenience helper that normalises user-supplied objects – you can also build the canonical tx object yourself. |
| 77 | +
|
| 78 | +--- |
| 79 | + |
| 80 | +## 4. Access Tokens |
| 81 | + |
| 82 | +| Function | Purpose | |
| 83 | +| --- | --- | |
| 84 | +| `createAccessToken` | Mint a **base token** scoped by policies & metadata. Requires **admin key**. | |
| 85 | +| `createSignedAccessToken` | Pure-client helper that turns a *base* token into a short-lived, signed JWT (prefixed with `vt_sat_`). No server round-trip required. | |
| 86 | +| `listAccessTokens` | List existing tokens with pagination and optional metadata filters. | |
| 87 | +| `revokeAccessToken` | Immediately invalidate a token (or all derived signed tokens) by `id`. | |
| 88 | + |
| 89 | +```ts |
| 90 | +// Derive a time-boxed signed token for a serverless function |
| 91 | +const sat = await createSignedAccessToken({ |
| 92 | + vaultClient: client, |
| 93 | + baseAccessToken: process.env.VAULT_BASE_TOKEN!, |
| 94 | + additionalPolicies: [ |
| 95 | + { type: "eoa:signMessage", chainId: 1, messagePattern: "^0x.*" }, |
| 96 | + ], |
| 97 | + expiryTimestamp: Math.floor(Date.now() / 1000) + 60 * 5, // 5 min |
| 98 | +}); |
| 99 | +``` |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## 5. Utilities |
| 104 | + |
| 105 | +| Function | Notes | |
| 106 | +| --- | --- | |
| 107 | +| `parseTransaction` | Normalises user input into a canonical `EthereumTypedTransaction` (supports Legacy, 2930, 1559, 4844, 7702). Throws `ParseTransactionError` on invalid input. | |
| 108 | +| `ParseTransactionError` | Custom error class thrown by the above helper. | |
| 109 | + |
| 110 | +```ts |
| 111 | +try { |
| 112 | + parseTransaction({ gas: 100_000 }); |
| 113 | +} catch (err) { |
| 114 | + if (err instanceof ParseTransactionError) { |
| 115 | + console.error(err.message); |
| 116 | + } |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +### Types |
| 123 | + |
| 124 | +All request & response shapes are exported as TypeScript types so you can easily model higher-level abstractions: |
| 125 | + |
| 126 | +```ts |
| 127 | +import type { CreateEoaPayload, SignMessagePayload, PolicyComponent } from "@thirdweb-dev/vault-sdk"; |
| 128 | +``` |
| 129 | + |
| 130 | +Refer to the generated `.d.ts` files for the complete list. |
0 commit comments