Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@civic/gateway-client-core
Advanced tools
Sample project for creating typescript library with support of iife and types.
The Civic gateway-client-core library is a state-management library for managing interactions with the Civic Pass system. It listens to inputs from sources such as Civic gatekeeper, on-chain events, Civic Pass data collection iframe, and orchestrates calls to the Civic Gatekeeper API, outputting the gatewayStatus and flowParameters that can be used to present a Civic Pass UI to the user and move forward with pass creation and refresh.
npm run build
builds the library to dist
, generating three files:
dist/civic-gateway-client-core.cjs.js
A CommonJS bundle, suitable for use in Node.js, that require
s the external dependency. This corresponds to the "main"
field in package.jsondist/civic-gateway-client-core.esm.js
an ES module bundle, suitable for use in other people's libraries and applications, that import
s the external dependency. This corresponds to the "module"
field in package.jsondist/civic-gateway-client-core.umd.js
a UMD build, suitable for use in any environment (including the browser, as a <script>
tag), that includes the external dependency. This corresponds to the "browser"
field in package.jsonnpm run dev
builds the library, then keeps rebuilding it whenever the source files change using rollup-watch.
npm test
builds the library, then tests it.
The library uses zustand for inernal state management, where the state is divided into separate concerns:
inputs: ClientCoreInput;
internal: ClientCoreInternal;
output?: ClientCoreOutput;
functions: {
reset: () => void;
};
The high-level flow is that:
This represents the state of different external inputs to the client-core:
civicSign: GatewayInput<CivicSignEventTypeRequestMessage, ChainError>;
civicPass: GatewayInput<CivicPassMessageResponse>;
gatewayToken: GatewayInput<GatewayToken>;
gatekeeperRecord: GatewayInput<GatekeeperRecordResponse>;
parameters: GatewayClientParameters | null;
civicSign events are sent and received using postMessage and can be considered 'outside' of the gatewayStatus flow, in that a signature request or did request can be received at any point in any flow. CivicSign events are subscribed to in the listenerManager and handled by 'remoteSign'
civicPass is an external frontend application that collects data and posts events that gateway-client-core listens to. These events are subscribed to in the listener manager and normally cause a change in the computed gatewayStatus that in turn can trigger orchestration flows
gatewayToken represents the on-chain state, where the input chainImplementation is used to query for and listen to token events. Changes to gatewayToken will also trigger gatewayStatus changes and trigger orchestration flows
gatekeeperRecord represents the civic-gatekeeper-api view of a pass: civic checks are applied on requests to the gatekeeper and can result in token rejections. The orchestrator's main function is to call the gatekeeper-api during different orchestration flows (issuance, refresh etc.) using data collected and provided by civic-pass events.
The parameters represent the instantiation parameters of gateway-client-core and represent options for things like wallet address, gatekeeper-network etc. that remain constant during a flow.
export type ClientCoreOutput = {
gatewayStatus: GatewayStatus;
gatewayToken?: GatewayToken;
flowParameters: FlowParameters | null;
pendingRequests: PendingPayload | undefined;
flowState?: {
status?: FlowStatus;
userInteraction: UserInteraction;
};
};
The outputs represent states that the instantiator of the gateway-client-core would be interested in:
Most of the input parameters to the client-core are static, i.e. any change in them should cause state to be reset and a new instance of the client-core to be used. However, there are some dynamic inputs that should not cause a reset but instead should trigger a new flow.
In order to allow a dApp to implement custom refresh logic, a boolean flag forceRequireRefresh
can be set by calling the updateDynamicParameters()
function on a gateway-client-core instance.
This flag will only cause a flow if an ACTIVE gatewayToken already exists for a given wallet. Setting it will cause the client-core to view the currrent gatewayToken as expired, and thus trigger set the gatewayStatus to REFRESH_TOKEN_REQUIRED, and to guide the user through a refresh-token flow. When the token expiry is updated to a value in the future, then the flow is viewed as finished and the gatewayStatus will once again be ACTIVE.
The core offers optional UI state management using output variables that can be used to control a remote frontend, and providing input methods that can be wired up to user interface elements.
The UI input consists of 3 methods that are exposed directly on the gateway-client-core instance:
onShow: () => void
: will set the Civic Pass frontend visibility to true and start or resume a user-flow, normally connected to the Civic Identity button, or other UI element that the user starts the Civic Pass flow withonHide: () => void
: will set the Civic Pass frontend visibily to false. Normally connected to the 'close' button on the frontend, if applicableonLoad: () => void
: to trigger when the frontend loads, i.e. on the iframe 'onLoad' methodThe UI output takes the form of state variables that can be wired to UI elements to show different states:
{
isVisible: boolean; // the frontend visibility
url?: string; // the URL to load frontend content
isLoading: boolean; // current loading status
isLoaded: boolean; // current loaded status
}
const inputs = <define core inputs>;
const [clientCoreOutput, setClientCoreOutput] = useState<ReactClientCoreOutput | undefined>(undefined);
const onOutputChange = (output: ClientCoreOutput | undefined) => {
setClientCoreOutput(output);
};
const core = GatewayClientCore.getSingleInstance({ ...inputs, onOutputChange});
{clientCoreOutput?.ui?.url && (
<IframeWrapper>
{ui?.output?.isLoading && <LoaderOverlay />}
<CloseButton onClick={() => core?.ui?.onHide()} />
<iframe
src={clientCoreOutput?.ui?.url}
style={{
pointerEvents: ui?.output?.isLoaded ? 'auto' : 'none', // disables user input during loading
}}
onLoad={() => {
core?.ui?.onLoad?.();
}}
/>
</IframeWrapper>
<IdentityButton onClick={() => core?.ui?.onShow()}>
)}
If the user rejects a transaction, or the chainImplementation.proveWalletOwnership() function failes for any reason, the 'chainError' flow starts. Civic-sign errors are currently not retriable within the normal data-collection flow, as the iframe loses its context, so the gateway-client will choose to restart the flow using either RESTART
or RESTART_REFRESH
.
canRequestFreshTx: true
in the responseISSUANCE_CLIENT_SENDS_START_NEW_TX
or REFRESH_CLIENT_SENDS_START_NEW_TXstartPreApprovedTransaction
computeIssuanceStartPreApprovedTransaction
state fires and calculates a new status of ISSUANCE_CLIENT_SENDS_REQUEST_NEW_TX
ISSUANCE_CLIENT_SENDS_REQUEST_NEW_TX
state and calls a new function on the issuance/refresh services fetchFreshTransaction()
fetchFreshTransaction({ payer, payload })
which updates the gatekeeperRecord.received value in statecomputeIssuanceInReview()
state function fires and we're back in the normal 'client-sends' flow waiting to send the on-chain transactionISSUANCE_CLIENT_SENDS_REQUEST_NEW_TX
statusISSUANCE_CLIENT_SENDS_REQUEST_NEW_TX
state and calls a new function on the issuance/refresh services fetchFreshTransaction()
fetchFreshTransaction({ payer, payload })
which updates the gatekeeperRecord.received value in statecomputeIssuanceInReview()
state function fires and we're back in the normal 'client-sends' flow waiting to send the on-chain transactionFAQs
Sample project for creating typescript library with support of iife and types.
The npm package @civic/gateway-client-core receives a total of 771 weekly downloads. As such, @civic/gateway-client-core popularity was classified as not popular.
We found that @civic/gateway-client-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.