New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@civic/common-gateway-react

Package Overview
Dependencies
Maintainers
16
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@civic/common-gateway-react - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10-alpha.1

4

dist/cjs/actionCreator/actionCreator.types.d.ts

@@ -7,4 +7,4 @@ import { WalletAdapter, Chain } from '../types';

wallet: WalletAdapter;
chainImplementation: Chain;
gatekeeperClient: () => GatekeeperClient;
chainImplementation?: Chain;
gatekeeperClient: () => GatekeeperClient | undefined;
dispatch: (value: Action) => void;

@@ -11,0 +11,0 @@ networkConfig: NetworkConfig;

@@ -19,3 +19,3 @@ "use strict";

const pollForActiveOnChainToken = async (pollChainNumberRetries = networkConfig.pollChainNumberRetries) => {
return (0, utils_1.pollUntilConditionMet)(chainImplementation.findGatewayToken, (onChainToken) => {
return (0, utils_1.pollUntilConditionMet)(chainImplementation ? chainImplementation.findGatewayToken : Promise.reject, (onChainToken) => {
if (!onChainToken)

@@ -31,2 +31,3 @@ return false; // keep polling

const waitForGatewayToken = async (pollChainNumberRetries = networkConfig.pollChainNumberRetries) => {
var _a;
// poll the gatekeeper until we have a status for a created record

@@ -58,4 +59,4 @@ // if we don't get a created token, then we consider it a failure

logError('Failed to find Gateway token on-chain with ownerSigns:false, checking with gatekeeper');
const gkApiStatus = await gatekeeperClient().getGatekeeperStatus(wallet.publicKey);
if (isRequestedRetriesExhausted(gkApiStatus)) {
const gkApiStatus = await ((_a = gatekeeperClient()) === null || _a === void 0 ? void 0 : _a.getGatekeeperStatus(wallet.publicKey));
if (gkApiStatus && isRequestedRetriesExhausted(gkApiStatus)) {
logError('Retried exhausted', { gkApiStatus });

@@ -66,3 +67,3 @@ dispatch({ type: 'civicPass_requested_retries_exhausted' });

// if the token is still pending or in review then keep polling on-chain
if (isTokenPending(gkApiStatus)) {
if (gkApiStatus && isTokenPending(gkApiStatus)) {
// we don't want to wait the whole amount of time if we've got to here, so just 4 retries = 3 x 2 seconds, a further

@@ -74,3 +75,3 @@ // 6 seconds before we will ask the GK API for status again

// or the gatekeeper threw an error during issuance attempt
if (isTokenCreated(gkApiStatus) || isFailure(gkApiStatus)) {
if ((gkApiStatus && isTokenCreated(gkApiStatus)) || (gkApiStatus && isFailure(gkApiStatus))) {
logError('Failed to find Gateway token with gatekeeper status code', types_1.GatekeeperAPIStatus[gkApiStatus]);

@@ -77,0 +78,0 @@ dispatch({ type: 'tokenNotFoundError' });

@@ -71,3 +71,3 @@ "use strict";

gatekeeperNetworkAddress,
chainType: chainImplementation.chainType,
chainType: chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.chainType,
ownerSigns,

@@ -88,16 +88,16 @@ });

}, [redirectUrl, stage, wallet === null || wallet === void 0 ? void 0 : wallet.publicKey, gatekeeperNetworkAddress, ownerSigns]);
const { network } = chainImplementation.httpConfig.queryParams;
const { headers } = chainImplementation.httpConfig;
const gatekeeperEndpoint = chainImplementation.httpConfig.baseUrl;
const gatekeeperClient = (0, react_1.useCallback)(() => {
if (!gatekeeperNetworkAddress) {
throw new Error('No gatekeeper network passed in.');
if (gatekeeperNetworkAddress && chainImplementation) {
const { network } = chainImplementation.httpConfig.queryParams;
const { headers } = chainImplementation.httpConfig;
const gatekeeperEndpoint = chainImplementation.httpConfig.baseUrl;
return new gatekeeperClient_1.default({
baseUrl: gatekeeperEndpoint,
stage,
queryParams: { network, gatekeeperNetworkAddress },
headers,
});
}
return new gatekeeperClient_1.default({
baseUrl: gatekeeperEndpoint,
stage,
queryParams: { network, gatekeeperNetworkAddress },
headers,
});
}, [stage, gatekeeperEndpoint, gatekeeperNetworkAddress, network]);
return undefined;
}, [stage, chainImplementation]);
// this hook implements the main business logic and handles requesting and refreshing gateway tokens

@@ -104,0 +104,0 @@ (0, useOrchestration_1.default)({ wallet, chainImplementation, stage, gatekeeperClient }, state, dispatch);

@@ -85,3 +85,3 @@ /// <reference types="react" />

gatekeeperNetwork: string | undefined;
chainImplementation: Chain;
chainImplementation?: Chain;
ownerSigns: boolean;

@@ -150,3 +150,3 @@ stage?: string;

gatekeeperNetworkAddress?: string;
chainType: ChainType;
chainType?: ChainType;
ownerSigns: boolean;

@@ -153,0 +153,0 @@ gatewayTokenTransaction?: string;

@@ -12,3 +12,3 @@ import type { Action } from '../useReducer';

wallet: WalletAdapter | undefined;
chainImplementation: Chain;
chainImplementation?: Chain | undefined;
networkConfig: NetworkConfig;

@@ -15,0 +15,0 @@ }, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {

@@ -30,3 +30,3 @@ "use strict";

logDebug('Removing onChainListener with id: ', listernerId);
chainImplementation.removeOnGatewayTokenChangeListener(listernerId);
chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.removeOnGatewayTokenChangeListener(listernerId);
}

@@ -47,3 +47,3 @@ catch (error) {

};
const listernerId = await chainImplementation.addOnGatewayTokenChangeListener(gatewayToken, tokenChangeCallback);
const listernerId = await (chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.addOnGatewayTokenChangeListener(gatewayToken, tokenChangeCallback));
logDebug('Adding onChainListener with id: ', listernerId);

@@ -80,3 +80,3 @@ return listernerId;

logDebug('Fetching token from chain');
const token = await chainImplementation.findGatewayToken();
const token = await (chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.findGatewayToken());
if (!token) {

@@ -83,0 +83,0 @@ dispatch({ type: 'tokenOnChainNotFound' });

@@ -53,3 +53,3 @@ "use strict";

const action = gatewayStatusToCivicPassAction[status];
const searchParams = new URLSearchParams(Object.assign(Object.assign({}, civicPass.requestPayload), { redirectUrl, networkAddress: gatekeeperNetworkAddress, action, wallet: walletAddress, chain: chainType, ownerSigns: ownerSigns ? 'true' : 'false' }));
const searchParams = new URLSearchParams(Object.assign(Object.assign({}, civicPass.requestPayload), { redirectUrl, networkAddress: gatekeeperNetworkAddress, action, wallet: walletAddress, chain: chainType !== null && chainType !== void 0 ? chainType : '', ownerSigns: ownerSigns ? 'true' : 'false' }));
logDebug('Civic pass query params', {

@@ -56,0 +56,0 @@ searchParams: searchParams.toString(),

@@ -5,3 +5,3 @@ import { CivicSignEventTypeRequest, RemoteSign } from '../utils/remoteSign';

wallet: WalletAdapter | undefined;
chainImplementation: Chain;
chainImplementation?: Chain | undefined;
remoteSign?: RemoteSign | undefined;

@@ -8,0 +8,0 @@ }) => {

@@ -27,4 +27,6 @@ "use strict";

try {
const proof = await chainImplementation.proveWalletOwnership();
remoteSigner === null || remoteSigner === void 0 ? void 0 : remoteSigner.sendSignedProof(proof);
const proof = await (chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.proveWalletOwnership());
if (proof) {
remoteSigner === null || remoteSigner === void 0 ? void 0 : remoteSigner.sendSignedProof(proof);
}
}

@@ -31,0 +33,0 @@ catch (err) {

@@ -7,3 +7,3 @@ import { RootState, WalletAdapter } from '../types';

stage: string;
gatekeeperClient: () => GatekeeperClient;
gatekeeperClient: () => GatekeeperClient | undefined;
}, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {

@@ -13,5 +13,4 @@ waitForGatekeeperIssuanceRequest: (value: {

payload?: unknown;
}) => PromiseLike<string>;
gatekeeperClient: () => GatekeeperClient;
}) => PromiseLike<string | undefined>;
};
export default useGatekeeper;

@@ -19,2 +19,3 @@ "use strict";

async ({ payload, proof }) => {
var _a;
const connectedWallet = expectWalletConnected();

@@ -25,3 +26,3 @@ logger_1.default.debug('waitForGatekeeperIssuanceRequest ready to call requestGatewayTokenFromGatekeeper', {

dispatch({ type: 'requestGatekeeperIssuance' });
const requestGatewayTokenFromGatekeeperResult = await gatekeeperClient().requestGatewayTokenFromGatekeeper({
const requestGatewayTokenFromGatekeeperResult = await ((_a = gatekeeperClient()) === null || _a === void 0 ? void 0 : _a.requestGatewayTokenFromGatekeeper({
wallet: connectedWallet,

@@ -31,13 +32,16 @@ payload,

ownerSigns: ownerSigns !== null && ownerSigns !== void 0 ? ownerSigns : false,
});
}));
logger_1.default.debug('requestGatewayTokenFromGatekeeperResult', requestGatewayTokenFromGatekeeperResult);
if (requestGatewayTokenFromGatekeeperResult.status >= 400) {
logger_1.default.error('Error requesting token from gatekeeper');
dispatch({ type: 'requestGatekeeperIssuanceFailed' });
throw new Error('Error requesting token from gatekeeper');
if (requestGatewayTokenFromGatekeeperResult) {
if (requestGatewayTokenFromGatekeeperResult && requestGatewayTokenFromGatekeeperResult.status >= 400) {
logger_1.default.error('Error requesting token from gatekeeper');
dispatch({ type: 'requestGatekeeperIssuanceFailed' });
throw new Error('Error requesting token from gatekeeper');
}
const { transaction } = requestGatewayTokenFromGatekeeperResult;
logger_1.default.debug('Successfully requested gatekeeper token');
dispatch({ type: 'requestGatekeeperIssuanceComplete', gatewayTokenTransaction: transaction });
return transaction;
}
const { transaction } = requestGatewayTokenFromGatekeeperResult;
logger_1.default.debug('Successfully requested gatekeeper token');
dispatch({ type: 'requestGatekeeperIssuanceComplete', gatewayTokenTransaction: transaction });
return transaction;
return undefined;
}, [gatekeeperClient, expectWalletConnected, stage, ownerSigns]);

@@ -54,5 +58,4 @@ /**

waitForGatekeeperIssuanceRequest,
gatekeeperClient,
};
};
exports.default = useGatekeeper;

@@ -32,4 +32,4 @@ import GatekeeperClient, { GatekeeperRecordResponse } from '../utils/gatekeeperClient';

wallet: WalletAdapter | undefined;
gatekeeperClient: () => GatekeeperClient;
httpConfig: ChainHttpConfig;
gatekeeperClient: () => GatekeeperClient | undefined;
httpConfig: ChainHttpConfig | undefined;
networkConfig: NetworkConfig;

@@ -36,0 +36,0 @@ }, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {

@@ -110,2 +110,3 @@ "use strict";

const dispatchGatekeeperRecord = async () => {
var _a;
const walletAddress = expectWalletConnected();

@@ -115,11 +116,13 @@ logDebug('Fetching Gatekeeper record...', walletAddress);

try {
const record = await gatekeeperClient().getGatekeeperRecordWithPayload(walletAddress.publicKey);
logDebug('Gatekeeper record response state: ', types_1.GatekeeperAPIStatus[record.state]);
const action = getAction(record);
if (!action) {
logger_1.default.error('Cannot dispatch action for invalid Gatekeeper Record State.', { record });
dispatch(dispatchFailure());
return;
const record = await ((_a = gatekeeperClient()) === null || _a === void 0 ? void 0 : _a.getGatekeeperRecordWithPayload(walletAddress.publicKey));
if (record) {
logDebug('Gatekeeper record response state: ', types_1.GatekeeperAPIStatus[record.state]);
const action = getAction(record);
if (!action) {
logger_1.default.error('Cannot dispatch action for invalid Gatekeeper Record State.', { record });
dispatch(dispatchFailure());
return;
}
dispatch(action());
}
dispatch(action());
}

@@ -126,0 +129,0 @@ catch (error) {

@@ -19,5 +19,5 @@ import { Chain, RootState, WalletAdapter } from '../types';

stage: string;
chainImplementation: Chain;
gatekeeperClient: () => GatekeeperClient;
chainImplementation?: Chain | undefined;
gatekeeperClient: () => GatekeeperClient | undefined;
}, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => void;
export default useOrchestration;

@@ -38,3 +38,2 @@ "use strict";

const { waitForConfirmPOWO, waitForPOWO, waitForHandleTransaction } = (0, usePOWO_1.default)({ wallet, chainImplementation }, state, dispatch);
const gatekeeperEndpoint = chainImplementation.httpConfig.baseUrl;
const { waitForGatekeeperIssuanceRequest } = (0, useGatekeeper_1.default)({ wallet, stage, gatekeeperClient }, state, dispatch);

@@ -45,3 +44,3 @@ const { checkForRefreshWithTimeout, refreshToken, waitForUnexpiredGatewayToken } = (0, useRefresh_1.default)({ stage, gatekeeperClient, networkConfig }, state, dispatch);

(0, useChain_1.default)({ wallet, chainImplementation, networkConfig }, state, dispatch);
(0, useGatekeeperRecord_1.default)({ wallet, gatekeeperClient, httpConfig: chainImplementation.httpConfig, networkConfig }, state, dispatch);
(0, useGatekeeperRecord_1.default)({ wallet, gatekeeperClient, httpConfig: chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.httpConfig, networkConfig }, state, dispatch);
/**

@@ -116,3 +115,3 @@ * Refresh Flows ----------------------------------------------------------------

return null;
}, [gatekeeperEndpoint, gatekeeperClient, expectWalletConnected]);
}, [gatekeeperClient, expectWalletConnected]);
/**

@@ -119,0 +118,0 @@ * wait until a presentation request id has been emitted by the CivicPass iframe

@@ -5,6 +5,6 @@ import { RootState, WalletAdapter, Chain } from '../types';

wallet: WalletAdapter | undefined;
chainImplementation: Chain;
chainImplementation: Chain | undefined;
}, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {
waitForConfirmPOWO: (payload: unknown) => Promise<unknown>;
waitForHandleTransaction: (transaction: string) => Promise<void>;
waitForHandleTransaction: (transaction: string | undefined) => Promise<void>;
waitForPOWO: (payload: unknown) => Promise<{

@@ -11,0 +11,0 @@ proof?: string | undefined;

@@ -50,10 +50,7 @@ "use strict";

});
chainImplementation
.proveWalletOwnership()
.then((proof) => {
chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.proveWalletOwnership().then((proof) => {
resolve({ proof, payload });
dispatch({ type: 'walletPowoComplete' });
dispatch({ type: 'civicPass_check_token_status' });
})
.catch((error) => {
}).catch((error) => {
logger_1.default.error('Proof of wallet ownership error: ', error);

@@ -67,5 +64,7 @@ dispatch({ type: 'walletPowoIncomplete' });

const waitForHandleTransaction = (0, react_1.useCallback)(async (transaction) => {
await chainImplementation.handleUserSignedTransaction(transaction);
dispatch({ type: 'walletPowoComplete' });
dispatch({ type: 'civicPass_check_token_status' });
if (transaction) {
await (chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.handleUserSignedTransaction(transaction));
dispatch({ type: 'walletPowoComplete' });
dispatch({ type: 'civicPass_check_token_status' });
}
}, [walletPowoInProgress, chainImplementation]);

@@ -72,0 +71,0 @@ return {

@@ -28,3 +28,3 @@ import { RootState, WalletAdapter } from '../types';

stage: string;
gatekeeperClient: () => GatekeeperClient;
gatekeeperClient: () => GatekeeperClient | undefined;
networkConfig: NetworkConfig;

@@ -37,4 +37,4 @@ }, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {

payload?: unknown;
}) => Promise<string>;
}) => Promise<string | undefined>;
};
export default useRefresh;

@@ -83,5 +83,6 @@ "use strict";

const refreshToken = (0, react_1.useCallback)((useWallet) => async ({ proof, payload }) => {
var _a;
logDebug('Refresh token', { payload, proof });
dispatch({ type: 'refresh_with_powo_in_progress' });
const refreshResult = await gatekeeperClient().refreshToken({
const refreshResult = await ((_a = gatekeeperClient()) === null || _a === void 0 ? void 0 : _a.refreshToken({
wallet: useWallet,

@@ -91,5 +92,5 @@ payload,

ownerSigns: ownerSigns !== null && ownerSigns !== void 0 ? ownerSigns : false,
});
}));
dispatch({ type: 'refresh_token_success' });
return refreshResult.transaction;
return refreshResult === null || refreshResult === void 0 ? void 0 : refreshResult.transaction;
}, [gatewayToken, gatekeeperClient, checkForRefreshWithTimeout, ownerSigns, walletAddress]);

@@ -96,0 +97,0 @@ /**

import { RootState, GatewayToken, InternalGatewayStatus } from '../types';
export declare const resetState: (state: RootState) => RootState;
export declare const statusFromToken: (state: RootState, gatewayToken?: GatewayToken) => InternalGatewayStatus;
export declare const statusFromToken: (state: RootState, gatewayToken?: GatewayToken | undefined) => InternalGatewayStatus;

@@ -7,4 +7,4 @@ import { WalletAdapter, Chain } from '../types';

wallet: WalletAdapter;
chainImplementation: Chain;
gatekeeperClient: () => GatekeeperClient;
chainImplementation?: Chain;
gatekeeperClient: () => GatekeeperClient | undefined;
dispatch: (value: Action) => void;

@@ -11,0 +11,0 @@ networkConfig: NetworkConfig;

@@ -19,3 +19,3 @@ "use strict";

const pollForActiveOnChainToken = async (pollChainNumberRetries = networkConfig.pollChainNumberRetries) => {
return (0, utils_1.pollUntilConditionMet)(chainImplementation.findGatewayToken, (onChainToken) => {
return (0, utils_1.pollUntilConditionMet)(chainImplementation ? chainImplementation.findGatewayToken : Promise.reject, (onChainToken) => {
if (!onChainToken)

@@ -31,2 +31,3 @@ return false; // keep polling

const waitForGatewayToken = async (pollChainNumberRetries = networkConfig.pollChainNumberRetries) => {
var _a;
// poll the gatekeeper until we have a status for a created record

@@ -58,4 +59,4 @@ // if we don't get a created token, then we consider it a failure

logError('Failed to find Gateway token on-chain with ownerSigns:false, checking with gatekeeper');
const gkApiStatus = await gatekeeperClient().getGatekeeperStatus(wallet.publicKey);
if (isRequestedRetriesExhausted(gkApiStatus)) {
const gkApiStatus = await ((_a = gatekeeperClient()) === null || _a === void 0 ? void 0 : _a.getGatekeeperStatus(wallet.publicKey));
if (gkApiStatus && isRequestedRetriesExhausted(gkApiStatus)) {
logError('Retried exhausted', { gkApiStatus });

@@ -66,3 +67,3 @@ dispatch({ type: 'civicPass_requested_retries_exhausted' });

// if the token is still pending or in review then keep polling on-chain
if (isTokenPending(gkApiStatus)) {
if (gkApiStatus && isTokenPending(gkApiStatus)) {
// we don't want to wait the whole amount of time if we've got to here, so just 4 retries = 3 x 2 seconds, a further

@@ -74,3 +75,3 @@ // 6 seconds before we will ask the GK API for status again

// or the gatekeeper threw an error during issuance attempt
if (isTokenCreated(gkApiStatus) || isFailure(gkApiStatus)) {
if ((gkApiStatus && isTokenCreated(gkApiStatus)) || (gkApiStatus && isFailure(gkApiStatus))) {
logError('Failed to find Gateway token with gatekeeper status code', types_1.GatekeeperAPIStatus[gkApiStatus]);

@@ -77,0 +78,0 @@ dispatch({ type: 'tokenNotFoundError' });

@@ -71,3 +71,3 @@ "use strict";

gatekeeperNetworkAddress,
chainType: chainImplementation.chainType,
chainType: chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.chainType,
ownerSigns,

@@ -88,16 +88,16 @@ });

}, [redirectUrl, stage, wallet === null || wallet === void 0 ? void 0 : wallet.publicKey, gatekeeperNetworkAddress, ownerSigns]);
const { network } = chainImplementation.httpConfig.queryParams;
const { headers } = chainImplementation.httpConfig;
const gatekeeperEndpoint = chainImplementation.httpConfig.baseUrl;
const gatekeeperClient = (0, react_1.useCallback)(() => {
if (!gatekeeperNetworkAddress) {
throw new Error('No gatekeeper network passed in.');
if (gatekeeperNetworkAddress && chainImplementation) {
const { network } = chainImplementation.httpConfig.queryParams;
const { headers } = chainImplementation.httpConfig;
const gatekeeperEndpoint = chainImplementation.httpConfig.baseUrl;
return new gatekeeperClient_1.default({
baseUrl: gatekeeperEndpoint,
stage,
queryParams: { network, gatekeeperNetworkAddress },
headers,
});
}
return new gatekeeperClient_1.default({
baseUrl: gatekeeperEndpoint,
stage,
queryParams: { network, gatekeeperNetworkAddress },
headers,
});
}, [stage, gatekeeperEndpoint, gatekeeperNetworkAddress, network]);
return undefined;
}, [stage, chainImplementation]);
// this hook implements the main business logic and handles requesting and refreshing gateway tokens

@@ -104,0 +104,0 @@ (0, useOrchestration_1.default)({ wallet, chainImplementation, stage, gatekeeperClient }, state, dispatch);

@@ -85,3 +85,3 @@ /// <reference types="react" />

gatekeeperNetwork: string | undefined;
chainImplementation: Chain;
chainImplementation?: Chain;
ownerSigns: boolean;

@@ -150,3 +150,3 @@ stage?: string;

gatekeeperNetworkAddress?: string;
chainType: ChainType;
chainType?: ChainType;
ownerSigns: boolean;

@@ -153,0 +153,0 @@ gatewayTokenTransaction?: string;

@@ -12,3 +12,3 @@ import type { Action } from '../useReducer';

wallet: WalletAdapter | undefined;
chainImplementation: Chain;
chainImplementation?: Chain | undefined;
networkConfig: NetworkConfig;

@@ -15,0 +15,0 @@ }, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {

@@ -30,3 +30,3 @@ "use strict";

logDebug('Removing onChainListener with id: ', listernerId);
chainImplementation.removeOnGatewayTokenChangeListener(listernerId);
chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.removeOnGatewayTokenChangeListener(listernerId);
}

@@ -47,3 +47,3 @@ catch (error) {

};
const listernerId = await chainImplementation.addOnGatewayTokenChangeListener(gatewayToken, tokenChangeCallback);
const listernerId = await (chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.addOnGatewayTokenChangeListener(gatewayToken, tokenChangeCallback));
logDebug('Adding onChainListener with id: ', listernerId);

@@ -80,3 +80,3 @@ return listernerId;

logDebug('Fetching token from chain');
const token = await chainImplementation.findGatewayToken();
const token = await (chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.findGatewayToken());
if (!token) {

@@ -83,0 +83,0 @@ dispatch({ type: 'tokenOnChainNotFound' });

@@ -53,3 +53,3 @@ "use strict";

const action = gatewayStatusToCivicPassAction[status];
const searchParams = new URLSearchParams(Object.assign(Object.assign({}, civicPass.requestPayload), { redirectUrl, networkAddress: gatekeeperNetworkAddress, action, wallet: walletAddress, chain: chainType, ownerSigns: ownerSigns ? 'true' : 'false' }));
const searchParams = new URLSearchParams(Object.assign(Object.assign({}, civicPass.requestPayload), { redirectUrl, networkAddress: gatekeeperNetworkAddress, action, wallet: walletAddress, chain: chainType !== null && chainType !== void 0 ? chainType : '', ownerSigns: ownerSigns ? 'true' : 'false' }));
logDebug('Civic pass query params', {

@@ -56,0 +56,0 @@ searchParams: searchParams.toString(),

@@ -5,3 +5,3 @@ import { CivicSignEventTypeRequest, RemoteSign } from '../utils/remoteSign';

wallet: WalletAdapter | undefined;
chainImplementation: Chain;
chainImplementation?: Chain | undefined;
remoteSign?: RemoteSign | undefined;

@@ -8,0 +8,0 @@ }) => {

@@ -27,4 +27,6 @@ "use strict";

try {
const proof = await chainImplementation.proveWalletOwnership();
remoteSigner === null || remoteSigner === void 0 ? void 0 : remoteSigner.sendSignedProof(proof);
const proof = await (chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.proveWalletOwnership());
if (proof) {
remoteSigner === null || remoteSigner === void 0 ? void 0 : remoteSigner.sendSignedProof(proof);
}
}

@@ -31,0 +33,0 @@ catch (err) {

@@ -7,3 +7,3 @@ import { RootState, WalletAdapter } from '../types';

stage: string;
gatekeeperClient: () => GatekeeperClient;
gatekeeperClient: () => GatekeeperClient | undefined;
}, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {

@@ -13,5 +13,4 @@ waitForGatekeeperIssuanceRequest: (value: {

payload?: unknown;
}) => PromiseLike<string>;
gatekeeperClient: () => GatekeeperClient;
}) => PromiseLike<string | undefined>;
};
export default useGatekeeper;

@@ -19,2 +19,3 @@ "use strict";

async ({ payload, proof }) => {
var _a;
const connectedWallet = expectWalletConnected();

@@ -25,3 +26,3 @@ logger_1.default.debug('waitForGatekeeperIssuanceRequest ready to call requestGatewayTokenFromGatekeeper', {

dispatch({ type: 'requestGatekeeperIssuance' });
const requestGatewayTokenFromGatekeeperResult = await gatekeeperClient().requestGatewayTokenFromGatekeeper({
const requestGatewayTokenFromGatekeeperResult = await ((_a = gatekeeperClient()) === null || _a === void 0 ? void 0 : _a.requestGatewayTokenFromGatekeeper({
wallet: connectedWallet,

@@ -31,13 +32,16 @@ payload,

ownerSigns: ownerSigns !== null && ownerSigns !== void 0 ? ownerSigns : false,
});
}));
logger_1.default.debug('requestGatewayTokenFromGatekeeperResult', requestGatewayTokenFromGatekeeperResult);
if (requestGatewayTokenFromGatekeeperResult.status >= 400) {
logger_1.default.error('Error requesting token from gatekeeper');
dispatch({ type: 'requestGatekeeperIssuanceFailed' });
throw new Error('Error requesting token from gatekeeper');
if (requestGatewayTokenFromGatekeeperResult) {
if (requestGatewayTokenFromGatekeeperResult && requestGatewayTokenFromGatekeeperResult.status >= 400) {
logger_1.default.error('Error requesting token from gatekeeper');
dispatch({ type: 'requestGatekeeperIssuanceFailed' });
throw new Error('Error requesting token from gatekeeper');
}
const { transaction } = requestGatewayTokenFromGatekeeperResult;
logger_1.default.debug('Successfully requested gatekeeper token');
dispatch({ type: 'requestGatekeeperIssuanceComplete', gatewayTokenTransaction: transaction });
return transaction;
}
const { transaction } = requestGatewayTokenFromGatekeeperResult;
logger_1.default.debug('Successfully requested gatekeeper token');
dispatch({ type: 'requestGatekeeperIssuanceComplete', gatewayTokenTransaction: transaction });
return transaction;
return undefined;
}, [gatekeeperClient, expectWalletConnected, stage, ownerSigns]);

@@ -54,5 +58,4 @@ /**

waitForGatekeeperIssuanceRequest,
gatekeeperClient,
};
};
exports.default = useGatekeeper;

@@ -32,4 +32,4 @@ import GatekeeperClient, { GatekeeperRecordResponse } from '../utils/gatekeeperClient';

wallet: WalletAdapter | undefined;
gatekeeperClient: () => GatekeeperClient;
httpConfig: ChainHttpConfig;
gatekeeperClient: () => GatekeeperClient | undefined;
httpConfig: ChainHttpConfig | undefined;
networkConfig: NetworkConfig;

@@ -36,0 +36,0 @@ }, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {

@@ -110,2 +110,3 @@ "use strict";

const dispatchGatekeeperRecord = async () => {
var _a;
const walletAddress = expectWalletConnected();

@@ -115,11 +116,13 @@ logDebug('Fetching Gatekeeper record...', walletAddress);

try {
const record = await gatekeeperClient().getGatekeeperRecordWithPayload(walletAddress.publicKey);
logDebug('Gatekeeper record response state: ', types_1.GatekeeperAPIStatus[record.state]);
const action = getAction(record);
if (!action) {
logger_1.default.error('Cannot dispatch action for invalid Gatekeeper Record State.', { record });
dispatch(dispatchFailure());
return;
const record = await ((_a = gatekeeperClient()) === null || _a === void 0 ? void 0 : _a.getGatekeeperRecordWithPayload(walletAddress.publicKey));
if (record) {
logDebug('Gatekeeper record response state: ', types_1.GatekeeperAPIStatus[record.state]);
const action = getAction(record);
if (!action) {
logger_1.default.error('Cannot dispatch action for invalid Gatekeeper Record State.', { record });
dispatch(dispatchFailure());
return;
}
dispatch(action());
}
dispatch(action());
}

@@ -126,0 +129,0 @@ catch (error) {

@@ -19,5 +19,5 @@ import { Chain, RootState, WalletAdapter } from '../types';

stage: string;
chainImplementation: Chain;
gatekeeperClient: () => GatekeeperClient;
chainImplementation?: Chain | undefined;
gatekeeperClient: () => GatekeeperClient | undefined;
}, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => void;
export default useOrchestration;

@@ -38,3 +38,2 @@ "use strict";

const { waitForConfirmPOWO, waitForPOWO, waitForHandleTransaction } = (0, usePOWO_1.default)({ wallet, chainImplementation }, state, dispatch);
const gatekeeperEndpoint = chainImplementation.httpConfig.baseUrl;
const { waitForGatekeeperIssuanceRequest } = (0, useGatekeeper_1.default)({ wallet, stage, gatekeeperClient }, state, dispatch);

@@ -45,3 +44,3 @@ const { checkForRefreshWithTimeout, refreshToken, waitForUnexpiredGatewayToken } = (0, useRefresh_1.default)({ stage, gatekeeperClient, networkConfig }, state, dispatch);

(0, useChain_1.default)({ wallet, chainImplementation, networkConfig }, state, dispatch);
(0, useGatekeeperRecord_1.default)({ wallet, gatekeeperClient, httpConfig: chainImplementation.httpConfig, networkConfig }, state, dispatch);
(0, useGatekeeperRecord_1.default)({ wallet, gatekeeperClient, httpConfig: chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.httpConfig, networkConfig }, state, dispatch);
/**

@@ -116,3 +115,3 @@ * Refresh Flows ----------------------------------------------------------------

return null;
}, [gatekeeperEndpoint, gatekeeperClient, expectWalletConnected]);
}, [gatekeeperClient, expectWalletConnected]);
/**

@@ -119,0 +118,0 @@ * wait until a presentation request id has been emitted by the CivicPass iframe

@@ -5,6 +5,6 @@ import { RootState, WalletAdapter, Chain } from '../types';

wallet: WalletAdapter | undefined;
chainImplementation: Chain;
chainImplementation: Chain | undefined;
}, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {
waitForConfirmPOWO: (payload: unknown) => Promise<unknown>;
waitForHandleTransaction: (transaction: string) => Promise<void>;
waitForHandleTransaction: (transaction: string | undefined) => Promise<void>;
waitForPOWO: (payload: unknown) => Promise<{

@@ -11,0 +11,0 @@ proof?: string | undefined;

@@ -50,10 +50,7 @@ "use strict";

});
chainImplementation
.proveWalletOwnership()
.then((proof) => {
chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.proveWalletOwnership().then((proof) => {
resolve({ proof, payload });
dispatch({ type: 'walletPowoComplete' });
dispatch({ type: 'civicPass_check_token_status' });
})
.catch((error) => {
}).catch((error) => {
logger_1.default.error('Proof of wallet ownership error: ', error);

@@ -67,5 +64,7 @@ dispatch({ type: 'walletPowoIncomplete' });

const waitForHandleTransaction = (0, react_1.useCallback)(async (transaction) => {
await chainImplementation.handleUserSignedTransaction(transaction);
dispatch({ type: 'walletPowoComplete' });
dispatch({ type: 'civicPass_check_token_status' });
if (transaction) {
await (chainImplementation === null || chainImplementation === void 0 ? void 0 : chainImplementation.handleUserSignedTransaction(transaction));
dispatch({ type: 'walletPowoComplete' });
dispatch({ type: 'civicPass_check_token_status' });
}
}, [walletPowoInProgress, chainImplementation]);

@@ -72,0 +71,0 @@ return {

@@ -28,3 +28,3 @@ import { RootState, WalletAdapter } from '../types';

stage: string;
gatekeeperClient: () => GatekeeperClient;
gatekeeperClient: () => GatekeeperClient | undefined;
networkConfig: NetworkConfig;

@@ -37,4 +37,4 @@ }, state: Partial<RootState>, dispatch: React.Dispatch<Action>) => {

payload?: unknown;
}) => Promise<string>;
}) => Promise<string | undefined>;
};
export default useRefresh;

@@ -83,5 +83,6 @@ "use strict";

const refreshToken = (0, react_1.useCallback)((useWallet) => async ({ proof, payload }) => {
var _a;
logDebug('Refresh token', { payload, proof });
dispatch({ type: 'refresh_with_powo_in_progress' });
const refreshResult = await gatekeeperClient().refreshToken({
const refreshResult = await ((_a = gatekeeperClient()) === null || _a === void 0 ? void 0 : _a.refreshToken({
wallet: useWallet,

@@ -91,5 +92,5 @@ payload,

ownerSigns: ownerSigns !== null && ownerSigns !== void 0 ? ownerSigns : false,
});
}));
dispatch({ type: 'refresh_token_success' });
return refreshResult.transaction;
return refreshResult === null || refreshResult === void 0 ? void 0 : refreshResult.transaction;
}, [gatewayToken, gatekeeperClient, checkForRefreshWithTimeout, ownerSigns, walletAddress]);

@@ -96,0 +97,0 @@ /**

import { RootState, GatewayToken, InternalGatewayStatus } from '../types';
export declare const resetState: (state: RootState) => RootState;
export declare const statusFromToken: (state: RootState, gatewayToken?: GatewayToken) => InternalGatewayStatus;
export declare const statusFromToken: (state: RootState, gatewayToken?: GatewayToken | undefined) => InternalGatewayStatus;
{
"name": "@civic/common-gateway-react",
"version": "0.1.9",
"version": "0.1.10-alpha.1",
"main": "./dist/cjs/index.js",

@@ -5,0 +5,0 @@ "module": "./dist/esm/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc