Skip to content

Commit e0d8b86

Browse files
committed
feat(payment): add auth-service delegation routes, and sdk helpers.
- wire `/register-payer` and `/add-users` into the auth Express app - lazily manage Lit client lifecycle, reusing worker instance when present - derive payer wallets deterministically and delegate via PaymentManager - expose auth-service `registerPayer` / `delegateUsers` helpers in networks + client SDK
1 parent 3e06601 commit e0d8b86

File tree

10 files changed

+624
-7
lines changed

10 files changed

+624
-7
lines changed

apps/lit-auth-server/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const litAuthServer = createLitAuthServer({
77
network: process.env['NETWORK'],
88
litTxsenderRpcUrl: process.env['LIT_TXSENDER_RPC_URL'] as string,
99
litTxsenderPrivateKey: process.env['LIT_TXSENDER_PRIVATE_KEY'],
10+
litDelegationRootMnemonic: process.env['LIT_DELEGATION_ROOT_MNEMONIC'],
1011
enableApiKeyGate: process.env['ENABLE_API_KEY_GATE'] === 'true',
1112
stytchProjectId: process.env['STYTCH_PROJECT_ID'],
1213
stytchSecretKey: process.env['STYTCH_SECRET'],

packages/auth-services/src/auth-server/src/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import rateLimit from 'express-rate-limit';
55
import { json, urlencoded } from 'express';
66
import { registerStatusRoutes } from './routes/status.express';
77
import { registerPkpRoutes } from './routes/pkp.express';
8+
import { registerPaymentRoutes } from './routes/payment.express';
89
import { registerStytchRoutes } from './routes/auth/stytch.express';
910
import { registerWebAuthnRoutes } from './routes/auth/webauthn.express';
1011
import { apiKeyGate } from '../middleware/apiKeyGate.express';
@@ -20,6 +21,8 @@ export const createApp = (config?: Partial<AppConfig>): Express => {
2021
litTxsenderRpcUrl: config?.litTxsenderRpcUrl ?? env.LIT_TXSENDER_RPC_URL,
2122
litTxsenderPrivateKey:
2223
config?.litTxsenderPrivateKey ?? env.LIT_TXSENDER_PRIVATE_KEY,
24+
litDelegationRootMnemonic:
25+
config?.litDelegationRootMnemonic ?? env.LIT_DELEGATION_ROOT_MNEMONIC,
2326
enableApiKeyGate: config?.enableApiKeyGate ?? env.ENABLE_API_KEY_GATE,
2427
redisUrl: config?.redisUrl ?? env.REDIS_URL,
2528
stytchProjectId: config?.stytchProjectId ?? env.STYTCH_PROJECT_ID,
@@ -56,6 +59,7 @@ export const createApp = (config?: Partial<AppConfig>): Express => {
5659
// routes
5760
registerStatusRoutes(app);
5861
registerPkpRoutes(app);
62+
registerPaymentRoutes(app, cfg);
5963
registerStytchRoutes(app, createStytchClient(cfg));
6064
registerWebAuthnRoutes(app);
6165

packages/auth-services/src/auth-server/src/createAuthServer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type CreateLitAuthServerOptions = {
1010
network?: string;
1111
litTxsenderRpcUrl?: string;
1212
litTxsenderPrivateKey?: string;
13+
litDelegationRootMnemonic?: string;
1314
enableApiKeyGate?: boolean;
1415
redisUrl?: string;
1516
stytchProjectId?: string;
@@ -33,6 +34,7 @@ export const createLitAuthServer = (
3334
network: options.network,
3435
litTxsenderRpcUrl: options.litTxsenderRpcUrl,
3536
litTxsenderPrivateKey: options.litTxsenderPrivateKey,
37+
litDelegationRootMnemonic: options.litDelegationRootMnemonic,
3638
enableApiKeyGate: options.enableApiKeyGate ?? false,
3739
redisUrl: options.redisUrl,
3840
stytchProjectId: options.stytchProjectId,

packages/auth-services/src/auth-server/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const cfg = {
1111
network: env.NETWORK,
1212
litTxsenderRpcUrl: env.LIT_TXSENDER_RPC_URL,
1313
litTxsenderPrivateKey: env.LIT_TXSENDER_PRIVATE_KEY,
14+
litDelegationRootMnemonic: env.LIT_DELEGATION_ROOT_MNEMONIC,
1415
enableApiKeyGate: env.ENABLE_API_KEY_GATE,
1516
redisUrl: env.REDIS_URL,
1617
stytchProjectId: env.STYTCH_PROJECT_ID,

packages/auth-services/src/auth-server/src/providers/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const env = createEnv({
1818
STYTCH_SECRET: z.string().min(1).optional(),
1919
MAX_REQUESTS_PER_WINDOW: z.coerce.number().int().positive().default(60),
2020
WINDOW_MS: z.coerce.number().int().positive().default(60_000),
21+
LIT_DELEGATION_ROOT_MNEMONIC: z.string().min(1).optional(),
2122
},
2223
clientPrefix: 'PUBLIC_',
2324
client: {},
@@ -36,4 +37,5 @@ export type AppConfig = {
3637
stytchSecretKey?: string;
3738
maxRequestsPerWindow: number;
3839
windowMs: number;
40+
litDelegationRootMnemonic?: string;
3941
};

0 commit comments

Comments
 (0)