@levrbet/shared 0.1.24 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ export declare const PRIVY_ACCESS_TOKEN_HEADER = "privy-access-token";
2
+ export declare const PRIVY_ID_TOKEN_HEADER = "privy-id-token";
3
+ export declare const ETH_ADDRESS_HEADER = "x-eth-address";
4
+ export declare const PRIVY_APP_ID = "cmbqis2px002olc0mrst5g8m4";
5
+ export declare const PRIVY_ADMIN_APP_ID = "cmg20fmvw00ario0dglp3v6hm";
6
+ export declare const PRIVY_VERIFICATION_KEY = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7CcgncUum6Zy+HWg4/MnGJJpWBuGXTvc9WcKxo97+Zq+HuVlNUs8SR0Xo/cG0z6AIGSdvwMOtJv/KGVrJB5NTw==\n-----END PUBLIC KEY-----";
7
+ export declare const PRIVY_ADMIN_VERIFICATION_KEY = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEcuBbOngKnfn6i6NcwBKUT3E363NUpKo4vKMBqeldrPt3LOym5AdKAWmmHVPOR4wr7pNcFtbkLzzmmvmmt2iswA==\n-----END PUBLIC KEY-----";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRIVY_ADMIN_VERIFICATION_KEY = exports.PRIVY_VERIFICATION_KEY = exports.PRIVY_ADMIN_APP_ID = exports.PRIVY_APP_ID = exports.ETH_ADDRESS_HEADER = exports.PRIVY_ID_TOKEN_HEADER = exports.PRIVY_ACCESS_TOKEN_HEADER = void 0;
4
+ exports.PRIVY_ACCESS_TOKEN_HEADER = "privy-access-token";
5
+ exports.PRIVY_ID_TOKEN_HEADER = "privy-id-token";
6
+ exports.ETH_ADDRESS_HEADER = "x-eth-address";
7
+ exports.PRIVY_APP_ID = "cmbqis2px002olc0mrst5g8m4";
8
+ exports.PRIVY_ADMIN_APP_ID = "cmg20fmvw00ario0dglp3v6hm";
9
+ exports.PRIVY_VERIFICATION_KEY = `-----BEGIN PUBLIC KEY-----
10
+ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7CcgncUum6Zy+HWg4/MnGJJpWBuGXTvc9WcKxo97+Zq+HuVlNUs8SR0Xo/cG0z6AIGSdvwMOtJv/KGVrJB5NTw==
11
+ -----END PUBLIC KEY-----`;
12
+ exports.PRIVY_ADMIN_VERIFICATION_KEY = `-----BEGIN PUBLIC KEY-----
13
+ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEcuBbOngKnfn6i6NcwBKUT3E363NUpKo4vKMBqeldrPt3LOym5AdKAWmmHVPOR4wr7pNcFtbkLzzmmvmmt2iswA==
14
+ -----END PUBLIC KEY-----`;
15
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,yBAAyB,GAAG,oBAAoB,CAAA;AAChD,QAAA,qBAAqB,GAAG,gBAAgB,CAAA;AACxC,QAAA,kBAAkB,GAAG,eAAe,CAAA;AAEpC,QAAA,YAAY,GAAG,2BAA2B,CAAA;AAC1C,QAAA,kBAAkB,GAAG,2BAA2B,CAAA;AAEhD,QAAA,sBAAsB,GAAG;;yBAEb,CAAA;AACZ,QAAA,4BAA4B,GAAG;;yBAEnB,CAAA"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A React Query hook that provides authentication headers for API requests.
3
+ *
4
+ * This hook automatically manages the retrieval and caching of authentication headers
5
+ * including the user's Ethereum address, Privy access token, and identity token.
6
+ * The headers are refreshed every 10 minutes and cached for optimal performance.
7
+ *
8
+ * @returns A React Query result containing the authentication headers object
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Basic usage in a component
13
+ * const {data: authHeaders = {}} = useAuthHeaders()
14
+ * ```
15
+ */
16
+ export declare const useAuthHeaders: () => import("@tanstack/react-query").UseQueryResult<{
17
+ "x-eth-address"?: undefined;
18
+ "privy-access-token"?: undefined;
19
+ "privy-id-token"?: undefined;
20
+ } | {
21
+ "x-eth-address": `0x${string}` | undefined;
22
+ "privy-access-token": string | null;
23
+ "privy-id-token": {
24
+ identityToken: string | null;
25
+ };
26
+ }, Error>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useAuthHeaders = void 0;
7
+ const react_auth_1 = require("@privy-io/react-auth");
8
+ const react_query_1 = require("@tanstack/react-query");
9
+ const lodash_1 = __importDefault(require("lodash"));
10
+ const ms_1 = __importDefault(require("ms"));
11
+ const wagmi_1 = require("wagmi");
12
+ const constants_1 = require("../../../core/constants");
13
+ /**
14
+ * A React Query hook that provides authentication headers for API requests.
15
+ *
16
+ * This hook automatically manages the retrieval and caching of authentication headers
17
+ * including the user's Ethereum address, Privy access token, and identity token.
18
+ * The headers are refreshed every 10 minutes and cached for optimal performance.
19
+ *
20
+ * @returns A React Query result containing the authentication headers object
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // Basic usage in a component
25
+ * const {data: authHeaders = {}} = useAuthHeaders()
26
+ * ```
27
+ */
28
+ const useAuthHeaders = () => {
29
+ const { user, getAccessToken } = (0, react_auth_1.usePrivy)();
30
+ const identityToken = (0, react_auth_1.useIdentityToken)();
31
+ const { refreshUser } = (0, react_auth_1.useUser)();
32
+ const { address } = (0, wagmi_1.useAccount)();
33
+ return (0, react_query_1.useQuery)({
34
+ queryKey: ["authHeaders", user?.id, address],
35
+ queryFn: async () => {
36
+ if (!user)
37
+ return {};
38
+ await refreshUser();
39
+ return {
40
+ [constants_1.ETH_ADDRESS_HEADER]: address,
41
+ [constants_1.PRIVY_ACCESS_TOKEN_HEADER]: await getAccessToken(),
42
+ [constants_1.PRIVY_ID_TOKEN_HEADER]: identityToken,
43
+ };
44
+ },
45
+ enabled: !lodash_1.default.isNil(user),
46
+ refetchInterval: (0, ms_1.default)("10m"),
47
+ staleTime: (0, ms_1.default)("10m"),
48
+ gcTime: (0, ms_1.default)("10m"),
49
+ });
50
+ };
51
+ exports.useAuthHeaders = useAuthHeaders;
52
+ //# sourceMappingURL=useAuthHeaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthHeaders.js","sourceRoot":"","sources":["../../../../src/react/hooks/auth/useAuthHeaders.ts"],"names":[],"mappings":";;;;;;AAAA,qDAA0E;AAC1E,uDAAgD;AAChD,oDAAsB;AACtB,4CAAmB;AACnB,iCAAkC;AAClC,uDAA8G;AAE9G;;;;;;;;;;;;;;GAcG;AACI,MAAM,cAAc,GAAG,GAAG,EAAE;IAC/B,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,IAAA,qBAAQ,GAAE,CAAA;IAC3C,MAAM,aAAa,GAAG,IAAA,6BAAgB,GAAE,CAAA;IACxC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,oBAAO,GAAE,CAAA;IACjC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAA;IAEhC,OAAO,IAAA,sBAAQ,EAAC;QACZ,QAAQ,EAAE,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC;QAC5C,OAAO,EAAE,KAAK,IAAI,EAAE;YAChB,IAAI,CAAC,IAAI;gBAAE,OAAO,EAAE,CAAA;YACpB,MAAM,WAAW,EAAE,CAAA;YAEnB,OAAO;gBACH,CAAC,8BAAkB,CAAC,EAAE,OAAO;gBAC7B,CAAC,qCAAyB,CAAC,EAAE,MAAM,cAAc,EAAE;gBACnD,CAAC,iCAAqB,CAAC,EAAE,aAAa;aACzC,CAAA;QACL,CAAC;QACD,OAAO,EAAE,CAAC,gBAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QACvB,eAAe,EAAE,IAAA,YAAE,EAAC,KAAK,CAAC;QAC1B,SAAS,EAAE,IAAA,YAAE,EAAC,KAAK,CAAC;QACpB,MAAM,EAAE,IAAA,YAAE,EAAC,KAAK,CAAC;KACpB,CAAC,CAAA;AACN,CAAC,CAAA;AAvBY,QAAA,cAAc,kBAuB1B"}
@@ -1,4 +1,4 @@
1
- import type { User as PrivyUser } from "@privy-io/server-auth";
1
+ import type { User as PrivyUser } from "@privy-io/node";
2
2
  import type { NextFunction, Request, Response } from "express";
3
3
  import Redis from "ioredis";
4
4
  import type { Address } from "viem";
@@ -9,4 +9,4 @@ declare module "express-serve-static-core" {
9
9
  }
10
10
  }
11
11
  export declare const authMiddleWare: (redis: Redis) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
12
- export declare const privyAuthExpressMiddleware: (req: Request, res: Response, next: NextFunction) => Promise<void>;
12
+ export * from "./privy.middleware";
@@ -1,13 +1,25 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
18
  };
5
19
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.privyAuthExpressMiddleware = exports.authMiddleWare = void 0;
7
- const axios_1 = __importDefault(require("axios"));
20
+ exports.authMiddleWare = void 0;
8
21
  const jose_1 = require("jose");
9
22
  const dotenv_1 = require("../../config/dotenv");
10
- const urls_1 = require("../../config/urls");
11
23
  const winston_1 = __importDefault(require("../../config/winston"));
12
24
  const kms_1 = require("../kms");
13
25
  // TODO: instantiate this such that it doesn't break services that do not use kms config
@@ -68,32 +80,5 @@ const authMiddleWare = (redis) => {
68
80
  };
69
81
  };
70
82
  exports.authMiddleWare = authMiddleWare;
71
- const privyAuthExpressMiddleware = async (req, res, next) => {
72
- const ethAddress = req.headers["eth-address"];
73
- const cookies = req.cookies;
74
- const privyToken = req.headers["privy-token"] || cookies["privy-token"];
75
- const privyIdToken = req.headers["privy-id-token"] || cookies["privy-id-token"];
76
- try {
77
- const response = await axios_1.default.get(urls_1.urls.auth + "/privy-auth", {
78
- headers: {
79
- "privy-token": privyToken,
80
- "privy-id-token": privyIdToken,
81
- "eth-address": ethAddress,
82
- },
83
- });
84
- if (!response.data.privyUser || !response.data.ethAddress) {
85
- res.status(401).json({ message: "Unauthorized" });
86
- return;
87
- }
88
- req.privyUser = response.data.privyUser;
89
- req.ethAddress = response.data.ethAddress;
90
- next();
91
- }
92
- catch (err) {
93
- winston_1.default.error("Privy auth failed", err);
94
- res.status(401).json({ message: "Unauthorized" });
95
- return;
96
- }
97
- };
98
- exports.privyAuthExpressMiddleware = privyAuthExpressMiddleware;
83
+ __exportStar(require("./privy.middleware"), exports);
99
84
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/server/auth/middleware/index.ts"],"names":[],"mappings":";;;;;;AACA,kDAAyB;AAGzB,+BAAoD;AAEpD,gDAAkD;AAClD,4CAAwC;AACxC,mEAAyC;AACzC,gCAA4D;AAS5D,wFAAwF;AACxF,MAAM,IAAI,GAAG,IAAA,yBAAkB,EAAC,IAAI,GAAG,CAAC,qBAAqB,CAAC,qCAAqC,CAAC,CAAC,CAAA;AAE9F,MAAM,c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OAAO,EAAE,wBAAwB,EAAE,CAAC,CAAA;YAC/D,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,IAAI,EAAE,CAAA;QACV,CAAC;IACL,CAAC,CAAA;AACL,CAAC,CAAA;AApDY,QAAA,cAAc,kBAoD1B;AAED,qDAAkC"}
@@ -0,0 +1,17 @@
1
+ import type { NextFunction, Request, Response } from "express";
2
+ /**
3
+ * Creates authentication middleware for Privy token validation.
4
+ *
5
+ * This middleware validates Privy access tokens and ID tokens, authenticates users,
6
+ * and sets the authenticated user context on the request object. It supports both
7
+ * User and Admin authentication types.
8
+ *
9
+ * @param type - The authentication type, either "User" or "Admin"
10
+ * @returns An Express middleware function that:
11
+ * - Extracts Privy tokens and ETH address from request headers
12
+ * - Validates the tokens using the appropriate Privy service method
13
+ * - Sets `req.privyUser` and `req.ethAddress` properties on successful authentication
14
+ * - Returns 401 Unauthorized response if authentication fails
15
+ *
16
+ */
17
+ export declare const privyAuthMiddleware: (type: "User" | "Admin") => (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.privyAuthMiddleware = void 0;
4
+ const viem_1 = require("viem");
5
+ const constants_1 = require("../../../core/constants");
6
+ const privy_service_1 = require("../privy.service");
7
+ /**
8
+ * Creates authentication middleware for Privy token validation.
9
+ *
10
+ * This middleware validates Privy access tokens and ID tokens, authenticates users,
11
+ * and sets the authenticated user context on the request object. It supports both
12
+ * User and Admin authentication types.
13
+ *
14
+ * @param type - The authentication type, either "User" or "Admin"
15
+ * @returns An Express middleware function that:
16
+ * - Extracts Privy tokens and ETH address from request headers
17
+ * - Validates the tokens using the appropriate Privy service method
18
+ * - Sets `req.privyUser` and `req.ethAddress` properties on successful authentication
19
+ * - Returns 401 Unauthorized response if authentication fails
20
+ *
21
+ */
22
+ const privyAuthMiddleware = (type) => {
23
+ return async (req, res, next) => {
24
+ const privyToken = req.headers[constants_1.PRIVY_ACCESS_TOKEN_HEADER]?.toString();
25
+ const privyIdToken = req.headers[constants_1.PRIVY_ID_TOKEN_HEADER]?.toString();
26
+ const ethAddress = req.headers[constants_1.ETH_ADDRESS_HEADER]?.toString();
27
+ const privyUser = await privy_service_1.privyService[`authenticate${type}`]({ privyToken, privyIdToken, ethAddress });
28
+ if (!privyUser) {
29
+ res.status(401).json({ message: "Unauthorized" });
30
+ return;
31
+ }
32
+ req.privyUser = privyUser;
33
+ req.ethAddress = ethAddress && (0, viem_1.isAddress)(ethAddress) ? (0, viem_1.getAddress)(ethAddress) : privy_service_1.privyService.getUserEthAddress(privyUser);
34
+ next();
35
+ };
36
+ };
37
+ exports.privyAuthMiddleware = privyAuthMiddleware;
38
+ //# sourceMappingURL=privy.middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privy.middleware.js","sourceRoot":"","sources":["../../../../src/server/auth/middleware/privy.middleware.ts"],"names":[],"mappings":";;;AACA,+BAA4C;AAC5C,uDAA8G;AAC9G,oDAA+C;AAE/C;;;;;;;;;;;;;;GAcG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAsB,EAAE,EAAE;IAC1D,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAiB,EAAE;QAC5E,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,qCAAyB,CAAC,EAAE,QAAQ,EAAE,CAAA;QACrE,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,iCAAqB,CAAC,EAAE,QAAQ,EAAE,CAAA;QACnE,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,8BAAkB,CAAC,EAAE,QAAQ,EAAE,CAAA;QAE9D,MAAM,SAAS,GAAG,MAAM,4BAAY,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CAAA;QAErG,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAA;YACjD,OAAM;QACV,CAAC;QAED,GAAG,CAAC,SAAS,GAAG,SAAS,CAAA;QACzB,GAAG,CAAC,UAAU,GAAG,UAAU,IAAI,IAAA,gBAAS,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,4BAAY,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAA;QAEzH,IAAI,EAAE,CAAA;IACV,CAAC,CAAA;AACL,CAAC,CAAA;AAlBY,QAAA,mBAAmB,uBAkB/B"}
@@ -0,0 +1,24 @@
1
+ import { User as PrivyUser } from "@privy-io/node";
2
+ import { Address } from "viem";
3
+ interface AuthRequest {
4
+ privyToken?: string;
5
+ privyIdToken?: string;
6
+ ethAddress?: string;
7
+ }
8
+ declare class PrivyService {
9
+ authenticateUser: (req: AuthRequest) => Promise<PrivyUser | undefined>;
10
+ authenticateAdmin: (req: AuthRequest) => Promise<PrivyUser | undefined>;
11
+ /**
12
+ * Gets the user's Ethereum wallet address, prioritizing external wallets over Privy wallets.
13
+ * Returns the first external wallet found, or falls back to a Privy wallet if none exist.
14
+ */
15
+ getUserEthAddress: (user: PrivyUser) => Address | undefined;
16
+ private authenticate;
17
+ /**
18
+ * Verifies that an Ethereum address belongs to a user by checking their linked accounts.
19
+ */
20
+ private verifyUserOwnsAddress;
21
+ private getPrivyClients;
22
+ }
23
+ export declare const privyService: PrivyService;
24
+ export {};
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.privyService = void 0;
13
+ const node_1 = require("@privy-io/node");
14
+ const typescript_memoize_1 = require("typescript-memoize");
15
+ const viem_1 = require("viem");
16
+ const zod_1 = __importDefault(require("zod"));
17
+ const core_1 = require("../../core");
18
+ const constants_1 = require("../../core/constants");
19
+ const config_1 = require("../config");
20
+ class PrivyService {
21
+ constructor() {
22
+ this.authenticateUser = async (req) => {
23
+ return this.authenticate(this.getPrivyClients().privyClient, req);
24
+ };
25
+ this.authenticateAdmin = async (req) => {
26
+ return this.authenticate(this.getPrivyClients().privyAdminClient, req);
27
+ };
28
+ /**
29
+ * Gets the user's Ethereum wallet address, prioritizing external wallets over Privy wallets.
30
+ * Returns the first external wallet found, or falls back to a Privy wallet if none exist.
31
+ */
32
+ this.getUserEthAddress = (user) => {
33
+ let address = undefined;
34
+ for (const account of user.linked_accounts) {
35
+ if (account.type !== "wallet" || account.chain_type !== "ethereum")
36
+ continue;
37
+ address = account.address;
38
+ if (account.wallet_client_type !== "privy")
39
+ break;
40
+ }
41
+ return address ? (0, viem_1.getAddress)(address) : undefined;
42
+ };
43
+ /**
44
+ * Verifies that an Ethereum address belongs to a user by checking their linked accounts.
45
+ */
46
+ this.verifyUserOwnsAddress = (user, addressToVerify) => {
47
+ return user.linked_accounts.some((account) => account.type === "wallet" &&
48
+ account.chain_type === "ethereum" &&
49
+ account.address?.toLowerCase() === addressToVerify.toLowerCase());
50
+ };
51
+ }
52
+ async authenticate(client, { privyToken, privyIdToken, ethAddress }) {
53
+ if (!privyToken || !privyIdToken)
54
+ return undefined;
55
+ try {
56
+ await client.utils().auth().verifyAuthToken(privyToken);
57
+ const user = await client.users().get({ id_token: privyIdToken });
58
+ if (ethAddress && !this.verifyUserOwnsAddress(user, ethAddress)) {
59
+ config_1.logger.warn(`User ${user.id} attempted to authenticate with an unlinked address ${ethAddress}.`);
60
+ return undefined;
61
+ }
62
+ return user;
63
+ }
64
+ catch (error) {
65
+ config_1.logger.warn(`Privy authentication failed with error ${error.message}.`);
66
+ config_1.logger.error(error);
67
+ }
68
+ }
69
+ getPrivyClients() {
70
+ const schema = zod_1.default.object({
71
+ PRIVY_APP_SECRET: zod_1.default.string().min(1),
72
+ PRIVY_ADMIN_APP_SECRET: zod_1.default.string().min(1),
73
+ });
74
+ const { PRIVY_APP_SECRET, PRIVY_ADMIN_APP_SECRET } = core_1.Config.init(schema);
75
+ const privyClient = new node_1.PrivyClient({
76
+ appId: constants_1.PRIVY_APP_ID,
77
+ appSecret: PRIVY_APP_SECRET,
78
+ jwtVerificationKey: constants_1.PRIVY_VERIFICATION_KEY,
79
+ });
80
+ const privyAdminClient = new node_1.PrivyClient({
81
+ appId: constants_1.PRIVY_ADMIN_APP_ID,
82
+ appSecret: PRIVY_ADMIN_APP_SECRET,
83
+ jwtVerificationKey: constants_1.PRIVY_ADMIN_VERIFICATION_KEY,
84
+ });
85
+ return { privyClient, privyAdminClient };
86
+ }
87
+ }
88
+ __decorate([
89
+ (0, typescript_memoize_1.Memoize)()
90
+ ], PrivyService.prototype, "getPrivyClients", null);
91
+ exports.privyService = new PrivyService();
92
+ //# sourceMappingURL=privy.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privy.service.js","sourceRoot":"","sources":["../../../src/server/auth/privy.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAA+D;AAC/D,2DAA4C;AAC5C,+BAA0C;AAC1C,8CAAmB;AACnB,qCAAmC;AACnC,oDAA6H;AAC7H,sCAAkC;AAQlC,MAAM,YAAY;IAAlB;QACI,qBAAgB,GAAG,KAAK,EAAE,GAAgB,EAAE,EAAE;YAC1C,OAAO,IAAI,CAAC,YAAY,CAAC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SACnD,CAAC,CAAA;QAEF,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAA;IAC5C,CAAC;CACJ;AArBW;IADP,IAAA,4BAAO,GAAE;mDAqBT;AAGQ,QAAA,YAAY,GAAG,IAAI,YAAY,EAAE,CAAA"}
@@ -4,5 +4,6 @@ export * from "./config";
4
4
  export * from "./contracts";
5
5
  export * from "./liquidation-engine";
6
6
  export * from "./logging";
7
+ export * from "./middleware";
7
8
  export * from "./oracle";
8
9
  export * from "./utils";
@@ -26,6 +26,7 @@ __exportStar(require("./config"), exports);
26
26
  __exportStar(require("./contracts"), exports);
27
27
  __exportStar(require("./liquidation-engine"), exports);
28
28
  __exportStar(require("./logging"), exports);
29
+ __exportStar(require("./middleware"), exports);
29
30
  __exportStar(require("./oracle"), exports);
30
31
  __exportStar(require("./utils"), exports);
31
32
  // export { sdk } from "./instrumentation"
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iFAAiF;AACjF,IAAI,OAAQ,UAAkB,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;IACpD,MAAM,IAAI,KAAK,CACX,0EAA0E;QACtE,0GAA0G;QAC1G,kFAAkF,CACzF,CAAA;AACL,CAAC;AAED,0CAAuB;AACvB,yCAAsB;AACtB,2CAAwB;AACxB,8CAA2B;AAC3B,uDAAoC;AACpC,4CAAyB;AACzB,2CAAwB;AACxB,0CAAuB;AAEvB,0CAA0C;AAC1C,6DAA6D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iFAAiF;AACjF,IAAI,OAAQ,UAAkB,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;IACpD,MAAM,IAAI,KAAK,CACX,0EAA0E;QACtE,0GAA0G;QAC1G,kFAAkF,CACzF,CAAA;AACL,CAAC;AAED,0CAAuB;AACvB,yCAAsB;AACtB,2CAAwB;AACxB,8CAA2B;AAC3B,uDAAoC;AACpC,4CAAyB;AACzB,+CAA4B;AAC5B,2CAAwB;AACxB,0CAAuB;AAEvB,0CAA0C;AAC1C,6DAA6D"}
@@ -0,0 +1 @@
1
+ export * from "./rateLimit.middleware";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./rateLimit.middleware"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/middleware/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC"}
@@ -0,0 +1,2 @@
1
+ import Redis from "ioredis";
2
+ export declare const rateLimiter: (requestsWindow: number, maxRequests: number, client?: Redis) => import("express-rate-limit").RateLimitRequestHandler;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rateLimiter = void 0;
4
+ const express_rate_limit_1 = require("express-rate-limit");
5
+ const rate_limit_redis_1 = require("rate-limit-redis");
6
+ const config_1 = require("../config");
7
+ const rateLimiter = (requestsWindow, maxRequests, client) => {
8
+ if (!client)
9
+ client = new config_1.RedisClientManager().primaryClient;
10
+ return (0, express_rate_limit_1.rateLimit)({
11
+ windowMs: requestsWindow,
12
+ max: maxRequests,
13
+ standardHeaders: true,
14
+ legacyHeaders: false,
15
+ store: new rate_limit_redis_1.RedisStore({
16
+ sendCommand: (command, ...args) => client.call(command, ...args),
17
+ }),
18
+ });
19
+ };
20
+ exports.rateLimiter = rateLimiter;
21
+ //# sourceMappingURL=rateLimit.middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rateLimit.middleware.js","sourceRoot":"","sources":["../../../src/server/middleware/rateLimit.middleware.ts"],"names":[],"mappings":";;;AAAA,2DAA8C;AAE9C,uDAAyD;AACzD,sCAA8C;AAEvC,MAAM,WAAW,GAAG,CAAC,cAAsB,EAAE,WAAmB,EAAE,MAAc,EAAE,EAAE;IACvF,IAAI,CAAC,MAAM;QAAE,MAAM,GAAG,IAAI,2BAAkB,EAAE,CAAC,aAAa,CAAA;IAE5D,OAAO,IAAA,8BAAS,EAAC;QACb,QAAQ,EAAE,cAAc;QACxB,GAAG,EAAE,WAAW;QAChB,eAAe,EAAE,IAAI;QACrB,aAAa,EAAE,KAAK;QACpB,KAAK,EAAE,IAAI,6BAAU,CAAC;YAClB,WAAW,EAAE,CAAC,OAAe,EAAE,GAAG,IAAc,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAwB;SAC5G,CAAC;KACL,CAAC,CAAA;AACN,CAAC,CAAA;AAZY,QAAA,WAAW,eAYvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levrbet/shared",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -39,11 +39,23 @@
39
39
  "prepublishOnly": "npm run build"
40
40
  },
41
41
  "peerDependencies": {
42
- "react": ">=18"
42
+ "@privy-io/react-auth": ">=3",
43
+ "@tanstack/react-query": ">=5",
44
+ "react": ">=18",
45
+ "wagmi": ">=2"
43
46
  },
44
47
  "peerDependenciesMeta": {
45
48
  "react": {
46
49
  "optional": true
50
+ },
51
+ "@tanstack/react-query": {
52
+ "optional": true
53
+ },
54
+ "@privy-io/react-auth": {
55
+ "optional": true
56
+ },
57
+ "wagmi": {
58
+ "optional": true
47
59
  }
48
60
  },
49
61
  "dependencies": {
@@ -57,7 +69,7 @@
57
69
  "@opentelemetry/sdk-node": "^0.205.0",
58
70
  "@openzeppelin/relayer-sdk": "^1.5.0",
59
71
  "@prisma/client": "^6.16.2",
60
- "@privy-io/server-auth": "^1.32.4",
72
+ "@privy-io/node": "^0.2.0",
61
73
  "@types/amqplib": "^0.10.7",
62
74
  "amqplib": "^0.10.9",
63
75
  "axios": "^1.12.2",
@@ -66,9 +78,12 @@
66
78
  "dayjs": "^1.11.18",
67
79
  "dotenv": "^17.2.2",
68
80
  "express": "^5.1.0",
81
+ "express-rate-limit": "^8.1.0",
69
82
  "ioredis": "^5.7.0",
70
83
  "jose": "^6.1.0",
84
+ "lodash": "^4.17.21",
71
85
  "ms": "^2.1.3",
86
+ "rate-limit-redis": "^4.2.2",
72
87
  "redis": "^5.8.2",
73
88
  "typescript-memoize": "^1.1.1",
74
89
  "viem": "^2.37.6",
@@ -76,13 +91,20 @@
76
91
  "zod": "^4.1.9"
77
92
  },
78
93
  "devDependencies": {
94
+ "@privy-io/react-auth": "^3.0.1",
95
+ "@tanstack/react-query": "^5.90.2",
79
96
  "@types/express": "^5.0.3",
97
+ "@types/lodash": "^4.17.20",
80
98
  "@types/ms": "^2.1.0",
81
99
  "@types/node": "^24.5.1",
82
- "@types/react": "^19.1.13",
100
+ "@types/react": "19.1.15",
83
101
  "cross-fetch": "^4.1.0",
84
102
  "prisma": "^6.16.2",
85
- "react": "^19.1.1"
103
+ "react": "^19.1.1",
104
+ "wagmi": "^2.17.5"
105
+ },
106
+ "overrides": {
107
+ "ox": "^0.9.0"
86
108
  },
87
109
  "publishConfig": {
88
110
  "access": "public"