@metamask-previews/claims-controller 0.2.0-preview-9379dbe4 → 0.2.0-preview-de995bed

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.
@@ -137,7 +137,6 @@ class ClaimsController extends base_controller_1.BaseController {
137
137
  */
138
138
  saveOrUpdateClaimDraft(draft) {
139
139
  const { drafts } = this.state;
140
- const draftCount = drafts.length;
141
140
  const isExistingDraft = drafts.some((existingDraft) => draft.draftId && existingDraft.draftId === draft.draftId);
142
141
  if (isExistingDraft) {
143
142
  this.update((state) => {
@@ -148,12 +147,10 @@ class ClaimsController extends base_controller_1.BaseController {
148
147
  return draft;
149
148
  }
150
149
  // generate a new draft id, name and add it to the state
151
- const draftId = `claims-draft-${Date.now()}`;
152
- const draftName = draft.draftName ?? `Draft ${draftCount + 1}`;
150
+ const draftId = `draft-${Date.now()}`;
153
151
  const newDraft = {
154
152
  ...draft,
155
153
  draftId,
156
- draftName,
157
154
  };
158
155
  this.update((state) => {
159
156
  state.drafts.push(newDraft);
@@ -1 +1 @@
1
- {"version":3,"file":"ClaimsController.cjs","sourceRoot":"","sources":["../src/ClaimsController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAC3D,iEAA+D;AAG/D,2CAA4D;AAU5D,+CAKqB;AA2CrB,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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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;CAgBF;AA5MD,4CA4MC;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,yCAA6B,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 {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetRequestHeadersAction,\n} from './ClaimsService';\nimport {\n ClaimsControllerErrorMessages,\n CONTROLLER_NAME,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n SERVICE_NAME,\n} from './constants';\nimport type {\n Claim,\n ClaimDraft,\n ClaimsConfigurations,\n ClaimsControllerState,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types';\n\nexport type ClaimsControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerActions = ClaimsControllerGetStateAction;\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\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\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 const draftCount = drafts.length;\n\n const isExistingDraft = drafts.some(\n (existingDraft) =>\n draft.draftId && existingDraft.draftId === draft.draftId,\n );\n\n if (isExistingDraft) {\n this.update((state) => {\n state.drafts = state.drafts.map((existingDraft) =>\n existingDraft.draftId === draft.draftId\n ? { ...existingDraft, ...draft }\n : existingDraft,\n );\n });\n return draft as ClaimDraft;\n }\n\n // generate a new draft id, name and add it to the state\n const draftId = `claims-draft-${Date.now()}`;\n const draftName = draft.draftName ?? `Draft ${draftCount + 1}`;\n\n const newDraft: ClaimDraft = {\n ...draft,\n draftId,\n draftName,\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 * 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;AAU5D,+CAKqB;AA2CrB,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,yCAA6B;QACnD,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE;KACX,CAAC;AACJ,CAAC;AAND,0EAMC;AAED,MAAa,gBAAiB,SAAQ,gCAIrC;IACC,YAAY,EAAE,SAAS,EAAE,KAAK,EAA2B;QACvD,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,6BAA6B;YACvC,IAAI,EAAE,2BAAe;YACrB,KAAK,EAAE,EAAE,GAAG,+BAA+B,EAAE,EAAE,GAAG,KAAK,EAAE;SA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AAK,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,yCAA6B,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 {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetRequestHeadersAction,\n} from './ClaimsService';\nimport {\n ClaimsControllerErrorMessages,\n CONTROLLER_NAME,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n SERVICE_NAME,\n} from './constants';\nimport type {\n Claim,\n ClaimDraft,\n ClaimsConfigurations,\n ClaimsControllerState,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types';\n\nexport type ClaimsControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerActions = ClaimsControllerGetStateAction;\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\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\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 this.update((state) => {\n state.drafts = state.drafts.map((existingDraft) =>\n existingDraft.draftId === draft.draftId\n ? { ...existingDraft, ...draft }\n : existingDraft,\n );\n });\n return draft 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 };\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 * 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 +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,EACV,4CAA4C,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UAAU,EAAE;IAI9B;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMvC;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAoB7B"}
@@ -133,7 +133,6 @@ export class ClaimsController extends BaseController {
133
133
  */
134
134
  saveOrUpdateClaimDraft(draft) {
135
135
  const { drafts } = this.state;
136
- const draftCount = drafts.length;
137
136
  const isExistingDraft = drafts.some((existingDraft) => draft.draftId && existingDraft.draftId === draft.draftId);
138
137
  if (isExistingDraft) {
139
138
  this.update((state) => {
@@ -144,12 +143,10 @@ export class ClaimsController extends BaseController {
144
143
  return draft;
145
144
  }
146
145
  // generate a new draft id, name and add it to the state
147
- const draftId = `claims-draft-${Date.now()}`;
148
- const draftName = draft.draftName ?? `Draft ${draftCount + 1}`;
146
+ const draftId = `draft-${Date.now()}`;
149
147
  const newDraft = {
150
148
  ...draft,
151
149
  draftId,
152
- draftName,
153
150
  };
154
151
  this.update((state) => {
155
152
  state.drafts.push(newDraft);
@@ -1 +1 @@
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;AAU5D,OAAO,EACL,6BAA6B,EAC7B,eAAe,EACf,6BAA6B,EAC7B,YAAY,EACb,wBAAoB;AA2CrB,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,M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;IAClB,CAAC;IAED;;;;OAIG;IACH,cAAc;QACZ,OAAO,IAAI,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;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 {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetRequestHeadersAction,\n} from './ClaimsService';\nimport {\n ClaimsControllerErrorMessages,\n CONTROLLER_NAME,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n SERVICE_NAME,\n} from './constants';\nimport type {\n Claim,\n ClaimDraft,\n ClaimsConfigurations,\n ClaimsControllerState,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types';\n\nexport type ClaimsControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerActions = ClaimsControllerGetStateAction;\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\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\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 const draftCount = drafts.length;\n\n const isExistingDraft = drafts.some(\n (existingDraft) =>\n draft.draftId && existingDraft.draftId === draft.draftId,\n );\n\n if (isExistingDraft) {\n this.update((state) => {\n state.drafts = state.drafts.map((existingDraft) =>\n existingDraft.draftId === draft.draftId\n ? { ...existingDraft, ...draft }\n : existingDraft,\n );\n });\n return draft as ClaimDraft;\n }\n\n // generate a new draft id, name and add it to the state\n const draftId = `claims-draft-${Date.now()}`;\n const draftName = draft.draftName ?? `Draft ${draftCount + 1}`;\n\n const newDraft: ClaimDraft = {\n ...draft,\n draftId,\n draftName,\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 * 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;AAU5D,OAAO,EACL,6BAA6B,EAC7B,eAAe,EACf,6BAA6B,EAC7B,YAAY,EACb,wBAAoB;AA2CrB,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;AA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,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;QACpB,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 {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetRequestHeadersAction,\n} from './ClaimsService';\nimport {\n ClaimsControllerErrorMessages,\n CONTROLLER_NAME,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n SERVICE_NAME,\n} from './constants';\nimport type {\n Claim,\n ClaimDraft,\n ClaimsConfigurations,\n ClaimsControllerState,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types';\n\nexport type ClaimsControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n ClaimsControllerState\n>;\n\nexport type ClaimsControllerActions = ClaimsControllerGetStateAction;\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\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\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 this.update((state) => {\n state.drafts = state.drafts.map((existingDraft) =>\n existingDraft.draftId === draft.draftId\n ? { ...existingDraft, ...draft }\n : existingDraft,\n );\n });\n return draft 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 };\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 * 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 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { ClaimStatusEnum } from './constants';\n\nexport type Attachment = {\n publicUrl: string;\n contentType: string;\n originalname: string;\n};\n\nexport type ClaimsConfigurations = {\n /**\n * The number of days the claim is valid for submission.\n */\n validSubmissionWindowDays: number;\n\n /**\n * List of supported chain IDs in hexadecimal format.\n */\n supportedNetworks: `0x${string}`[];\n};\n\nexport type ClaimsConfigurationsResponse = Omit<\n ClaimsConfigurations,\n 'supportedNetworks'\n> & {\n /**\n * List of supported chain IDs.\n * Claims API response for `supportedNetworks` field (in decimal format).\n */\n networks: number[];\n};\n\nexport type Claim = {\n id: string;\n shortId: string;\n chainId: string;\n email: string;\n impactedWalletAddress: Hex;\n impactedTxHash: Hex;\n reimbursementWalletAddress: Hex;\n description: string;\n signature: Hex;\n attachments?: Attachment[];\n status: ClaimStatusEnum;\n createdAt: string;\n updatedAt: string;\n intercomId?: string;\n};\n\nexport type ClaimDraft = Partial<\n Omit<\n Claim,\n | 'id'\n | 'shortId'\n | 'createdAt'\n | 'updatedAt'\n | 'intercomId'\n | 'status'\n | 'attachments'\n >\n> & {\n /**\n * The draft ID.\n */\n draftId: string;\n /**\n * The draft name.\n */\n draftName?: string;\n};\n\nexport type CreateClaimRequest = Omit<\n Claim,\n 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'\n>;\n\nexport type ClaimsControllerState = {\n /**\n * List of claims.\n */\n claims: Claim[];\n\n /**\n * The claims configurations.\n * This is used to store the claims configurations fetched from the backend.\n */\n claimsConfigurations: ClaimsConfigurations;\n\n /**\n * List of claim drafts before submission.\n */\n drafts: ClaimDraft[];\n};\n\nexport type SubmitClaimConfig = {\n /**\n * The sanitized and validated data to be submitted.\n */\n data: CreateClaimRequest;\n /**\n * The headers to be used in the request.\n */\n headers: Record<string, string>;\n /**\n * The HTTP method to submit.\n */\n method: 'POST';\n /**\n * The URL to submit the claim to.\n */\n url: string;\n};\n\nexport type GenerateSignatureMessageResponse = {\n message: string;\n nonce: string;\n};\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { ClaimStatusEnum } from './constants';\n\nexport type Attachment = {\n publicUrl: string;\n contentType: string;\n originalname: string;\n};\n\nexport type ClaimsConfigurations = {\n /**\n * The number of days the claim is valid for submission.\n */\n validSubmissionWindowDays: number;\n\n /**\n * List of supported chain IDs in hexadecimal format.\n */\n supportedNetworks: `0x${string}`[];\n};\n\nexport type ClaimsConfigurationsResponse = Omit<\n ClaimsConfigurations,\n 'supportedNetworks'\n> & {\n /**\n * List of supported chain IDs.\n * Claims API response for `supportedNetworks` field (in decimal format).\n */\n networks: number[];\n};\n\nexport type Claim = {\n id: string;\n shortId: string;\n chainId: string;\n email: string;\n impactedWalletAddress: Hex;\n impactedTxHash: Hex;\n reimbursementWalletAddress: Hex;\n description: string;\n signature: Hex;\n attachments?: Attachment[];\n status: ClaimStatusEnum;\n createdAt: string;\n updatedAt: string;\n intercomId?: string;\n};\n\nexport type ClaimDraft = Partial<\n Omit<\n Claim,\n | 'id'\n | 'shortId'\n | 'createdAt'\n | 'updatedAt'\n | 'intercomId'\n | 'status'\n | 'attachments'\n >\n> & {\n /**\n * The draft ID.\n */\n draftId: string;\n};\n\nexport type CreateClaimRequest = Omit<\n Claim,\n 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'\n>;\n\nexport type ClaimsControllerState = {\n /**\n * List of claims.\n */\n claims: Claim[];\n\n /**\n * The claims configurations.\n * This is used to store the claims configurations fetched from the backend.\n */\n claimsConfigurations: ClaimsConfigurations;\n\n /**\n * List of claim drafts before submission.\n */\n drafts: ClaimDraft[];\n};\n\nexport type SubmitClaimConfig = {\n /**\n * The sanitized and validated data to be submitted.\n */\n data: CreateClaimRequest;\n /**\n * The headers to be used in the request.\n */\n headers: Record<string, string>;\n /**\n * The HTTP method to submit.\n */\n method: 'POST';\n /**\n * The URL to submit the claim to.\n */\n url: string;\n};\n\nexport type GenerateSignatureMessageResponse = {\n message: string;\n nonce: string;\n};\n"]}
package/dist/types.d.cts CHANGED
@@ -43,10 +43,6 @@ export type ClaimDraft = Partial<Omit<Claim, 'id' | 'shortId' | 'createdAt' | 'u
43
43
  * The draft ID.
44
44
  */
45
45
  draftId: string;
46
- /**
47
- * The draft name.
48
- */
49
- draftName?: string;
50
46
  };
51
47
  export type CreateClaimRequest = Omit<Claim, 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'>;
52
48
  export type ClaimsControllerState = {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAoB;AAEnD,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAElC;;OAEG;IACH,iBAAiB,EAAE,KAAK,MAAM,EAAE,EAAE,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,oBAAoB,EACpB,mBAAmB,CACpB,GAAG;IACF;;;OAGG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,qBAAqB,EAAE,GAAG,CAAC;IAC3B,cAAc,EAAE,GAAG,CAAC;IACpB,0BAA0B,EAAE,GAAG,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,GAAG,CAAC;IACf,WAAW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AW,GAAG,WAAW,GAAG,YAAY,GAAG,QAAQ,CACvE,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB;;;OAGG;IACH,oBAAoB,EAAE,oBAAoB,CAAC;IAE3C;;OAEG;IACH,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,IAAI,EAAE,kBAAkB,CAAC;IACzB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
package/dist/types.d.mts CHANGED
@@ -43,10 +43,6 @@ export type ClaimDraft = Partial<Omit<Claim, 'id' | 'shortId' | 'createdAt' | 'u
43
43
  * The draft ID.
44
44
  */
45
45
  draftId: string;
46
- /**
47
- * The draft name.
48
- */
49
- draftName?: string;
50
46
  };
51
47
  export type CreateClaimRequest = Omit<Claim, 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'>;
52
48
  export type ClaimsControllerState = {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAoB;AAEnD,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IAC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","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { ClaimStatusEnum } from './constants';\n\nexport type Attachment = {\n publicUrl: string;\n contentType: string;\n originalname: string;\n};\n\nexport type ClaimsConfigurations = {\n /**\n * The number of days the claim is valid for submission.\n */\n validSubmissionWindowDays: number;\n\n /**\n * List of supported chain IDs in hexadecimal format.\n */\n supportedNetworks: `0x${string}`[];\n};\n\nexport type ClaimsConfigurationsResponse = Omit<\n ClaimsConfigurations,\n 'supportedNetworks'\n> & {\n /**\n * List of supported chain IDs.\n * Claims API response for `supportedNetworks` field (in decimal format).\n */\n networks: number[];\n};\n\nexport type Claim = {\n id: string;\n shortId: string;\n chainId: string;\n email: string;\n impactedWalletAddress: Hex;\n impactedTxHash: Hex;\n reimbursementWalletAddress: Hex;\n description: string;\n signature: Hex;\n attachments?: Attachment[];\n status: ClaimStatusEnum;\n createdAt: string;\n updatedAt: string;\n intercomId?: string;\n};\n\nexport type ClaimDraft = Partial<\n Omit<\n Claim,\n | 'id'\n | 'shortId'\n | 'createdAt'\n | 'updatedAt'\n | 'intercomId'\n | 'status'\n | 'attachments'\n >\n> & {\n /**\n * The draft ID.\n */\n draftId: string;\n /**\n * The draft name.\n */\n draftName?: string;\n};\n\nexport type CreateClaimRequest = Omit<\n Claim,\n 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'\n>;\n\nexport type ClaimsControllerState = {\n /**\n * List of claims.\n */\n claims: Claim[];\n\n /**\n * The claims configurations.\n * This is used to store the claims configurations fetched from the backend.\n */\n claimsConfigurations: ClaimsConfigurations;\n\n /**\n * List of claim drafts before submission.\n */\n drafts: ClaimDraft[];\n};\n\nexport type SubmitClaimConfig = {\n /**\n * The sanitized and validated data to be submitted.\n */\n data: CreateClaimRequest;\n /**\n * The headers to be used in the request.\n */\n headers: Record<string, string>;\n /**\n * The HTTP method to submit.\n */\n method: 'POST';\n /**\n * The URL to submit the claim to.\n */\n url: string;\n};\n\nexport type GenerateSignatureMessageResponse = {\n message: string;\n nonce: string;\n};\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { ClaimStatusEnum } from './constants';\n\nexport type Attachment = {\n publicUrl: string;\n contentType: string;\n originalname: string;\n};\n\nexport type ClaimsConfigurations = {\n /**\n * The number of days the claim is valid for submission.\n */\n validSubmissionWindowDays: number;\n\n /**\n * List of supported chain IDs in hexadecimal format.\n */\n supportedNetworks: `0x${string}`[];\n};\n\nexport type ClaimsConfigurationsResponse = Omit<\n ClaimsConfigurations,\n 'supportedNetworks'\n> & {\n /**\n * List of supported chain IDs.\n * Claims API response for `supportedNetworks` field (in decimal format).\n */\n networks: number[];\n};\n\nexport type Claim = {\n id: string;\n shortId: string;\n chainId: string;\n email: string;\n impactedWalletAddress: Hex;\n impactedTxHash: Hex;\n reimbursementWalletAddress: Hex;\n description: string;\n signature: Hex;\n attachments?: Attachment[];\n status: ClaimStatusEnum;\n createdAt: string;\n updatedAt: string;\n intercomId?: string;\n};\n\nexport type ClaimDraft = Partial<\n Omit<\n Claim,\n | 'id'\n | 'shortId'\n | 'createdAt'\n | 'updatedAt'\n | 'intercomId'\n | 'status'\n | 'attachments'\n >\n> & {\n /**\n * The draft ID.\n */\n draftId: string;\n};\n\nexport type CreateClaimRequest = Omit<\n Claim,\n 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'\n>;\n\nexport type ClaimsControllerState = {\n /**\n * List of claims.\n */\n claims: Claim[];\n\n /**\n * The claims configurations.\n * This is used to store the claims configurations fetched from the backend.\n */\n claimsConfigurations: ClaimsConfigurations;\n\n /**\n * List of claim drafts before submission.\n */\n drafts: ClaimDraft[];\n};\n\nexport type SubmitClaimConfig = {\n /**\n * The sanitized and validated data to be submitted.\n */\n data: CreateClaimRequest;\n /**\n * The headers to be used in the request.\n */\n headers: Record<string, string>;\n /**\n * The HTTP method to submit.\n */\n method: 'POST';\n /**\n * The URL to submit the claim to.\n */\n url: string;\n};\n\nexport type GenerateSignatureMessageResponse = {\n message: string;\n nonce: string;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/claims-controller",
3
- "version": "0.2.0-preview-9379dbe4",
3
+ "version": "0.2.0-preview-de995bed",
4
4
  "description": "Controller handling shield subscription claims logic",
5
5
  "keywords": [
6
6
  "MetaMask",