@civic/gateway-client-core
Advanced tools
Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
{ | ||
"extends": ["airbnb-typescript", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"], | ||
"plugins": ["@typescript-eslint", "import", "prettier", "chai-friendly"], | ||
"plugins": ["@typescript-eslint", "import", "prettier", "chai-friendly", "no-only-tests"], | ||
"env": { | ||
@@ -5,0 +5,0 @@ "browser": true, |
@@ -1,1 +0,1 @@ | ||
{"processes":{"7be95443-f2b6-4d94-99b0-185fd0f455a3":{"parent":null,"children":[]},"d96b23c6-ad8e-4947-b0f1-ffb5911f577a":{"parent":null,"children":[]}},"files":{"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/gatekeeperClient.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/url.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/logger/index.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/logger/local.logger.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/logger/provider.logger.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/gatekeeperApi.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/gatekeeperNetworkService.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/state.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/gateway.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/stateMapping.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/civicPass.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/flow.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/flow.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/userInteraction.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/expiry.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/chain.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/gatewayStatus.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/fetch.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/common.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/error.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/defaults.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3","d96b23c6-ad8e-4947-b0f1-ffb5911f577a"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/initialisation.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/issuance.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/errors.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/partnerReview.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/refresh.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/flowParameters.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/object.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/partnerReview.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/index.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/eventInterface.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/orchestrate.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/listeners.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/civicSign.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/inputs.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/remoteSign.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/issuance.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/refresh.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/userInteraction.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/log.ts":["7be95443-f2b6-4d94-99b0-185fd0f455a3"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/partnerReview.ts":["d96b23c6-ad8e-4947-b0f1-ffb5911f577a"]},"externalIds":{}} | ||
{"processes":{"28a3bebe-b91d-4046-9787-9731b3815112":{"parent":null,"children":[]},"2fcab246-015f-496c-b05e-01647cf18e5f":{"parent":null,"children":["c9bb2c1a-8768-44d2-9d25-757294ceb561"]},"c9bb2c1a-8768-44d2-9d25-757294ceb561":{"parent":"2fcab246-015f-496c-b05e-01647cf18e5f","children":[]},"ca85135c-aa52-4710-a5ec-1a58b7e5ecfd":{"parent":null,"children":[]}},"files":{"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/gatekeeperClient.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/url.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/logger/index.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/logger/local.logger.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/logger/provider.logger.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/gatekeeperApi.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/chain.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/gatekeeperNetworkService.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/state.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/gateway.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/stateMapping.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/civicPass.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/flow.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/flow.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/userInteraction.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/expiry.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/gatewayStatus.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/fetch.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/common.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/error.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/defaults.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561","ca85135c-aa52-4710-a5ec-1a58b7e5ecfd"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/initialisation.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/issuance.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/errors.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/partnerReview.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/refresh.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/flowParameters.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/object.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/partnerReview.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/index.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/eventInterface.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/orchestrate.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/listeners.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/civicSign.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/inputs.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/remoteSign.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/issuance.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/refresh.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/utils/userInteraction.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/types/log.ts":["28a3bebe-b91d-4046-9787-9731b3815112","c9bb2c1a-8768-44d2-9d25-757294ceb561"],"/Users/kevincolgan/code/ociv-gatekeeper/packages/gateway-client-core/src/state/partnerReview.ts":["ca85135c-aa52-4710-a5ec-1a58b7e5ecfd"]},"externalIds":{}} |
import { GatekeeperAPIStatus, GatekeeperClientConfig, GatekeeperRecordResponse, RequestTokenIssuanceResponse, RequestTokenRefreshResponse, TokenRequest } from './types/gatekeeperApi'; | ||
import { ChainType } from './types/chain'; | ||
export declare const GATEKEEPER_BASE_ENDPOINTS: Record<string, string>; | ||
export declare const getGatekeeperEndpoint: (stage: string, chainType: ChainType) => string; | ||
export declare const isGkApiStatusTokenCreated: (code: number) => boolean; | ||
@@ -3,0 +6,0 @@ export declare const isGkApiStatusTokenPending: (code: number) => boolean; |
import { ClientCoreInput } from './types/clientCore'; | ||
export { GatekeeperClient } from './gatekeeperClient'; | ||
export { GatekeeperClient, getGatekeeperEndpoint } from './gatekeeperClient'; | ||
export { SignatureMethod, TokenState, State, ChainType } from './types/chain'; | ||
export type { Chain, GatewayToken, ProveWalletOwnershipResponse } from './types/chain'; | ||
export type { ChainClientInterface, GatewayToken, ProveWalletOwnershipResponse, ChainEvent, DID, ChainDetails, } from './types/chain'; | ||
export { ChainError, ErrorCode } from './utils/errors'; | ||
@@ -16,5 +16,8 @@ export { GatewayStatus } from './types/gateway'; | ||
export { prefixLogger } from './logger'; | ||
export type { UserInteraction } from './types/userInteraction'; | ||
export * from './types/gateway'; | ||
export type { ClientCoreInput } from './types/clientCore'; | ||
export type * from './types/gatewayCore'; | ||
import { GatewayClientCoreInterface } from './types/gatewayCore'; | ||
import { DynamicGatewayClientParameters } from './types/parameters'; | ||
export * from './types/gateway'; | ||
declare class GatewayClientCore implements GatewayClientCoreInterface { | ||
@@ -30,4 +33,2 @@ readonly inputs: ClientCoreInput; | ||
} | ||
export type { ClientCoreInput } from './types/clientCore'; | ||
export type * from './types/gatewayCore'; | ||
export default GatewayClientCore; |
import { GatekeeperClient } from './gatekeeperClient'; | ||
import { LoggingInterface } from './logger/provider.logger'; | ||
import { Store } from './state/state'; | ||
import { Chain } from './types/chain'; | ||
import { ChainClientInterface } from './types/chain'; | ||
import { GatewayCoreState } from './types/gatewayCore'; | ||
export declare class Issuance { | ||
readonly gatewayCoreStore: Store; | ||
readonly chainImplementation: Chain; | ||
readonly chainImplementation: ChainClientInterface; | ||
readonly gatekeeperClient: GatekeeperClient; | ||
@@ -14,3 +14,3 @@ readonly abortController: AbortController; | ||
protected timers: Partial<Record<'expectOnChainToken' | 'refreshCountdownTimer', any>>; | ||
constructor(gatewayCoreStore: Store, chainImplementation: Chain, gatekeeperClient: GatekeeperClient, abortController: AbortController, expectTokenTimeoutSeconds?: number); | ||
constructor(gatewayCoreStore: Store, chainImplementation: ChainClientInterface, gatekeeperClient: GatekeeperClient, abortController: AbortController, expectTokenTimeoutSeconds?: number); | ||
sendTransaction(): void; | ||
@@ -17,0 +17,0 @@ gatekeeperRequest(payer: string | undefined, fullState: GatewayCoreState): Promise<import("./types/gatekeeperApi").RequestTokenIssuanceResponse | null>; |
@@ -5,12 +5,11 @@ import { MessageEventInterface } from './types/eventInterface'; | ||
import { CivicSignEventTypeRequestMessage } from './types/civicSign'; | ||
import { Chain, GatewayToken } from './types/chain'; | ||
import { ChainClientInterface, GatewayToken } from './types/chain'; | ||
type ListenerHandler = (arg: unknown) => void; | ||
export declare class ListenerManager { | ||
readonly messageEventInterface: MessageEventInterface; | ||
readonly chainImplementation: Chain; | ||
readonly chainImplementation: ChainClientInterface; | ||
readonly instanceId: string; | ||
readonly log: LoggingInterface; | ||
readonly messageListeners: Record<string, ListenerHandler>; | ||
readonly chainListenerIds: Record<string, number>; | ||
constructor(messageEventInterface: MessageEventInterface, chainImplementation: Chain, instanceId: string, log?: LoggingInterface); | ||
constructor(messageEventInterface: MessageEventInterface, chainImplementation: ChainClientInterface, instanceId: string, log?: LoggingInterface); | ||
registerCivicPassListener(onMessage: (data: CivicPassMessageResponse) => void): void; | ||
@@ -17,0 +16,0 @@ registerCivicSignListener(onMessage: (data: CivicSignEventTypeRequestMessage) => void): void; |
@@ -5,3 +5,3 @@ import { ListenerManager } from './listeners'; | ||
import { GatekeeperClient } from './gatekeeperClient'; | ||
import { Chain } from './types/chain'; | ||
import { ChainClientInterface } from './types/chain'; | ||
import { WalletAdapter } from './types/parameters'; | ||
@@ -18,5 +18,5 @@ import { InternalGatewayStatus } from './types/gateway'; | ||
readonly postMessageTargetCallback: PostMessageTargetCallback; | ||
readonly chainImplementation: ChainClientInterface; | ||
readonly listenerManager: ListenerManager; | ||
readonly gatekeeperClient: GatekeeperClient; | ||
readonly chainImplementation: Chain; | ||
readonly payer: string | undefined; | ||
@@ -30,3 +30,3 @@ readonly wallet: WalletAdapter; | ||
private _partnerReview; | ||
constructor(gatewayCoreStore: Store, messageEventInterface: MessageEventInterface, instanceId: string, inputs: OrchestratorInputs, fetchConfig: FetchConfig, postMessageTargetCallback: PostMessageTargetCallback); | ||
constructor(gatewayCoreStore: Store, messageEventInterface: MessageEventInterface, instanceId: string, inputs: OrchestratorInputs, fetchConfig: FetchConfig, postMessageTargetCallback: PostMessageTargetCallback, chainImplementation: ChainClientInterface); | ||
private get issuance(); | ||
@@ -36,2 +36,3 @@ private get refresh(); | ||
getRemoteSignInstance(): RemoteSignWindowEventEmitter; | ||
getOwnerDids(): Promise<void>; | ||
lookupTokenState(): Promise<void>; | ||
@@ -38,0 +39,0 @@ initialise(): Promise<void>; |
import { GatekeeperClient } from './gatekeeperClient'; | ||
import { Issuance } from './issuance'; | ||
import { Store } from './state/state'; | ||
import { Chain } from './types/chain'; | ||
import { ChainClientInterface } from './types/chain'; | ||
import { GatewayCoreState } from './types/gatewayCore'; | ||
export declare class Refresh extends Issuance { | ||
readonly gatewayCoreStore: Store; | ||
readonly chainImplementation: Chain; | ||
readonly chainImplementation: ChainClientInterface; | ||
readonly gatekeeperClient: GatekeeperClient; | ||
readonly abortController: AbortController; | ||
readonly expectTokenTimeoutSeconds: number; | ||
constructor(gatewayCoreStore: Store, chainImplementation: Chain, gatekeeperClient: GatekeeperClient, abortController: AbortController, expectTokenTimeoutSeconds?: number); | ||
constructor(gatewayCoreStore: Store, chainImplementation: ChainClientInterface, gatekeeperClient: GatekeeperClient, abortController: AbortController, expectTokenTimeoutSeconds?: number); | ||
clearStateBeforeGatekeeperRequest(): void; | ||
@@ -14,0 +14,0 @@ gatekeeperRequest(payer: string | undefined, fullState: GatewayCoreState): Promise<import("./types/gatekeeperApi").RequestTokenIssuanceResponse | null>; |
@@ -1,2 +0,2 @@ | ||
import { Chain, ProveWalletOwnershipResponse, SignatureMethod } from './types/chain'; | ||
import { ChainClientInterface, DID, ProveWalletOwnershipResponse, SignatureMethod } from './types/chain'; | ||
import { CivicSignEventTypeRequestMessage, RemoteSign } from './types/civicSign'; | ||
@@ -21,3 +21,4 @@ import { PostMessageInterface } from './types/eventInterface'; | ||
wallet: WalletAdapter; | ||
chainImplementation: Chain; | ||
chainImplementation: ChainClientInterface; | ||
ownerDids?: DID[]; | ||
}) => Promise<string | ProveWalletOwnershipResponse | Uint8Array | undefined>; |
@@ -12,3 +12,3 @@ import { ValidationStatus } from '../types/civicPass'; | ||
export declare const handleGatewayTokenExistsStatus: (state: GatewayCoreState) => GatewayTokenCheckType; | ||
export type StatusIfGatekeeperRecordRejectedType = GatewayStatus.REJECTED | GatewayStatus.LOCATION_NOT_SUPPORTED | GatewayStatus.VPN_NOT_SUPPORTED | GatewayStatus.ERROR; | ||
export type StatusIfGatekeeperRecordRejectedType = GatewayStatus.REJECTED | GatewayStatus.LOCATION_NOT_SUPPORTED | GatewayStatus.VPN_NOT_SUPPORTED | GatewayStatus.REFRESH_TOKEN_REQUIRED | GatewayStatus.ERROR; | ||
export declare const statusIfGatekeeperRecordRejected: (state: GatewayCoreState) => StatusIfGatekeeperRecordRejectedType | undefined; |
@@ -0,1 +1,2 @@ | ||
import { GatekeeperHttpConfig } from './parameters'; | ||
export declare enum State { | ||
@@ -21,7 +22,2 @@ ACTIVE = "ACTIVE", | ||
} | ||
export type ChainHttpConfig = { | ||
baseUrl: string; | ||
queryParams: Record<string, string>; | ||
headers: Record<string, string>; | ||
}; | ||
export declare enum ChainType { | ||
@@ -46,3 +42,20 @@ SOLANA = "solana", | ||
}; | ||
export interface Chain { | ||
type DIDMethod = string; | ||
type DIDIdentifier = string; | ||
export type DID = `did:${DIDMethod}:${DIDIdentifier}`; | ||
export type ChainEvent = 'TOKEN_CREATED' | 'TOKEN_CHANGED'; | ||
export type ChainDetails = { | ||
chainType: ChainType; | ||
chainNetwork: string; | ||
}; | ||
export interface ChainClientInterface { | ||
on: (event: ChainEvent, listener: (GatewayToken: GatewayToken) => void) => this; | ||
findGatewayToken: () => Promise<GatewayToken | undefined>; | ||
proveWalletOwnership: (message?: string) => Promise<ProveWalletOwnershipResponse>; | ||
handleTransaction?: (partiallySignedTx: string) => Promise<string>; | ||
ownerDids: () => Promise<DID[]>; | ||
chainDetails: ChainDetails; | ||
onDestroy: () => Promise<void>; | ||
} | ||
export interface ChainLegacy { | ||
addOnGatewayTokenChangeListener: (gatewayToken: GatewayToken, tokenDidChange: (GatewayToken: GatewayToken) => void) => Promise<number>; | ||
@@ -56,3 +69,3 @@ addOnGatewayTokenCreatedOrChangedListener?: (tokenChange: (GatewayToken: GatewayToken) => void) => number; | ||
did: string; | ||
httpConfig: ChainHttpConfig; | ||
httpConfig: GatekeeperHttpConfig; | ||
chainType: ChainType; | ||
@@ -64,1 +77,2 @@ chainNetwork: string; | ||
} | ||
export {}; |
@@ -0,1 +1,2 @@ | ||
import { ChainClientInterface } from './chain'; | ||
import { MessageEventInterface, PostMessageTargetCallback } from './eventInterface'; | ||
@@ -9,2 +10,3 @@ import { FetchConfig } from './fetch'; | ||
parameters: GatewayClientParameters; | ||
chainImplementation: ChainClientInterface; | ||
fetchConfig: FetchConfig; | ||
@@ -11,0 +13,0 @@ onOutputChange: (output: ClientCoreOutput | undefined) => void; |
export type MessageEventInterface = { | ||
addMessageEventListener: <T>(handler: (response: T) => void) => number; | ||
addMessageEventListener: <T>(handler: (response: T) => void) => void; | ||
removeMessageEventListener: <T>(handler: (response: T) => void) => void; | ||
@@ -4,0 +4,0 @@ }; |
import { RequestInitRetryParams } from 'fetch-retry'; | ||
import { ChainType } from './chain'; | ||
export declare enum GatekeeperAPIStatus { | ||
@@ -23,3 +24,3 @@ REQUESTING = 0, | ||
export type GatekeeperClientConfig = { | ||
baseUrl: string; | ||
baseUrl?: string; | ||
queryParams?: Record<string, string>; | ||
@@ -31,2 +32,3 @@ headers?: Record<string, string>; | ||
walletAddress: string; | ||
chainType: ChainType; | ||
abortController: AbortController; | ||
@@ -33,0 +35,0 @@ }; |
import { ChainConfirmationTimeout, ChainError } from '../utils/errors'; | ||
import { ChainType, GatewayToken } from './chain'; | ||
import { ChainDetails, ChainType, GatewayToken } from './chain'; | ||
import { CivicPassMessageResponse } from './civicPass'; | ||
@@ -22,3 +22,3 @@ import { CivicSignEventTypeRequestMessage } from './civicSign'; | ||
wallet: string; | ||
chain: ChainType; | ||
chain?: ChainType; | ||
chainNetwork?: string; | ||
@@ -63,2 +63,4 @@ ownerSigns: boolean; | ||
}; | ||
ownerDids: string[]; | ||
chainDetails?: ChainDetails; | ||
}; | ||
@@ -65,0 +67,0 @@ export type ClientCoreInput = { |
import { GatewayClientParameters } from './parameters'; | ||
export type OrchestratorInputs = Pick<GatewayClientParameters, 'wallet' | 'chainImplementation' | 'gatekeeperNetwork' | 'stage' | 'payer' | 'gatekeeperSendsTransaction' | 'expectTokenTimeoutSeconds' | 'disableInitialGatekeeperLookup'>; | ||
export type OrchestratorInputs = Pick<GatewayClientParameters, 'wallet' | 'gatekeeperNetwork' | 'stage' | 'payer' | 'gatekeeperSendsTransaction' | 'expectTokenTimeoutSeconds' | 'disableInitialGatekeeperLookup' | 'xCivicClientHeader' | 'gatekeeperConfig'>; |
@@ -1,2 +0,1 @@ | ||
import { Chain } from './chain'; | ||
import { LogLevel } from './log'; | ||
@@ -10,6 +9,9 @@ export type Options = { | ||
} | ||
export type GatekeeperHttpConfig = { | ||
baseUrl: string; | ||
headers: Record<string, string>; | ||
}; | ||
export type GatewayClientParameters = { | ||
wallet: WalletAdapter | undefined; | ||
gatekeeperNetwork: string | undefined; | ||
chainImplementation: Chain | undefined; | ||
payer?: string; | ||
@@ -26,3 +28,5 @@ gatekeeperSendsTransaction: boolean; | ||
disableInitialGatekeeperLookup?: boolean; | ||
gatekeeperConfig?: GatekeeperHttpConfig; | ||
flowIdPrefix?: string; | ||
xCivicClientHeader?: string; | ||
referrer?: string; | ||
@@ -29,0 +33,0 @@ }; |
{ | ||
"name": "@civic/gateway-client-core", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "Sample project for creating typescript library with support of iife and types.", | ||
@@ -11,3 +11,3 @@ "main": "dist/civic-gateway-client-core.min.js", | ||
"scripts": { | ||
"lint": "eslint 'src/**/*.ts' --max-warnings 0", | ||
"lint": "eslint '{src,test}/**/*.ts' --max-warnings 0", | ||
"lint:fix": "yarn lint --fix", | ||
@@ -36,3 +36,5 @@ "build": "rimraf dist && NODE_ENV=production rollup -c", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-chai-friendly": "^0.7.4", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-no-only-tests": "^3.1.0", | ||
"eslint-plugin-prettier": "^3.*", | ||
@@ -50,3 +52,2 @@ "mocha": "^10.4.0", | ||
"dependencies": { | ||
"eslint-plugin-chai-friendly": "^0.7.4", | ||
"fetch-retry": "^6.0.0", | ||
@@ -60,3 +61,3 @@ "immer": "^10.0.4", | ||
"license": "MIT", | ||
"gitHead": "ddf19ebbfe030a34888aaaf4f398144444d7ece4" | ||
"gitHead": "9b1e421cc9b0eecc7ab24bad2895a48360d2de5d" | ||
} |
@@ -14,3 +14,25 @@ import { default as fetchBuilder } from 'fetch-retry'; | ||
} from './types/gatekeeperApi'; | ||
import { ChainType } from './types/chain'; | ||
export const GATEKEEPER_BASE_ENDPOINTS: Record<string, string> = { | ||
local: `http://localhost:3001/local`, | ||
test: `https://dev-gatekeeper-api.civic.com`, // for automated tests | ||
dev: `https://dev-gatekeeper-api.civic.com`, | ||
preprod: `https://preprod-gatekeeper-api.civic.com`, | ||
prod: `https://gatekeeper-api.civic.com`, | ||
}; | ||
const logDebug = prefixLogger('GatekeeperClient').debug; | ||
const logWarn = prefixLogger('GatekeeperClient').warn; | ||
const logError = prefixLogger('GatekeeperClient').error; | ||
export const getGatekeeperEndpoint = (stage: string, chainType: ChainType): string => { | ||
let baseUrl = GATEKEEPER_BASE_ENDPOINTS[stage]; | ||
if (!baseUrl) { | ||
logWarn(`No Gatekeeper endpoint for stage ${stage} . Using dev endpoint.`); | ||
baseUrl = GATEKEEPER_BASE_ENDPOINTS.dev; | ||
} | ||
return `${baseUrl}/v1/token/${chainType}`; | ||
}; | ||
export const isGkApiStatusTokenCreated = (code: number): boolean => code === GatekeeperAPIStatus.ISSUED; | ||
@@ -25,5 +47,2 @@ export const isGkApiStatusTokenPending = (code: number): boolean => code === GatekeeperAPIStatus.REQUESTED; | ||
const logDebug = prefixLogger('GatekeeperClient').debug; | ||
const logError = prefixLogger('GatekeeperClient').error; | ||
export class GatekeeperClient { | ||
@@ -47,3 +66,3 @@ private abortController: AbortController; | ||
this.abortController = initConfig.abortController; | ||
this.baseUrl = initConfig.baseUrl; | ||
this.baseUrl = initConfig.baseUrl || getGatekeeperEndpoint(initConfig.stage, initConfig.chainType); | ||
this.queryParams = initConfig.queryParams; | ||
@@ -50,0 +69,0 @@ this.headers = objectToURLParams({ ...initConfig.headers, 'x-civic-flowid': flowId }); |
import { v4 as uuid } from 'uuid'; | ||
import { ClientCoreInput } from './types/clientCore'; | ||
import { prefixLogger } from './logger'; | ||
export { GatekeeperClient } from './gatekeeperClient'; | ||
export { GatekeeperClient, getGatekeeperEndpoint } from './gatekeeperClient'; | ||
export { SignatureMethod, TokenState, State, ChainType } from './types/chain'; | ||
export type { Chain, GatewayToken, ProveWalletOwnershipResponse } from './types/chain'; | ||
export type { | ||
ChainClientInterface, | ||
GatewayToken, | ||
ProveWalletOwnershipResponse, | ||
ChainEvent, | ||
DID, | ||
ChainDetails, | ||
} from './types/chain'; | ||
export { ChainError, ErrorCode } from './utils/errors'; | ||
@@ -21,2 +28,6 @@ | ||
export { prefixLogger } from './logger'; | ||
export type { UserInteraction } from './types/userInteraction'; | ||
export * from './types/gateway'; | ||
export type { ClientCoreInput } from './types/clientCore'; | ||
export type * from './types/gatewayCore'; | ||
@@ -31,4 +42,2 @@ import { Orchestrator } from './orchestrate'; | ||
export * from './types/gateway'; | ||
let logDebug = prefixLogger('main').debug; | ||
@@ -70,3 +79,4 @@ | ||
inputs.fetchConfig, | ||
inputs.postMessageTargetCallback | ||
inputs.postMessageTargetCallback, | ||
inputs.chainImplementation | ||
); | ||
@@ -76,2 +86,3 @@ | ||
state.inputs.parameters = { ...inputs.parameters, payer: getPayer(inputs.parameters) }; | ||
state.internal.chainDetails = inputs.chainImplementation.chainDetails; | ||
state.inputs.dynamicParameters = inputs.dynamicParameters; | ||
@@ -111,5 +122,2 @@ state.internal.instanceId = this.instanceId; | ||
export type { ClientCoreInput } from './types/clientCore'; | ||
export type * from './types/gatewayCore'; | ||
export default GatewayClientCore; |
@@ -5,3 +5,3 @@ import { GatekeeperClient } from './gatekeeperClient'; | ||
import { Store } from './state/state'; | ||
import { Chain } from './types/chain'; | ||
import { ChainClientInterface } from './types/chain'; | ||
import { InputStatus } from './types/fetch'; | ||
@@ -21,3 +21,3 @@ import { TokenRequest } from './types/gatekeeperApi'; | ||
readonly gatewayCoreStore: Store, | ||
readonly chainImplementation: Chain, | ||
readonly chainImplementation: ChainClientInterface, | ||
readonly gatekeeperClient: GatekeeperClient, | ||
@@ -64,4 +64,9 @@ readonly abortController: AbortController, | ||
// client sends case | ||
if (!this.chainImplementation.handleTransaction) { | ||
this.log.error('No handleTransaction defined on chainImplementation.'); | ||
return; | ||
} | ||
this.chainImplementation | ||
.handleUserSignedTransaction(fullState.inputs.gatekeeperRecord.received.transaction) | ||
.handleTransaction(fullState.inputs.gatekeeperRecord.received.transaction) | ||
.then((txId) => { | ||
@@ -68,0 +73,0 @@ if (this.abortController.signal.aborted) return; |
@@ -9,3 +9,3 @@ // A Class to register the different listeners we need to orchestrate the different parts of the gateway | ||
import { CivicSignEventTypeRequest, CivicSignEventTypeRequestMessage } from './types/civicSign'; | ||
import { Chain, GatewayToken } from './types/chain'; | ||
import { ChainClientInterface, GatewayToken } from './types/chain'; | ||
@@ -16,7 +16,5 @@ type ListenerHandler = (arg: unknown) => void; | ||
readonly chainListenerIds: Record<string, number> = {}; | ||
constructor( | ||
readonly messageEventInterface: MessageEventInterface, | ||
readonly chainImplementation: Chain, | ||
readonly chainImplementation: ChainClientInterface, | ||
readonly instanceId: string, | ||
@@ -82,9 +80,4 @@ readonly log: LoggingInterface = prefixLogger('ListenerManager') | ||
registerOnChainListeners(onTokenChange: (gatewayToken: GatewayToken) => void) { | ||
if (this.chainImplementation.addOnGatewayTokenCreatedOrChangedListener === undefined) { | ||
this.log.warn('Could not register on-chain listener. Chain implementation does not support it.'); | ||
return; | ||
} | ||
const listenerId = this.chainImplementation.addOnGatewayTokenCreatedOrChangedListener(onTokenChange); | ||
this.chainListenerIds.gatewayToken = listenerId; | ||
this.chainImplementation.on('TOKEN_CREATED', onTokenChange); | ||
this.chainImplementation.on('TOKEN_CHANGED', onTokenChange); | ||
} | ||
@@ -98,9 +91,3 @@ | ||
}); | ||
Object.entries(this.chainListenerIds).forEach(([key, id]) => { | ||
this.log.debug('Removing chain event listener', key); | ||
this.chainImplementation?.removeOnGatewayTokenChangeListener(id); | ||
delete this.chainListenerIds[key]; | ||
}); | ||
} | ||
} |
@@ -12,3 +12,2 @@ /** | ||
*/ | ||
import { ListenerManager } from './listeners'; | ||
@@ -19,3 +18,3 @@ import { MessageEventInterface, PostMessageTargetCallback } from './types/eventInterface'; | ||
import { GatekeeperClient } from './gatekeeperClient'; | ||
import { Chain, GatewayToken } from './types/chain'; | ||
import { ChainClientInterface, DID, GatewayToken } from './types/chain'; | ||
import { WalletAdapter } from './types/parameters'; | ||
@@ -41,4 +40,2 @@ import { ExtendedGatewayStatus, GatewayStatus, InternalGatewayStatus } from './types/gateway'; | ||
readonly chainImplementation: Chain; | ||
readonly payer: string | undefined; | ||
@@ -66,6 +63,7 @@ | ||
fetchConfig: FetchConfig, | ||
readonly postMessageTargetCallback: PostMessageTargetCallback | ||
readonly postMessageTargetCallback: PostMessageTargetCallback, | ||
readonly chainImplementation: ChainClientInterface | ||
) { | ||
this.abortController = new AbortController(); | ||
if (!inputs.chainImplementation || !inputs.wallet?.address || !inputs.stage) { | ||
if (!this.chainImplementation || !inputs.wallet?.address || !inputs.stage) { | ||
throw new Error('chainImplementation wallet and stage are required'); | ||
@@ -75,14 +73,17 @@ } | ||
this.payer = getPayer(inputs); | ||
this.chainImplementation = inputs.chainImplementation; | ||
this.log = prefixLogger(`Orchestrator`); | ||
this.listenerManager = new ListenerManager(this.messageEventInterface, this.chainImplementation, this.instanceId); | ||
const { network } = this.chainImplementation?.httpConfig.queryParams || {}; | ||
const chainNetwork = this.chainImplementation?.chainDetails?.chainNetwork; | ||
this.gatekeeperClient = new GatekeeperClient({ | ||
abortController: this.abortController, | ||
baseUrl: this.chainImplementation?.httpConfig.baseUrl, | ||
baseUrl: inputs.gatekeeperConfig?.baseUrl, // if not set, this will be derived from the stage in gatekeeperClient.ts | ||
queryParams: inputs.gatekeeperNetwork | ||
? { network, gatekeeperNetworkAddress: inputs.gatekeeperNetwork } | ||
? { network: chainNetwork, gatekeeperNetworkAddress: inputs.gatekeeperNetwork } | ||
: undefined, | ||
headers: this.chainImplementation?.httpConfig.headers || {}, | ||
headers: { | ||
...(inputs.gatekeeperConfig?.headers || {}), | ||
...(inputs.xCivicClientHeader ? { 'x-civic-client': inputs.xCivicClientHeader } : {}), | ||
}, | ||
stage: inputs.stage, | ||
@@ -92,2 +93,3 @@ fetchImplementation: fetchConfig.fetchImplementation, | ||
walletAddress: inputs.wallet?.address, | ||
chainType: this.chainImplementation?.chainDetails?.chainType, | ||
}); | ||
@@ -141,2 +143,11 @@ | ||
async getOwnerDids() { | ||
// The dids are exported as part of the computed flowParameters, but they are async on the chainImplementation, | ||
// so we fetch them here and set them on state so zustand-compute can get them synchronously. | ||
const dids = await this.chainImplementation.ownerDids(); | ||
this.gatewayCoreStore.setState((state) => { | ||
state.internal.ownerDids = dids; | ||
}); | ||
} | ||
async lookupTokenState() { | ||
@@ -206,3 +217,2 @@ const retrieveGKRecord = async () => { | ||
// TODO add error handling like in Ty's PR: https://github.com/civicteam/ociv-gatekeeper/pull/2977/files | ||
async initialise() { | ||
@@ -212,3 +222,8 @@ this.abortController = new AbortController(); | ||
this.lookupTokenState(); | ||
await Promise.allSettled([ | ||
// The dids are exported as part of the computed flowParameters, but they are async on the chainImplementation, | ||
// so we fetch them here and set them on state so zustand-compute can get them synchronously. | ||
this.getOwnerDids(), | ||
this.lookupTokenState(), | ||
]); | ||
} | ||
@@ -323,24 +338,27 @@ | ||
state.inputs.civicSign.received = response; | ||
handleRemoteSignEvent(response, this.getRemoteSignInstance(), { | ||
chainImplementation: this.chainImplementation, | ||
wallet: this.wallet, | ||
}); | ||
const ownerDids = this.gatewayCoreStore.getState().internal.ownerDids; | ||
handleRemoteSignEvent(response, this.getRemoteSignInstance(), { | ||
chainImplementation: this.chainImplementation, | ||
wallet: this.wallet, | ||
ownerDids: ownerDids as DID[], | ||
}) | ||
.then((result) => { | ||
if (result) { | ||
this.log.error('No result from remote sign event'); | ||
} | ||
this.gatewayCoreStore.setState((draft) => { | ||
draft.inputs.civicSign.received = null; | ||
draft.inputs.civicSign.sent = result; | ||
draft.inputs.civicSign.error = null; | ||
draft.inputs.civicSign.status = InputStatus.RESPONDED; | ||
}); | ||
}) | ||
.then((result) => { | ||
if (result) { | ||
this.log.error('No result from remote sign event'); | ||
} | ||
this.gatewayCoreStore.setState((draft) => { | ||
draft.inputs.civicSign.received = null; | ||
draft.inputs.civicSign.sent = result; | ||
draft.inputs.civicSign.error = null; | ||
draft.inputs.civicSign.status = InputStatus.RESPONDED; | ||
}); | ||
}) | ||
.catch((error) => { | ||
this.gatewayCoreStore.setState((draft) => { | ||
draft.inputs.civicSign.error = error; | ||
draft.inputs.civicSign.status = InputStatus.ERROR; | ||
}); | ||
.catch((error) => { | ||
this.gatewayCoreStore.setState((draft) => { | ||
draft.inputs.civicSign.error = error; | ||
draft.inputs.civicSign.status = InputStatus.ERROR; | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -357,2 +375,3 @@ | ||
this.log.debug('Aborting orchestration'); | ||
this.chainImplementation.onDestroy(); | ||
this._issuance?.abort(); | ||
@@ -359,0 +378,0 @@ this._refresh?.abort(); |
import { GatekeeperClient } from './gatekeeperClient'; | ||
import { Issuance } from './issuance'; | ||
import { Store } from './state/state'; | ||
import { Chain } from './types/chain'; | ||
import { ChainClientInterface } from './types/chain'; | ||
import { InputStatus } from './types/fetch'; | ||
@@ -14,3 +14,3 @@ import { TokenRequest } from './types/gatekeeperApi'; | ||
readonly gatewayCoreStore: Store, | ||
readonly chainImplementation: Chain, | ||
readonly chainImplementation: ChainClientInterface, | ||
readonly gatekeeperClient: GatekeeperClient, | ||
@@ -17,0 +17,0 @@ readonly abortController: AbortController, |
import { prefixLogger } from './logger'; | ||
import { Chain, ProveWalletOwnershipResponse, SignatureMethod } from './types/chain'; | ||
import { ChainClientInterface, DID, ProveWalletOwnershipResponse, SignatureMethod } from './types/chain'; | ||
import { | ||
@@ -70,10 +70,11 @@ CivicSignEventTypeRequest, | ||
remoteSignerInst: RemoteSignWindowEventEmitter, | ||
inputs: { wallet: WalletAdapter; chainImplementation: Chain } | ||
inputs: { wallet: WalletAdapter; chainImplementation: ChainClientInterface; ownerDids?: DID[] } | ||
): Promise<string | ProveWalletOwnershipResponse | Uint8Array | undefined> => { | ||
const { wallet, chainImplementation } = inputs; | ||
const ownerDids = inputs.ownerDids || (await chainImplementation.ownerDids()); | ||
logDebug(`handleRemoteSignEvent ${message.request}`, { | ||
remoteSignerInst, | ||
wallet, | ||
chainImplDid: chainImplementation.did, | ||
chainImplInitProps: chainImplementation.initProps, | ||
chainImplDids: ownerDids, | ||
}); | ||
@@ -89,4 +90,4 @@ if (!Object.values(CivicSignEventTypeRequest).includes(message.request)) { | ||
if (message.request === CivicSignEventTypeRequest.REQUEST_DID) { | ||
remoteSignerInst?.sendDid(chainImplementation.did); | ||
return chainImplementation.did; | ||
remoteSignerInst?.sendDid(ownerDids?.[0]); | ||
return ownerDids?.[0]; | ||
} | ||
@@ -100,9 +101,10 @@ if (message.request === CivicSignEventTypeRequest.REQUEST_SIGNED_PROOF) { | ||
if (message.request === CivicSignEventTypeRequest.REQUEST_SIGNED_MESSAGE) { | ||
if (message.payload && chainImplementation.signMessage) { | ||
const signedMessage = await chainImplementation.signMessage(message.payload as Uint8Array); | ||
if (message.payload) { | ||
// TODO CPASS-1271 Check string vs UintArray | ||
const proveOwnershipResponse = await chainImplementation.proveWalletOwnership(message.payload as string); | ||
// TODO send back a remote sign error: this requires the iframe to handle this | ||
remoteSignerInst?.sendSignedMessage(signedMessage); | ||
return signedMessage; | ||
remoteSignerInst?.sendSignedMessage(Buffer.from(proveOwnershipResponse.proof)); | ||
return proveOwnershipResponse; | ||
} | ||
} | ||
}; |
@@ -96,2 +96,3 @@ import { isTokenRefreshRequired } from '../utils/expiry'; | ||
| GatewayStatus.VPN_NOT_SUPPORTED | ||
| GatewayStatus.REFRESH_TOKEN_REQUIRED | ||
| GatewayStatus.ERROR; | ||
@@ -102,4 +103,9 @@ export const statusIfGatekeeperRecordRejected = ( | ||
const gatekeeperRecord = state.inputs.gatekeeperRecord; | ||
const gatewayToken = state.inputs.gatewayToken; | ||
const recordState = gatekeeperRecord?.received?.state; | ||
switch (recordState) { | ||
case GatekeeperAPIStatus.ISSUED_EXPIRED: | ||
// we only want to handle the error case here | ||
// the refresh case will be handled by statusFromGatewayTokenIfExists | ||
return gatewayToken?.received ? undefined : GatewayStatus.ERROR; | ||
case GatekeeperAPIStatus.REJECTED: | ||
@@ -106,0 +112,0 @@ return GatewayStatus.REJECTED; |
@@ -14,7 +14,3 @@ import { FlowParameters, GatewayCoreState } from '../types/gatewayCore'; | ||
if ( | ||
!( | ||
state.inputs.parameters?.wallet && | ||
state.inputs.parameters.chainImplementation?.chainType && | ||
state.internal?.instanceId | ||
) || | ||
!(state.inputs.parameters?.wallet && state.internal.chainDetails?.chainType && state.internal?.instanceId) || | ||
[GatewayStatus.UNKNOWN, GatewayStatus.CHECKING].includes(computedInternalStatus as GatewayStatus) | ||
@@ -53,5 +49,5 @@ ) { | ||
wallet: state.inputs.parameters.wallet.address, | ||
chain: state.inputs.parameters.chainImplementation?.chainType, | ||
chainNetwork: state.inputs.parameters.chainImplementation?.chainNetwork, | ||
did: state.inputs.parameters.chainImplementation.did, | ||
chain: state.internal.chainDetails?.chainType, | ||
chainNetwork: state.internal.chainDetails?.chainNetwork, | ||
did: state.internal.ownerDids?.[0], | ||
gatekeeperSendsTransaction: state.inputs.parameters.gatekeeperSendsTransaction, | ||
@@ -58,0 +54,0 @@ partnerAppId: state.inputs.parameters.partnerAppId, |
@@ -41,6 +41,8 @@ import { InputStatus } from '../types/fetch'; | ||
| CalculateIssuanceStatusReturn; | ||
export const computeInitialState = (state: GatewayCoreState): ComputeInitialStateType => | ||
computeChecking(state) || | ||
statusIfGatekeeperRecordRejected(state) || | ||
computeChecking(state) || | ||
statusFromGatewayTokenIfExists(state) || | ||
computeIssuanceStatus(state) || | ||
(state.internal?.status as ComputeInitialStateType); |
@@ -67,2 +67,4 @@ /** | ||
errors: {}, | ||
ownerDids: [], // Dids will be queried using async chainImplementation.ownerDids() and updated here | ||
chainDetails: undefined, | ||
}; | ||
@@ -153,2 +155,4 @@ | ||
instanceId: state.internal.instanceId, | ||
ownerDids: [], // Dids will be queried using async chainImplementation.ownerDids() and updated here | ||
chainDetails: state.internal.chainDetails, | ||
}; | ||
@@ -155,0 +159,0 @@ state.output = { ...initialOutputState }; |
@@ -0,1 +1,3 @@ | ||
import { GatekeeperHttpConfig } from './parameters'; | ||
export enum State { | ||
@@ -24,8 +26,2 @@ ACTIVE = 'ACTIVE', | ||
export type ChainHttpConfig = { | ||
baseUrl: string; | ||
queryParams: Record<string, string>; | ||
headers: Record<string, string>; | ||
}; | ||
export enum ChainType { | ||
@@ -53,4 +49,25 @@ SOLANA = 'solana', | ||
}; | ||
type DIDMethod = string; | ||
type DIDIdentifier = string; | ||
// or string if that makes things easier | ||
export type DID = `did:${DIDMethod}:${DIDIdentifier}`; | ||
export interface Chain { | ||
export type ChainEvent = 'TOKEN_CREATED' | 'TOKEN_CHANGED'; | ||
export type ChainDetails = { | ||
chainType: ChainType; | ||
chainNetwork: string; | ||
}; | ||
export interface ChainClientInterface { | ||
on: (event: ChainEvent, listener: (GatewayToken: GatewayToken) => void) => this; | ||
findGatewayToken: () => Promise<GatewayToken | undefined>; | ||
proveWalletOwnership: (message?: string) => Promise<ProveWalletOwnershipResponse>; | ||
handleTransaction?: (partiallySignedTx: string) => Promise<string>; | ||
// dids that own the passed-in address | ||
ownerDids: () => Promise<DID[]>; | ||
chainDetails: ChainDetails; | ||
// In some cases, chain listeners have to be explicitly de-registered, for example. | ||
onDestroy: () => Promise<void>; | ||
} | ||
export interface ChainLegacy { | ||
addOnGatewayTokenChangeListener: ( | ||
@@ -68,3 +85,3 @@ gatewayToken: GatewayToken, | ||
did: string; | ||
httpConfig: ChainHttpConfig; | ||
httpConfig: GatekeeperHttpConfig; | ||
chainType: ChainType; | ||
@@ -71,0 +88,0 @@ chainNetwork: string; |
@@ -0,1 +1,2 @@ | ||
import { ChainClientInterface } from './chain'; | ||
import { MessageEventInterface, PostMessageTargetCallback } from './eventInterface'; | ||
@@ -10,2 +11,3 @@ import { FetchConfig } from './fetch'; | ||
parameters: GatewayClientParameters; | ||
chainImplementation: ChainClientInterface; // An implementation conforming to the ChainClientInterface, representing the blockchain cluster you are interacting with | ||
fetchConfig: FetchConfig; | ||
@@ -12,0 +14,0 @@ onOutputChange: (output: ClientCoreOutput | undefined) => void; |
export type MessageEventInterface = { | ||
addMessageEventListener: <T>(handler: (response: T) => void) => number; | ||
addMessageEventListener: <T>(handler: (response: T) => void) => void; | ||
removeMessageEventListener: <T>(handler: (response: T) => void) => void; | ||
@@ -4,0 +4,0 @@ }; |
import { RequestInitRetryParams } from 'fetch-retry'; | ||
import { ChainType } from './chain'; | ||
@@ -26,3 +27,3 @@ export enum GatekeeperAPIStatus { | ||
export type GatekeeperClientConfig = { | ||
baseUrl: string; | ||
baseUrl?: string; // If not passed in, this will be taken from the stage-based config in gatekeeperClient.ts | ||
queryParams?: Record<string, string>; | ||
@@ -34,2 +35,3 @@ headers?: Record<string, string>; | ||
walletAddress: string; | ||
chainType: ChainType; | ||
abortController: AbortController; | ||
@@ -36,0 +38,0 @@ }; |
import { ChainConfirmationTimeout, ChainError } from '../utils/errors'; | ||
import { ChainType, GatewayToken } from './chain'; | ||
import { ChainDetails, ChainType, GatewayToken } from './chain'; | ||
import { CivicPassMessageResponse } from './civicPass'; | ||
@@ -25,3 +25,3 @@ import { CivicSignEventTypeRequestMessage } from './civicSign'; | ||
wallet: string; // mandatory without default, should always be provided | ||
chain: ChainType; | ||
chain?: ChainType; | ||
chainNetwork?: string; | ||
@@ -69,2 +69,4 @@ ownerSigns: boolean; | ||
}; | ||
ownerDids: string[]; // Dids are queried via the chainImplementation using the async ownerDids() function. | ||
chainDetails?: ChainDetails; | ||
}; | ||
@@ -71,0 +73,0 @@ |
@@ -6,3 +6,2 @@ import { GatewayClientParameters } from './parameters'; | ||
| 'wallet' | ||
| 'chainImplementation' | ||
| 'gatekeeperNetwork' | ||
@@ -14,2 +13,4 @@ | 'stage' | ||
| 'disableInitialGatekeeperLookup' | ||
| 'xCivicClientHeader' | ||
| 'gatekeeperConfig' | ||
>; |
@@ -1,2 +0,1 @@ | ||
import { Chain } from './chain'; | ||
import { LogLevel } from './log'; | ||
@@ -13,6 +12,10 @@ | ||
export type GatekeeperHttpConfig = { | ||
baseUrl: string; | ||
headers: Record<string, string>; | ||
}; | ||
export type GatewayClientParameters = { | ||
wallet: WalletAdapter | undefined; // the wallet connected to the dApp, can be null initially pre-user wallet connection | ||
gatekeeperNetwork: string | undefined; // the gatekeeper network public key address | ||
chainImplementation: Chain | undefined; // An implementation conforming to the Chain interface, representing the blockchain cluster you are interacting with | ||
payer?: string; | ||
@@ -29,3 +32,5 @@ gatekeeperSendsTransaction: boolean; // Note - cannot be true if payer is set. Used here only to send to the iframe and check if civic-sends is allowed | ||
disableInitialGatekeeperLookup?: boolean; // when set to true, the client will not call the GK-API on load | ||
gatekeeperConfig?: GatekeeperHttpConfig; | ||
flowIdPrefix?: string; // a prefix to add to the flowId | ||
xCivicClientHeader?: string; // If set, send this to the Gatekeeper in the X-Civic-Client header. Used for tracking the client version. | ||
referrer?: string; // the client referrer | ||
@@ -32,0 +37,0 @@ }; |
@@ -5,2 +5,3 @@ import sinon from 'sinon'; | ||
GatekeeperClient, | ||
getGatekeeperEndpoint, | ||
isGkApiStatusFailure, | ||
@@ -11,2 +12,3 @@ isGkApiStatusRequestedRetriesExhausted, | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import { ChainType } from '../src/types/chain'; | ||
import { AbortError } from 'node-fetch'; | ||
@@ -50,2 +52,3 @@ | ||
stage: 'prod', | ||
chainType: ChainType.SOLANA, | ||
}; | ||
@@ -57,2 +60,25 @@ | ||
describe('getGatekeeperEndpoint', () => { | ||
it('should return correct endpoint for stage "dev"', () => { | ||
expect(getGatekeeperEndpoint('dev', ChainType.SOLANA)).to.equal( | ||
'https://dev-gatekeeper-api.civic.com/v1/token/solana' | ||
); | ||
}); | ||
it('should return correct endpoint for stage "preprod"', () => { | ||
expect(getGatekeeperEndpoint('preprod', ChainType.SOLANA)).to.equal( | ||
'https://preprod-gatekeeper-api.civic.com/v1/token/solana' | ||
); | ||
}); | ||
it('should return correct endpoint for stage "prod"', () => { | ||
expect(getGatekeeperEndpoint('prod', ChainType.SOLANA)).to.equal( | ||
'https://gatekeeper-api.civic.com/v1/token/solana' | ||
); | ||
}); | ||
it('should return "dev" endpoint for unknown stage', () => { | ||
expect(getGatekeeperEndpoint('unknown', ChainType.SOLANA)).to.equal( | ||
'https://dev-gatekeeper-api.civic.com/v1/token/solana' | ||
); | ||
}); | ||
}); | ||
describe('getGatekeeperRecordWithPayload', function () { | ||
@@ -59,0 +85,0 @@ it('should return null if the fetch call is aborted', async () => { |
@@ -15,2 +15,4 @@ import chai from 'chai'; | ||
// Setup fetch stub | ||
// For some unknown reason, the stub doesn't work on my machine unless I console.log(global.fetch) first. | ||
console.log(global.fetch); | ||
fetchStub = sandbox.stub(global, 'fetch'); | ||
@@ -17,0 +19,0 @@ }); |
@@ -8,2 +8,3 @@ import sinon from 'sinon'; | ||
import { PartnerReview } from '../src/partnerReview'; | ||
import { ChainType } from '../src/types/chain'; | ||
@@ -43,2 +44,3 @@ chai.use(chaiSubset); | ||
queryParams: { network: 'test_network', gatekeeperNetworkAddress: 'test_gatekeeperNetworkAddress' }, | ||
chainType: ChainType.SOLANA, | ||
}; | ||
@@ -52,14 +54,15 @@ | ||
context('pollForReviewFinished', () => { | ||
context('when the gatekeeper call returns a record with state not REQUESTED', () => { | ||
it('should call getGatekeeperRecordWithPayload and update the store', async () => { | ||
// Arrange | ||
const getGatekeeperRecordWithPayloadStub = sandbox.stub(gatekeeperClient, 'getGatekeeperRecordWithPayload').resolves({ | ||
state: GatekeeperAPIStatus.ISSUED, | ||
}); | ||
const getGatekeeperRecordWithPayloadStub = sandbox | ||
.stub(gatekeeperClient, 'getGatekeeperRecordWithPayload') | ||
.resolves({ | ||
state: GatekeeperAPIStatus.ISSUED, | ||
}); | ||
partnerReview = new PartnerReview(gatewayCoreStore, gatekeeperClient, abortController); | ||
// Act | ||
await partnerReview.pollForReviewFinished(); | ||
// Assert | ||
@@ -76,10 +79,12 @@ expect(getGatekeeperRecordWithPayloadStub.called).to.be.true; | ||
// Arrange | ||
const getGatekeeperRecordWithPayloadStub = sandbox.stub(gatekeeperClient, 'getGatekeeperRecordWithPayload').resolves({ | ||
state: GatekeeperAPIStatus.REQUESTED, | ||
}); | ||
const getGatekeeperRecordWithPayloadStub = sandbox | ||
.stub(gatekeeperClient, 'getGatekeeperRecordWithPayload') | ||
.resolves({ | ||
state: GatekeeperAPIStatus.REQUESTED, | ||
}); | ||
partnerReview = new PartnerReview(gatewayCoreStore, gatekeeperClient, abortController); | ||
// Act | ||
await partnerReview.pollForReviewFinished(); | ||
// Assert | ||
@@ -107,3 +112,3 @@ expect(getGatekeeperRecordWithPayloadStub.called).to.be.true; | ||
partnerReview = new PartnerReview(gatewayCoreStore, gatekeeperClient, abortController); | ||
// Act | ||
@@ -113,3 +118,3 @@ const promise = partnerReview.pollForReviewFinished(); | ||
await promise; | ||
// Assert | ||
@@ -116,0 +121,0 @@ expect(getGatekeeperRecordWithPayloadStub.calledTwice).to.be.true; |
@@ -35,3 +35,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -38,0 +38,0 @@ }); |
@@ -44,3 +44,3 @@ import { step } from 'mocha-steps'; | ||
context(`with GK record state ${gkAPIState} mapping to gateway status ${expectedGatewayStatus}`, () => { | ||
step('1. expect the Gatekeeper client to successful initialize', () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -47,0 +47,0 @@ }); |
@@ -30,3 +30,3 @@ import { step } from 'mocha-steps'; | ||
}); | ||
step('1. expect the Gatekeeper client to successful initialize', () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', () => { | ||
testHelpers.initializeGatewayCore({ disableInitialGatekeeperLookup: true }); | ||
@@ -49,3 +49,3 @@ }); | ||
}); | ||
step('1. expect the Gatekeeper client to successful initialize', () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -52,0 +52,0 @@ }); |
@@ -27,3 +27,3 @@ import { step } from 'mocha-steps'; | ||
}); | ||
step('1. expect the Gatekeeper client to successful initialize', () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', () => { | ||
testHelpers.initializeGatewayCore({ disableInitialGatekeeperLookup: true }); | ||
@@ -46,3 +46,3 @@ }); | ||
}); | ||
step('1. expect the Gatekeeper client to successful initialize', () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -49,0 +49,0 @@ }); |
@@ -50,3 +50,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -53,0 +53,0 @@ // wait for GK and on-chain checks to complete |
@@ -50,3 +50,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -53,0 +53,0 @@ // wait for GK and on-chain checks to complete |
@@ -51,3 +51,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -54,0 +54,0 @@ // wait for GK and on-chain checks to complete |
@@ -36,3 +36,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -39,0 +39,0 @@ // wait for GK and on-chain checks to complete |
@@ -31,3 +31,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -34,0 +34,0 @@ // wait for GK and on-chain checks to complete |
@@ -49,3 +49,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -52,0 +52,0 @@ // wait for GK and on-chain checks to complete |
@@ -49,3 +49,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -52,0 +52,0 @@ // wait for GK and on-chain checks to complete |
@@ -40,3 +40,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -43,0 +43,0 @@ // wait for GK and on-chain checks to complete |
@@ -29,3 +29,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize with clientSendMaxRetries of 2', () => { | ||
step('1. expect the Gatekeeper client to successfully initialize with clientSendMaxRetries of 2', () => { | ||
testHelpers.initializeGatewayCore({ clientSendMaxRetries: 2 }); | ||
@@ -110,3 +110,3 @@ }); | ||
step('1. expect the Gatekeeper client to successful initialize with clientSendMaxRetries of 2', () => { | ||
step('1. expect the Gatekeeper client to successfully initialize with clientSendMaxRetries of 2', () => { | ||
testHelpers.initializeGatewayCore({ clientSendMaxRetries: 2 }); | ||
@@ -113,0 +113,0 @@ }); |
@@ -27,3 +27,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', () => { | ||
testHelpers.initializeGatewayCore({ expectTokenTimeoutSeconds: 2 }); | ||
@@ -30,0 +30,0 @@ }); |
@@ -31,3 +31,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -34,0 +34,0 @@ // wait for GK and on-chain checks to complete |
@@ -32,3 +32,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -35,0 +35,0 @@ // wait for GK and on-chain checks to complete |
@@ -41,3 +41,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -44,0 +44,0 @@ // wait for GK and on-chain checks to complete |
@@ -37,3 +37,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -40,0 +40,0 @@ // wait for GK and on-chain checks to complete |
@@ -41,3 +41,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -44,0 +44,0 @@ // wait for GK and on-chain checks to complete |
@@ -37,3 +37,3 @@ import { step } from 'mocha-steps'; | ||
step('1. expect the Gatekeeper client to successful initialize', async () => { | ||
step('1. expect the Gatekeeper client to successfully initialize', async () => { | ||
testHelpers.initializeGatewayCore(); | ||
@@ -40,0 +40,0 @@ // wait for GK and on-chain checks to complete |
@@ -8,3 +8,10 @@ import GatewayClientCore, { | ||
} from '../../src'; | ||
import { Chain, ChainType, GatewayToken, SignatureMethod, State } from '../../src/types/chain'; | ||
import { | ||
ChainClientInterface, | ||
ChainEvent, | ||
ChainType, | ||
GatewayToken, | ||
SignatureMethod, | ||
State, | ||
} from '../../src/types/chain'; | ||
import EventEmitter from 'events'; | ||
@@ -24,3 +31,3 @@ import chai from 'chai'; | ||
import { CivicSignEventTypeRequest, CivicSignEventTypeResponse } from '../../src/types/civicSign'; | ||
import { GatewayClientParameters } from '../../src/types/parameters'; | ||
import { GatekeeperHttpConfig, GatewayClientParameters } from '../../src/types/parameters'; | ||
import { nowSeconds } from '../../src/utils/expiry'; | ||
@@ -87,2 +94,4 @@ import { UserInteractionStatus } from '../../src/types/userInteraction'; | ||
protected gatekeeperConfig: GatekeeperHttpConfig; | ||
protected postMessageCallbackStub: sinon.SinonStub<any[], any>; | ||
@@ -92,3 +101,3 @@ | ||
protected handleUserSignedTransactionStub: sinon.SinonStub<any[], any>; | ||
protected handleTransactionStub: sinon.SinonStub<any[], any>; | ||
@@ -105,3 +114,3 @@ protected fetchStub: sinon.SinonStub<any[], any>; | ||
protected chainImplementationStub: Chain; | ||
protected chainImplementationStub: ChainClientInterface; | ||
@@ -122,2 +131,6 @@ protected findTokenStub: sinon.SinonStub<[], Promise<GatewayToken | undefined>>; | ||
) { | ||
this.gatekeeperConfig = { | ||
baseUrl: 'https://civicgatekeeperapi.com', | ||
headers: {}, | ||
}; | ||
this.inputs = { ...defaultHelperInputs, ...inInputs }; | ||
@@ -128,3 +141,3 @@ this.postMessageCallbackStub = sandbox.stub(); | ||
this.signMessageStub = this.sandbox.stub(); | ||
this.handleUserSignedTransactionStub = sandbox.stub(); | ||
this.handleTransactionStub = sandbox.stub(); | ||
this.fetchStub = sandbox.stub(); | ||
@@ -141,23 +154,16 @@ this.proveWalletOwnershipStub = sandbox.stub(); | ||
this.chainImplementationStub = { | ||
httpConfig: { | ||
baseUrl: 'https://civicgatekeeperapi.com', | ||
queryParams: { | ||
network: this.inputs.network, | ||
}, | ||
headers: {}, | ||
on: (_event: ChainEvent, listener: (GatewayToken: GatewayToken) => void) => { | ||
this.onTokenChange = listener; | ||
}, | ||
addOnGatewayTokenChangeListener: sandbox.stub(), | ||
addOnGatewayTokenCreatedOrChangedListener: (tokenChange: (gatewayToken: GatewayToken) => void) => { | ||
this.onTokenChange = tokenChange; | ||
return 42; | ||
}, | ||
removeOnGatewayTokenChangeListener: sandbox.stub(), | ||
findGatewayToken: this.findTokenStub, | ||
handleUserSignedTransaction: this.handleUserSignedTransactionStub, | ||
proveWalletOwnership: this.proveWalletOwnershipStub, | ||
signMessage: this.signMessageStub, | ||
did: this.inputs.did, | ||
chainNetwork: this.inputs.network, | ||
chainType: ChainType.SOLANA, | ||
} as unknown as Chain; | ||
handleTransaction: this.handleTransactionStub, | ||
// dids that own the passed-in address | ||
ownerDids: () => Promise.resolve([this.inputs.did]), | ||
chainDetails: { | ||
chainType: ChainType.SOLANA, | ||
chainNetwork: this.inputs.network, | ||
}, | ||
onDestroy: () => {}, | ||
} as unknown as ChainClientInterface; | ||
} | ||
@@ -195,3 +201,3 @@ | ||
.withArgs( | ||
`${this.chainImplementationStub.httpConfig.baseUrl}/${this.inputs.walletAddress}?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
`${this.gatekeeperConfig.baseUrl}/${this.inputs.walletAddress}?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
{ | ||
@@ -219,3 +225,3 @@ method: 'GET', | ||
console.log('fetchStub args', [ | ||
`${this.chainImplementationStub.httpConfig.baseUrl}/?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
`${this.gatekeeperConfig.baseUrl}/?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
{ | ||
@@ -230,3 +236,3 @@ method: 'POST', | ||
.withArgs( | ||
`${this.chainImplementationStub.httpConfig.baseUrl}/?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
`${this.gatekeeperConfig.baseUrl}/?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
{ | ||
@@ -256,3 +262,3 @@ method: 'POST', | ||
.withArgs( | ||
`${this.chainImplementationStub.httpConfig.baseUrl}/${this.inputs.walletAddress}?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
`${this.gatekeeperConfig.baseUrl}/${this.inputs.walletAddress}?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
{ | ||
@@ -276,3 +282,3 @@ method: 'GET', | ||
.withArgs( | ||
`${this.chainImplementationStub.httpConfig.baseUrl}/?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
`${this.gatekeeperConfig.baseUrl}/?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
{ | ||
@@ -300,3 +306,3 @@ method: 'POST', | ||
.withArgs( | ||
`${this.chainImplementationStub.httpConfig.baseUrl}/${this.inputs.walletAddress}?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
`${this.gatekeeperConfig.baseUrl}/${this.inputs.walletAddress}?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
sinon.match({ | ||
@@ -333,5 +339,4 @@ method: 'PATCH', | ||
messageEventInterface: { | ||
addMessageEventListener: (handler: EventListener) => { | ||
addMessageEventListener: (handler: EventListener): void => { | ||
this.emitter.on('message', handler); | ||
return 123; | ||
}, | ||
@@ -342,3 +347,3 @@ removeMessageEventListener: () => ({}), | ||
wallet: { address: this.inputs.walletAddress }, | ||
chainImplementation: this.chainImplementationStub, | ||
gatekeeperConfig: this.gatekeeperConfig, | ||
gatekeeperNetwork: this.inputs.gatekeeperNetwork, | ||
@@ -355,2 +360,3 @@ stage: 'testStage', | ||
}, | ||
chainImplementation: this.chainImplementationStub, | ||
} as ClientCoreInput; | ||
@@ -394,3 +400,3 @@ | ||
.withArgs( | ||
`${this.chainImplementationStub.httpConfig.baseUrl}/${this.inputs.walletAddress}?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
`${this.gatekeeperConfig.baseUrl}/${this.inputs.walletAddress}?network=${this.inputs.network}&gatekeeperNetworkAddress=${this.inputs.gatekeeperNetwork}`, | ||
{ | ||
@@ -436,2 +442,5 @@ method: 'GET', | ||
}); | ||
// The event handler is asynchronous. The call above just emits the event, it doesn't await the promise of the handler. | ||
// So we have to give the event time to be handled. | ||
await sleep(200); | ||
this.expectCivicSignResponse({ | ||
@@ -453,2 +462,5 @@ event: CivicSignEventTypeResponse.RESPONSE_PUBLIC_KEY, | ||
}); | ||
// The event handler is asynchronous. The call above just emits the event, it doesn't await the promise of the handler. | ||
// So we have to give the event time to be handled. | ||
await sleep(200); | ||
this.expectCivicSignResponse({ | ||
@@ -471,2 +483,5 @@ event: CivicSignEventTypeResponse.RESPONSE_DID, | ||
}); | ||
// The event handler is asynchronous. The call above just emits the event, it doesn't await the promise of the handler. | ||
// So we have to give the event time to be handled. | ||
await sleep(200); | ||
expect(this.proveWalletOwnershipStub).to.have.been.calledWith('message-to-sign'); | ||
@@ -481,5 +496,5 @@ this.expectCivicSignResponse({ | ||
async expectSuccessfulCivicSignProofFlow() { | ||
await this.expectSuccessfulCivicSignPublicKeyRequestResponse(); | ||
// await this.expectSuccessfulCivicSignPublicKeyRequestResponse(); | ||
await this.expectSuccessfulCivicSignDIDRequestResponse(); | ||
await this.expectSuccessfulCivicSignProofRequestResponse(); | ||
// await this.expectSuccessfulCivicSignProofRequestResponse(); | ||
} | ||
@@ -546,3 +561,3 @@ | ||
prepareUserAbortedTransaction() { | ||
this.handleUserSignedTransactionStub.rejects(new Error('User aborted')); | ||
this.handleTransactionStub.rejects(new Error('User aborted')); | ||
} | ||
@@ -576,3 +591,3 @@ | ||
async prepareSuccessfulHandleTransaction() { | ||
this.handleUserSignedTransactionStub.callsFake(() => { | ||
this.handleTransactionStub.callsFake(() => { | ||
this.clientSendsAttemptCount += 1; | ||
@@ -584,3 +599,3 @@ return Promise.resolve(`${transactionId}_${this.clientSendsAttemptCount}`); | ||
async prepareSuccessfulThirdPartyHandleTransaction() { | ||
this.handleUserSignedTransactionStub.callsFake(() => { | ||
this.handleTransactionStub.callsFake(() => { | ||
return Promise.resolve(`${transactionId}_third_party`); | ||
@@ -631,3 +646,3 @@ }); | ||
expectClientSendTransactionToBeSent(expectedNumberOfAttempts = this.clientSendsAttemptCount) { | ||
expect(this.handleUserSignedTransactionStub.callCount).to.eq(expectedNumberOfAttempts); | ||
expect(this.handleTransactionStub.callCount).to.eq(expectedNumberOfAttempts); | ||
expect(this.clientOutput.gatewayStatus).to.equal(GatewayStatus.IN_REVIEW); | ||
@@ -634,0 +649,0 @@ this.expectFlowParameterInputs({ |
@@ -7,3 +7,3 @@ import sinon from 'sinon'; | ||
import { GatekeeperClient } from '../src/gatekeeperClient'; | ||
import { Chain, GatewayCoreState } from '../src'; | ||
import { ChainClientInterface, ChainType, GatewayCoreState } from '../src'; | ||
import { Issuance } from '../src/issuance'; | ||
@@ -25,3 +25,3 @@ import { InputStatus } from '../src/types/fetch'; | ||
let gatekeeperClient: GatekeeperClient; | ||
let chainImplementation: Chain; | ||
let chainImplementation: ChainClientInterface; | ||
let setStateStub: sinon.SinonStub<any[], any>; | ||
@@ -38,3 +38,3 @@ let getStateStub: sinon.SinonStub<any[], any>; | ||
let handleUserSignedTransactionStub: sinon.SinonStub<any[], any>; | ||
let handleTransactionStub: sinon.SinonStub<any[], any>; | ||
beforeEach(() => { | ||
@@ -59,4 +59,5 @@ abortController = new AbortController(); | ||
queryParams: { network: 'test_network', gatekeeperNetworkAddress: 'test_gatekeeperNetworkAddress' }, | ||
chainType: ChainType.ETHEREUM, | ||
}; | ||
handleUserSignedTransactionStub = sandbox.stub(); | ||
handleTransactionStub = sandbox.stub(); | ||
chainImplementation = { | ||
@@ -70,4 +71,4 @@ httpConfig: { | ||
}, | ||
handleUserSignedTransaction: handleUserSignedTransactionStub, | ||
} as unknown as Chain; | ||
handleTransaction: handleTransactionStub, | ||
} as unknown as ChainClientInterface; | ||
@@ -200,3 +201,3 @@ // Initialize the GatekeeperClient with the stubbed fetch | ||
beforeEach(() => { | ||
handleUserSignedTransactionStub.withArgs('test_transaction').resolves('txId'); | ||
handleTransactionStub.withArgs('test_transaction').resolves('txId'); | ||
}); | ||
@@ -215,3 +216,3 @@ | ||
beforeEach(() => { | ||
handleUserSignedTransactionStub.withArgs('test_transaction').rejects(new Error('test_error')); | ||
handleTransactionStub.withArgs('test_transaction').rejects(new Error('test_error')); | ||
}); | ||
@@ -218,0 +219,0 @@ it('should update the error in state', async () => { |
@@ -7,3 +7,3 @@ import { expect } from 'chai'; | ||
import { CivicPassMessageAction } from '../src/types/civicPass'; | ||
import { Chain } from '../src/types/chain'; | ||
import { ChainClientInterface } from '../src/types/chain'; | ||
@@ -16,3 +16,3 @@ const sandbox = sinon.createSandbox(); | ||
let mockResponse: { data: any }; | ||
let chainImplementationStub: SinonStubbedInstance<Chain>; | ||
let chainImplementationStub: SinonStubbedInstance<ChainClientInterface>; | ||
@@ -29,5 +29,4 @@ afterEach(sandbox.restore); | ||
chainImplementationStub = { | ||
addOnGatewayTokenCreatedOrChangedListener: sandbox.stub(), | ||
removeOnGatewayTokenChangeListener: sandbox.stub(), | ||
} as SinonStubbedInstance<Chain>; | ||
on: sandbox.stub(), | ||
} as SinonStubbedInstance<ChainClientInterface>; | ||
@@ -128,31 +127,9 @@ listenerManager = new ListenerManager(messageEventInterface, chainImplementationStub, 'testInstance', log); | ||
context('with addOnGatewayTokenCreatedOrChangedListener defined', () => { | ||
it('should call addOnGatewayTokenCreatedOrChangedListener on chain adapter', () => { | ||
chainImplementationStub.addOnGatewayTokenCreatedOrChangedListener?.returns(42); | ||
listenerManager.registerOnChainListeners(callbackStub); | ||
expect(chainImplementationStub.addOnGatewayTokenCreatedOrChangedListener).to.have.been.calledOnceWith( | ||
callbackStub | ||
); | ||
}); | ||
it('should save the listenerId from the chainImplementation in listeners object', () => { | ||
chainImplementationStub.addOnGatewayTokenCreatedOrChangedListener?.returns(42); | ||
listenerManager.registerOnChainListeners(callbackStub); | ||
expect(listenerManager.chainListenerIds.gatewayToken).to.equal(42); | ||
}); | ||
it('should call "on()" on chain adapter for TOKEN_CREATED and TOKEN_CHANGED', () => { | ||
chainImplementationStub.on?.returns('test-chain-implementation' as unknown as ChainClientInterface); | ||
listenerManager.registerOnChainListeners(callbackStub); | ||
expect(chainImplementationStub.on).to.have.been.calledTwice; | ||
expect(chainImplementationStub.on).to.have.been.calledWith('TOKEN_CREATED', callbackStub); | ||
expect(chainImplementationStub.on).to.have.been.calledWith('TOKEN_CHANGED', callbackStub); | ||
}); | ||
context('with addOnGatewayTokenCreatedOrChangedListener not defined', () => { | ||
it('should not throw an error', () => { | ||
listenerManager.registerOnChainListeners(callbackStub); | ||
}); | ||
it('should log a warning', () => { | ||
chainImplementationStub.addOnGatewayTokenCreatedOrChangedListener = undefined; | ||
listenerManager.registerOnChainListeners(callbackStub); | ||
expect(log.warn).to.have.been.calledOnceWith( | ||
'Could not register on-chain listener. Chain implementation does not support it.' | ||
); | ||
}); | ||
}); | ||
}); | ||
@@ -169,25 +146,5 @@ | ||
listenerManager.unregisterAllListeners(); | ||
expect(listenerManager.chainListenerIds).to.deep.equal({}); | ||
expect(listenerManager.messageListeners).to.deep.equal({}); | ||
}); | ||
context('with chainImplementation returning a listenerId for on-chain listener', () => { | ||
let callbackStub: SinonStub; | ||
beforeEach(() => { | ||
callbackStub = sandbox.stub(); | ||
}); | ||
it('should call remove on chainImplementation', () => { | ||
chainImplementationStub.addOnGatewayTokenCreatedOrChangedListener?.returns(42); | ||
listenerManager.registerOnChainListeners(callbackStub); | ||
listenerManager.unregisterAllListeners(); | ||
expect(chainImplementationStub.removeOnGatewayTokenChangeListener).to.have.been.calledOnceWith(42); | ||
}); | ||
it('should remove listenerId from listeners object', () => { | ||
listenerManager.unregisterAllListeners(); | ||
expect(listenerManager.messageListeners.gatewayToken).to.be.undefined; | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -36,3 +36,3 @@ import { expect } from 'chai'; | ||
context('should instantiate a new loggingProvider with the log level from the window', () => { | ||
let originalWindow = global.window; | ||
const originalWindow = global.window; | ||
@@ -62,3 +62,3 @@ beforeEach(() => { | ||
context('should instantiate a new loggingProvider with the default level from the params', () => { | ||
let originalWindow = global.window; | ||
const originalWindow = global.window; | ||
@@ -65,0 +65,0 @@ beforeEach(() => { |
import sinon, { SinonStub } from 'sinon'; | ||
import { Orchestrator } from '../src/orchestrate'; | ||
import { RemoteSignWindowEventEmitter } from '../src/remoteSign'; | ||
import { Chain } from '../src/types/chain'; | ||
import { ChainClientInterface } from '../src/types/chain'; | ||
import { MessageEventInterface, PostMessageInterface, PostMessageTargetCallback } from '../src/types/eventInterface'; | ||
@@ -50,11 +50,6 @@ import { FetchConfig } from '../src/types/fetch'; | ||
wallet: { address: '0x123' }, | ||
chainImplementation: { | ||
httpConfig: { | ||
baseUrl: 'https://example.com', | ||
queryParams: { | ||
network: '0x123', | ||
}, | ||
headers: {}, | ||
}, | ||
} as unknown as Chain, | ||
gatekeeperConfig: { | ||
baseUrl: 'https://example.com', | ||
headers: {}, | ||
}, | ||
gatekeeperNetwork: '0x456', | ||
@@ -79,3 +74,4 @@ stage: 'testStage', | ||
fetchConfig, | ||
postMessageTargetCallback | ||
postMessageTargetCallback, | ||
{} as unknown as ChainClientInterface | ||
); | ||
@@ -105,3 +101,4 @@ | ||
fetchConfig, | ||
postMessageTargetCallback | ||
postMessageTargetCallback, | ||
{} as unknown as ChainClientInterface | ||
); | ||
@@ -119,3 +116,4 @@ orchestrator.reset(); | ||
fetchConfig, | ||
postMessageTargetCallback | ||
postMessageTargetCallback, | ||
{} as unknown as ChainClientInterface | ||
); | ||
@@ -136,3 +134,4 @@ const spy = sandbox.spy(orchestrator, 'initialise'); | ||
fetchConfig, | ||
postMessageTargetCallback | ||
postMessageTargetCallback, | ||
{} as unknown as ChainClientInterface | ||
); | ||
@@ -159,3 +158,4 @@ const spy = sandbox.spy(orchestrator, 'reset'); | ||
fetchConfig, | ||
postMessageTargetCallback | ||
postMessageTargetCallback, | ||
{} as unknown as ChainClientInterface | ||
); | ||
@@ -162,0 +162,0 @@ orchestrator.orchestrate(); |
@@ -9,2 +9,3 @@ import sinon from 'sinon'; | ||
import { getFetchStub } from './integration/testSupport'; | ||
import { ChainType } from '../src/types/chain'; | ||
@@ -49,2 +50,3 @@ chai.use(chaiSubset); | ||
queryParams: { network: 'test_network', gatekeeperNetworkAddress: 'test_gatekeeperNetworkAddress' }, | ||
chainType: ChainType.ETHEREUM, | ||
}; | ||
@@ -57,3 +59,3 @@ | ||
context('pollForReviewFinished', () => { | ||
context('when the gatekeeper record is in the requested state', () => { | ||
context('when the gatekeeper record is in the REQUESTED state', () => { | ||
beforeEach(() => { | ||
@@ -85,28 +87,48 @@ fetchImplementationStub | ||
}); | ||
}); | ||
context('should stop polling on aborted signal', () => { | ||
beforeEach(() => { | ||
fetchImplementationStub | ||
.withArgs( | ||
`'https://api.example.com'/0x123?network=test_network&gatekeeperNetworkAddress=test_gatekeeperNetworkAddress`, | ||
{ | ||
method: 'GET', | ||
headers: {}, | ||
signal: sinon.match.any, | ||
} | ||
) | ||
.resolves(getFetchStub(GatekeeperAPIStatus.REQUESTED, { pending: { presentationRequestId: '123' } })); | ||
context('when the gatekeeper returns SERVER_FAILURE', () => { | ||
beforeEach(() => { | ||
fetchImplementationStub | ||
.withArgs( | ||
`'https://api.example.com'/0x123?network=test_network&gatekeeperNetworkAddress=test_gatekeeperNetworkAddress`, | ||
{ | ||
method: 'GET', | ||
headers: {}, | ||
signal: sinon.match.any, | ||
} | ||
) | ||
.resolves(getFetchStub(GatekeeperAPIStatus.SERVER_FAILURE, {})); | ||
}); | ||
it('should clear interval and not poll again', async () => { | ||
partnerReview = new PartnerReview(gatewayCoreStore, gatekeeperClient, abortController); | ||
await partnerReview.pollForReviewFinished(); | ||
expect(fetchImplementationStub.callCount).to.equal(1); | ||
}); | ||
}); | ||
it('should stop polling after abort is called', async () => { | ||
partnerReview = new PartnerReview(gatewayCoreStore, gatekeeperClient, abortController); | ||
await partnerReview.pollForReviewFinished(); | ||
clock.tick(2100); | ||
expect(fetchImplementationStub.callCount).to.equal(2); | ||
// should stop the polling | ||
partnerReview.abort(); | ||
fetchImplementationStub.resetHistory(); | ||
clock.tick(8000); | ||
expect(fetchImplementationStub.callCount).to.equal(0); | ||
context('should stop polling on aborted signal', () => { | ||
beforeEach(() => { | ||
fetchImplementationStub | ||
.withArgs( | ||
`'https://api.example.com'/0x123?network=test_network&gatekeeperNetworkAddress=test_gatekeeperNetworkAddress`, | ||
{ | ||
method: 'GET', | ||
headers: {}, | ||
signal: sinon.match.any, | ||
} | ||
) | ||
.resolves(getFetchStub(GatekeeperAPIStatus.REQUESTED, { pending: { presentationRequestId: '123' } })); | ||
}); | ||
it('should stop polling after abort is called', async () => { | ||
partnerReview = new PartnerReview(gatewayCoreStore, gatekeeperClient, abortController); | ||
await partnerReview.pollForReviewFinished(); | ||
clock.tick(2100); | ||
expect(fetchImplementationStub.callCount).to.equal(2); | ||
// should stop the polling | ||
partnerReview.abort(); | ||
fetchImplementationStub.resetHistory(); | ||
clock.tick(8000); | ||
expect(fetchImplementationStub.callCount).to.equal(0); | ||
}); | ||
}); | ||
@@ -113,0 +135,0 @@ }); |
@@ -7,3 +7,3 @@ import sinon from 'sinon'; | ||
import { GatekeeperClient } from '../src/gatekeeperClient'; | ||
import { Chain, ExtendedGatewayStatus, GatewayCoreState } from '../src'; | ||
import { ChainClientInterface, ChainType, ExtendedGatewayStatus, GatewayCoreState } from '../src'; | ||
import { Refresh } from '../src/refresh'; | ||
@@ -26,3 +26,3 @@ import * as expiryUtils from '../src/utils/expiry'; | ||
let gatekeeperClient: GatekeeperClient; | ||
let chainImplementation: Chain; | ||
let chainImplementation: ChainClientInterface; | ||
let setStateStub: sinon.SinonStub<any[], any>; | ||
@@ -61,2 +61,3 @@ let getStateStub: sinon.SinonStub<any[], any>; | ||
queryParams: { network: 'test_network', gatekeeperNetworkAddress: 'test_gatekeeperNetworkAddress' }, | ||
chainType: ChainType.ETHEREUM, | ||
}; | ||
@@ -72,3 +73,3 @@ | ||
}, | ||
} as unknown as Chain; | ||
} as unknown as ChainClientInterface; | ||
@@ -75,0 +76,0 @@ // Initialize the GatekeeperClient with the stubbed fetch |
import { SinonStubbedInstance } from 'sinon'; | ||
import { CivicSignEventTypeRequest, CivicSignEventTypeRequestMessage } from '../src/types/civicSign'; | ||
import { handleRemoteSignEvent, RemoteSignWindowEventEmitter } from '../src/remoteSign'; | ||
import { Chain, ProveWalletOwnershipResponse } from '../src/types/chain'; | ||
import { ChainClientInterface, ProveWalletOwnershipResponse, SignatureMethod } from '../src/types/chain'; | ||
import { WalletAdapter } from '../src/types/parameters'; | ||
import chai from 'chai'; | ||
import sinon = require('sinon'); | ||
import sinon from 'sinon'; | ||
@@ -17,3 +17,3 @@ const { expect } = chai; | ||
let did: string; | ||
let chainImplementationStub: Chain; | ||
let chainImplementationStub: ChainClientInterface; | ||
@@ -27,6 +27,6 @@ afterEach(sandbox.restore); | ||
chainImplementationStub = { | ||
did, | ||
ownerDids: () => Promise.resolve([did]), | ||
proveWalletOwnership: () => {}, | ||
signMessage: () => {}, | ||
} as unknown as Chain; | ||
} as unknown as ChainClientInterface; | ||
@@ -125,5 +125,5 @@ remoteSignerInstStub = sandbox.createStubInstance(RemoteSignWindowEventEmitter); | ||
sinon | ||
.stub(chainImplementationStub, 'signMessage') | ||
.withArgs(message.payload as Uint8Array) | ||
.resolves('test_signedMessage' as unknown as Uint8Array); | ||
.stub(chainImplementationStub, 'proveWalletOwnership') | ||
.withArgs(message.payload?.toString() as string) | ||
.resolves({ proof: 'test_signedMessage', signatureMethod: SignatureMethod.MESSAGE }); | ||
}); | ||
@@ -136,3 +136,3 @@ | ||
}); | ||
expect(chainImplementationStub.signMessage).calledWith('proof'); | ||
expect(chainImplementationStub.proveWalletOwnership).calledWith('proof'); | ||
}); | ||
@@ -145,3 +145,3 @@ | ||
}); | ||
expect(remoteSignerInstStub.sendSignedMessage).calledWith('test_signedMessage'); | ||
expect(remoteSignerInstStub.sendSignedMessage).calledWith(Buffer.from('test_signedMessage')); | ||
}); | ||
@@ -154,3 +154,3 @@ | ||
}); | ||
expect(response).to.equal('test_signedMessage'); | ||
expect(response).to.deep.equal({ proof: 'test_signedMessage', signatureMethod: SignatureMethod.MESSAGE }); | ||
}); | ||
@@ -157,0 +157,0 @@ }); |
@@ -24,2 +24,3 @@ import { ClientCoreInternal, ExtendedGatewayStatus, GatewayCoreState, GatewayStatus } from '../../src'; | ||
errors: {}, | ||
ownerDids: [], | ||
}; | ||
@@ -82,2 +83,3 @@ }); | ||
errors: {}, | ||
ownerDids: [], | ||
}; | ||
@@ -141,2 +143,3 @@ }); | ||
errors: {}, | ||
ownerDids: [], | ||
}; | ||
@@ -143,0 +146,0 @@ }); |
@@ -14,3 +14,3 @@ import { ExtendedGatewayStatus, GatewayCoreState, GatewayStatus, InternalGatewayStatus } from '../../src'; | ||
afterEach(sandbox.restore); | ||
context('with no wallet, chainImplementation, or instanceId', () => { | ||
context('with no wallet, chainDetails, or instanceId', () => { | ||
it('should return null', () => { | ||
@@ -22,3 +22,2 @@ // Arrange | ||
wallet: undefined, | ||
chainImplementation: undefined, | ||
}, | ||
@@ -29,4 +28,5 @@ dynamicParameters: {}, | ||
instanceId: undefined, | ||
chainDetails: undefined, | ||
}, | ||
} as GatewayCoreState; | ||
} as unknown as GatewayCoreState; | ||
const computedInternalStatus = GatewayStatus.UNKNOWN; | ||
@@ -49,7 +49,2 @@ // Act | ||
}, | ||
chainImplementation: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
did: 'did', | ||
}, | ||
}, | ||
@@ -59,2 +54,6 @@ }, | ||
instanceId: 'instanceId', | ||
chainDetails: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
}, | ||
}, | ||
@@ -110,7 +109,2 @@ } as unknown as GatewayCoreState; | ||
}, | ||
chainImplementation: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
did: 'did', | ||
}, | ||
}, | ||
@@ -120,2 +114,6 @@ }, | ||
instanceId: 'instanceId', | ||
chainDetails: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
}, | ||
}, | ||
@@ -143,7 +141,2 @@ } as unknown as GatewayCoreState; | ||
}, | ||
chainImplementation: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
did: 'did', | ||
}, | ||
flowIdPrefix: 'TEST_CORE', | ||
@@ -154,2 +147,6 @@ }, | ||
instanceId: 'instanceId', | ||
chainDetails: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
}, | ||
}, | ||
@@ -169,7 +166,2 @@ } as unknown as GatewayCoreState; | ||
}, | ||
chainImplementation: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
did: 'did', | ||
}, | ||
}, | ||
@@ -179,2 +171,6 @@ }, | ||
instanceId: 'instanceId', | ||
chainDetails: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
}, | ||
}, | ||
@@ -197,7 +193,2 @@ } as unknown as GatewayCoreState; | ||
}, | ||
chainImplementation: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
did: 'did', | ||
}, | ||
referrer: 'referrer', | ||
@@ -208,2 +199,6 @@ }, | ||
instanceId: 'instanceId', | ||
chainDetails: { | ||
chainType: 'chainType', | ||
chainNetwork: 'chainNetwork', | ||
}, | ||
}, | ||
@@ -210,0 +205,0 @@ } as unknown as GatewayCoreState; |
@@ -21,2 +21,4 @@ import { ExtendedGatewayStatus, GatewayStatus } from '../../src'; | ||
ExtendedGatewayStatus.REFRESH_AWAITING_ON_CHAIN_TOKEN, | ||
ExtendedGatewayStatus.ISSUANCE_AWAITING_THIRD_PARTY_TRANSACTION_SEND, | ||
ExtendedGatewayStatus.REFRESH_AWAITING_THIRD_PARTY_TRANSACTION_SEND, | ||
].forEach((status) => { | ||
@@ -23,0 +25,0 @@ it(`should map ${status} to GatewayStatus.IN_REVIEW`, () => { |
import chai from 'chai'; | ||
import { getTokenRefreshIntervalMilliseconds, hasExpired, isTokenRefreshRequired } from "../../src/utils/expiry"; | ||
import { getTokenRefreshIntervalMilliseconds, hasExpired, isTokenRefreshRequired } from '../../src/utils/expiry'; | ||
import { GatewayToken, State } from '../../src/types/chain'; | ||
@@ -30,21 +30,27 @@ | ||
it('should return false if gatewayToken is not active', () => { | ||
expect(isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: 0, state: State.FROZEN } as GatewayToken, | ||
tokenExpirationMarginSeconds: 0, | ||
})).to.be.false; | ||
expect( | ||
isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: 0, state: State.FROZEN } as GatewayToken, | ||
tokenExpirationMarginSeconds: 0, | ||
}) | ||
).to.be.false; | ||
}); | ||
it('should return false if expiryTime is not set', () => { | ||
expect(isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: 0, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 0, | ||
})).to.be.false; | ||
expect( | ||
isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: 0, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 0, | ||
}) | ||
).to.be.false; | ||
}); | ||
it('should return true if forceRequireRefresh is set', () => { | ||
expect(isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: 1, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 0, | ||
forceRequireRefresh: true, | ||
})).to.be.true; | ||
expect( | ||
isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: 1, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 0, | ||
forceRequireRefresh: true, | ||
}) | ||
).to.be.true; | ||
}); | ||
@@ -54,6 +60,8 @@ | ||
const now = Math.floor(Date.now() / 1000); | ||
expect(isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: now - 1, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 0, | ||
})).to.be.true; | ||
expect( | ||
isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: now - 1, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 0, | ||
}) | ||
).to.be.true; | ||
}); | ||
@@ -63,6 +71,8 @@ | ||
const now = Math.floor(Date.now() / 1000); | ||
expect(isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: now + 1, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 1, | ||
})).to.be.true; | ||
expect( | ||
isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: now + 1, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 1, | ||
}) | ||
).to.be.true; | ||
}); | ||
@@ -72,6 +82,8 @@ | ||
const now = Math.floor(Date.now() / 1000); | ||
expect(isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: now + 3, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 2, | ||
})).to.be.false; | ||
expect( | ||
isTokenRefreshRequired({ | ||
gatewayToken: { expiryTime: now + 3, state: State.ACTIVE } as GatewayToken, | ||
tokenExpirationMarginSeconds: 2, | ||
}) | ||
).to.be.false; | ||
}); | ||
@@ -78,0 +90,0 @@ }); |
@@ -1,4 +0,5 @@ | ||
import { ExtendedGatewayStatus, FlowType, GatewayCoreState, GatewayStatus } from '../../src'; | ||
import { UserInteractionStatus } from '../../src/types/userInteraction'; | ||
import { ExtendedGatewayStatus, FlowStatus, FlowType, GatewayCoreState, GatewayStatus } from '../../src'; | ||
import { nowSeconds } from '../../src/utils/expiry'; | ||
import { flowTypeFromState, getFlowId } from '../../src/utils/flow'; | ||
import { flowStatusFromState, flowTypeFromState, getFlowId } from '../../src/utils/flow'; | ||
import chai from 'chai'; | ||
@@ -305,2 +306,22 @@ | ||
}); | ||
context('flowStatusFromState', () => { | ||
context('with no userInteraction in internal state', () => { | ||
it('should return undefined', () => { | ||
expect( | ||
flowStatusFromState({ internal: { someOtherValue: 42 } } as unknown as GatewayCoreState, GatewayStatus.ACTIVE) | ||
).to.be.undefined; | ||
}); | ||
}); | ||
context('with userInteraction status STARTED', () => { | ||
it('should return IN_PROGRESS', () => { | ||
expect( | ||
flowStatusFromState( | ||
{ internal: { userInteraction: { status: UserInteractionStatus.STARTED } } } as unknown as GatewayCoreState, | ||
GatewayStatus.ACTIVE | ||
) | ||
).to.equal(FlowStatus.IN_PROGRESS); | ||
}); | ||
}); | ||
}); | ||
}); |
import chai from 'chai'; | ||
import { getPayer } from "../../src/utils/inputs"; | ||
import { getPayer } from '../../src/utils/inputs'; | ||
@@ -4,0 +4,0 @@ const { expect } = chai; |
import chai from 'chai'; | ||
import { objectToURLParams } from "../../src/utils/url"; | ||
import { objectToURLParams } from '../../src/utils/url'; | ||
@@ -28,2 +28,2 @@ const { expect } = chai; | ||
}); | ||
}); | ||
}); |
@@ -24,4 +24,4 @@ { | ||
}, | ||
"include": ["src/**/*"], | ||
"include": ["src/**/*", "test/**/*.ts"], | ||
"exclude": ["node_modules", "dist"] | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2688643
6
17774
28
- Removedeslint-plugin-chai-friendly@^0.7.4
- Removed@eslint-community/eslint-utils@4.4.1(transitive)
- Removed@eslint-community/regexpp@4.12.1(transitive)
- Removed@eslint/config-array@0.19.1(transitive)
- Removed@eslint/core@0.9.1(transitive)
- Removed@eslint/eslintrc@3.2.0(transitive)
- Removed@eslint/js@9.17.0(transitive)
- Removed@eslint/object-schema@2.1.5(transitive)
- Removed@eslint/plugin-kit@0.2.4(transitive)
- Removed@humanfs/core@0.19.1(transitive)
- Removed@humanfs/node@0.16.6(transitive)
- Removed@humanwhocodes/module-importer@1.0.1(transitive)
- Removed@humanwhocodes/retry@0.3.10.4.1(transitive)
- Removed@types/estree@1.0.6(transitive)
- Removed@types/json-schema@7.0.15(transitive)
- Removedacorn@8.14.0(transitive)
- Removedacorn-jsx@5.3.2(transitive)
- Removedajv@6.12.6(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedargparse@2.0.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcallsites@3.1.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcross-spawn@7.0.6(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removedescape-string-regexp@4.0.0(transitive)
- Removedeslint@9.17.0(transitive)
- Removedeslint-plugin-chai-friendly@0.7.4(transitive)
- Removedeslint-scope@8.2.0(transitive)
- Removedeslint-visitor-keys@3.4.34.2.0(transitive)
- Removedespree@10.3.0(transitive)
- Removedesquery@1.6.0(transitive)
- Removedesrecurse@4.3.0(transitive)
- Removedestraverse@5.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedfile-entry-cache@8.0.0(transitive)
- Removedfind-up@5.0.0(transitive)
- Removedflat-cache@4.0.1(transitive)
- Removedflatted@3.3.2(transitive)
- Removedglob-parent@6.0.2(transitive)
- Removedglobals@14.0.0(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedignore@5.3.2(transitive)
- Removedimport-fresh@3.3.0(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjs-yaml@4.1.0(transitive)
- Removedjson-buffer@3.0.1(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stable-stringify-without-jsonify@1.0.1(transitive)
- Removedkeyv@4.5.4(transitive)
- Removedlevn@0.4.1(transitive)
- Removedlocate-path@6.0.0(transitive)
- Removedlodash.merge@4.6.2(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedms@2.1.3(transitive)
- Removednatural-compare@1.4.0(transitive)
- Removedoptionator@0.9.4(transitive)
- Removedp-limit@3.1.0(transitive)
- Removedp-locate@5.0.0(transitive)
- Removedparent-module@1.0.1(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedprelude-ls@1.2.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedresolve-from@4.0.0(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedstrip-json-comments@3.1.1(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedtype-check@0.4.0(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedwhich@2.0.2(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedyocto-queue@0.1.0(transitive)