@metamask-previews/kyc-controller 0.0.0-preview-11d78534e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +6 -0
  3. package/LICENSE.APACHE2 +201 -0
  4. package/LICENSE.MIT +21 -0
  5. package/README.md +648 -0
  6. package/dist/KycController-method-action-types.cjs +7 -0
  7. package/dist/KycController-method-action-types.cjs.map +1 -0
  8. package/dist/KycController-method-action-types.d.cts +143 -0
  9. package/dist/KycController-method-action-types.d.cts.map +1 -0
  10. package/dist/KycController-method-action-types.d.mts +143 -0
  11. package/dist/KycController-method-action-types.d.mts.map +1 -0
  12. package/dist/KycController-method-action-types.mjs +6 -0
  13. package/dist/KycController-method-action-types.mjs.map +1 -0
  14. package/dist/KycController.cjs +800 -0
  15. package/dist/KycController.cjs.map +1 -0
  16. package/dist/KycController.d.cts +219 -0
  17. package/dist/KycController.d.cts.map +1 -0
  18. package/dist/KycController.d.mts +219 -0
  19. package/dist/KycController.d.mts.map +1 -0
  20. package/dist/KycController.mjs +795 -0
  21. package/dist/KycController.mjs.map +1 -0
  22. package/dist/KycService-method-action-types.cjs +7 -0
  23. package/dist/KycService-method-action-types.cjs.map +1 -0
  24. package/dist/KycService-method-action-types.d.cts +74 -0
  25. package/dist/KycService-method-action-types.d.cts.map +1 -0
  26. package/dist/KycService-method-action-types.d.mts +74 -0
  27. package/dist/KycService-method-action-types.d.mts.map +1 -0
  28. package/dist/KycService-method-action-types.mjs +6 -0
  29. package/dist/KycService-method-action-types.mjs.map +1 -0
  30. package/dist/KycService.cjs +238 -0
  31. package/dist/KycService.cjs.map +1 -0
  32. package/dist/KycService.d.cts +169 -0
  33. package/dist/KycService.d.cts.map +1 -0
  34. package/dist/KycService.d.mts +169 -0
  35. package/dist/KycService.d.mts.map +1 -0
  36. package/dist/KycService.mjs +234 -0
  37. package/dist/KycService.mjs.map +1 -0
  38. package/dist/countryCodes.cjs +274 -0
  39. package/dist/countryCodes.cjs.map +1 -0
  40. package/dist/countryCodes.d.cts +18 -0
  41. package/dist/countryCodes.d.cts.map +1 -0
  42. package/dist/countryCodes.d.mts +18 -0
  43. package/dist/countryCodes.d.mts.map +1 -0
  44. package/dist/countryCodes.mjs +270 -0
  45. package/dist/countryCodes.mjs.map +1 -0
  46. package/dist/crypto.cjs +165 -0
  47. package/dist/crypto.cjs.map +1 -0
  48. package/dist/crypto.d.cts +83 -0
  49. package/dist/crypto.d.cts.map +1 -0
  50. package/dist/crypto.d.mts +83 -0
  51. package/dist/crypto.d.mts.map +1 -0
  52. package/dist/crypto.mjs +160 -0
  53. package/dist/crypto.mjs.map +1 -0
  54. package/dist/index.cjs +21 -0
  55. package/dist/index.cjs.map +1 -0
  56. package/dist/index.d.cts +12 -0
  57. package/dist/index.d.cts.map +1 -0
  58. package/dist/index.d.mts +12 -0
  59. package/dist/index.d.mts.map +1 -0
  60. package/dist/index.mjs +6 -0
  61. package/dist/index.mjs.map +1 -0
  62. package/dist/selectors.cjs +30 -0
  63. package/dist/selectors.cjs.map +1 -0
  64. package/dist/selectors.d.cts +24 -0
  65. package/dist/selectors.d.cts.map +1 -0
  66. package/dist/selectors.d.mts +24 -0
  67. package/dist/selectors.d.mts.map +1 -0
  68. package/dist/selectors.mjs +24 -0
  69. package/dist/selectors.mjs.map +1 -0
  70. package/dist/types.cjs +10 -0
  71. package/dist/types.cjs.map +1 -0
  72. package/dist/types.d.cts +93 -0
  73. package/dist/types.d.cts.map +1 -0
  74. package/dist/types.d.mts +93 -0
  75. package/dist/types.d.mts.map +1 -0
  76. package/dist/types.mjs +9 -0
  77. package/dist/types.mjs.map +1 -0
  78. package/package.json +89 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KycController.cjs","sourceRoot":"","sources":["../src/KycController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAI3D,yCAA+D;AAY/D,kBAAkB;AAEL,QAA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AK,CAAC,KAAK,GAAG,OAAO,CAAC;QACtB,KAAK,CAAC,aAAa;YACjB,yDAAyD,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,2EA4RC,UAAkB,EAClB,OAA4C;IAE5C,IAAI,uBAAA,IAAI,iCAAY,KAAK,UAAU,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,uBAAA,IAAI,4DAAa,MAAjB,IAAI,EAAc,OAAO,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC,mEAiBY,OAA4C;IACvD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,OAAO,CAAC,KAAsC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,qDAOK,OAAe;IACnB,uBAAA,IAAI,4DAAa,MAAjB,IAAI,EAAc,CAAC,KAAK,EAAE,EAAE;QAC1B,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC;QACtB,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport { decryptCredentials, generateKeyPair } from './crypto';\nimport type { EncryptedCredentialsEnvelope, X25519KeyPair } from './crypto';\nimport type { KycControllerMethodActions } from './KycController-method-action-types';\nimport type { KycServiceMethodActions } from './KycService-method-action-types';\nimport type {\n KycDisclaimer,\n KycPhase,\n KycProduct,\n KycSumSubLauncher,\n KycSumSubStatus,\n} from './types';\n\n// === GENERAL ===\n\nexport const controllerName = 'KycController';\n\nconst FRAMES_BASE_URL = 'https://blocks.moonpay.com/platform/v1';\nconst CHANNEL_CHECK = 'ch_1';\nconst CHANNEL_AUTH = 'ch_2';\nconst CHANNEL_RESET = 'ch_reset';\n\n// Placeholder credentials for the SumSub sub-flow. These are demo values that\n// must be replaced with real UKYC-issued material before production use.\nconst MOCK_JWT_TOKEN = 'mock-jwt-token';\n\n// The SumSub SDK status that signals the applicant finished the flow\n// successfully. Any other resolution (abandonment, failure, or a non-success\n// outcome) must not be recorded as `complete`.\nconst SUMSUB_COMPLETED_STATUS = 'Completed';\n\n// === STATE ===\n\n/**\n * Describes the shape of the state object for {@link KycController}.\n */\nexport type KycControllerState = {\n /** Current phase of the identity flow. */\n phase: KycPhase;\n /** Human-readable status message for the current phase. */\n statusMessage: string;\n /** The current error message, or `null`. */\n error: string | null;\n\n /** Email associated with the session (sourced from the account). */\n email: string | null;\n\n /** ISO-8601 timestamp of the customer's terms acceptance (persisted). */\n termsAcceptedAt: string | null;\n /** IDs of the disclaimers the customer accepted (persisted). */\n acceptedDisclaimerIds: string[];\n\n /** Disclaimers fetched for the current country. */\n disclaimers: KycDisclaimer[];\n /** Error encountered while loading disclaimers, or `null`. */\n disclaimersError: string | null;\n\n /** Resolved ISO 3166-1 alpha-3 country code. */\n geoCountry: string | null;\n\n /** Vendor session token (not persisted, not logged). */\n sessionToken: string | null;\n /** Vendor access token (not persisted, not logged). */\n accessToken: string | null;\n /** Vendor customer id, used for the SumSub hand-off. */\n moonpayCustomerId: string | null;\n\n /**\n * The product the current flow is running for. Captured at `initialize`\n * (or `acceptTermsAndStartSession`) and used to automatically run the\n * KYC-required check once authentication completes. `null` outside a\n * product-scoped flow (in which case the flow stops at `form` and the\n * consumer drives the check manually).\n */\n activeProduct: KycProduct | null;\n\n /** Cached \"is KYC required\" result per product (persisted). */\n kycRequiredByProduct: Partial<Record<KycProduct, boolean>>;\n /** ISO-8601 timestamp of the last KYC-required check (persisted). */\n lastCheckedAt: string | null;\n\n /** SumSub document-verification sub-flow state. */\n sumsub: {\n status: KycSumSubStatus;\n result: Json | null;\n sessionId: string | null;\n applicantAccessToken: string | null;\n };\n};\n\nconst kycControllerMetadata = {\n phase: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n statusMessage: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n error: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n email: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: false,\n usedInUi: false,\n },\n termsAcceptedAt: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: true,\n usedInUi: false,\n },\n acceptedDisclaimerIds: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: true,\n usedInUi: false,\n },\n disclaimers: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: false,\n usedInUi: true,\n },\n disclaimersError: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n geoCountry: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n sessionToken: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: false,\n usedInUi: false,\n },\n accessToken: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: false,\n usedInUi: false,\n },\n moonpayCustomerId: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: false,\n usedInUi: false,\n },\n activeProduct: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n kycRequiredByProduct: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: true,\n usedInUi: true,\n },\n lastCheckedAt: {\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n persist: true,\n usedInUi: false,\n },\n sumsub: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: false,\n usedInUi: true,\n },\n} satisfies StateMetadata<KycControllerState>;\n\n/**\n * Constructs the default {@link KycController} state.\n *\n * @returns The default state.\n */\nexport function getDefaultKycControllerState(): KycControllerState {\n return {\n phase: 'idle',\n statusMessage: '',\n error: null,\n email: null,\n termsAcceptedAt: null,\n acceptedDisclaimerIds: [],\n disclaimers: [],\n disclaimersError: null,\n geoCountry: null,\n sessionToken: null,\n accessToken: null,\n moonpayCustomerId: null,\n activeProduct: null,\n kycRequiredByProduct: {},\n lastCheckedAt: null,\n sumsub: {\n status: 'idle',\n result: null,\n sessionId: null,\n applicantAccessToken: null,\n },\n };\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'initialize',\n 'loadDisclaimers',\n 'acceptTermsAndStartSession',\n 'clearSavedTerms',\n 'handleFrameMessage',\n 'buildCheckFrameUrl',\n 'buildAuthFrameUrl',\n 'buildResetFrameUrl',\n 'checkKycRequired',\n 'getKycStatus',\n 'startSumSub',\n 'reset',\n] as const;\n\nexport type KycControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n KycControllerState\n>;\n\nexport type KycControllerActions =\n | KycControllerGetStateAction\n | KycControllerMethodActions;\n\ntype AllowedActions = KycServiceMethodActions;\n\nexport type KycControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n KycControllerState\n>;\n\nexport type KycControllerEvents = KycControllerStateChangeEvent;\n\ntype AllowedEvents = never;\n\nexport type KycControllerMessenger = Messenger<\n typeof controllerName,\n KycControllerActions | AllowedActions,\n KycControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for constructing a {@link KycController}.\n */\nexport type KycControllerOptions = {\n messenger: KycControllerMessenger;\n state?: Partial<KycControllerState>;\n /**\n * Platform adapter that presents the SumSub SDK. Injected by each client so\n * the controller stays platform-agnostic.\n */\n sumsubLauncher: KycSumSubLauncher;\n};\n\n/**\n * The shape of a message posted by a Check/Auth frame.\n */\ntype FrameMessage = {\n meta?: { channelId?: string };\n kind?: string;\n payload?: {\n status?:\n | 'active'\n | 'connectionRequired'\n | 'termsAcceptanceRequired'\n | 'pending'\n | 'unavailable'\n | 'failed';\n credentials?: EncryptedCredentialsEnvelope | string;\n customer?: { id?: string };\n };\n};\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `KycController` orchestrates the vendor-backed KYC / identity-verification\n * flow (MoonPay identity + SumSub documents) behind a vendor-neutral, per\n * product surface used by ramps and card. It owns all state, HTTP\n * orchestration (via `KycService`), crypto, and the frame message protocol;\n * platform-specific presentation (WebView/iframe, SumSub SDK) is injected.\n */\nexport class KycController extends BaseController<\n typeof controllerName,\n KycControllerState,\n KycControllerMessenger\n> {\n readonly #sumsubLauncher: KycSumSubLauncher;\n\n /** Ephemeral X25519 keypair for the frame key exchange (never persisted). */\n readonly #keypair: X25519KeyPair;\n\n /** Auth-frame client token, kept out of state. */\n #authClientToken: string | null = null;\n\n /**\n * Monotonic flow generation. Incremented by {@link reset} so in-flight async\n * work (e.g. the KYC-required check) can detect that it was superseded and\n * avoid writing stale results onto a reset controller.\n */\n #generation = 0;\n\n /**\n * Guards the automatic post-authentication continuation. The Check/Auth\n * frames can post more than one `complete` message (duplicate or late), each\n * of which resolves to an `active` outcome with an access token. Without this\n * flag, every such message would re-enter {@link #continueAfterAuthentication}\n * and run the KYC-required check / SumSub sub-flow again while a prior run is\n * still in flight. Set for the duration of a continuation and cleared by\n * {@link reset} so a fresh flow can continue again.\n */\n #continuationInFlight = false;\n\n /**\n * Constructs a new {@link KycController}.\n *\n * @param options - The constructor options.\n * @param options.messenger - The messenger suited for this controller.\n * @param options.state - Partial initial state; merged over defaults.\n * @param options.sumsubLauncher - The platform SumSub launcher adapter.\n */\n constructor({ messenger, state, sumsubLauncher }: KycControllerOptions) {\n super({\n messenger,\n metadata: kycControllerMetadata,\n name: controllerName,\n state: { ...getDefaultKycControllerState(), ...state },\n });\n\n this.#sumsubLauncher = sumsubLauncher;\n this.#keypair = generateKeyPair();\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Resolves persisted terms + geolocation, and auto-creates a session when\n * terms are already accepted and an email is available.\n *\n * @param params - Optional parameters.\n * @param params.email - The account email to associate with the session.\n * @param params.product - The consuming feature the flow runs for. When\n * provided, the controller automatically runs the KYC-required check once\n * authentication completes (and chains into document verification when KYC\n * is required). When omitted, the flow stops at `form` and the consumer must\n * call `checkKycRequired` manually.\n */\n async initialize(params?: {\n email?: string;\n product?: KycProduct;\n }): Promise<void> {\n // `initialize` starts a fresh flow, so `activeProduct` is always reset to\n // this call's product (or `null`). Otherwise a prior run's product could\n // linger and cause `#continueAfterAuthentication` to auto-run the check /\n // sub-flow when the caller intended the manual (product-less) flow.\n this.#applyUpdate((state) => {\n if (params?.email) {\n state.email = params.email;\n }\n state.activeProduct = params?.product ?? null;\n });\n\n // Resolve country for display; non-blocking.\n try {\n const country = await this.messenger.call('KycService:getGeoCountry');\n this.#applyUpdate((state) => {\n state.geoCountry = country;\n });\n } catch {\n // Ignore; disclaimers loading will surface a country error if needed.\n }\n\n const hasTerms =\n Boolean(this.state.termsAcceptedAt) &&\n this.state.acceptedDisclaimerIds.length > 0;\n\n if (hasTerms && this.state.email) {\n await this.#createSession();\n return;\n }\n\n this.#applyUpdate((state) => {\n state.phase = 'terms';\n });\n await this.loadDisclaimers();\n }\n\n /**\n * Loads the disclaimers for the resolved (or provided) country.\n *\n * @param params - Optional parameters.\n * @param params.country - ISO 3166-1 alpha-3 country code override.\n */\n async loadDisclaimers(params?: { country?: string }): Promise<void> {\n try {\n const country =\n params?.country ??\n this.state.geoCountry ??\n (await this.messenger.call('KycService:getGeoCountry'));\n if (country !== this.state.geoCountry) {\n this.#applyUpdate((state) => {\n state.geoCountry = country;\n });\n }\n const disclaimers = await this.messenger.call(\n 'KycService:fetchDisclaimers',\n { country },\n );\n this.#applyUpdate((state) => {\n state.disclaimers = disclaimers;\n state.disclaimersError = null;\n });\n } catch (error) {\n this.#applyUpdate((state) => {\n state.disclaimersError = `Failed to load disclaimers: ${String(error)}`;\n });\n }\n }\n\n /**\n * Captures terms acceptance for the currently loaded disclaimers and creates\n * a session.\n *\n * @param params - Optional parameters.\n * @param params.email - The account email to associate with the session.\n * @param params.product - The consuming feature the flow runs for. See\n * {@link initialize} for how the product drives the automatic post\n * authentication continuation.\n */\n async acceptTermsAndStartSession(params?: {\n email?: string;\n product?: KycProduct;\n }): Promise<void> {\n const termsAcceptedAt = new Date().toISOString();\n const disclaimerIds = this.state.disclaimers.map(\n (disclaimer) => disclaimer.id,\n );\n this.#applyUpdate((state) => {\n if (params?.email) {\n state.email = params.email;\n }\n if (params?.product) {\n state.activeProduct = params.product;\n }\n state.termsAcceptedAt = termsAcceptedAt;\n state.acceptedDisclaimerIds = disclaimerIds;\n });\n await this.#createSession();\n }\n\n /**\n * Creates a vendor session from the currently stored terms + email.\n */\n async #createSession(): Promise<void> {\n const { email, termsAcceptedAt, acceptedDisclaimerIds } = this.state;\n if (!email) {\n this.#fail('Missing email for session creation.');\n return;\n }\n if (!termsAcceptedAt || acceptedDisclaimerIds.length === 0) {\n this.#fail('Missing terms acceptance for session creation.');\n return;\n }\n\n // A new session invalidates any authentication carried over from a prior\n // session. Clear the stale access token and auth-frame client token so\n // `buildAuthFrameUrl` cannot return a URL tied to an old client token and\n // `checkKycRequired` cannot run with an access token from an earlier\n // authentication. The Check/Auth frames re-populate these for the new\n // session.\n this.#authClientToken = null;\n this.#applyUpdate((state) => {\n state.error = null;\n state.phase = 'session';\n state.statusMessage = 'Creating session...';\n state.accessToken = null;\n });\n\n try {\n const { sessionToken } = await this.messenger.call(\n 'KycService:createSession',\n { email, termsAcceptedAt, disclaimerIds: acceptedDisclaimerIds },\n );\n this.#applyUpdate((state) => {\n state.sessionToken = sessionToken;\n state.phase = 'check';\n state.statusMessage = 'Authenticating via Check frame...';\n });\n } catch (error) {\n // Invalidate the stored acceptance so the customer can retry. Also clear\n // `activeProduct` so a later `acceptTermsAndStartSession` that omits a\n // product cannot auto-run the KYC check / SumSub chain for this failed\n // flow's product — matching how `initialize` starts from a clean product.\n this.#applyUpdate((state) => {\n this.#clearAcceptedTerms(state);\n state.activeProduct = null;\n state.error = `Session creation failed: ${String(error)}`;\n state.statusMessage =\n 'Session creation failed — accept the terms to try again.';\n state.phase = 'terms';\n });\n await this.loadDisclaimers();\n }\n }\n\n /**\n * Clears the persisted terms acceptance.\n */\n clearSavedTerms(): void {\n this.#applyUpdate((state) => {\n this.#clearAcceptedTerms(state);\n });\n }\n\n /**\n * Clears the stored terms acceptance on the given draft state. Shared by the\n * paths that must invalidate acceptance — explicit clear, vendor terms\n * update, and session-creation failure — so they stay in sync. This is a\n * targeted invalidation and, unlike {@link reset}, deliberately leaves the\n * rest of the flow (geolocation, disclaimers, phase) untouched.\n *\n * @param state - The state to mutate.\n */\n #clearAcceptedTerms(state: KycControllerState): void {\n state.termsAcceptedAt = null;\n state.acceptedDisclaimerIds = [];\n }\n\n /**\n * Handles a message posted by a Check/Auth frame and advances the flow.\n *\n * The transport-agnostic caller (WebView on mobile, iframe on web) forwards\n * the raw message and injects the returned `reply` back into the frame.\n *\n * @param params - The parameters.\n * @param params.message - The raw message posted by the frame.\n * @returns An object whose optional `reply` should be posted back.\n */\n async handleFrameMessage(params: {\n message: unknown;\n }): Promise<{ reply?: unknown }> {\n const payload = params.message as FrameMessage | undefined;\n\n if (!payload) {\n return {};\n }\n\n if (payload.kind === 'handshake') {\n const channelId = payload.meta?.channelId;\n return { reply: { version: 2, meta: { channelId }, kind: 'ack' } };\n }\n\n if (payload.kind !== 'complete') {\n return {};\n }\n\n const channelId = payload.meta?.channelId;\n const status = payload.payload?.status;\n const credsEnvelope = payload.payload?.credentials;\n\n const customerId = payload.payload?.customer?.id ?? null;\n if (customerId) {\n this.#applyUpdate((state) => {\n state.moonpayCustomerId = customerId;\n });\n }\n\n if (!status) {\n return {};\n }\n\n let accessToken: string | undefined;\n let clientToken: string | undefined;\n if (credsEnvelope) {\n try {\n const { credentials } = decryptCredentials(\n credsEnvelope,\n this.#keypair.privateKey,\n );\n accessToken = credentials.accessToken;\n clientToken = credentials.clientToken;\n } catch (error) {\n this.#fail(`Failed to decrypt frame credentials: ${String(error)}`);\n return {};\n }\n }\n\n if (channelId === CHANNEL_CHECK) {\n await this.#handleCheckOutcome(status, accessToken, clientToken);\n return {};\n }\n\n if (channelId === CHANNEL_AUTH) {\n await this.#handleAuthOutcome(status, accessToken);\n return {};\n }\n\n return {};\n }\n\n /**\n * Applies a Check-frame outcome.\n *\n * @param status - The frame status.\n * @param accessToken - The decrypted access token, if any.\n * @param clientToken - The decrypted client token, if any.\n */\n async #handleCheckOutcome(\n status: NonNullable<FrameMessage['payload']>['status'],\n accessToken?: string,\n clientToken?: string,\n ): Promise<void> {\n if (status === 'active' && accessToken) {\n this.#applyUpdate((state) => {\n state.accessToken = accessToken;\n state.phase = 'form';\n state.statusMessage = 'Already authenticated. Review to submit.';\n });\n await this.#continueAfterAuthentication();\n return;\n }\n if (status === 'connectionRequired' && clientToken) {\n this.#authClientToken = clientToken;\n this.#applyUpdate((state) => {\n state.phase = 'auth';\n state.statusMessage = 'Verify your email via OTP in the Auth frame.';\n });\n return;\n }\n if (status === 'termsAcceptanceRequired') {\n this.#requireTermsReacceptance();\n return;\n }\n this.#fail(`Check frame returned status: ${status}`);\n }\n\n /**\n * Applies an Auth-frame outcome.\n *\n * @param status - The frame status.\n * @param accessToken - The decrypted access token, if any.\n */\n async #handleAuthOutcome(\n status: NonNullable<FrameMessage['payload']>['status'],\n accessToken?: string,\n ): Promise<void> {\n if (status === 'active' && accessToken) {\n this.#applyUpdate((state) => {\n state.accessToken = accessToken;\n state.phase = 'form';\n state.statusMessage = 'Authenticated. Review to submit.';\n });\n await this.#continueAfterAuthentication();\n return;\n }\n if (status === 'termsAcceptanceRequired') {\n this.#requireTermsReacceptance();\n return;\n }\n this.#fail(`Auth frame returned status: ${status}`);\n }\n\n /**\n * Continues the flow once authentication has completed (phase `form`).\n *\n * When the flow is scoped to a product (see {@link initialize}), the\n * KYC-required check runs automatically, and — when KYC is required — the\n * document-verification sub-flow is launched. When no product is set, this is\n * a no-op and the flow stays at `form` for the consumer to drive manually.\n *\n * Errors are already recorded on state by `checkKycRequired` (`error`\n * phase) and `startSumSub` (`sumsub.status = 'failed'`); this method swallows\n * them so it can be awaited safely from the frame-message handler.\n */\n async #continueAfterAuthentication(): Promise<void> {\n const product = this.state.activeProduct;\n if (!product) {\n return;\n }\n\n // A duplicate or late `complete` message can re-enter here while a prior\n // continuation is still running; ignore it so the check / sub-flow does not\n // run twice concurrently.\n if (this.#continuationInFlight) {\n return;\n }\n this.#continuationInFlight = true;\n\n // Capture the generation so a `reset()` landing mid-continuation does not\n // let the `finally` clear a flag that belongs to a newer flow.\n const generation = this.#generation;\n\n try {\n const kycRequired = await this.checkKycRequired({ product });\n if (!kycRequired) {\n return;\n }\n\n try {\n await this.startSumSub();\n } catch {\n // `startSumSub` already records `sumsub.status = 'failed'`; swallow the\n // rethrown error (e.g. SDK unavailable) so the awaited continuation\n // resolves cleanly rather than surfacing as an unhandled rejection.\n }\n } finally {\n if (this.#generation === generation) {\n this.#continuationInFlight = false;\n }\n }\n }\n\n /**\n * Invalidates stored terms and returns to the terms phase.\n */\n #requireTermsReacceptance(): void {\n this.#applyUpdate((state) => {\n this.#clearAcceptedTerms(state);\n state.phase = 'terms';\n state.statusMessage =\n 'The vendor updated its Terms of Use — please re-accept.';\n });\n }\n\n /**\n * Builds the Check-frame URL, or `null` when no session exists yet.\n *\n * @returns The Check-frame URL or `null`.\n */\n buildCheckFrameUrl(): string | null {\n if (!this.state.sessionToken) {\n return null;\n }\n const url = new URL(`${FRAMES_BASE_URL}/check-connection`);\n url.searchParams.set('sessionToken', this.state.sessionToken);\n url.searchParams.set('publicKey', this.#keypair.publicKeyHex);\n url.searchParams.set('channelId', CHANNEL_CHECK);\n url.searchParams.set('skipKyc', 'true');\n return url.toString();\n }\n\n /**\n * Builds the Auth-frame URL, or `null` when no client token is available.\n *\n * @returns The Auth-frame URL or `null`.\n */\n buildAuthFrameUrl(): string | null {\n if (!this.#authClientToken) {\n return null;\n }\n const url = new URL(`${FRAMES_BASE_URL}/auth`);\n url.searchParams.set('clientToken', this.#authClientToken);\n url.searchParams.set('publicKey', this.#keypair.publicKeyHex);\n url.searchParams.set('channelId', CHANNEL_AUTH);\n return url.toString();\n }\n\n /**\n * Builds the Reset-frame URL.\n *\n * @returns The Reset-frame URL.\n */\n buildResetFrameUrl(): string {\n const url = new URL(`${FRAMES_BASE_URL}/reset`);\n url.searchParams.set('channelId', CHANNEL_RESET);\n return url.toString();\n }\n\n /**\n * Checks whether KYC is required for a product and caches the result.\n *\n * @param params - The parameters.\n * @param params.product - The consuming feature.\n * @param params.country - Optional alpha-3 country override.\n * @returns Whether KYC is required.\n */\n async checkKycRequired(params: {\n product: KycProduct;\n country?: string;\n }): Promise<boolean> {\n const { accessToken } = this.state;\n if (!accessToken) {\n this.#fail('Missing accessToken — repeat the authentication step.');\n return false;\n }\n const country = params.country ?? this.state.geoCountry;\n if (!country) {\n this.#fail('Missing country for KYC-required check.');\n return false;\n }\n\n // Capture the flow generation so we can detect a `reset()` that happens\n // while the HTTP call is in flight and avoid writing stale results.\n const generation = this.#generation;\n\n this.#applyUpdate((state) => {\n state.phase = 'submit';\n state.statusMessage = 'Checking KYC status...';\n });\n\n try {\n const { kycRequired } = await this.messenger.call(\n 'KycService:checkKycRequired',\n { accessToken, country, capabilities: [{ product: params.product }] },\n );\n // The flow was reset while the check was in flight; discard the result\n // rather than resurrecting a done/cached state on an idle controller.\n if (this.#generation !== generation) {\n return false;\n }\n this.#applyUpdate((state) => {\n state.kycRequiredByProduct[params.product] = kycRequired;\n state.lastCheckedAt = new Date().toISOString();\n state.phase = 'done';\n state.statusMessage = 'KYC check complete.';\n });\n return kycRequired;\n } catch (error) {\n if (this.#generation !== generation) {\n return false;\n }\n this.#fail(`KYC check failed: ${String(error)}`);\n return false;\n }\n }\n\n /**\n * Reads the cached \"is KYC required\" result for a product.\n *\n * @param params - The parameters.\n * @param params.product - The consuming feature.\n * @returns The cached value, or `undefined` if not yet checked.\n */\n getKycStatus(params: { product: KycProduct }): boolean | undefined {\n return this.state.kycRequiredByProduct[params.product];\n }\n\n /**\n * Runs the SumSub document-verification sub-flow: creates a UKYC session,\n * exchanges the wrapped key for an applicant access token, and presents the\n * SDK via the injected launcher.\n *\n * @param params - Optional parameters.\n * @param params.locale - BCP-47 locale for the SDK UI.\n * @param params.debug - Enables SDK debug logging.\n * @returns The SDK result.\n */\n async startSumSub(params?: {\n locale?: string;\n debug?: boolean;\n }): Promise<Record<string, unknown>> {\n if (!this.#sumsubLauncher.isAvailable()) {\n const error = 'SumSub SDK is not available in this runtime.';\n this.#applyUpdate((state) => {\n state.sumsub.status = 'failed';\n state.sumsub.result = { error };\n });\n throw new Error(error);\n }\n\n // Capture the flow generation so each async step can detect a `reset()`\n // that lands mid-flight and avoid writing stale sub-flow state (or, worse,\n // presenting the SDK) on a controller that is now idle.\n const generation = this.#generation;\n\n try {\n this.#applyUpdate((state) => {\n state.sumsub.status = 'creatingSession';\n state.sumsub.result = null;\n });\n\n const jwtToken = MOCK_JWT_TOKEN;\n const { sessionId, wrappingPublicKey, idosSessionId } =\n await this.messenger.call('KycService:createUkycSession', {\n jwtToken,\n vendorMetadata: {\n moonPayAccessToken: this.state.accessToken,\n moonPayUserId: this.state.moonpayCustomerId,\n },\n });\n // Retain the exchange material so the SDK can refresh its token. The\n // session's `wrappingPublicKey` is forwarded opaquely as the request's\n // `wrappedUserKey` field (the /wrapped-key endpoint's body is unchanged).\n const exchange = {\n sessionId,\n wrappedUserKey: wrappingPublicKey,\n idosSessionId,\n jwtToken,\n };\n\n this.#updateIfCurrent(generation, (state) => {\n state.sumsub.status = 'fetchingToken';\n state.sumsub.sessionId = sessionId;\n });\n\n const { applicantAccessToken } = await this.messenger.call(\n 'KycService:submitWrappedKey',\n exchange,\n );\n\n // A reset() landed while the session/token was being prepared; abort\n // before presenting the SDK rather than launching on an idle controller.\n if (this.#generation !== generation) {\n return {};\n }\n\n this.#applyUpdate((state) => {\n state.sumsub.status = 'launching';\n state.sumsub.applicantAccessToken = applicantAccessToken;\n });\n\n // Track whether the SDK ever reported a successful completion. A resolved\n // `launch` alone does not imply success — the applicant may have\n // abandoned the flow or the SDK may have reported a non-success outcome.\n let reachedCompletion = false;\n\n const result = await this.#sumsubLauncher.launch({\n applicantAccessToken,\n onTokenExpiration: async () => {\n // A reset() may have superseded this flow while the SDK stayed open.\n // Refuse to refresh against the now-stale UKYC session rather than\n // silently keeping an orphaned SDK alive.\n if (this.#generation !== generation) {\n throw new Error(\n 'KYC flow was reset; SumSub session is no longer active.',\n );\n }\n const refreshed = await this.messenger.call(\n 'KycService:submitWrappedKey',\n exchange,\n );\n return refreshed.applicantAccessToken;\n },\n onStatusChange: (_prev, next) => {\n if (next === SUMSUB_COMPLETED_STATUS) {\n reachedCompletion = true;\n }\n this.#updateIfCurrent(generation, (state) => {\n state.sumsub.status =\n next === SUMSUB_COMPLETED_STATUS ? 'complete' : 'inProgress';\n });\n },\n locale: params?.locale ?? 'en',\n debug: params?.debug ?? false,\n });\n\n // Only record `complete` when the SDK actually reported completion;\n // otherwise treat the resolved-but-unfinished flow as `failed` so\n // consumers and UI do not mistake it for a finished verification.\n this.#updateIfCurrent(generation, (state) => {\n state.sumsub.status = reachedCompletion ? 'complete' : 'failed';\n state.sumsub.result = result as Json;\n });\n return result;\n } catch (error) {\n const result = { error: String(error) };\n this.#updateIfCurrent(generation, (state) => {\n state.sumsub.status = 'failed';\n state.sumsub.result = result;\n });\n return result;\n }\n }\n\n /**\n * Resets the flow to idle, clearing session tokens and sub-flow state while\n * preserving persisted terms acceptance and the per-product cache.\n */\n reset(): void {\n this.#authClientToken = null;\n // Invalidate any in-flight async work started before this reset.\n this.#generation += 1;\n // Allow the next authenticated flow to auto-continue; any continuation from\n // the superseded generation will no longer clear this flag (see the\n // generation guard in `#continueAfterAuthentication`).\n this.#continuationInFlight = false;\n this.#applyUpdate((state) => {\n state.phase = 'idle';\n state.statusMessage = '';\n state.error = null;\n state.disclaimers = [];\n state.disclaimersError = null;\n state.sessionToken = null;\n state.accessToken = null;\n state.moonpayCustomerId = null;\n state.activeProduct = null;\n state.sumsub = {\n status: 'idle',\n result: null,\n sessionId: null,\n applicantAccessToken: null,\n };\n });\n }\n\n /**\n * Applies a state update only when the flow has not been reset since\n * `generation` was captured. Prevents an in-flight async step from writing\n * stale results onto a controller that a concurrent {@link reset} has\n * returned to idle.\n *\n * @param generation - The flow generation captured before the async work.\n * @param updater - The state mutation to apply when still current.\n * @returns `true` if the update was applied, `false` if it was superseded.\n */\n #updateIfCurrent(\n generation: number,\n updater: (state: KycControllerState) => void,\n ): boolean {\n if (this.#generation !== generation) {\n return false;\n }\n this.#applyUpdate(updater);\n return true;\n }\n\n /**\n * The single state-update path for this controller. All mutations go through\n * here (rather than calling `this.update` directly) so the mechanism stays\n * consistent and one subtlety is handled in a single place:\n *\n * `sumsub.result` is typed as the recursive `Json`, and expanding\n * `Draft<Json>` (which happens whenever an updater touches `sumsub.result`)\n * trips TypeScript's \"type instantiation is excessively deep\" guard. By\n * typing the callback parameter as the plain {@link KycControllerState}\n * instead of Immer's `Draft`, we avoid expanding the draft type while keeping\n * the same mutate-in-place semantics (the underlying value is still the Immer\n * draft at runtime).\n *\n * @param updater - The state mutation to apply.\n */\n #applyUpdate(updater: (state: KycControllerState) => void): void {\n this.update((state) => {\n updater(state as unknown as KycControllerState);\n });\n }\n\n /**\n * Transitions to the error phase with a message.\n *\n * @param message - The error message.\n */\n #fail(message: string): void {\n this.#applyUpdate((state) => {\n state.error = message;\n state.phase = 'error';\n });\n }\n}\n"]}
@@ -0,0 +1,219 @@
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import { BaseController } from "@metamask/base-controller";
3
+ import type { Messenger } from "@metamask/messenger";
4
+ import type { Json } from "@metamask/utils";
5
+ import type { KycControllerMethodActions } from "./KycController-method-action-types.cjs";
6
+ import type { KycServiceMethodActions } from "./KycService-method-action-types.cjs";
7
+ import type { KycDisclaimer, KycPhase, KycProduct, KycSumSubLauncher, KycSumSubStatus } from "./types.cjs";
8
+ export declare const controllerName = "KycController";
9
+ /**
10
+ * Describes the shape of the state object for {@link KycController}.
11
+ */
12
+ export type KycControllerState = {
13
+ /** Current phase of the identity flow. */
14
+ phase: KycPhase;
15
+ /** Human-readable status message for the current phase. */
16
+ statusMessage: string;
17
+ /** The current error message, or `null`. */
18
+ error: string | null;
19
+ /** Email associated with the session (sourced from the account). */
20
+ email: string | null;
21
+ /** ISO-8601 timestamp of the customer's terms acceptance (persisted). */
22
+ termsAcceptedAt: string | null;
23
+ /** IDs of the disclaimers the customer accepted (persisted). */
24
+ acceptedDisclaimerIds: string[];
25
+ /** Disclaimers fetched for the current country. */
26
+ disclaimers: KycDisclaimer[];
27
+ /** Error encountered while loading disclaimers, or `null`. */
28
+ disclaimersError: string | null;
29
+ /** Resolved ISO 3166-1 alpha-3 country code. */
30
+ geoCountry: string | null;
31
+ /** Vendor session token (not persisted, not logged). */
32
+ sessionToken: string | null;
33
+ /** Vendor access token (not persisted, not logged). */
34
+ accessToken: string | null;
35
+ /** Vendor customer id, used for the SumSub hand-off. */
36
+ moonpayCustomerId: string | null;
37
+ /**
38
+ * The product the current flow is running for. Captured at `initialize`
39
+ * (or `acceptTermsAndStartSession`) and used to automatically run the
40
+ * KYC-required check once authentication completes. `null` outside a
41
+ * product-scoped flow (in which case the flow stops at `form` and the
42
+ * consumer drives the check manually).
43
+ */
44
+ activeProduct: KycProduct | null;
45
+ /** Cached "is KYC required" result per product (persisted). */
46
+ kycRequiredByProduct: Partial<Record<KycProduct, boolean>>;
47
+ /** ISO-8601 timestamp of the last KYC-required check (persisted). */
48
+ lastCheckedAt: string | null;
49
+ /** SumSub document-verification sub-flow state. */
50
+ sumsub: {
51
+ status: KycSumSubStatus;
52
+ result: Json | null;
53
+ sessionId: string | null;
54
+ applicantAccessToken: string | null;
55
+ };
56
+ };
57
+ /**
58
+ * Constructs the default {@link KycController} state.
59
+ *
60
+ * @returns The default state.
61
+ */
62
+ export declare function getDefaultKycControllerState(): KycControllerState;
63
+ export type KycControllerGetStateAction = ControllerGetStateAction<typeof controllerName, KycControllerState>;
64
+ export type KycControllerActions = KycControllerGetStateAction | KycControllerMethodActions;
65
+ type AllowedActions = KycServiceMethodActions;
66
+ export type KycControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, KycControllerState>;
67
+ export type KycControllerEvents = KycControllerStateChangeEvent;
68
+ type AllowedEvents = never;
69
+ export type KycControllerMessenger = Messenger<typeof controllerName, KycControllerActions | AllowedActions, KycControllerEvents | AllowedEvents>;
70
+ /**
71
+ * Options for constructing a {@link KycController}.
72
+ */
73
+ export type KycControllerOptions = {
74
+ messenger: KycControllerMessenger;
75
+ state?: Partial<KycControllerState>;
76
+ /**
77
+ * Platform adapter that presents the SumSub SDK. Injected by each client so
78
+ * the controller stays platform-agnostic.
79
+ */
80
+ sumsubLauncher: KycSumSubLauncher;
81
+ };
82
+ /**
83
+ * `KycController` orchestrates the vendor-backed KYC / identity-verification
84
+ * flow (MoonPay identity + SumSub documents) behind a vendor-neutral, per
85
+ * product surface used by ramps and card. It owns all state, HTTP
86
+ * orchestration (via `KycService`), crypto, and the frame message protocol;
87
+ * platform-specific presentation (WebView/iframe, SumSub SDK) is injected.
88
+ */
89
+ export declare class KycController extends BaseController<typeof controllerName, KycControllerState, KycControllerMessenger> {
90
+ #private;
91
+ /**
92
+ * Constructs a new {@link KycController}.
93
+ *
94
+ * @param options - The constructor options.
95
+ * @param options.messenger - The messenger suited for this controller.
96
+ * @param options.state - Partial initial state; merged over defaults.
97
+ * @param options.sumsubLauncher - The platform SumSub launcher adapter.
98
+ */
99
+ constructor({ messenger, state, sumsubLauncher }: KycControllerOptions);
100
+ /**
101
+ * Resolves persisted terms + geolocation, and auto-creates a session when
102
+ * terms are already accepted and an email is available.
103
+ *
104
+ * @param params - Optional parameters.
105
+ * @param params.email - The account email to associate with the session.
106
+ * @param params.product - The consuming feature the flow runs for. When
107
+ * provided, the controller automatically runs the KYC-required check once
108
+ * authentication completes (and chains into document verification when KYC
109
+ * is required). When omitted, the flow stops at `form` and the consumer must
110
+ * call `checkKycRequired` manually.
111
+ */
112
+ initialize(params?: {
113
+ email?: string;
114
+ product?: KycProduct;
115
+ }): Promise<void>;
116
+ /**
117
+ * Loads the disclaimers for the resolved (or provided) country.
118
+ *
119
+ * @param params - Optional parameters.
120
+ * @param params.country - ISO 3166-1 alpha-3 country code override.
121
+ */
122
+ loadDisclaimers(params?: {
123
+ country?: string;
124
+ }): Promise<void>;
125
+ /**
126
+ * Captures terms acceptance for the currently loaded disclaimers and creates
127
+ * a session.
128
+ *
129
+ * @param params - Optional parameters.
130
+ * @param params.email - The account email to associate with the session.
131
+ * @param params.product - The consuming feature the flow runs for. See
132
+ * {@link initialize} for how the product drives the automatic post
133
+ * authentication continuation.
134
+ */
135
+ acceptTermsAndStartSession(params?: {
136
+ email?: string;
137
+ product?: KycProduct;
138
+ }): Promise<void>;
139
+ /**
140
+ * Clears the persisted terms acceptance.
141
+ */
142
+ clearSavedTerms(): void;
143
+ /**
144
+ * Handles a message posted by a Check/Auth frame and advances the flow.
145
+ *
146
+ * The transport-agnostic caller (WebView on mobile, iframe on web) forwards
147
+ * the raw message and injects the returned `reply` back into the frame.
148
+ *
149
+ * @param params - The parameters.
150
+ * @param params.message - The raw message posted by the frame.
151
+ * @returns An object whose optional `reply` should be posted back.
152
+ */
153
+ handleFrameMessage(params: {
154
+ message: unknown;
155
+ }): Promise<{
156
+ reply?: unknown;
157
+ }>;
158
+ /**
159
+ * Builds the Check-frame URL, or `null` when no session exists yet.
160
+ *
161
+ * @returns The Check-frame URL or `null`.
162
+ */
163
+ buildCheckFrameUrl(): string | null;
164
+ /**
165
+ * Builds the Auth-frame URL, or `null` when no client token is available.
166
+ *
167
+ * @returns The Auth-frame URL or `null`.
168
+ */
169
+ buildAuthFrameUrl(): string | null;
170
+ /**
171
+ * Builds the Reset-frame URL.
172
+ *
173
+ * @returns The Reset-frame URL.
174
+ */
175
+ buildResetFrameUrl(): string;
176
+ /**
177
+ * Checks whether KYC is required for a product and caches the result.
178
+ *
179
+ * @param params - The parameters.
180
+ * @param params.product - The consuming feature.
181
+ * @param params.country - Optional alpha-3 country override.
182
+ * @returns Whether KYC is required.
183
+ */
184
+ checkKycRequired(params: {
185
+ product: KycProduct;
186
+ country?: string;
187
+ }): Promise<boolean>;
188
+ /**
189
+ * Reads the cached "is KYC required" result for a product.
190
+ *
191
+ * @param params - The parameters.
192
+ * @param params.product - The consuming feature.
193
+ * @returns The cached value, or `undefined` if not yet checked.
194
+ */
195
+ getKycStatus(params: {
196
+ product: KycProduct;
197
+ }): boolean | undefined;
198
+ /**
199
+ * Runs the SumSub document-verification sub-flow: creates a UKYC session,
200
+ * exchanges the wrapped key for an applicant access token, and presents the
201
+ * SDK via the injected launcher.
202
+ *
203
+ * @param params - Optional parameters.
204
+ * @param params.locale - BCP-47 locale for the SDK UI.
205
+ * @param params.debug - Enables SDK debug logging.
206
+ * @returns The SDK result.
207
+ */
208
+ startSumSub(params?: {
209
+ locale?: string;
210
+ debug?: boolean;
211
+ }): Promise<Record<string, unknown>>;
212
+ /**
213
+ * Resets the flow to idle, clearing session tokens and sub-flow state while
214
+ * preserving persisted terms acceptance and the per-product cache.
215
+ */
216
+ reset(): void;
217
+ }
218
+ export {};
219
+ //# sourceMappingURL=KycController.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KycController.d.cts","sourceRoot":"","sources":["../src/KycController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EAAE,0BAA0B,EAAE,gDAA4C;AACtF,OAAO,KAAK,EAAE,uBAAuB,EAAE,6CAAyC;AAChF,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EAC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;;;;OASG;IACG,0BAA0B,CAAC,MAAM,CAAC,EAAE;QACxC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,UAAU,CAAC;KACtB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyEjB;;OAEG;IACH,eAAe,IAAI,IAAI;IAoBvB;;;;;;;;;OASG;IACG,kBAAkB,CAAC,MAAM,EAAE;QAC/B,OAAO,EAAE,OAAO,CAAC;KAClB,GAAG,OAAO,CAAC;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAwLhC;;;;OAIG;IACH,kBAAkB,IAAI,MAAM,GAAG,IAAI;IAYnC;;;;OAIG;IACH,iBAAiB,IAAI,MAAM,GAAG,IAAI;IAWlC;;;;OAIG;IACH,kBAAkB,IAAI,MAAM;IAM5B;;;;;;;OAOG;IACG,gBAAgB,CAAC,MAAM,EAAE;QAC7B,OAAO,EAAE,UAAU,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,OAAO,CAAC;IA+CpB;;;;;;OAMG;IACH,YAAY,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,GAAG,SAAS;IAIlE;;;;;;;;;OASG;IACG,WAAW,CAAC,MAAM,CAAC,EAAE;QACzB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAkHpC;;;OAGG;IACH,KAAK,IAAI,IAAI;CAgFd"}
@@ -0,0 +1,219 @@
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import { BaseController } from "@metamask/base-controller";
3
+ import type { Messenger } from "@metamask/messenger";
4
+ import type { Json } from "@metamask/utils";
5
+ import type { KycControllerMethodActions } from "./KycController-method-action-types.mjs";
6
+ import type { KycServiceMethodActions } from "./KycService-method-action-types.mjs";
7
+ import type { KycDisclaimer, KycPhase, KycProduct, KycSumSubLauncher, KycSumSubStatus } from "./types.mjs";
8
+ export declare const controllerName = "KycController";
9
+ /**
10
+ * Describes the shape of the state object for {@link KycController}.
11
+ */
12
+ export type KycControllerState = {
13
+ /** Current phase of the identity flow. */
14
+ phase: KycPhase;
15
+ /** Human-readable status message for the current phase. */
16
+ statusMessage: string;
17
+ /** The current error message, or `null`. */
18
+ error: string | null;
19
+ /** Email associated with the session (sourced from the account). */
20
+ email: string | null;
21
+ /** ISO-8601 timestamp of the customer's terms acceptance (persisted). */
22
+ termsAcceptedAt: string | null;
23
+ /** IDs of the disclaimers the customer accepted (persisted). */
24
+ acceptedDisclaimerIds: string[];
25
+ /** Disclaimers fetched for the current country. */
26
+ disclaimers: KycDisclaimer[];
27
+ /** Error encountered while loading disclaimers, or `null`. */
28
+ disclaimersError: string | null;
29
+ /** Resolved ISO 3166-1 alpha-3 country code. */
30
+ geoCountry: string | null;
31
+ /** Vendor session token (not persisted, not logged). */
32
+ sessionToken: string | null;
33
+ /** Vendor access token (not persisted, not logged). */
34
+ accessToken: string | null;
35
+ /** Vendor customer id, used for the SumSub hand-off. */
36
+ moonpayCustomerId: string | null;
37
+ /**
38
+ * The product the current flow is running for. Captured at `initialize`
39
+ * (or `acceptTermsAndStartSession`) and used to automatically run the
40
+ * KYC-required check once authentication completes. `null` outside a
41
+ * product-scoped flow (in which case the flow stops at `form` and the
42
+ * consumer drives the check manually).
43
+ */
44
+ activeProduct: KycProduct | null;
45
+ /** Cached "is KYC required" result per product (persisted). */
46
+ kycRequiredByProduct: Partial<Record<KycProduct, boolean>>;
47
+ /** ISO-8601 timestamp of the last KYC-required check (persisted). */
48
+ lastCheckedAt: string | null;
49
+ /** SumSub document-verification sub-flow state. */
50
+ sumsub: {
51
+ status: KycSumSubStatus;
52
+ result: Json | null;
53
+ sessionId: string | null;
54
+ applicantAccessToken: string | null;
55
+ };
56
+ };
57
+ /**
58
+ * Constructs the default {@link KycController} state.
59
+ *
60
+ * @returns The default state.
61
+ */
62
+ export declare function getDefaultKycControllerState(): KycControllerState;
63
+ export type KycControllerGetStateAction = ControllerGetStateAction<typeof controllerName, KycControllerState>;
64
+ export type KycControllerActions = KycControllerGetStateAction | KycControllerMethodActions;
65
+ type AllowedActions = KycServiceMethodActions;
66
+ export type KycControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, KycControllerState>;
67
+ export type KycControllerEvents = KycControllerStateChangeEvent;
68
+ type AllowedEvents = never;
69
+ export type KycControllerMessenger = Messenger<typeof controllerName, KycControllerActions | AllowedActions, KycControllerEvents | AllowedEvents>;
70
+ /**
71
+ * Options for constructing a {@link KycController}.
72
+ */
73
+ export type KycControllerOptions = {
74
+ messenger: KycControllerMessenger;
75
+ state?: Partial<KycControllerState>;
76
+ /**
77
+ * Platform adapter that presents the SumSub SDK. Injected by each client so
78
+ * the controller stays platform-agnostic.
79
+ */
80
+ sumsubLauncher: KycSumSubLauncher;
81
+ };
82
+ /**
83
+ * `KycController` orchestrates the vendor-backed KYC / identity-verification
84
+ * flow (MoonPay identity + SumSub documents) behind a vendor-neutral, per
85
+ * product surface used by ramps and card. It owns all state, HTTP
86
+ * orchestration (via `KycService`), crypto, and the frame message protocol;
87
+ * platform-specific presentation (WebView/iframe, SumSub SDK) is injected.
88
+ */
89
+ export declare class KycController extends BaseController<typeof controllerName, KycControllerState, KycControllerMessenger> {
90
+ #private;
91
+ /**
92
+ * Constructs a new {@link KycController}.
93
+ *
94
+ * @param options - The constructor options.
95
+ * @param options.messenger - The messenger suited for this controller.
96
+ * @param options.state - Partial initial state; merged over defaults.
97
+ * @param options.sumsubLauncher - The platform SumSub launcher adapter.
98
+ */
99
+ constructor({ messenger, state, sumsubLauncher }: KycControllerOptions);
100
+ /**
101
+ * Resolves persisted terms + geolocation, and auto-creates a session when
102
+ * terms are already accepted and an email is available.
103
+ *
104
+ * @param params - Optional parameters.
105
+ * @param params.email - The account email to associate with the session.
106
+ * @param params.product - The consuming feature the flow runs for. When
107
+ * provided, the controller automatically runs the KYC-required check once
108
+ * authentication completes (and chains into document verification when KYC
109
+ * is required). When omitted, the flow stops at `form` and the consumer must
110
+ * call `checkKycRequired` manually.
111
+ */
112
+ initialize(params?: {
113
+ email?: string;
114
+ product?: KycProduct;
115
+ }): Promise<void>;
116
+ /**
117
+ * Loads the disclaimers for the resolved (or provided) country.
118
+ *
119
+ * @param params - Optional parameters.
120
+ * @param params.country - ISO 3166-1 alpha-3 country code override.
121
+ */
122
+ loadDisclaimers(params?: {
123
+ country?: string;
124
+ }): Promise<void>;
125
+ /**
126
+ * Captures terms acceptance for the currently loaded disclaimers and creates
127
+ * a session.
128
+ *
129
+ * @param params - Optional parameters.
130
+ * @param params.email - The account email to associate with the session.
131
+ * @param params.product - The consuming feature the flow runs for. See
132
+ * {@link initialize} for how the product drives the automatic post
133
+ * authentication continuation.
134
+ */
135
+ acceptTermsAndStartSession(params?: {
136
+ email?: string;
137
+ product?: KycProduct;
138
+ }): Promise<void>;
139
+ /**
140
+ * Clears the persisted terms acceptance.
141
+ */
142
+ clearSavedTerms(): void;
143
+ /**
144
+ * Handles a message posted by a Check/Auth frame and advances the flow.
145
+ *
146
+ * The transport-agnostic caller (WebView on mobile, iframe on web) forwards
147
+ * the raw message and injects the returned `reply` back into the frame.
148
+ *
149
+ * @param params - The parameters.
150
+ * @param params.message - The raw message posted by the frame.
151
+ * @returns An object whose optional `reply` should be posted back.
152
+ */
153
+ handleFrameMessage(params: {
154
+ message: unknown;
155
+ }): Promise<{
156
+ reply?: unknown;
157
+ }>;
158
+ /**
159
+ * Builds the Check-frame URL, or `null` when no session exists yet.
160
+ *
161
+ * @returns The Check-frame URL or `null`.
162
+ */
163
+ buildCheckFrameUrl(): string | null;
164
+ /**
165
+ * Builds the Auth-frame URL, or `null` when no client token is available.
166
+ *
167
+ * @returns The Auth-frame URL or `null`.
168
+ */
169
+ buildAuthFrameUrl(): string | null;
170
+ /**
171
+ * Builds the Reset-frame URL.
172
+ *
173
+ * @returns The Reset-frame URL.
174
+ */
175
+ buildResetFrameUrl(): string;
176
+ /**
177
+ * Checks whether KYC is required for a product and caches the result.
178
+ *
179
+ * @param params - The parameters.
180
+ * @param params.product - The consuming feature.
181
+ * @param params.country - Optional alpha-3 country override.
182
+ * @returns Whether KYC is required.
183
+ */
184
+ checkKycRequired(params: {
185
+ product: KycProduct;
186
+ country?: string;
187
+ }): Promise<boolean>;
188
+ /**
189
+ * Reads the cached "is KYC required" result for a product.
190
+ *
191
+ * @param params - The parameters.
192
+ * @param params.product - The consuming feature.
193
+ * @returns The cached value, or `undefined` if not yet checked.
194
+ */
195
+ getKycStatus(params: {
196
+ product: KycProduct;
197
+ }): boolean | undefined;
198
+ /**
199
+ * Runs the SumSub document-verification sub-flow: creates a UKYC session,
200
+ * exchanges the wrapped key for an applicant access token, and presents the
201
+ * SDK via the injected launcher.
202
+ *
203
+ * @param params - Optional parameters.
204
+ * @param params.locale - BCP-47 locale for the SDK UI.
205
+ * @param params.debug - Enables SDK debug logging.
206
+ * @returns The SDK result.
207
+ */
208
+ startSumSub(params?: {
209
+ locale?: string;
210
+ debug?: boolean;
211
+ }): Promise<Record<string, unknown>>;
212
+ /**
213
+ * Resets the flow to idle, clearing session tokens and sub-flow state while
214
+ * preserving persisted terms acceptance and the per-product cache.
215
+ */
216
+ reset(): void;
217
+ }
218
+ export {};
219
+ //# sourceMappingURL=KycController.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KycController.d.mts","sourceRoot":"","sources":["../src/KycController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EAAE,0BAA0B,EAAE,gDAA4C;AACtF,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