'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _tslib = require('../../../../../_virtual/_tslib.cjs');
var React = require('react');
require('@dynamic-labs-sdk/client/core');
require('@dynamic-labs/sdk-api-core');
require('../../../client/client.cjs');
require('@dynamic-labs-sdk/client');
require('../../../config/ApiEndpoint.cjs');
require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
require('react/jsx-runtime');
require('../../../context/ViewContext/ViewContext.cjs');
var logger = require('../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('@dynamic-labs/utils');
require('../../constants/colors.cjs');
require('../../constants/values.cjs');
require('../../../shared/consts/index.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../../store/state/nonce/nonce.cjs');
require('@dynamic-labs/locale');
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
var getClientSessionKeys = require('../../functions/clientSessionKeys/getClientSessionKeys.cjs');
require('../../../events/dynamicEvents.cjs');
var useOnboardingCompleteUser = require('../../../client/extension/user/useOnboardingCompleteUser/useOnboardingCompleteUser.cjs');
var usePromise = require('../usePromise/usePromise.cjs');

const useClientSessionKeys = () => {
    const user = useOnboardingCompleteUser.useOnboardingCompleteUser();
    const sessionPublicKey = getClientSessionKeys.getClientSessionPublicKey();
    const getSignedSessionId = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
        if (!(user === null || user === void 0 ? void 0 : user.sessionId) || !sessionPublicKey) {
            throw new Error('Session ID and public key are required');
        }
        const result = yield getClientSessionKeys.getClientSessionSignature({
            sessionId: user === null || user === void 0 ? void 0 : user.sessionId,
        });
        logger.logger.instrument('[SessionChaining] Generated session signature', {
            environmentId: user.projectEnvironmentId,
            key: 'generated_session_signature',
            sessionId: user.sessionId,
            sessionPublicKey,
            sessionSignature: result.sessionSignature,
            time: 0,
        });
        return result.sessionSignature;
    }), [user === null || user === void 0 ? void 0 : user.sessionId, sessionPublicKey]);
    const { data: sessionSignatureResult } = usePromise.usePromise(getSignedSessionId, {
        deps: [user === null || user === void 0 ? void 0 : user.sessionId, sessionPublicKey],
        enabled: Boolean(user === null || user === void 0 ? void 0 : user.sessionId) && Boolean(sessionPublicKey),
        initialData: undefined,
        retries: 2,
    });
    return {
        getSignedSessionId,
        sessionPublicKey,
        sessionSignature: sessionSignatureResult,
    };
};

exports.useClientSessionKeys = useClientSessionKeys;
