@metamask-previews/claims-controller 0.5.4-preview-4c8a5dfcb → 0.6.0-preview-d74e69d

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 (38) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/ClaimsController.cjs.map +1 -1
  3. package/dist/ClaimsController.d.cts +1 -1
  4. package/dist/ClaimsController.d.cts.map +1 -1
  5. package/dist/ClaimsController.d.mts +1 -1
  6. package/dist/ClaimsController.d.mts.map +1 -1
  7. package/dist/ClaimsController.mjs.map +1 -1
  8. package/dist/ClaimsService-method-action-types.cjs +7 -0
  9. package/dist/ClaimsService-method-action-types.cjs.map +1 -0
  10. package/dist/ClaimsService-method-action-types.d.cts +67 -0
  11. package/dist/ClaimsService-method-action-types.d.cts.map +1 -0
  12. package/dist/ClaimsService-method-action-types.d.mts +67 -0
  13. package/dist/ClaimsService-method-action-types.d.mts.map +1 -0
  14. package/dist/ClaimsService-method-action-types.mjs +6 -0
  15. package/dist/ClaimsService-method-action-types.mjs.map +1 -0
  16. package/dist/ClaimsService-structs.cjs +36 -0
  17. package/dist/ClaimsService-structs.cjs.map +1 -0
  18. package/dist/ClaimsService-structs.d.cts +71 -0
  19. package/dist/ClaimsService-structs.d.cts.map +1 -0
  20. package/dist/ClaimsService-structs.d.mts +71 -0
  21. package/dist/ClaimsService-structs.d.mts.map +1 -0
  22. package/dist/ClaimsService-structs.mjs +33 -0
  23. package/dist/ClaimsService-structs.mjs.map +1 -0
  24. package/dist/ClaimsService.cjs +122 -62
  25. package/dist/ClaimsService.cjs.map +1 -1
  26. package/dist/ClaimsService.d.cts +56 -32
  27. package/dist/ClaimsService.d.cts.map +1 -1
  28. package/dist/ClaimsService.d.mts +56 -32
  29. package/dist/ClaimsService.d.mts.map +1 -1
  30. package/dist/ClaimsService.mjs +122 -62
  31. package/dist/ClaimsService.mjs.map +1 -1
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +3 -2
  34. package/dist/index.d.cts.map +1 -1
  35. package/dist/index.d.mts +3 -2
  36. package/dist/index.d.mts.map +1 -1
  37. package/dist/index.mjs.map +1 -1
  38. package/package.json +5 -2
package/CHANGELOG.md CHANGED
@@ -7,8 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.0]
11
+
12
+ ### Added
13
+
14
+ - Export `ClaimsControllerOptions` and `ClaimsServiceConfig` types ([#9588](https://github.com/MetaMask/core/pull/9588))
15
+ - Add `ClaimsService-method-action-types.ts` with generated method action types for `ClaimsService` ([#9588](https://github.com/MetaMask/core/pull/9588))
16
+ - Add `ClaimsService:invalidateQueries` action and `ClaimsService:cacheUpdated` events via `BaseDataService` ([#9588](https://github.com/MetaMask/core/pull/9588))
17
+ - Add `@metamask/base-data-service` `^0.1.3`, `@metamask/superstruct` `^3.1.0`, and `@tanstack/query-core` `^4.43.0` as dependencies ([#9588](https://github.com/MetaMask/core/pull/9588))
18
+
10
19
  ### Changed
11
20
 
21
+ - Migrate `ClaimsService` to `BaseDataService` with TanStack Query caching, circuit-breaker policy support, and response validation ([#9588](https://github.com/MetaMask/core/pull/9588))
22
+ - `ClaimsServiceConfig.fetchFunction` is optional and defaults to `globalThis.fetch` ([#9588](https://github.com/MetaMask/core/pull/9588))
12
23
  - Bump `@metamask/keyring-controller` from `^27.1.0` to `^27.1.1` ([#9791](https://github.com/MetaMask/core/pull/9791))
13
24
 
14
25
  ## [0.5.4]
@@ -151,7 +162,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
151
162
  - `generateMessageForClaimSignature`: generate message to sign for the claim signature.
152
163
  - `verifyClaimSignature`: verify claim signature produced by user.
153
164
 
154
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.5.4...HEAD
165
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.6.0...HEAD
166
+ [0.6.0]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.5.4...@metamask/claims-controller@0.6.0
155
167
  [0.5.4]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.5.3...@metamask/claims-controller@0.5.4
156
168
  [0.5.3]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.5.2...@metamask/claims-controller@0.5.3
157
169
  [0.5.2]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.5.1...@metamask/claims-controller@0.5.2
@@ -1 +1 @@
1
- {"version":3,"file":"ClaimsController.cjs","sourceRoot":"","sources":["../src/ClaimsController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAC3D,iEAA+D;AAG/D,2CAA4D;AAW5D,kDAKwB;AA6CxB,MAAM,6BAA6B,GAAyC;IAC1E,MAAM,EAAE;QACN,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,oBAAoB,EAAE;QACpB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF;;;;GAIG;AACH,SAAgB,+BAA+B;IAC7C,OAAO;QACL,oBAAoB,EAAE,4CAA6B;QACnD,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE;KACX,CAAC;AACJ,CAAC;AAND,0EAMC;AAED,MAAM,yBAAyB,GAAG;IAChC,2BAA2B;IAC3B,sBAAsB;IACtB,wBAAwB;IACxB,WAAW;IACX,wBAAwB;IACxB,gBAAgB;IAChB,kBAAkB;IAClB,sBAAsB;IACtB,YAAY;CACJ,CAAC;AAEX,MAAa,gBAAiB,SAAQ,gCAIrC;IACC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AE;YACpB,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;QAC3E,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,OAAO,+BAA+B,EAAE,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;CAgBF;AA7ND,4CA6NC;kJAT6B,KAAyB;IACnD,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IAC9C,MAAM,uBAAuB,GAAG,cAAc,CAAC,IAAI,CACjD,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,CAAC,cAAc,KAAK,KAAK,CAAC,cAAc,CACzE,CAAC;IACF,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,4CAA6B,CAAC,uBAAuB,CAAC,CAAC;IACzE,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { detectSIWE, toHex } from '@metamask/controller-utils';\nimport type { KeyringControllerSignPersonalMessageAction } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { bytesToHex, stringToBytes } from '@metamask/utils';\n\nimport type { ClaimsControllerMethodActions } from './ClaimsController-method-action-types.js';\nimport type {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetRequestHeadersAction,\n} from './ClaimsService.js';\nimport {\n ClaimsControllerErrorMessages,\n CONTROLLER_NAME,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n SERVICE_NAME,\n} from './constants.js';\nimport type {\n Claim,\n ClaimDraft,\n ClaimsConfigurations,\n ClaimsControllerState,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types.js';\n\nexport type ClaimsControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerActions =\n | ClaimsControllerGetStateAction\n | ClaimsControllerMethodActions;\n\nexport type AllowedActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction\n | ClaimsServiceGetClaimsAction\n | KeyringControllerSignPersonalMessageAction;\n\nexport type ClaimsControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n ClaimsControllerActions | AllowedActions,\n ClaimsControllerStateChangeEvent\n>;\n\nexport type ClaimsControllerOptions = {\n messenger: ClaimsControllerMessenger;\n state?: Partial<ClaimsControllerState>;\n};\n\nconst ClaimsControllerStateMetadata: StateMetadata<ClaimsControllerState> = {\n claims: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n claimsConfigurations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n drafts: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\n/**\n * Get an initial default state for the controller.\n *\n * @returns The initial default controller state.\n */\nexport function getDefaultClaimsControllerState(): ClaimsControllerState {\n return {\n claimsConfigurations: DEFAULT_CLAIMS_CONFIGURATIONS,\n claims: [],\n drafts: [],\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchClaimsConfigurations',\n 'getSubmitClaimConfig',\n 'generateClaimSignature',\n 'getClaims',\n 'saveOrUpdateClaimDraft',\n 'getClaimDrafts',\n 'deleteClaimDraft',\n 'deleteAllClaimDrafts',\n 'clearState',\n] as const;\n\nexport class ClaimsController extends BaseController<\n typeof CONTROLLER_NAME,\n ClaimsControllerState,\n ClaimsControllerMessenger\n> {\n constructor({ messenger, state }: ClaimsControllerOptions) {\n super({\n messenger,\n metadata: ClaimsControllerStateMetadata,\n name: CONTROLLER_NAME,\n state: { ...getDefaultClaimsControllerState(), ...state },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetch the required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurations> {\n const configurations = await this.messenger.call(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n );\n\n const supportedNetworks = configurations.networks.map((network) =>\n toHex(network),\n );\n const claimsConfigurations = {\n validSubmissionWindowDays: configurations.validSubmissionWindowDays,\n supportedNetworks,\n };\n\n this.update((state) => {\n state.claimsConfigurations = claimsConfigurations;\n });\n return claimsConfigurations;\n }\n\n /**\n * Get required config for submitting a claim.\n *\n * @param claim - The claim request to get the required config for.\n * @returns The required config for submitting the claim.\n */\n async getSubmitClaimConfig(\n claim: CreateClaimRequest,\n ): Promise<SubmitClaimConfig> {\n // Validate the claim before submitting it.\n this.#validateSubmitClaimRequest(claim);\n\n const headers = await this.messenger.call(\n `${SERVICE_NAME}:getRequestHeaders`,\n );\n const baseUrl = this.messenger.call(`${SERVICE_NAME}:getClaimsApiUrl`);\n const url = `${baseUrl}/claims`;\n\n return {\n data: claim,\n headers,\n method: 'POST',\n url,\n };\n }\n\n /**\n * Generate a signature for a claim.\n *\n * @param chainId - The chain id of the claim.\n * @param walletAddress - The impacted wallet address of the claim.\n * @returns The signature for the claim.\n */\n async generateClaimSignature(\n chainId: number,\n walletAddress: `0x${string}`,\n ): Promise<string> {\n // generate the message to be signed\n const { message } = await this.messenger.call(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n chainId,\n walletAddress,\n );\n\n // generate and parse the SIWE message\n const messageBytes = stringToBytes(message);\n const messageHex = bytesToHex(messageBytes);\n const siwe = detectSIWE({ data: messageHex });\n if (!siwe.isSIWEMessage) {\n throw new Error(ClaimsControllerErrorMessages.INVALID_SIGNATURE_MESSAGE);\n }\n\n // sign the message\n const signature = await this.messenger.call(\n 'KeyringController:signPersonalMessage',\n {\n data: message,\n from: walletAddress,\n siwe,\n },\n );\n\n return signature;\n }\n\n /**\n * Get the list of claims for the current user.\n *\n * @returns The list of claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n const claims = await this.messenger.call(`${SERVICE_NAME}:getClaims`);\n this.update((state) => {\n state.claims = claims;\n });\n return claims;\n }\n\n /**\n * Save a claim draft to the state.\n * If the draft name is not provided, a default name will be generated.\n * If the draft with the same id already exists, it will be updated.\n *\n * @param draft - The draft to save.\n * @returns The saved draft.\n */\n saveOrUpdateClaimDraft(draft: Partial<ClaimDraft>): ClaimDraft {\n const { drafts } = this.state;\n\n const isExistingDraft = drafts.some(\n (existingDraft) =>\n draft.draftId && existingDraft.draftId === draft.draftId,\n );\n\n if (isExistingDraft) {\n const updatedAt = new Date().toISOString();\n this.update((state) => {\n state.drafts = state.drafts.map((existingDraft) =>\n existingDraft.draftId === draft.draftId\n ? {\n ...existingDraft,\n ...draft,\n updatedAt,\n }\n : existingDraft,\n );\n });\n return { ...draft, updatedAt } as ClaimDraft;\n }\n\n // generate a new draft id, name and add it to the state\n const draftId = `draft-${Date.now()}`;\n\n const newDraft: ClaimDraft = {\n ...draft,\n draftId,\n updatedAt: new Date().toISOString(),\n };\n\n this.update((state) => {\n state.drafts.push(newDraft);\n });\n\n return newDraft;\n }\n\n /**\n * Get the list of claim drafts.\n *\n * @returns The list of claim drafts.\n */\n getClaimDrafts(): ClaimDraft[] {\n return this.state.drafts;\n }\n\n /**\n * Delete a claim draft from the state.\n *\n * @param draftId - The ID of the draft to delete.\n */\n deleteClaimDraft(draftId: string): void {\n this.update((state) => {\n state.drafts = state.drafts.filter((draft) => draft.draftId !== draftId);\n });\n }\n\n /**\n * Delete all claim drafts from the state.\n */\n deleteAllClaimDrafts(): void {\n this.update((state) => {\n state.drafts = [];\n });\n }\n\n /**\n * Clears the claims state and resets to default values.\n */\n clearState(): void {\n this.update(() => {\n return getDefaultClaimsControllerState();\n });\n }\n\n /**\n * Validate the claim before submitting it.\n *\n * @param claim - The claim to validate.\n */\n #validateSubmitClaimRequest(claim: CreateClaimRequest): void {\n const { claims: existingClaims } = this.state;\n const isClaimAlreadySubmitted = existingClaims.some(\n (existingClaim) => existingClaim.impactedTxHash === claim.impactedTxHash,\n );\n if (isClaimAlreadySubmitted) {\n throw new Error(ClaimsControllerErrorMessages.CLAIM_ALREADY_SUBMITTED);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ClaimsController.cjs","sourceRoot":"","sources":["../src/ClaimsController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAC3D,iEAA+D;AAG/D,2CAA4D;AAW5D,kDAKwB;AA6CxB,MAAM,6BAA6B,GAAyC;IAC1E,MAAM,EAAE;QACN,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,oBAAoB,EAAE;QACpB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAA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E,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { detectSIWE, toHex } from '@metamask/controller-utils';\nimport type { KeyringControllerSignPersonalMessageAction } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { bytesToHex, stringToBytes } from '@metamask/utils';\n\nimport type { ClaimsControllerMethodActions } from './ClaimsController-method-action-types.js';\nimport type {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetRequestHeadersAction,\n} from './ClaimsService-method-action-types.js';\nimport {\n ClaimsControllerErrorMessages,\n CONTROLLER_NAME,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n SERVICE_NAME,\n} from './constants.js';\nimport type {\n Claim,\n ClaimDraft,\n ClaimsConfigurations,\n ClaimsControllerState,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types.js';\n\nexport type ClaimsControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerActions =\n | ClaimsControllerGetStateAction\n | ClaimsControllerMethodActions;\n\nexport type AllowedActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction\n | ClaimsServiceGetClaimsAction\n | KeyringControllerSignPersonalMessageAction;\n\nexport type ClaimsControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n ClaimsControllerActions | AllowedActions,\n ClaimsControllerStateChangeEvent\n>;\n\nexport type ClaimsControllerOptions = {\n messenger: ClaimsControllerMessenger;\n state?: Partial<ClaimsControllerState>;\n};\n\nconst ClaimsControllerStateMetadata: StateMetadata<ClaimsControllerState> = {\n claims: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n claimsConfigurations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n drafts: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\n/**\n * Get an initial default state for the controller.\n *\n * @returns The initial default controller state.\n */\nexport function getDefaultClaimsControllerState(): ClaimsControllerState {\n return {\n claimsConfigurations: DEFAULT_CLAIMS_CONFIGURATIONS,\n claims: [],\n drafts: [],\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchClaimsConfigurations',\n 'getSubmitClaimConfig',\n 'generateClaimSignature',\n 'getClaims',\n 'saveOrUpdateClaimDraft',\n 'getClaimDrafts',\n 'deleteClaimDraft',\n 'deleteAllClaimDrafts',\n 'clearState',\n] as const;\n\nexport class ClaimsController extends BaseController<\n typeof CONTROLLER_NAME,\n ClaimsControllerState,\n ClaimsControllerMessenger\n> {\n constructor({ messenger, state }: ClaimsControllerOptions) {\n super({\n messenger,\n metadata: ClaimsControllerStateMetadata,\n name: CONTROLLER_NAME,\n state: { ...getDefaultClaimsControllerState(), ...state },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetch the required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurations> {\n const configurations = await this.messenger.call(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n );\n\n const supportedNetworks = configurations.networks.map((network) =>\n toHex(network),\n );\n const claimsConfigurations = {\n validSubmissionWindowDays: configurations.validSubmissionWindowDays,\n supportedNetworks,\n };\n\n this.update((state) => {\n state.claimsConfigurations = claimsConfigurations;\n });\n return claimsConfigurations;\n }\n\n /**\n * Get required config for submitting a claim.\n *\n * @param claim - The claim request to get the required config for.\n * @returns The required config for submitting the claim.\n */\n async getSubmitClaimConfig(\n claim: CreateClaimRequest,\n ): Promise<SubmitClaimConfig> {\n // Validate the claim before submitting it.\n this.#validateSubmitClaimRequest(claim);\n\n const headers = await this.messenger.call(\n `${SERVICE_NAME}:getRequestHeaders`,\n );\n const baseUrl = this.messenger.call(`${SERVICE_NAME}:getClaimsApiUrl`);\n const url = `${baseUrl}/claims`;\n\n return {\n data: claim,\n headers,\n method: 'POST',\n url,\n };\n }\n\n /**\n * Generate a signature for a claim.\n *\n * @param chainId - The chain id of the claim.\n * @param walletAddress - The impacted wallet address of the claim.\n * @returns The signature for the claim.\n */\n async generateClaimSignature(\n chainId: number,\n walletAddress: `0x${string}`,\n ): Promise<string> {\n // generate the message to be signed\n const { message } = await this.messenger.call(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n chainId,\n walletAddress,\n );\n\n // generate and parse the SIWE message\n const messageBytes = stringToBytes(message);\n const messageHex = bytesToHex(messageBytes);\n const siwe = detectSIWE({ data: messageHex });\n if (!siwe.isSIWEMessage) {\n throw new Error(ClaimsControllerErrorMessages.INVALID_SIGNATURE_MESSAGE);\n }\n\n // sign the message\n const signature = await this.messenger.call(\n 'KeyringController:signPersonalMessage',\n {\n data: message,\n from: walletAddress,\n siwe,\n },\n );\n\n return signature;\n }\n\n /**\n * Get the list of claims for the current user.\n *\n * @returns The list of claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n const claims = await this.messenger.call(`${SERVICE_NAME}:getClaims`);\n this.update((state) => {\n state.claims = claims;\n });\n return claims;\n }\n\n /**\n * Save a claim draft to the state.\n * If the draft name is not provided, a default name will be generated.\n * If the draft with the same id already exists, it will be updated.\n *\n * @param draft - The draft to save.\n * @returns The saved draft.\n */\n saveOrUpdateClaimDraft(draft: Partial<ClaimDraft>): ClaimDraft {\n const { drafts } = this.state;\n\n const isExistingDraft = drafts.some(\n (existingDraft) =>\n draft.draftId && existingDraft.draftId === draft.draftId,\n );\n\n if (isExistingDraft) {\n const updatedAt = new Date().toISOString();\n this.update((state) => {\n state.drafts = state.drafts.map((existingDraft) =>\n existingDraft.draftId === draft.draftId\n ? {\n ...existingDraft,\n ...draft,\n updatedAt,\n }\n : existingDraft,\n );\n });\n return { ...draft, updatedAt } as ClaimDraft;\n }\n\n // generate a new draft id, name and add it to the state\n const draftId = `draft-${Date.now()}`;\n\n const newDraft: ClaimDraft = {\n ...draft,\n draftId,\n updatedAt: new Date().toISOString(),\n };\n\n this.update((state) => {\n state.drafts.push(newDraft);\n });\n\n return newDraft;\n }\n\n /**\n * Get the list of claim drafts.\n *\n * @returns The list of claim drafts.\n */\n getClaimDrafts(): ClaimDraft[] {\n return this.state.drafts;\n }\n\n /**\n * Delete a claim draft from the state.\n *\n * @param draftId - The ID of the draft to delete.\n */\n deleteClaimDraft(draftId: string): void {\n this.update((state) => {\n state.drafts = state.drafts.filter((draft) => draft.draftId !== draftId);\n });\n }\n\n /**\n * Delete all claim drafts from the state.\n */\n deleteAllClaimDrafts(): void {\n this.update((state) => {\n state.drafts = [];\n });\n }\n\n /**\n * Clears the claims state and resets to default values.\n */\n clearState(): void {\n this.update(() => {\n return getDefaultClaimsControllerState();\n });\n }\n\n /**\n * Validate the claim before submitting it.\n *\n * @param claim - The claim to validate.\n */\n #validateSubmitClaimRequest(claim: CreateClaimRequest): void {\n const { claims: existingClaims } = this.state;\n const isClaimAlreadySubmitted = existingClaims.some(\n (existingClaim) => existingClaim.impactedTxHash === claim.impactedTxHash,\n );\n if (isClaimAlreadySubmitted) {\n throw new Error(ClaimsControllerErrorMessages.CLAIM_ALREADY_SUBMITTED);\n }\n }\n}\n"]}
@@ -3,7 +3,7 @@ import { BaseController } from "@metamask/base-controller";
3
3
  import type { KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
4
4
  import type { Messenger } from "@metamask/messenger";
5
5
  import type { ClaimsControllerMethodActions } from "./ClaimsController-method-action-types.cjs";
6
- import type { ClaimsServiceFetchClaimsConfigurationsAction, ClaimsServiceGenerateMessageForClaimSignatureAction, ClaimsServiceGetClaimByIdAction, ClaimsServiceGetClaimsAction, ClaimsServiceGetClaimsApiUrlAction, ClaimsServiceGetRequestHeadersAction } from "./ClaimsService.cjs";
6
+ import type { ClaimsServiceFetchClaimsConfigurationsAction, ClaimsServiceGenerateMessageForClaimSignatureAction, ClaimsServiceGetClaimByIdAction, ClaimsServiceGetClaimsAction, ClaimsServiceGetClaimsApiUrlAction, ClaimsServiceGetRequestHeadersAction } from "./ClaimsService-method-action-types.cjs";
7
7
  import { CONTROLLER_NAME } from "./constants.cjs";
8
8
  import type { Claim, ClaimDraft, ClaimsConfigurations, ClaimsControllerState, CreateClaimRequest, SubmitClaimConfig } from "./types.cjs";
9
9
  export type ClaimsControllerGetStateAction = ControllerGetStateAction<typeof CONTROLLER_NAME, ClaimsControllerState>;
@@ -1 +1 @@
1
- {"version":3,"file":"ClaimsController.d.cts","sourceRoot":"","sources":["../src/ClaimsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,0CAA0C,EAAE,qCAAqC;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,6BAA6B,EAAE,mDAAkD;AAC/F,OAAO,KAAK,EACV,4CAA4C,EAC5C,mDAAmD,EACnD,+BAA+B,EAC/B,4BAA4B,EAC5B,kCAAkC,EAClC,oCAAoC,EACrC,4BAA2B;AAC5B,OAAO,EAEL,eAAe,EAGhB,wBAAuB;AACxB,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBA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,CACtB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,SAAS,CAC/C,OAAO,eAAe,EACtB,uBAAuB,GAAG,cAAc,EACxC,gCAAgC,CACjC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,yBAAyB,CAAC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACxC,CAAC;AAuBF;;;;GAIG;AACH,wBAAgB,+BAA+B,IAAI,qBAAqB,CAMvE;AAcD,qBAAa,gBAAiB,SAAQ,cAAc,CAClD,OAAO,eAAe,EACtB,qBAAqB,EACrB,yBAAyB,CAC1B;;gBACa,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,uBAAuB;IAczD;;;;OAIG;IACG,yBAAyB,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAmBhE;;;;;OAKG;IACG,oBAAoB,CACxB,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,iBAAiB,CAAC;IAkB7B;;;;;;OAMG;IACG,sBAAsB,CAC1B,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,KAAK,MAAM,EAAE,GAC3B,OAAO,CAAC,MAAM,CAAC;IA6BlB;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAQnC;;;;;;;OAOG;IACH,sBAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU;IAwC9D;;;;OAIG;IACH,cAAc,IAAI,UAAU,EAAE;IAI9B;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMvC;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAM5B;;OAEG;IACH,UAAU,IAAI,IAAI;CAoBnB"}
@@ -3,7 +3,7 @@ import { BaseController } from "@metamask/base-controller";
3
3
  import type { KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
4
4
  import type { Messenger } from "@metamask/messenger";
5
5
  import type { ClaimsControllerMethodActions } from "./ClaimsController-method-action-types.mjs";
6
- import type { ClaimsServiceFetchClaimsConfigurationsAction, ClaimsServiceGenerateMessageForClaimSignatureAction, ClaimsServiceGetClaimByIdAction, ClaimsServiceGetClaimsAction, ClaimsServiceGetClaimsApiUrlAction, ClaimsServiceGetRequestHeadersAction } from "./ClaimsService.mjs";
6
+ import type { ClaimsServiceFetchClaimsConfigurationsAction, ClaimsServiceGenerateMessageForClaimSignatureAction, ClaimsServiceGetClaimByIdAction, ClaimsServiceGetClaimsAction, ClaimsServiceGetClaimsApiUrlAction, ClaimsServiceGetRequestHeadersAction } from "./ClaimsService-method-action-types.mjs";
7
7
  import { CONTROLLER_NAME } from "./constants.mjs";
8
8
  import type { Claim, ClaimDraft, ClaimsConfigurations, ClaimsControllerState, CreateClaimRequest, SubmitClaimConfig } from "./types.mjs";
9
9
  export type ClaimsControllerGetStateAction = ControllerGetStateAction<typeof CONTROLLER_NAME, ClaimsControllerState>;
@@ -1 +1 @@
1
- {"version":3,"file":"ClaimsController.d.mts","sourceRoot":"","sources":["../src/ClaimsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,0CAA0C,EAAE,qCAAqC;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,6BAA6B,EAAE,mDAAkD;AAC/F,OAAO,KAAK,EACV,4CAA4C,EAC5C,mDAAmD,EACnD,+BAA+B,EAC/B,4BAA4B,EAC5B,kCAAkC,EAClC,oCAAoC,EACrC,4BAA2B;AAC5B,OAAO,EAEL,eAAe,EAGhB,wBAAuB;AACxB,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EAClB,oBAAmB;AAEpB,MAAM,MAAM,8BAA8B,GA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C,GAAG,EAAE;YACf,OAAO,+BAA+B,EAAE,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;CAgBF;kJAT6B,KAAyB;IACnD,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IAC9C,MAAM,uBAAuB,GAAG,cAAc,CAAC,IAAI,CACjD,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,CAAC,cAAc,KAAK,KAAK,CAAC,cAAc,CACzE,CAAC;IACF,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,uBAAuB,CAAC,CAAC;IACzE,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { detectSIWE, toHex } from '@metamask/controller-utils';\nimport type { KeyringControllerSignPersonalMessageAction } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { bytesToHex, stringToBytes } from '@metamask/utils';\n\nimport type { ClaimsControllerMethodActions } from './ClaimsController-method-action-types.js';\nimport type {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetRequestHeadersAction,\n} from './ClaimsService.js';\nimport {\n ClaimsControllerErrorMessages,\n CONTROLLER_NAME,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n SERVICE_NAME,\n} from './constants.js';\nimport type {\n Claim,\n ClaimDraft,\n ClaimsConfigurations,\n ClaimsControllerState,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types.js';\n\nexport type ClaimsControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerActions =\n | ClaimsControllerGetStateAction\n | ClaimsControllerMethodActions;\n\nexport type AllowedActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction\n | ClaimsServiceGetClaimsAction\n | KeyringControllerSignPersonalMessageAction;\n\nexport type ClaimsControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n ClaimsControllerActions | AllowedActions,\n ClaimsControllerStateChangeEvent\n>;\n\nexport type ClaimsControllerOptions = {\n messenger: ClaimsControllerMessenger;\n state?: Partial<ClaimsControllerState>;\n};\n\nconst ClaimsControllerStateMetadata: StateMetadata<ClaimsControllerState> = {\n claims: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n claimsConfigurations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n drafts: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\n/**\n * Get an initial default state for the controller.\n *\n * @returns The initial default controller state.\n */\nexport function getDefaultClaimsControllerState(): ClaimsControllerState {\n return {\n claimsConfigurations: DEFAULT_CLAIMS_CONFIGURATIONS,\n claims: [],\n drafts: [],\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchClaimsConfigurations',\n 'getSubmitClaimConfig',\n 'generateClaimSignature',\n 'getClaims',\n 'saveOrUpdateClaimDraft',\n 'getClaimDrafts',\n 'deleteClaimDraft',\n 'deleteAllClaimDrafts',\n 'clearState',\n] as const;\n\nexport class ClaimsController extends BaseController<\n typeof CONTROLLER_NAME,\n ClaimsControllerState,\n ClaimsControllerMessenger\n> {\n constructor({ messenger, state }: ClaimsControllerOptions) {\n super({\n messenger,\n metadata: ClaimsControllerStateMetadata,\n name: CONTROLLER_NAME,\n state: { ...getDefaultClaimsControllerState(), ...state },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetch the required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurations> {\n const configurations = await this.messenger.call(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n );\n\n const supportedNetworks = configurations.networks.map((network) =>\n toHex(network),\n );\n const claimsConfigurations = {\n validSubmissionWindowDays: configurations.validSubmissionWindowDays,\n supportedNetworks,\n };\n\n this.update((state) => {\n state.claimsConfigurations = claimsConfigurations;\n });\n return claimsConfigurations;\n }\n\n /**\n * Get required config for submitting a claim.\n *\n * @param claim - The claim request to get the required config for.\n * @returns The required config for submitting the claim.\n */\n async getSubmitClaimConfig(\n claim: CreateClaimRequest,\n ): Promise<SubmitClaimConfig> {\n // Validate the claim before submitting it.\n this.#validateSubmitClaimRequest(claim);\n\n const headers = await this.messenger.call(\n `${SERVICE_NAME}:getRequestHeaders`,\n );\n const baseUrl = this.messenger.call(`${SERVICE_NAME}:getClaimsApiUrl`);\n const url = `${baseUrl}/claims`;\n\n return {\n data: claim,\n headers,\n method: 'POST',\n url,\n };\n }\n\n /**\n * Generate a signature for a claim.\n *\n * @param chainId - The chain id of the claim.\n * @param walletAddress - The impacted wallet address of the claim.\n * @returns The signature for the claim.\n */\n async generateClaimSignature(\n chainId: number,\n walletAddress: `0x${string}`,\n ): Promise<string> {\n // generate the message to be signed\n const { message } = await this.messenger.call(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n chainId,\n walletAddress,\n );\n\n // generate and parse the SIWE message\n const messageBytes = stringToBytes(message);\n const messageHex = bytesToHex(messageBytes);\n const siwe = detectSIWE({ data: messageHex });\n if (!siwe.isSIWEMessage) {\n throw new Error(ClaimsControllerErrorMessages.INVALID_SIGNATURE_MESSAGE);\n }\n\n // sign the message\n const signature = await this.messenger.call(\n 'KeyringController:signPersonalMessage',\n {\n data: message,\n from: walletAddress,\n siwe,\n },\n );\n\n return signature;\n }\n\n /**\n * Get the list of claims for the current user.\n *\n * @returns The list of claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n const claims = await this.messenger.call(`${SERVICE_NAME}:getClaims`);\n this.update((state) => {\n state.claims = claims;\n });\n return claims;\n }\n\n /**\n * Save a claim draft to the state.\n * If the draft name is not provided, a default name will be generated.\n * If the draft with the same id already exists, it will be updated.\n *\n * @param draft - The draft to save.\n * @returns The saved draft.\n */\n saveOrUpdateClaimDraft(draft: Partial<ClaimDraft>): ClaimDraft {\n const { drafts } = this.state;\n\n const isExistingDraft = drafts.some(\n (existingDraft) =>\n draft.draftId && existingDraft.draftId === draft.draftId,\n );\n\n if (isExistingDraft) {\n const updatedAt = new Date().toISOString();\n this.update((state) => {\n state.drafts = state.drafts.map((existingDraft) =>\n existingDraft.draftId === draft.draftId\n ? {\n ...existingDraft,\n ...draft,\n updatedAt,\n }\n : existingDraft,\n );\n });\n return { ...draft, updatedAt } as ClaimDraft;\n }\n\n // generate a new draft id, name and add it to the state\n const draftId = `draft-${Date.now()}`;\n\n const newDraft: ClaimDraft = {\n ...draft,\n draftId,\n updatedAt: new Date().toISOString(),\n };\n\n this.update((state) => {\n state.drafts.push(newDraft);\n });\n\n return newDraft;\n }\n\n /**\n * Get the list of claim drafts.\n *\n * @returns The list of claim drafts.\n */\n getClaimDrafts(): ClaimDraft[] {\n return this.state.drafts;\n }\n\n /**\n * Delete a claim draft from the state.\n *\n * @param draftId - The ID of the draft to delete.\n */\n deleteClaimDraft(draftId: string): void {\n this.update((state) => {\n state.drafts = state.drafts.filter((draft) => draft.draftId !== draftId);\n });\n }\n\n /**\n * Delete all claim drafts from the state.\n */\n deleteAllClaimDrafts(): void {\n this.update((state) => {\n state.drafts = [];\n });\n }\n\n /**\n * Clears the claims state and resets to default values.\n */\n clearState(): void {\n this.update(() => {\n return getDefaultClaimsControllerState();\n });\n }\n\n /**\n * Validate the claim before submitting it.\n *\n * @param claim - The claim to validate.\n */\n #validateSubmitClaimRequest(claim: CreateClaimRequest): void {\n const { claims: existingClaims } = this.state;\n const isClaimAlreadySubmitted = existingClaims.some(\n (existingClaim) => existingClaim.impactedTxHash === claim.impactedTxHash,\n );\n if (isClaimAlreadySubmitted) {\n throw new Error(ClaimsControllerErrorMessages.CLAIM_ALREADY_SUBMITTED);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ClaimsController.mjs","sourceRoot":"","sources":["../src/ClaimsController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,mCAAmC;AAG/D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,wBAAwB;AAW5D,OAAO,EACL,6BAA6B,EAC7B,eAAe,EACf,6BAA6B,EAC7B,YAAY,EACb,wBAAuB;AA6CxB,MAAM,6BAA6B,GAAyC;IAC1E,MAAM,EAAE;QACN,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,oBAAoB,EAAE;QACpB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,+BAA+B;IAC7C,OAAO;QACL,oBAAoB,EAAE,6BAA6B;QACnD,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE;KACX,CAAC;AACJ,CAAC;AAED,MAAM,yBAAyB,GAAG;IAChC,2B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I,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,OAAe;QAC9B,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;QAC3E,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,OAAO,+BAA+B,EAAE,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;CAgBF;kJAT6B,KAAyB;IACnD,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IAC9C,MAAM,uBAAuB,GAAG,cAAc,CAAC,IAAI,CACjD,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,CAAC,cAAc,KAAK,KAAK,CAAC,cAAc,CACzE,CAAC;IACF,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,uBAAuB,CAAC,CAAC;IACzE,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { detectSIWE, toHex } from '@metamask/controller-utils';\nimport type { KeyringControllerSignPersonalMessageAction } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { bytesToHex, stringToBytes } from '@metamask/utils';\n\nimport type { ClaimsControllerMethodActions } from './ClaimsController-method-action-types.js';\nimport type {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetRequestHeadersAction,\n} from './ClaimsService-method-action-types.js';\nimport {\n ClaimsControllerErrorMessages,\n CONTROLLER_NAME,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n SERVICE_NAME,\n} from './constants.js';\nimport type {\n Claim,\n ClaimDraft,\n ClaimsConfigurations,\n ClaimsControllerState,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types.js';\n\nexport type ClaimsControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerActions =\n | ClaimsControllerGetStateAction\n | ClaimsControllerMethodActions;\n\nexport type AllowedActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction\n | ClaimsServiceGetClaimsAction\n | KeyringControllerSignPersonalMessageAction;\n\nexport type ClaimsControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n ClaimsControllerActions | AllowedActions,\n ClaimsControllerStateChangeEvent\n>;\n\nexport type ClaimsControllerOptions = {\n messenger: ClaimsControllerMessenger;\n state?: Partial<ClaimsControllerState>;\n};\n\nconst ClaimsControllerStateMetadata: StateMetadata<ClaimsControllerState> = {\n claims: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n claimsConfigurations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n drafts: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\n/**\n * Get an initial default state for the controller.\n *\n * @returns The initial default controller state.\n */\nexport function getDefaultClaimsControllerState(): ClaimsControllerState {\n return {\n claimsConfigurations: DEFAULT_CLAIMS_CONFIGURATIONS,\n claims: [],\n drafts: [],\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchClaimsConfigurations',\n 'getSubmitClaimConfig',\n 'generateClaimSignature',\n 'getClaims',\n 'saveOrUpdateClaimDraft',\n 'getClaimDrafts',\n 'deleteClaimDraft',\n 'deleteAllClaimDrafts',\n 'clearState',\n] as const;\n\nexport class ClaimsController extends BaseController<\n typeof CONTROLLER_NAME,\n ClaimsControllerState,\n ClaimsControllerMessenger\n> {\n constructor({ messenger, state }: ClaimsControllerOptions) {\n super({\n messenger,\n metadata: ClaimsControllerStateMetadata,\n name: CONTROLLER_NAME,\n state: { ...getDefaultClaimsControllerState(), ...state },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetch the required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurations> {\n const configurations = await this.messenger.call(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n );\n\n const supportedNetworks = configurations.networks.map((network) =>\n toHex(network),\n );\n const claimsConfigurations = {\n validSubmissionWindowDays: configurations.validSubmissionWindowDays,\n supportedNetworks,\n };\n\n this.update((state) => {\n state.claimsConfigurations = claimsConfigurations;\n });\n return claimsConfigurations;\n }\n\n /**\n * Get required config for submitting a claim.\n *\n * @param claim - The claim request to get the required config for.\n * @returns The required config for submitting the claim.\n */\n async getSubmitClaimConfig(\n claim: CreateClaimRequest,\n ): Promise<SubmitClaimConfig> {\n // Validate the claim before submitting it.\n this.#validateSubmitClaimRequest(claim);\n\n const headers = await this.messenger.call(\n `${SERVICE_NAME}:getRequestHeaders`,\n );\n const baseUrl = this.messenger.call(`${SERVICE_NAME}:getClaimsApiUrl`);\n const url = `${baseUrl}/claims`;\n\n return {\n data: claim,\n headers,\n method: 'POST',\n url,\n };\n }\n\n /**\n * Generate a signature for a claim.\n *\n * @param chainId - The chain id of the claim.\n * @param walletAddress - The impacted wallet address of the claim.\n * @returns The signature for the claim.\n */\n async generateClaimSignature(\n chainId: number,\n walletAddress: `0x${string}`,\n ): Promise<string> {\n // generate the message to be signed\n const { message } = await this.messenger.call(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n chainId,\n walletAddress,\n );\n\n // generate and parse the SIWE message\n const messageBytes = stringToBytes(message);\n const messageHex = bytesToHex(messageBytes);\n const siwe = detectSIWE({ data: messageHex });\n if (!siwe.isSIWEMessage) {\n throw new Error(ClaimsControllerErrorMessages.INVALID_SIGNATURE_MESSAGE);\n }\n\n // sign the message\n const signature = await this.messenger.call(\n 'KeyringController:signPersonalMessage',\n {\n data: message,\n from: walletAddress,\n siwe,\n },\n );\n\n return signature;\n }\n\n /**\n * Get the list of claims for the current user.\n *\n * @returns The list of claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n const claims = await this.messenger.call(`${SERVICE_NAME}:getClaims`);\n this.update((state) => {\n state.claims = claims;\n });\n return claims;\n }\n\n /**\n * Save a claim draft to the state.\n * If the draft name is not provided, a default name will be generated.\n * If the draft with the same id already exists, it will be updated.\n *\n * @param draft - The draft to save.\n * @returns The saved draft.\n */\n saveOrUpdateClaimDraft(draft: Partial<ClaimDraft>): ClaimDraft {\n const { drafts } = this.state;\n\n const isExistingDraft = drafts.some(\n (existingDraft) =>\n draft.draftId && existingDraft.draftId === draft.draftId,\n );\n\n if (isExistingDraft) {\n const updatedAt = new Date().toISOString();\n this.update((state) => {\n state.drafts = state.drafts.map((existingDraft) =>\n existingDraft.draftId === draft.draftId\n ? {\n ...existingDraft,\n ...draft,\n updatedAt,\n }\n : existingDraft,\n );\n });\n return { ...draft, updatedAt } as ClaimDraft;\n }\n\n // generate a new draft id, name and add it to the state\n const draftId = `draft-${Date.now()}`;\n\n const newDraft: ClaimDraft = {\n ...draft,\n draftId,\n updatedAt: new Date().toISOString(),\n };\n\n this.update((state) => {\n state.drafts.push(newDraft);\n });\n\n return newDraft;\n }\n\n /**\n * Get the list of claim drafts.\n *\n * @returns The list of claim drafts.\n */\n getClaimDrafts(): ClaimDraft[] {\n return this.state.drafts;\n }\n\n /**\n * Delete a claim draft from the state.\n *\n * @param draftId - The ID of the draft to delete.\n */\n deleteClaimDraft(draftId: string): void {\n this.update((state) => {\n state.drafts = state.drafts.filter((draft) => draft.draftId !== draftId);\n });\n }\n\n /**\n * Delete all claim drafts from the state.\n */\n deleteAllClaimDrafts(): void {\n this.update((state) => {\n state.drafts = [];\n });\n }\n\n /**\n * Clears the claims state and resets to default values.\n */\n clearState(): void {\n this.update(() => {\n return getDefaultClaimsControllerState();\n });\n }\n\n /**\n * Validate the claim before submitting it.\n *\n * @param claim - The claim to validate.\n */\n #validateSubmitClaimRequest(claim: CreateClaimRequest): void {\n const { claims: existingClaims } = this.state;\n const isClaimAlreadySubmitted = existingClaims.some(\n (existingClaim) => existingClaim.impactedTxHash === claim.impactedTxHash,\n );\n if (isClaimAlreadySubmitted) {\n throw new Error(ClaimsControllerErrorMessages.CLAIM_ALREADY_SUBMITTED);\n }\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=ClaimsService-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClaimsService-method-action-types.cjs","sourceRoot":"","sources":["../src/ClaimsService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ClaimsService } from './ClaimsService.js';\n\n/**\n * Fetch required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\nexport type ClaimsServiceFetchClaimsConfigurationsAction = {\n type: `ClaimsService:fetchClaimsConfigurations`;\n handler: ClaimsService['fetchClaimsConfigurations'];\n};\n\n/**\n * Get the claims for the current user.\n *\n * @returns The claims for the current user.\n */\nexport type ClaimsServiceGetClaimsAction = {\n type: `ClaimsService:getClaims`;\n handler: ClaimsService['getClaims'];\n};\n\n/**\n * Get the claim by id.\n *\n * @param id - The id of the claim to get.\n * @returns The claim by id.\n */\nexport type ClaimsServiceGetClaimByIdAction = {\n type: `ClaimsService:getClaimById`;\n handler: ClaimsService['getClaimById'];\n};\n\n/**\n * Generate a message to be signed by the user for the claim request.\n *\n * @param chainId - The chain id of the claim.\n * @param walletAddress - The impacted wallet address of the claim.\n * @returns The message for the claim signature.\n */\nexport type ClaimsServiceGenerateMessageForClaimSignatureAction = {\n type: `ClaimsService:generateMessageForClaimSignature`;\n handler: ClaimsService['generateMessageForClaimSignature'];\n};\n\n/**\n * Create the headers for the current request.\n *\n * @returns The headers for the current request.\n */\nexport type ClaimsServiceGetRequestHeadersAction = {\n type: `ClaimsService:getRequestHeaders`;\n handler: ClaimsService['getRequestHeaders'];\n};\n\n/**\n * Get the URL for the claims API for the current environment.\n *\n * @returns The URL for the claims API for the current environment.\n */\nexport type ClaimsServiceGetClaimsApiUrlAction = {\n type: `ClaimsService:getClaimsApiUrl`;\n handler: ClaimsService['getClaimsApiUrl'];\n};\n\n/**\n * Union of all ClaimsService action types.\n */\nexport type ClaimsServiceMethodActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction;\n"]}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { ClaimsService } from "./ClaimsService.cjs";
6
+ /**
7
+ * Fetch required configurations for the claims service.
8
+ *
9
+ * @returns The required configurations for the claims service.
10
+ */
11
+ export type ClaimsServiceFetchClaimsConfigurationsAction = {
12
+ type: `ClaimsService:fetchClaimsConfigurations`;
13
+ handler: ClaimsService['fetchClaimsConfigurations'];
14
+ };
15
+ /**
16
+ * Get the claims for the current user.
17
+ *
18
+ * @returns The claims for the current user.
19
+ */
20
+ export type ClaimsServiceGetClaimsAction = {
21
+ type: `ClaimsService:getClaims`;
22
+ handler: ClaimsService['getClaims'];
23
+ };
24
+ /**
25
+ * Get the claim by id.
26
+ *
27
+ * @param id - The id of the claim to get.
28
+ * @returns The claim by id.
29
+ */
30
+ export type ClaimsServiceGetClaimByIdAction = {
31
+ type: `ClaimsService:getClaimById`;
32
+ handler: ClaimsService['getClaimById'];
33
+ };
34
+ /**
35
+ * Generate a message to be signed by the user for the claim request.
36
+ *
37
+ * @param chainId - The chain id of the claim.
38
+ * @param walletAddress - The impacted wallet address of the claim.
39
+ * @returns The message for the claim signature.
40
+ */
41
+ export type ClaimsServiceGenerateMessageForClaimSignatureAction = {
42
+ type: `ClaimsService:generateMessageForClaimSignature`;
43
+ handler: ClaimsService['generateMessageForClaimSignature'];
44
+ };
45
+ /**
46
+ * Create the headers for the current request.
47
+ *
48
+ * @returns The headers for the current request.
49
+ */
50
+ export type ClaimsServiceGetRequestHeadersAction = {
51
+ type: `ClaimsService:getRequestHeaders`;
52
+ handler: ClaimsService['getRequestHeaders'];
53
+ };
54
+ /**
55
+ * Get the URL for the claims API for the current environment.
56
+ *
57
+ * @returns The URL for the claims API for the current environment.
58
+ */
59
+ export type ClaimsServiceGetClaimsApiUrlAction = {
60
+ type: `ClaimsService:getClaimsApiUrl`;
61
+ handler: ClaimsService['getClaimsApiUrl'];
62
+ };
63
+ /**
64
+ * Union of all ClaimsService action types.
65
+ */
66
+ export type ClaimsServiceMethodActions = ClaimsServiceFetchClaimsConfigurationsAction | ClaimsServiceGetClaimsAction | ClaimsServiceGetClaimByIdAction | ClaimsServiceGenerateMessageForClaimSignatureAction | ClaimsServiceGetRequestHeadersAction | ClaimsServiceGetClaimsApiUrlAction;
67
+ //# sourceMappingURL=ClaimsService-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClaimsService-method-action-types.d.cts","sourceRoot":"","sources":["../src/ClaimsService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,4BAA2B;AAExD;;;;GAIG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,aAAa,CAAC,2BAA2B,CAAC,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACrC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,mDAAmD,GAAG;IAChE,IAAI,EAAE,gDAAgD,CAAC;IACvD,OAAO,EAAE,aAAa,CAAC,kCAAkC,CAAC,CAAC;CAC5D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAClC,4CAA4C,GAC5C,4BAA4B,GAC5B,+BAA+B,GAC/B,mDAAmD,GACnD,oCAAoC,GACpC,kCAAkC,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { ClaimsService } from "./ClaimsService.mjs";
6
+ /**
7
+ * Fetch required configurations for the claims service.
8
+ *
9
+ * @returns The required configurations for the claims service.
10
+ */
11
+ export type ClaimsServiceFetchClaimsConfigurationsAction = {
12
+ type: `ClaimsService:fetchClaimsConfigurations`;
13
+ handler: ClaimsService['fetchClaimsConfigurations'];
14
+ };
15
+ /**
16
+ * Get the claims for the current user.
17
+ *
18
+ * @returns The claims for the current user.
19
+ */
20
+ export type ClaimsServiceGetClaimsAction = {
21
+ type: `ClaimsService:getClaims`;
22
+ handler: ClaimsService['getClaims'];
23
+ };
24
+ /**
25
+ * Get the claim by id.
26
+ *
27
+ * @param id - The id of the claim to get.
28
+ * @returns The claim by id.
29
+ */
30
+ export type ClaimsServiceGetClaimByIdAction = {
31
+ type: `ClaimsService:getClaimById`;
32
+ handler: ClaimsService['getClaimById'];
33
+ };
34
+ /**
35
+ * Generate a message to be signed by the user for the claim request.
36
+ *
37
+ * @param chainId - The chain id of the claim.
38
+ * @param walletAddress - The impacted wallet address of the claim.
39
+ * @returns The message for the claim signature.
40
+ */
41
+ export type ClaimsServiceGenerateMessageForClaimSignatureAction = {
42
+ type: `ClaimsService:generateMessageForClaimSignature`;
43
+ handler: ClaimsService['generateMessageForClaimSignature'];
44
+ };
45
+ /**
46
+ * Create the headers for the current request.
47
+ *
48
+ * @returns The headers for the current request.
49
+ */
50
+ export type ClaimsServiceGetRequestHeadersAction = {
51
+ type: `ClaimsService:getRequestHeaders`;
52
+ handler: ClaimsService['getRequestHeaders'];
53
+ };
54
+ /**
55
+ * Get the URL for the claims API for the current environment.
56
+ *
57
+ * @returns The URL for the claims API for the current environment.
58
+ */
59
+ export type ClaimsServiceGetClaimsApiUrlAction = {
60
+ type: `ClaimsService:getClaimsApiUrl`;
61
+ handler: ClaimsService['getClaimsApiUrl'];
62
+ };
63
+ /**
64
+ * Union of all ClaimsService action types.
65
+ */
66
+ export type ClaimsServiceMethodActions = ClaimsServiceFetchClaimsConfigurationsAction | ClaimsServiceGetClaimsAction | ClaimsServiceGetClaimByIdAction | ClaimsServiceGenerateMessageForClaimSignatureAction | ClaimsServiceGetRequestHeadersAction | ClaimsServiceGetClaimsApiUrlAction;
67
+ //# sourceMappingURL=ClaimsService-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClaimsService-method-action-types.d.mts","sourceRoot":"","sources":["../src/ClaimsService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,4BAA2B;AAExD;;;;GAIG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,aAAa,CAAC,2BAA2B,CAAC,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACrC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,mDAAmD,GAAG;IAChE,IAAI,EAAE,gDAAgD,CAAC;IACvD,OAAO,EAAE,aAAa,CAAC,kCAAkC,CAAC,CAAC;CAC5D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAClC,4CAA4C,GAC5C,4BAA4B,GAC5B,+BAA+B,GAC/B,mDAAmD,GACnD,oCAAoC,GACpC,kCAAkC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=ClaimsService-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClaimsService-method-action-types.mjs","sourceRoot":"","sources":["../src/ClaimsService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ClaimsService } from './ClaimsService.js';\n\n/**\n * Fetch required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\nexport type ClaimsServiceFetchClaimsConfigurationsAction = {\n type: `ClaimsService:fetchClaimsConfigurations`;\n handler: ClaimsService['fetchClaimsConfigurations'];\n};\n\n/**\n * Get the claims for the current user.\n *\n * @returns The claims for the current user.\n */\nexport type ClaimsServiceGetClaimsAction = {\n type: `ClaimsService:getClaims`;\n handler: ClaimsService['getClaims'];\n};\n\n/**\n * Get the claim by id.\n *\n * @param id - The id of the claim to get.\n * @returns The claim by id.\n */\nexport type ClaimsServiceGetClaimByIdAction = {\n type: `ClaimsService:getClaimById`;\n handler: ClaimsService['getClaimById'];\n};\n\n/**\n * Generate a message to be signed by the user for the claim request.\n *\n * @param chainId - The chain id of the claim.\n * @param walletAddress - The impacted wallet address of the claim.\n * @returns The message for the claim signature.\n */\nexport type ClaimsServiceGenerateMessageForClaimSignatureAction = {\n type: `ClaimsService:generateMessageForClaimSignature`;\n handler: ClaimsService['generateMessageForClaimSignature'];\n};\n\n/**\n * Create the headers for the current request.\n *\n * @returns The headers for the current request.\n */\nexport type ClaimsServiceGetRequestHeadersAction = {\n type: `ClaimsService:getRequestHeaders`;\n handler: ClaimsService['getRequestHeaders'];\n};\n\n/**\n * Get the URL for the claims API for the current environment.\n *\n * @returns The URL for the claims API for the current environment.\n */\nexport type ClaimsServiceGetClaimsApiUrlAction = {\n type: `ClaimsService:getClaimsApiUrl`;\n handler: ClaimsService['getClaimsApiUrl'];\n};\n\n/**\n * Union of all ClaimsService action types.\n */\nexport type ClaimsServiceMethodActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction;\n"]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenerateSignatureMessageResponseStruct = exports.ClaimsConfigurationsResponseStruct = exports.ClaimStruct = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ const constants_js_1 = require("./constants.cjs");
6
+ const HexStringStruct = (0, superstruct_1.string)();
7
+ const AttachmentStruct = (0, superstruct_1.type)({
8
+ publicUrl: (0, superstruct_1.string)(),
9
+ contentType: (0, superstruct_1.string)(),
10
+ originalname: (0, superstruct_1.string)(),
11
+ });
12
+ exports.ClaimStruct = (0, superstruct_1.type)({
13
+ id: (0, superstruct_1.string)(),
14
+ shortId: (0, superstruct_1.string)(),
15
+ chainId: (0, superstruct_1.string)(),
16
+ email: (0, superstruct_1.string)(),
17
+ impactedWalletAddress: HexStringStruct,
18
+ impactedTxHash: HexStringStruct,
19
+ reimbursementWalletAddress: HexStringStruct,
20
+ description: (0, superstruct_1.string)(),
21
+ signature: HexStringStruct,
22
+ attachments: (0, superstruct_1.optional)((0, superstruct_1.array)(AttachmentStruct)),
23
+ status: (0, superstruct_1.enums)(Object.values(constants_js_1.ClaimStatusEnum)),
24
+ createdAt: (0, superstruct_1.string)(),
25
+ updatedAt: (0, superstruct_1.string)(),
26
+ intercomId: (0, superstruct_1.optional)((0, superstruct_1.string)()),
27
+ });
28
+ exports.ClaimsConfigurationsResponseStruct = (0, superstruct_1.type)({
29
+ validSubmissionWindowDays: (0, superstruct_1.integer)(),
30
+ networks: (0, superstruct_1.array)((0, superstruct_1.integer)()),
31
+ });
32
+ exports.GenerateSignatureMessageResponseStruct = (0, superstruct_1.type)({
33
+ message: (0, superstruct_1.string)(),
34
+ nonce: (0, superstruct_1.string)(),
35
+ });
36
+ //# sourceMappingURL=ClaimsService-structs.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClaimsService-structs.cjs","sourceRoot":"","sources":["../src/ClaimsService-structs.ts"],"names":[],"mappings":";;;AAAA,uDAO+B;AAE/B,kDAAiD;AAEjD,MAAM,eAAe,GAAG,IAAA,oBAAM,GAAE,CAAC;AAEjC,MAAM,gBAAgB,GAAG,IAAA,kBAAI,EAAC;IAC5B,SAAS,EAAE,IAAA,oBAAM,GAAE;IACnB,WAAW,EAAE,IAAA,oBAAM,GAAE;IACrB,YAAY,EAAE,IAAA,oBAAM,GAAE;CACvB,CAAC,CAAC;AAEU,QAAA,WAAW,GAAG,IAAA,kBAAI,EAAC;IAC9B,EAAE,EAAE,IAAA,oBAAM,GAAE;IACZ,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,KAAK,EAAE,IAAA,oBAAM,GAAE;IACf,qBAAqB,EAAE,eAAe;IACtC,cAAc,EAAE,eAAe;IAC/B,0BAA0B,EAAE,eAAe;IAC3C,WAAW,EAAE,IAAA,oBAAM,GAAE;IACrB,SAAS,EAAE,eAAe;IAC1B,WAAW,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,gBAAgB,CAAC,CAAC;IAC9C,MAAM,EAAE,IAAA,mBAAK,EAAC,MAAM,CAAC,MAAM,CAAC,8BAAe,CAAC,CAAC;IAC7C,SAAS,EAAE,IAAA,oBAAM,GAAE;IACnB,SAAS,EAAE,IAAA,oBAAM,GAAE;IACnB,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC/B,CAAC,CAAC;AAEU,QAAA,kCAAkC,GAAG,IAAA,kBAAI,EAAC;IACrD,yBAAyB,EAAE,IAAA,qBAAO,GAAE;IACpC,QAAQ,EAAE,IAAA,mBAAK,EAAC,IAAA,qBAAO,GAAE,CAAC;CAC3B,CAAC,CAAC;AAEU,QAAA,sCAAsC,GAAG,IAAA,kBAAI,EAAC;IACzD,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,KAAK,EAAE,IAAA,oBAAM,GAAE;CAChB,CAAC,CAAC","sourcesContent":["import {\n array,\n enums,\n integer,\n optional,\n string,\n type,\n} from '@metamask/superstruct';\n\nimport { ClaimStatusEnum } from './constants.js';\n\nconst HexStringStruct = string();\n\nconst AttachmentStruct = type({\n publicUrl: string(),\n contentType: string(),\n originalname: string(),\n});\n\nexport const ClaimStruct = type({\n id: string(),\n shortId: string(),\n chainId: string(),\n email: string(),\n impactedWalletAddress: HexStringStruct,\n impactedTxHash: HexStringStruct,\n reimbursementWalletAddress: HexStringStruct,\n description: string(),\n signature: HexStringStruct,\n attachments: optional(array(AttachmentStruct)),\n status: enums(Object.values(ClaimStatusEnum)),\n createdAt: string(),\n updatedAt: string(),\n intercomId: optional(string()),\n});\n\nexport const ClaimsConfigurationsResponseStruct = type({\n validSubmissionWindowDays: integer(),\n networks: array(integer()),\n});\n\nexport const GenerateSignatureMessageResponseStruct = type({\n message: string(),\n nonce: string(),\n});\n"]}
@@ -0,0 +1,71 @@
1
+ import { ClaimStatusEnum } from "./constants.cjs";
2
+ export declare const ClaimStruct: import("@metamask/superstruct").Struct<{
3
+ id: string;
4
+ shortId: string;
5
+ chainId: string;
6
+ email: string;
7
+ impactedWalletAddress: string;
8
+ impactedTxHash: string;
9
+ reimbursementWalletAddress: string;
10
+ description: string;
11
+ signature: string;
12
+ status: ClaimStatusEnum;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ attachments?: {
16
+ publicUrl: string;
17
+ contentType: string;
18
+ originalname: string;
19
+ }[] | undefined;
20
+ intercomId?: string | undefined;
21
+ }, {
22
+ id: import("@metamask/superstruct").Struct<string, null>;
23
+ shortId: import("@metamask/superstruct").Struct<string, null>;
24
+ chainId: import("@metamask/superstruct").Struct<string, null>;
25
+ email: import("@metamask/superstruct").Struct<string, null>;
26
+ impactedWalletAddress: import("@metamask/superstruct").Struct<string, null>;
27
+ impactedTxHash: import("@metamask/superstruct").Struct<string, null>;
28
+ reimbursementWalletAddress: import("@metamask/superstruct").Struct<string, null>;
29
+ description: import("@metamask/superstruct").Struct<string, null>;
30
+ signature: import("@metamask/superstruct").Struct<string, null>;
31
+ attachments: import("@metamask/superstruct").Struct<{
32
+ publicUrl: string;
33
+ contentType: string;
34
+ originalname: string;
35
+ }[] | undefined, import("@metamask/superstruct").Struct<{
36
+ publicUrl: string;
37
+ contentType: string;
38
+ originalname: string;
39
+ }, {
40
+ publicUrl: import("@metamask/superstruct").Struct<string, null>;
41
+ contentType: import("@metamask/superstruct").Struct<string, null>;
42
+ originalname: import("@metamask/superstruct").Struct<string, null>;
43
+ }>>;
44
+ status: import("@metamask/superstruct").Struct<ClaimStatusEnum, {
45
+ created: ClaimStatusEnum.CREATED;
46
+ submitted: ClaimStatusEnum.SUBMITTED;
47
+ in_progress: ClaimStatusEnum.IN_PROGRESS;
48
+ waiting_for_customer: ClaimStatusEnum.WAITING_FOR_CUSTOMER;
49
+ approved: ClaimStatusEnum.APPROVED;
50
+ rejected: ClaimStatusEnum.REJECTED;
51
+ unknown: ClaimStatusEnum.UNKNOWN;
52
+ }>;
53
+ createdAt: import("@metamask/superstruct").Struct<string, null>;
54
+ updatedAt: import("@metamask/superstruct").Struct<string, null>;
55
+ intercomId: import("@metamask/superstruct").Struct<string | undefined, null>;
56
+ }>;
57
+ export declare const ClaimsConfigurationsResponseStruct: import("@metamask/superstruct").Struct<{
58
+ validSubmissionWindowDays: number;
59
+ networks: number[];
60
+ }, {
61
+ validSubmissionWindowDays: import("@metamask/superstruct").Struct<number, null>;
62
+ networks: import("@metamask/superstruct").Struct<number[], import("@metamask/superstruct").Struct<number, null>>;
63
+ }>;
64
+ export declare const GenerateSignatureMessageResponseStruct: import("@metamask/superstruct").Struct<{
65
+ message: string;
66
+ nonce: string;
67
+ }, {
68
+ message: import("@metamask/superstruct").Struct<string, null>;
69
+ nonce: import("@metamask/superstruct").Struct<string, null>;
70
+ }>;
71
+ //# sourceMappingURL=ClaimsService-structs.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClaimsService-structs.d.cts","sourceRoot":"","sources":["../src/ClaimsService-structs.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,wBAAuB;AAUjD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAetB,CAAC;AAEH,eAAO,MAAM,kCAAkC;;;;;;EAG7C,CAAC;AAEH,eAAO,MAAM,sCAAsC;;;;;;EAGjD,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { ClaimStatusEnum } from "./constants.mjs";
2
+ export declare const ClaimStruct: import("@metamask/superstruct").Struct<{
3
+ id: string;
4
+ shortId: string;
5
+ chainId: string;
6
+ email: string;
7
+ impactedWalletAddress: string;
8
+ impactedTxHash: string;
9
+ reimbursementWalletAddress: string;
10
+ description: string;
11
+ signature: string;
12
+ status: ClaimStatusEnum;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ attachments?: {
16
+ publicUrl: string;
17
+ contentType: string;
18
+ originalname: string;
19
+ }[] | undefined;
20
+ intercomId?: string | undefined;
21
+ }, {
22
+ id: import("@metamask/superstruct").Struct<string, null>;
23
+ shortId: import("@metamask/superstruct").Struct<string, null>;
24
+ chainId: import("@metamask/superstruct").Struct<string, null>;
25
+ email: import("@metamask/superstruct").Struct<string, null>;
26
+ impactedWalletAddress: import("@metamask/superstruct").Struct<string, null>;
27
+ impactedTxHash: import("@metamask/superstruct").Struct<string, null>;
28
+ reimbursementWalletAddress: import("@metamask/superstruct").Struct<string, null>;
29
+ description: import("@metamask/superstruct").Struct<string, null>;
30
+ signature: import("@metamask/superstruct").Struct<string, null>;
31
+ attachments: import("@metamask/superstruct").Struct<{
32
+ publicUrl: string;
33
+ contentType: string;
34
+ originalname: string;
35
+ }[] | undefined, import("@metamask/superstruct").Struct<{
36
+ publicUrl: string;
37
+ contentType: string;
38
+ originalname: string;
39
+ }, {
40
+ publicUrl: import("@metamask/superstruct").Struct<string, null>;
41
+ contentType: import("@metamask/superstruct").Struct<string, null>;
42
+ originalname: import("@metamask/superstruct").Struct<string, null>;
43
+ }>>;
44
+ status: import("@metamask/superstruct").Struct<ClaimStatusEnum, {
45
+ created: ClaimStatusEnum.CREATED;
46
+ submitted: ClaimStatusEnum.SUBMITTED;
47
+ in_progress: ClaimStatusEnum.IN_PROGRESS;
48
+ waiting_for_customer: ClaimStatusEnum.WAITING_FOR_CUSTOMER;
49
+ approved: ClaimStatusEnum.APPROVED;
50
+ rejected: ClaimStatusEnum.REJECTED;
51
+ unknown: ClaimStatusEnum.UNKNOWN;
52
+ }>;
53
+ createdAt: import("@metamask/superstruct").Struct<string, null>;
54
+ updatedAt: import("@metamask/superstruct").Struct<string, null>;
55
+ intercomId: import("@metamask/superstruct").Struct<string | undefined, null>;
56
+ }>;
57
+ export declare const ClaimsConfigurationsResponseStruct: import("@metamask/superstruct").Struct<{
58
+ validSubmissionWindowDays: number;
59
+ networks: number[];
60
+ }, {
61
+ validSubmissionWindowDays: import("@metamask/superstruct").Struct<number, null>;
62
+ networks: import("@metamask/superstruct").Struct<number[], import("@metamask/superstruct").Struct<number, null>>;
63
+ }>;
64
+ export declare const GenerateSignatureMessageResponseStruct: import("@metamask/superstruct").Struct<{
65
+ message: string;
66
+ nonce: string;
67
+ }, {
68
+ message: import("@metamask/superstruct").Struct<string, null>;
69
+ nonce: import("@metamask/superstruct").Struct<string, null>;
70
+ }>;
71
+ //# sourceMappingURL=ClaimsService-structs.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClaimsService-structs.d.mts","sourceRoot":"","sources":["../src/ClaimsService-structs.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,wBAAuB;AAUjD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAetB,CAAC;AAEH,eAAO,MAAM,kCAAkC;;;;;;EAG7C,CAAC;AAEH,eAAO,MAAM,sCAAsC;;;;;;EAGjD,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { array, enums, integer, optional, string, type } from "@metamask/superstruct";
2
+ import { ClaimStatusEnum } from "./constants.mjs";
3
+ const HexStringStruct = string();
4
+ const AttachmentStruct = type({
5
+ publicUrl: string(),
6
+ contentType: string(),
7
+ originalname: string(),
8
+ });
9
+ export const ClaimStruct = type({
10
+ id: string(),
11
+ shortId: string(),
12
+ chainId: string(),
13
+ email: string(),
14
+ impactedWalletAddress: HexStringStruct,
15
+ impactedTxHash: HexStringStruct,
16
+ reimbursementWalletAddress: HexStringStruct,
17
+ description: string(),
18
+ signature: HexStringStruct,
19
+ attachments: optional(array(AttachmentStruct)),
20
+ status: enums(Object.values(ClaimStatusEnum)),
21
+ createdAt: string(),
22
+ updatedAt: string(),
23
+ intercomId: optional(string()),
24
+ });
25
+ export const ClaimsConfigurationsResponseStruct = type({
26
+ validSubmissionWindowDays: integer(),
27
+ networks: array(integer()),
28
+ });
29
+ export const GenerateSignatureMessageResponseStruct = type({
30
+ message: string(),
31
+ nonce: string(),
32
+ });
33
+ //# sourceMappingURL=ClaimsService-structs.mjs.map