@sui-tracker/shared 1.0.84 → 1.0.86

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sui-tracker/shared",
3
- "version": "1.0.84",
3
+ "version": "1.0.86",
4
4
  "description": "Shared types and utilities for Sui Tracker",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1 +0,0 @@
1
- export declare const GrpcUser: (...dataOrPipes: unknown[]) => ParameterDecorator;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GrpcUser = void 0;
4
- const common_1 = require("@nestjs/common");
5
- exports.GrpcUser = (0, common_1.createParamDecorator)((_data, ctx) => {
6
- const rpcHost = ctx.switchToRpc();
7
- const call = rpcHost.getContext();
8
- const metadata = call?.metadata;
9
- if (!metadata)
10
- return null;
11
- return {
12
- id: metadata.get('x-user-id')?.[0],
13
- token: metadata.get('authorization')?.[0],
14
- };
15
- });
16
- //# sourceMappingURL=grpc-user.decorator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grpc-user.decorator.js","sourceRoot":"","sources":["../../src/decorators/grpc-user.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAe3D,QAAA,QAAQ,GAAG,IAAA,6BAAoB,EAC1C,CAAC,KAAc,EAAE,GAAqB,EAAE,EAAE;IACxC,MAAM,OAAO,GAAqB,GAAG,CAAC,WAAW,EAAE,CAAC;IACpD,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAClC,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,CAAC;IAEhC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,OAAO;QACL,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAW;QAC5C,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAW;KACpD,CAAC;AACJ,CAAC,CACF,CAAC"}
@@ -1,19 +0,0 @@
1
- import { ClientGrpc } from '@nestjs/microservices';
2
- import { UserResponse } from '../interfaces/auth.interface';
3
- export declare class AccountUserGrpcService {
4
- private grpcClient;
5
- private readonly logger;
6
- constructor(grpcClient: ClientGrpc);
7
- getOrCreateUser(telegramData: {
8
- teleId: string;
9
- firstName?: string;
10
- lastName?: string;
11
- username?: string;
12
- }): Promise<UserResponse>;
13
- signTransaction(user: UserResponse): Promise<{
14
- signature: string;
15
- msg: string;
16
- signTime: number;
17
- }>;
18
- generateLoginUrl(user: UserResponse, signature: string, signTime: number): string;
19
- }
@@ -1,70 +0,0 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var AccountUserGrpcService_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.AccountUserGrpcService = void 0;
17
- const common_1 = require("@nestjs/common");
18
- const ethers_1 = require("ethers");
19
- let AccountUserGrpcService = AccountUserGrpcService_1 = class AccountUserGrpcService {
20
- constructor(grpcClient) {
21
- this.grpcClient = grpcClient;
22
- this.logger = new common_1.Logger(AccountUserGrpcService_1.name);
23
- }
24
- async getOrCreateUser(telegramData) {
25
- const userService = this.grpcClient.getService('AuthService');
26
- this.logger.log(`Getting or creating user for teleId: ${telegramData.teleId}`);
27
- const res = await new Promise((resolve, reject) => {
28
- userService.getOrCreateUser({
29
- teleId: telegramData.teleId,
30
- firstName: telegramData.firstName,
31
- lastName: telegramData.lastName,
32
- username: telegramData.username,
33
- }).subscribe({
34
- next: (response) => resolve(response),
35
- error: (error) => reject(error),
36
- });
37
- });
38
- if (!res.success || !res.user) {
39
- throw new Error(res.message || 'Failed to get or create user');
40
- }
41
- this.logger.log(`User retrieved: ${res.user.id}`);
42
- return res.user;
43
- }
44
- async signTransaction(user) {
45
- const privateKey = process.env.ADMIN_WALLET_PK;
46
- if (!privateKey) {
47
- throw new Error('ADMIN_WALLET_PK is not set');
48
- }
49
- const wallet = new ethers_1.ethers.Wallet(privateKey);
50
- const signTime = Date.now();
51
- const msg = `${user.teleId}-${signTime}`;
52
- const signature = await wallet.signMessage(msg);
53
- return {
54
- signature,
55
- msg,
56
- signTime,
57
- };
58
- }
59
- generateLoginUrl(user, signature, signTime) {
60
- const appDomain = process.env.APP_DOMAIN || 'https://app.example.com';
61
- return `${appDomain}?signature=${signature}&username=${user.teleUserName}&teleId=${user.teleId}&signTime=${signTime}`;
62
- }
63
- };
64
- exports.AccountUserGrpcService = AccountUserGrpcService;
65
- exports.AccountUserGrpcService = AccountUserGrpcService = AccountUserGrpcService_1 = __decorate([
66
- (0, common_1.Injectable)(),
67
- __param(0, (0, common_1.Inject)('AUTH')),
68
- __metadata("design:paramtypes", [Object])
69
- ], AccountUserGrpcService);
70
- //# sourceMappingURL=account-user-grpc.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account-user-grpc.service.js","sourceRoot":"","sources":["../../../src/modules/grpc-services/account-user-grpc.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4D;AAE5D,mCAAgC;AAKzB,IAAM,sBAAsB,8BAA5B,MAAM,s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C,eAAe,CAAC;QAE/C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAEhD,OAAO;YACL,SAAS;YACT,GAAG;YACH,QAAQ;SACT,CAAC;IACJ,CAAC;IAKD,gBAAgB,CACd,IAAkB,EAClB,SAAiB,EACjB,QAAgB;QAEhB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,yBAAyB,CAAC;QACtE,OAAO,GAAG,SAAS,cAAc,SAAS,aAAa,IAAI,CAAC,YAAY,WAAW,IAAI,CAAC,MAAM,aAAa,QAAQ,EAAE,CAAC;IACxH,CAAC;CACF,CAAA;AAlFY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,MAAM,CAAC,CAAA;;GAJN,sBAAsB,CAkFlC"}
@@ -1,22 +0,0 @@
1
- import { ClientGrpc } from "@nestjs/microservices";
2
- import { GetOrCreateUserRequest, GetOrCreateUserResponse } from "../interfaces/auth.interface";
3
- export declare class AuthGrpcService {
4
- private grpcClient;
5
- private readonly logger;
6
- constructor(grpcClient: ClientGrpc);
7
- getOrCreateUser(data: GetOrCreateUserRequest): Promise<GetOrCreateUserResponse>;
8
- login(data: {
9
- teleId: string;
10
- signature: string;
11
- signTime: string;
12
- }): Promise<any>;
13
- me(userId: string): Promise<any>;
14
- signTransaction(userId: string): Promise<{
15
- success: boolean;
16
- message: string;
17
- signature?: string;
18
- msg?: string;
19
- signTime?: number;
20
- }>;
21
- validateToken(token: string): Promise<any>;
22
- }
@@ -1,113 +0,0 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var AuthGrpcService_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.AuthGrpcService = void 0;
17
- const common_1 = require("@nestjs/common");
18
- const grpc_js_1 = require("@grpc/grpc-js");
19
- let AuthGrpcService = AuthGrpcService_1 = class AuthGrpcService {
20
- constructor(grpcClient) {
21
- this.grpcClient = grpcClient;
22
- this.logger = new common_1.Logger(AuthGrpcService_1.name);
23
- }
24
- async getOrCreateUser(data) {
25
- const authService = this.grpcClient.getService("AuthService");
26
- const res = await new Promise((resolve, reject) => {
27
- authService.getOrCreateUser(data).subscribe({
28
- next: (response) => resolve(response),
29
- error: (error) => reject({
30
- success: false,
31
- message: error.message,
32
- user: null,
33
- }),
34
- });
35
- });
36
- if (!res.success) {
37
- throw new Error(res.message);
38
- }
39
- return res;
40
- }
41
- async login(data) {
42
- const authService = this.grpcClient.getService("AuthService");
43
- const res = await new Promise((resolve, reject) => {
44
- authService.login(data).subscribe({
45
- next: (response) => resolve(response),
46
- error: (error) => reject(error),
47
- });
48
- });
49
- if (!res.success) {
50
- throw new Error(res.message);
51
- }
52
- return res;
53
- }
54
- async me(userId) {
55
- const authService = this.grpcClient.getService("AuthService");
56
- const metadata = new grpc_js_1.Metadata();
57
- const res = await new Promise((resolve, reject) => {
58
- authService.me({ userId }, metadata).subscribe({
59
- next: (response) => resolve(response),
60
- error: (error) => reject({
61
- success: false,
62
- message: error.message,
63
- user: null,
64
- }),
65
- });
66
- });
67
- if (!res.success) {
68
- throw new Error(res.message);
69
- }
70
- return res;
71
- }
72
- async signTransaction(userId) {
73
- const authService = this.grpcClient.getService("AuthService");
74
- const res = await new Promise((resolve, reject) => {
75
- authService.signTransaction({ userId }).subscribe({
76
- next: (response) => resolve(response),
77
- error: (error) => reject({
78
- success: false,
79
- message: error.message,
80
- }),
81
- });
82
- });
83
- if (!res.success) {
84
- throw new Error(res.message);
85
- }
86
- return res;
87
- }
88
- async validateToken(token) {
89
- const authService = this.grpcClient.getService("AuthService");
90
- const res = await new Promise((resolve, reject) => {
91
- authService.validateToken({ token }).subscribe({
92
- next: (response) => resolve(response),
93
- error: (error) => resolve({
94
- success: false,
95
- message: error.message,
96
- user: null,
97
- isValid: false,
98
- }),
99
- });
100
- });
101
- if (!res.success) {
102
- throw new Error(res.message);
103
- }
104
- return res;
105
- }
106
- };
107
- exports.AuthGrpcService = AuthGrpcService;
108
- exports.AuthGrpcService = AuthGrpcService = AuthGrpcService_1 = __decorate([
109
- (0, common_1.Injectable)(),
110
- __param(0, (0, common_1.Inject)("AUTH")),
111
- __metadata("design:paramtypes", [Object])
112
- ], AuthGrpcService);
113
- //# sourceMappingURL=auth-grpc.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth-grpc.service.js","sourceRoot":"","sources":["../../../src/modules/grpc-services/auth-grpc.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4D;AAS5D,2CAAyC;AAGlC,IAAM,eAAe,uBAArB,MAAM,eAAe;IAG1B,YACkB,UAA8B;QAAtB,eAAU,GAAV,UAAU,CAAY;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76 +0,0 @@
1
- import { Observable } from "rxjs";
2
- import { Metadata } from "@grpc/grpc-js";
3
- export interface UserResponse {
4
- id: string;
5
- firstName: string;
6
- lastName: string;
7
- teleId: string;
8
- teleUserName: string;
9
- isActive: boolean;
10
- referralCode: string;
11
- parentId: string;
12
- role: string;
13
- mainWalletAddress?: string;
14
- createdAt: string;
15
- updatedAt: string;
16
- }
17
- export interface TokenResponse {
18
- accessToken: string;
19
- expiresIn: number;
20
- }
21
- export interface GetOrCreateUserRequest {
22
- teleId: string;
23
- firstName?: string;
24
- lastName?: string;
25
- username?: string;
26
- }
27
- export interface GetOrCreateUserResponse {
28
- success: boolean;
29
- message: string;
30
- user?: UserResponse;
31
- }
32
- export interface LoginRequest {
33
- teleId: string;
34
- signature: string;
35
- signTime: string;
36
- }
37
- export interface LoginResponse {
38
- success: boolean;
39
- message: string;
40
- user?: UserResponse;
41
- token?: TokenResponse;
42
- }
43
- export interface MeRequest {
44
- userId: string;
45
- }
46
- export interface MeResponse {
47
- success: boolean;
48
- message: string;
49
- user?: UserResponse;
50
- }
51
- export interface SignTransactionRequest {
52
- userId: string;
53
- }
54
- export interface SignTransactionResponse {
55
- success: boolean;
56
- message: string;
57
- signature?: string;
58
- msg?: string;
59
- signTime?: number;
60
- }
61
- export interface ValidateTokenRequest {
62
- token: string;
63
- }
64
- export interface ValidateTokenResponse {
65
- success: boolean;
66
- message: string;
67
- user?: UserResponse;
68
- isValid: boolean;
69
- }
70
- export interface AuthService {
71
- getOrCreateUser(data: GetOrCreateUserRequest): Observable<GetOrCreateUserResponse>;
72
- login(request: LoginRequest): Observable<LoginResponse>;
73
- me(request: MeRequest, metadata?: Metadata): Observable<MeResponse>;
74
- signTransaction(request: SignTransactionRequest): Observable<SignTransactionResponse>;
75
- validateToken(request: ValidateTokenRequest): Observable<ValidateTokenResponse>;
76
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=auth.interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.interface.js","sourceRoot":"","sources":["../../../src/modules/interfaces/auth.interface.ts"],"names":[],"mappings":""}
@@ -1,117 +0,0 @@
1
- // Proto file for Auth Service
2
- // Được tạo từ auth.interface.ts
3
-
4
- // Proto3 syntax
5
- syntax = "proto3";
6
-
7
- package auth;
8
-
9
- // Auth Service
10
- service AuthService {
11
- // Login with signature
12
- rpc Login(LoginRequest) returns (LoginResponse);
13
-
14
- // Get or create user from Telegram data
15
- rpc GetOrCreateUser(GetOrCreateUserRequest) returns (GetOrCreateUserResponse);
16
-
17
- // Get current user information
18
- rpc Me(MeRequest) returns (MeResponse);
19
-
20
- // Sign transaction for authentication
21
- rpc SignTransaction(SignTransactionRequest) returns (SignTransactionResponse);
22
-
23
- // Validate JWT token
24
- rpc ValidateToken(ValidateTokenRequest) returns (ValidateTokenResponse);
25
- }
26
-
27
- // User entity
28
- message UserResponse {
29
- string id = 1;
30
- string firstName = 2;
31
- string lastName = 3;
32
- string teleId = 4;
33
- string teleUserName = 5;
34
- bool isActive = 6;
35
- string referralCode = 7;
36
- string parentId = 8;
37
- string role = 9;
38
- string mainWalletAddress = 10;
39
- string createdAt = 11;
40
- string updatedAt = 12;
41
- }
42
-
43
- // Get or create user request
44
- message GetOrCreateUserRequest {
45
- string teleId = 1;
46
- string firstName = 2;
47
- string lastName = 3;
48
- string username = 4;
49
- }
50
-
51
- // Get or create user response with user data
52
- message GetOrCreateUserResponse {
53
- bool success = 1;
54
- string message = 2;
55
- UserResponse user = 3;
56
- }
57
-
58
- // Login request
59
- message LoginRequest {
60
- string teleId = 1;
61
- string signature = 2;
62
- string signTime = 3;
63
- }
64
-
65
- // Token response
66
- message TokenResponse {
67
- string accessToken = 1;
68
- int32 expiresIn = 2;
69
- }
70
-
71
- // Login response
72
- message LoginResponse {
73
- bool success = 1;
74
- string message = 2;
75
- UserResponse user = 3;
76
- TokenResponse token = 4;
77
- }
78
-
79
- // Me request
80
- message MeRequest {
81
- string userId = 1;
82
- }
83
-
84
- // Me response
85
- message MeResponse {
86
- bool success = 1;
87
- string message = 2;
88
- UserResponse user = 3;
89
- }
90
-
91
- // Validate token request
92
- message ValidateTokenRequest {
93
- string token = 1;
94
- }
95
-
96
- // Sign transaction request
97
- message SignTransactionRequest {
98
- string userId = 1;
99
- }
100
-
101
- // Sign transaction response
102
- message SignTransactionResponse {
103
- bool success = 1;
104
- string message = 2;
105
- string signature = 3;
106
- string msg = 4;
107
- int64 signTime = 5;
108
- }
109
-
110
- // Validate token response
111
- message ValidateTokenResponse {
112
- bool success = 1;
113
- string message = 2;
114
- UserResponse user = 3;
115
- bool isValid = 4;
116
- }
117
-
@@ -1,2 +0,0 @@
1
- export declare function generateInternalToken(privateKey: string, from: string, targetService: string, scopes: string[]): any;
2
- export declare function verifyInternalToken(token: string, publicKey: string, iss: string, aud: string): any;
@@ -1,57 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.generateInternalToken = generateInternalToken;
37
- exports.verifyInternalToken = verifyInternalToken;
38
- const jwt = __importStar(require("jsonwebtoken"));
39
- function generateInternalToken(privateKey, from, targetService, scopes) {
40
- const payload = {
41
- iss: from,
42
- aud: targetService,
43
- sub: 'internal-call',
44
- scope: scopes,
45
- };
46
- return jwt.sign(payload, privateKey, {
47
- algorithm: 'RS256',
48
- expiresIn: '1m',
49
- });
50
- }
51
- function verifyInternalToken(token, publicKey, iss, aud) {
52
- const payload = jwt.verify(token, publicKey, { algorithms: ['RS256'], audience: aud });
53
- if (payload.iss !== iss)
54
- throw new Error('Invalid issuer');
55
- return payload;
56
- }
57
- //# sourceMappingURL=internal-token.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal-token.js","sourceRoot":"","sources":["../../src/utils/internal-token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sDAYC;AAED,kDAMC;AAvBD,kDAAoC;AAGpC,SAAgB,qBAAqB,CAAC,UAAkB,EAAE,IAAY,EAAE,aAAqB,EAAE,MAAgB;IAC7G,MAAM,OAAO,GAAG;QACd,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,aAAa;QAClB,GAAG,EAAE,eAAe;QACpB,KAAK,EAAE,MAAM;KACd,CAAC;IAEF,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE;QACnC,SAAS,EAAE,OAAO;QAClB,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,mBAAmB,CAAC,KAAa,EAAE,SAAiB,EAAE,GAAW,EAAE,GAAW;IAC5F,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;IAEvF,IAAI,OAAO,CAAC,GAAG,KAAK,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE3D,OAAO,OAAO,CAAC;AACjB,CAAC"}