@metamask/claims-controller 0.4.0 → 0.4.2
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.
- package/CHANGELOG.md +19 -1
- package/dist/ClaimsController.cjs +8 -0
- package/dist/ClaimsController.cjs.map +1 -1
- package/dist/ClaimsController.d.cts +4 -0
- package/dist/ClaimsController.d.cts.map +1 -1
- package/dist/ClaimsController.d.mts +4 -0
- package/dist/ClaimsController.d.mts.map +1 -1
- package/dist/ClaimsController.mjs +8 -0
- package/dist/ClaimsController.mjs.map +1 -1
- package/dist/ClaimsService.cjs +6 -4
- package/dist/ClaimsService.cjs.map +1 -1
- package/dist/ClaimsService.d.cts.map +1 -1
- package/dist/ClaimsService.d.mts.map +1 -1
- package/dist/ClaimsService.mjs +6 -4
- package/dist/ClaimsService.mjs.map +1 -1
- package/dist/logger.cjs +8 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +5 -0
- package/dist/logger.mjs.map +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.2]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Added new public method, `clearState` to clear/reset the claims controller state. ([#7780](https://github.com/MetaMask/core/pull/7780))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Bump `@metamask/controller-utils` from `^11.17.0` to `^11.18.0` ([#7583](https://github.com/MetaMask/core/pull/7583))
|
|
19
|
+
|
|
20
|
+
## [0.4.1]
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- Replaced global `console` logs with `ModuleLogger`. ([#7569](https://github.com/MetaMask/core/pull/7569))
|
|
25
|
+
|
|
10
26
|
## [0.4.0]
|
|
11
27
|
|
|
12
28
|
### Added
|
|
@@ -59,7 +75,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
59
75
|
- `generateMessageForClaimSignature`: generate message to sign for the claim signature.
|
|
60
76
|
- `verifyClaimSignature`: verify claim signature produced by user.
|
|
61
77
|
|
|
62
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.4.
|
|
78
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.4.2...HEAD
|
|
79
|
+
[0.4.2]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.4.1...@metamask/claims-controller@0.4.2
|
|
80
|
+
[0.4.1]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.4.0...@metamask/claims-controller@0.4.1
|
|
63
81
|
[0.4.0]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.3.1...@metamask/claims-controller@0.4.0
|
|
64
82
|
[0.3.1]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.3.0...@metamask/claims-controller@0.3.1
|
|
65
83
|
[0.3.0]: https://github.com/MetaMask/core/compare/@metamask/claims-controller@0.2.0...@metamask/claims-controller@0.3.0
|
|
@@ -189,6 +189,14 @@ class ClaimsController extends base_controller_1.BaseController {
|
|
|
189
189
|
state.drafts = [];
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Clears the claims state and resets to default values.
|
|
194
|
+
*/
|
|
195
|
+
clearState() {
|
|
196
|
+
this.update(() => {
|
|
197
|
+
return getDefaultClaimsControllerState();
|
|
198
|
+
});
|
|
199
|
+
}
|
|
192
200
|
}
|
|
193
201
|
exports.ClaimsController = ClaimsController;
|
|
194
202
|
_ClaimsController_instances = new WeakSet(), _ClaimsController_validateSubmitClaimRequest = function _ClaimsController_validateSubmitClaimRequest(cla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E,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 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 * 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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eEvent,\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 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"]}
|
|
@@ -75,5 +75,9 @@ export declare class ClaimsController extends BaseController<typeof CONTROLLER_N
|
|
|
75
75
|
* Delete all claim drafts from the state.
|
|
76
76
|
*/
|
|
77
77
|
deleteAllClaimDrafts(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Clears the claims state and resets to default values.
|
|
80
|
+
*/
|
|
81
|
+
clearState(): void;
|
|
78
82
|
}
|
|
79
83
|
//# sourceMappingURL=ClaimsController.d.cts.map
|
|
@@ -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,cAA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vC;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAM5B;;OAEG;IACH,UAAU,IAAI,IAAI;CAoBnB"}
|
|
@@ -75,5 +75,9 @@ export declare class ClaimsController extends BaseController<typeof CONTROLLER_N
|
|
|
75
75
|
* Delete all claim drafts from the state.
|
|
76
76
|
*/
|
|
77
77
|
deleteAllClaimDrafts(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Clears the claims state and resets to default values.
|
|
80
|
+
*/
|
|
81
|
+
clearState(): void;
|
|
78
82
|
}
|
|
79
83
|
//# sourceMappingURL=ClaimsController.d.mts.map
|
|
@@ -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,EACV,4CAA4C,EAC5C,mDAAmD,EACnD,+BAA+B,EAC/B,4BAA4B,EAC5B,kCAAkC,EAClC,oCAAoC,EACrC,4BAAwB;AACzB,OAAO,EAEL,eAAe,EAGhB,wBAAoB;AACrB,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EAClB,oBAAgB;AAEjB,MAAM,MAAM,8BAA8B,GAAG,wBAAwB,CACnE,OAAO,eAAe,EACtB,qBAAqB,CACtB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAErE,MAAM,MAAM,cAAc,GACtB,4CAA4C,GAC5C,4BAA4B,GAC5B,+BAA+B,GAC/B,oCAAoC,GACpC,kCAAkC,GAClC,mDAAmD,GACnD,4BAA4B,GAC5B,0CAA0C,CAAC;AAE/C,MA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BAAuB;IASzD;;;;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"}
|
|
@@ -185,6 +185,14 @@ export class ClaimsController extends BaseController {
|
|
|
185
185
|
state.drafts = [];
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Clears the claims state and resets to default values.
|
|
190
|
+
*/
|
|
191
|
+
clearState() {
|
|
192
|
+
this.update(() => {
|
|
193
|
+
return getDefaultClaimsControllerState();
|
|
194
|
+
});
|
|
195
|
+
}
|
|
188
196
|
}
|
|
189
197
|
_ClaimsController_instances = new WeakSet(), _ClaimsController_validateSubmitClaimRequest = function _ClaimsController_validateSubmitClaimRequest(claim) {
|
|
190
198
|
const { claims: existingClaims } = this.state;
|
|
@@ -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,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AC5B,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 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 * 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,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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 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"]}
|
package/dist/ClaimsService.cjs
CHANGED
|
@@ -14,7 +14,9 @@ var _ClaimsService_env, _ClaimsService_fetch, _ClaimsService_messenger;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ClaimsService = void 0;
|
|
16
16
|
const constants_1 = require("./constants.cjs");
|
|
17
|
+
const logger_1 = require("./logger.cjs");
|
|
17
18
|
const utils_1 = require("./utils.cjs");
|
|
19
|
+
const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'ClaimsService');
|
|
18
20
|
class ClaimsService {
|
|
19
21
|
constructor({ env, messenger, fetchFunction }) {
|
|
20
22
|
this.name = constants_1.SERVICE_NAME; // required for Modular Initialization
|
|
@@ -51,7 +53,7 @@ class ClaimsService {
|
|
|
51
53
|
return configurations;
|
|
52
54
|
}
|
|
53
55
|
catch (error) {
|
|
54
|
-
|
|
56
|
+
log('fetchClaimsConfigurations', error);
|
|
55
57
|
__classPrivateFieldGet(this, _ClaimsService_messenger, "f").captureException?.((0, utils_1.createSentryError)(constants_1.ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS, error));
|
|
56
58
|
throw new Error(constants_1.ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS);
|
|
57
59
|
}
|
|
@@ -76,7 +78,7 @@ class ClaimsService {
|
|
|
76
78
|
return claims;
|
|
77
79
|
}
|
|
78
80
|
catch (error) {
|
|
79
|
-
|
|
81
|
+
log('getClaims', error);
|
|
80
82
|
__classPrivateFieldGet(this, _ClaimsService_messenger, "f").captureException?.((0, utils_1.createSentryError)(constants_1.ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS, error));
|
|
81
83
|
throw new Error(constants_1.ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);
|
|
82
84
|
}
|
|
@@ -102,7 +104,7 @@ class ClaimsService {
|
|
|
102
104
|
return claim;
|
|
103
105
|
}
|
|
104
106
|
catch (error) {
|
|
105
|
-
|
|
107
|
+
log('getClaimById', error);
|
|
106
108
|
__classPrivateFieldGet(this, _ClaimsService_messenger, "f").captureException?.((0, utils_1.createSentryError)(constants_1.ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID, error));
|
|
107
109
|
throw new Error(constants_1.ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);
|
|
108
110
|
}
|
|
@@ -137,7 +139,7 @@ class ClaimsService {
|
|
|
137
139
|
return message;
|
|
138
140
|
}
|
|
139
141
|
catch (error) {
|
|
140
|
-
|
|
142
|
+
log('generateMessageForClaimSignature', error);
|
|
141
143
|
__classPrivateFieldGet(this, _ClaimsService_messenger, "f").captureException?.((0, utils_1.createSentryError)(constants_1.ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED, error));
|
|
142
144
|
throw new Error(constants_1.ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED);
|
|
143
145
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClaimsService.cjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,+CAIqB;AAOrB,uCAAkE;AAwDlE,MAAa,aAAa;IASxB,YAAY,EAAE,GAAG,EAAE,SAAS,EAAE,aAAa,EAAuB;QARzD,SAAI,GAAG,wBAAY,CAAC,CAAC,sCAAsC;QAE3D,qCAAU;QAEV,uCAAqB;QAErB,2CAAmC;QAG1C,uBAAA,IAAI,sBAAQ,GAAG,MAAA,CAAC;QAChB,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,wBAAU,aAAa,MAAA,CAAC;QAE5B,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,wBAAY,4BAA4B,EAC3C,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1C,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,wBAAY,YAAY,EAC3B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1B,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,wBAAY,eAAe,EAC9B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7B,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,wBAAY,oBAAoB,EACnC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,wBAAY,kBAAkB,EACjC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,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,CACF,CAAC;YACF,MAAM,IAAI,KAAK,CACb,sCAA0B,CAAC,mCAAmC,CAC/D,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,iBAAiB;QACrB,MAAM,WAAW,GAAG,MAAM,uBAAA,IAAI,gCAAW,CAAC,IAAI,CAC5C,yCAAyC,CAC1C,CAAC;QACF,OAAO;YACL,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,eAAe;QACb,OAAO,GAAG,8BAAkB,CAAC,uBAAA,IAAI,0BAAK,CAAC,EAAE,CAAC;IAC5C,CAAC;CACF;AAhND,sCAgNC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n CLAIMS_API_URL_MAP,\n ClaimsServiceErrorMessages,\n SERVICE_NAME,\n} from './constants';\nimport type { Env } from './constants';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\nimport { createSentryError, getErrorFromResponse } from './utils';\n\nexport type ClaimsServiceFetchClaimsConfigurationsAction = {\n type: `${typeof SERVICE_NAME}:fetchClaimsConfigurations`;\n handler: ClaimsService['fetchClaimsConfigurations'];\n};\n\nexport type ClaimsServiceGetClaimsAction = {\n type: `${typeof SERVICE_NAME}:getClaims`;\n handler: ClaimsService['getClaims'];\n};\n\nexport type ClaimsServiceGetClaimByIdAction = {\n type: `${typeof SERVICE_NAME}:getClaimById`;\n handler: ClaimsService['getClaimById'];\n};\n\nexport type ClaimsServiceGetRequestHeadersAction = {\n type: `${typeof SERVICE_NAME}:getRequestHeaders`;\n handler: ClaimsService['getRequestHeaders'];\n};\n\nexport type ClaimsServiceGetClaimsApiUrlAction = {\n type: `${typeof SERVICE_NAME}:getClaimsApiUrl`;\n handler: ClaimsService['getClaimsApiUrl'];\n};\n\nexport type ClaimsServiceGenerateMessageForClaimSignatureAction = {\n type: `${typeof SERVICE_NAME}:generateMessageForClaimSignature`;\n handler: ClaimsService['generateMessageForClaimSignature'];\n};\n\nexport type ClaimsServiceActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type ClaimsServiceEvents = never;\n\nexport type ClaimsServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n ClaimsServiceActions | AllowedActions\n>;\n\nexport type ClaimsServiceConfig = {\n env: Env;\n messenger: ClaimsServiceMessenger;\n fetchFunction: typeof fetch;\n};\n\nexport class ClaimsService {\n readonly name = SERVICE_NAME; // required for Modular Initialization\n\n readonly #env: Env;\n\n readonly #fetch: typeof fetch;\n\n readonly #messenger: ClaimsServiceMessenger;\n\n constructor({ env, messenger, fetchFunction }: ClaimsServiceConfig) {\n this.#env = env;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n this.fetchClaimsConfigurations.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaims`,\n this.getClaims.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimById`,\n this.getClaimById.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getRequestHeaders`,\n this.getRequestHeaders.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimsApiUrl`,\n this.getClaimsApiUrl.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n this.generateMessageForClaimSignature.bind(this),\n );\n }\n\n /**\n * Fetch required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurationsResponse> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/configurations`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const configurations = await response.json();\n return configurations;\n } catch (error) {\n console.error('fetchClaimsConfigurations', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n error as Error,\n ),\n );\n throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n }\n\n /**\n * Get the claims for the current user.\n *\n * @returns The claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const claims = await response.json();\n return claims;\n } catch (error) {\n console.error('getClaims', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS,\n error as Error,\n ),\n );\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\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 */\n async getClaimById(id: string): Promise<Claim> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims/byId/${id}`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const claim = await response.json();\n return claim;\n } catch (error) {\n console.error('getClaimById', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID,\n error as Error,\n ),\n );\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\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 */\n async generateMessageForClaimSignature(\n chainId: number,\n walletAddress: Hex,\n ): Promise<GenerateSignatureMessageResponse> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;\n const response = await this.#fetch(url, {\n method: 'POST',\n headers: {\n ...headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n chainId,\n walletAddress,\n }),\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const message = await response.json();\n return message;\n } catch (error) {\n console.error('generateMessageForClaimSignature', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n error as Error,\n ),\n );\n throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n }\n\n /**\n * Create the headers for the current request.\n *\n * @returns The headers for the current request.\n */\n async getRequestHeaders(): Promise<Record<string, string>> {\n const bearerToken = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return {\n Authorization: `Bearer ${bearerToken}`,\n };\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 */\n getClaimsApiUrl(): string {\n return `${CLAIMS_API_URL_MAP[this.#env]}`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ClaimsService.cjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,+CAIqB;AAErB,yCAA6D;AAM7D,uCAAkE;AAwDlE,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,eAAe,CAAC,CAAC;AAE/D,MAAa,aAAa;IASxB,YAAY,EAAE,GAAG,EAAE,SAAS,EAAE,aAAa,EA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,CAAC;IAC5C,CAAC;CACF;AAhND,sCAgNC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n CLAIMS_API_URL_MAP,\n ClaimsServiceErrorMessages,\n SERVICE_NAME,\n} from './constants';\nimport type { Env } from './constants';\nimport { createModuleLogger, projectLogger } from './logger';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\nimport { createSentryError, getErrorFromResponse } from './utils';\n\nexport type ClaimsServiceFetchClaimsConfigurationsAction = {\n type: `${typeof SERVICE_NAME}:fetchClaimsConfigurations`;\n handler: ClaimsService['fetchClaimsConfigurations'];\n};\n\nexport type ClaimsServiceGetClaimsAction = {\n type: `${typeof SERVICE_NAME}:getClaims`;\n handler: ClaimsService['getClaims'];\n};\n\nexport type ClaimsServiceGetClaimByIdAction = {\n type: `${typeof SERVICE_NAME}:getClaimById`;\n handler: ClaimsService['getClaimById'];\n};\n\nexport type ClaimsServiceGetRequestHeadersAction = {\n type: `${typeof SERVICE_NAME}:getRequestHeaders`;\n handler: ClaimsService['getRequestHeaders'];\n};\n\nexport type ClaimsServiceGetClaimsApiUrlAction = {\n type: `${typeof SERVICE_NAME}:getClaimsApiUrl`;\n handler: ClaimsService['getClaimsApiUrl'];\n};\n\nexport type ClaimsServiceGenerateMessageForClaimSignatureAction = {\n type: `${typeof SERVICE_NAME}:generateMessageForClaimSignature`;\n handler: ClaimsService['generateMessageForClaimSignature'];\n};\n\nexport type ClaimsServiceActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type ClaimsServiceEvents = never;\n\nexport type ClaimsServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n ClaimsServiceActions | AllowedActions\n>;\n\nexport type ClaimsServiceConfig = {\n env: Env;\n messenger: ClaimsServiceMessenger;\n fetchFunction: typeof fetch;\n};\n\nconst log = createModuleLogger(projectLogger, 'ClaimsService');\n\nexport class ClaimsService {\n readonly name = SERVICE_NAME; // required for Modular Initialization\n\n readonly #env: Env;\n\n readonly #fetch: typeof fetch;\n\n readonly #messenger: ClaimsServiceMessenger;\n\n constructor({ env, messenger, fetchFunction }: ClaimsServiceConfig) {\n this.#env = env;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n this.fetchClaimsConfigurations.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaims`,\n this.getClaims.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimById`,\n this.getClaimById.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getRequestHeaders`,\n this.getRequestHeaders.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimsApiUrl`,\n this.getClaimsApiUrl.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n this.generateMessageForClaimSignature.bind(this),\n );\n }\n\n /**\n * Fetch required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurationsResponse> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/configurations`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const configurations = await response.json();\n return configurations;\n } catch (error) {\n log('fetchClaimsConfigurations', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n error as Error,\n ),\n );\n throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n }\n\n /**\n * Get the claims for the current user.\n *\n * @returns The claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const claims = await response.json();\n return claims;\n } catch (error) {\n log('getClaims', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS,\n error as Error,\n ),\n );\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\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 */\n async getClaimById(id: string): Promise<Claim> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims/byId/${id}`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const claim = await response.json();\n return claim;\n } catch (error) {\n log('getClaimById', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID,\n error as Error,\n ),\n );\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\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 */\n async generateMessageForClaimSignature(\n chainId: number,\n walletAddress: Hex,\n ): Promise<GenerateSignatureMessageResponse> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;\n const response = await this.#fetch(url, {\n method: 'POST',\n headers: {\n ...headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n chainId,\n walletAddress,\n }),\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const message = await response.json();\n return message;\n } catch (error) {\n log('generateMessageForClaimSignature', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n error as Error,\n ),\n );\n throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n }\n\n /**\n * Create the headers for the current request.\n *\n * @returns The headers for the current request.\n */\n async getRequestHeaders(): Promise<Record<string, string>> {\n const bearerToken = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return {\n Authorization: `Bearer ${bearerToken}`,\n };\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 */\n getClaimsApiUrl(): string {\n return `${CLAIMS_API_URL_MAP[this.#env]}`;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClaimsService.d.cts","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAClF,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAGL,YAAY,EACb,wBAAoB;AACrB,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;
|
|
1
|
+
{"version":3,"file":"ClaimsService.d.cts","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAClF,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAGL,YAAY,EACb,wBAAoB;AACrB,OAAO,KAAK,EAAE,GAAG,EAAE,wB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YAAY,EACnB,oBAAoB,GAAG,cAAc,CACtC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,sBAAsB,CAAC;IAClC,aAAa,EAAE,OAAO,KAAK,CAAC;CAC7B,CAAC;AAIF,qBAAa,aAAa;;IACxB,QAAQ,CAAC,IAAI,mBAAgB;gBAQjB,EAAE,GAAG,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,mBAAmB;IA+BlE;;;;OAIG;IACG,yBAAyB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IA6BxE;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IA2BnC;;;;;OAKG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IA2B9C;;;;;;OAMG;IACG,gCAAgC,CACpC,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,GAAG,GACjB,OAAO,CAAC,gCAAgC,CAAC;IAqC5C;;;;OAIG;IACG,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAS1D;;;;OAIG;IACH,eAAe,IAAI,MAAM;CAG1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClaimsService.d.mts","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAClF,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAGL,YAAY,EACb,wBAAoB;AACrB,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;
|
|
1
|
+
{"version":3,"file":"ClaimsService.d.mts","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACr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mD,CAAC;AAExD,MAAM,MAAM,cAAc,GACxB,wBAAwB,CAAC,sCAAsC,CAAC;AAElE,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAExC,MAAM,MAAM,sBAAsB,GAAG,SAAS,CAC5C,OAAO,YAAY,EACnB,oBAAoB,GAAG,cAAc,CACtC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,sBAAsB,CAAC;IAClC,aAAa,EAAE,OAAO,KAAK,CAAC;CAC7B,CAAC;AAIF,qBAAa,aAAa;;IACxB,QAAQ,CAAC,IAAI,mBAAgB;gBAQjB,EAAE,GAAG,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,mBAAmB;IA+BlE;;;;OAIG;IACG,yBAAyB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IA6BxE;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IA2BnC;;;;;OAKG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IA2B9C;;;;;;OAMG;IACG,gCAAgC,CACpC,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,GAAG,GACjB,OAAO,CAAC,gCAAgC,CAAC;IAqC5C;;;;OAIG;IACG,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAS1D;;;;OAIG;IACH,eAAe,IAAI,MAAM;CAG1B"}
|
package/dist/ClaimsService.mjs
CHANGED
|
@@ -11,7 +11,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _ClaimsService_env, _ClaimsService_fetch, _ClaimsService_messenger;
|
|
13
13
|
import { CLAIMS_API_URL_MAP, ClaimsServiceErrorMessages, SERVICE_NAME } from "./constants.mjs";
|
|
14
|
+
import { createModuleLogger, projectLogger } from "./logger.mjs";
|
|
14
15
|
import { createSentryError, getErrorFromResponse } from "./utils.mjs";
|
|
16
|
+
const log = createModuleLogger(projectLogger, 'ClaimsService');
|
|
15
17
|
export class ClaimsService {
|
|
16
18
|
constructor({ env, messenger, fetchFunction }) {
|
|
17
19
|
this.name = SERVICE_NAME; // required for Modular Initialization
|
|
@@ -48,7 +50,7 @@ export class ClaimsService {
|
|
|
48
50
|
return configurations;
|
|
49
51
|
}
|
|
50
52
|
catch (error) {
|
|
51
|
-
|
|
53
|
+
log('fetchClaimsConfigurations', error);
|
|
52
54
|
__classPrivateFieldGet(this, _ClaimsService_messenger, "f").captureException?.(createSentryError(ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS, error));
|
|
53
55
|
throw new Error(ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS);
|
|
54
56
|
}
|
|
@@ -73,7 +75,7 @@ export class ClaimsService {
|
|
|
73
75
|
return claims;
|
|
74
76
|
}
|
|
75
77
|
catch (error) {
|
|
76
|
-
|
|
78
|
+
log('getClaims', error);
|
|
77
79
|
__classPrivateFieldGet(this, _ClaimsService_messenger, "f").captureException?.(createSentryError(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS, error));
|
|
78
80
|
throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);
|
|
79
81
|
}
|
|
@@ -99,7 +101,7 @@ export class ClaimsService {
|
|
|
99
101
|
return claim;
|
|
100
102
|
}
|
|
101
103
|
catch (error) {
|
|
102
|
-
|
|
104
|
+
log('getClaimById', error);
|
|
103
105
|
__classPrivateFieldGet(this, _ClaimsService_messenger, "f").captureException?.(createSentryError(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID, error));
|
|
104
106
|
throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);
|
|
105
107
|
}
|
|
@@ -134,7 +136,7 @@ export class ClaimsService {
|
|
|
134
136
|
return message;
|
|
135
137
|
}
|
|
136
138
|
catch (error) {
|
|
137
|
-
|
|
139
|
+
log('generateMessageForClaimSignature', error);
|
|
138
140
|
__classPrivateFieldGet(this, _ClaimsService_messenger, "f").captureException?.(createSentryError(ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED, error));
|
|
139
141
|
throw new Error(ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED);
|
|
140
142
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClaimsService.mjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACb,wBAAoB;AAOrB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,oBAAgB;AAwDlE,MAAM,OAAO,aAAa;IASxB,YAAY,EAAE,GAAG,EAAE,SAAS,EAAE,aAAa,EAAuB;QARzD,SAAI,GAAG,YAAY,CAAC,CAAC,sCAAsC;QAE3D,qCAAU;QAEV,uCAAqB;QAErB,2CAAmC;QAG1C,uBAAA,IAAI,sBAAQ,GAAG,MAAA,CAAC;QAChB,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,wBAAU,aAAa,MAAA,CAAC;QAE5B,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,YAAY,4BAA4B,EAC3C,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1C,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,YAAY,YAAY,EAC3B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1B,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,YAAY,eAAe,EAC9B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7B,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,q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YACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;YACzD,uBAAA,IAAI,gCAAW,CAAC,gBAAgB,EAAE,CAChC,iBAAiB,CACf,0BAA0B,CAAC,mCAAmC,EAC9D,KAAc,CACf,CACF,CAAC;YACF,MAAM,IAAI,KAAK,CACb,0BAA0B,CAAC,mCAAmC,CAC/D,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,iBAAiB;QACrB,MAAM,WAAW,GAAG,MAAM,uBAAA,IAAI,gCAAW,CAAC,IAAI,CAC5C,yCAAyC,CAC1C,CAAC;QACF,OAAO;YACL,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,eAAe;QACb,OAAO,GAAG,kBAAkB,CAAC,uBAAA,IAAI,0BAAK,CAAC,EAAE,CAAC;IAC5C,CAAC;CACF","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n CLAIMS_API_URL_MAP,\n ClaimsServiceErrorMessages,\n SERVICE_NAME,\n} from './constants';\nimport type { Env } from './constants';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\nimport { createSentryError, getErrorFromResponse } from './utils';\n\nexport type ClaimsServiceFetchClaimsConfigurationsAction = {\n type: `${typeof SERVICE_NAME}:fetchClaimsConfigurations`;\n handler: ClaimsService['fetchClaimsConfigurations'];\n};\n\nexport type ClaimsServiceGetClaimsAction = {\n type: `${typeof SERVICE_NAME}:getClaims`;\n handler: ClaimsService['getClaims'];\n};\n\nexport type ClaimsServiceGetClaimByIdAction = {\n type: `${typeof SERVICE_NAME}:getClaimById`;\n handler: ClaimsService['getClaimById'];\n};\n\nexport type ClaimsServiceGetRequestHeadersAction = {\n type: `${typeof SERVICE_NAME}:getRequestHeaders`;\n handler: ClaimsService['getRequestHeaders'];\n};\n\nexport type ClaimsServiceGetClaimsApiUrlAction = {\n type: `${typeof SERVICE_NAME}:getClaimsApiUrl`;\n handler: ClaimsService['getClaimsApiUrl'];\n};\n\nexport type ClaimsServiceGenerateMessageForClaimSignatureAction = {\n type: `${typeof SERVICE_NAME}:generateMessageForClaimSignature`;\n handler: ClaimsService['generateMessageForClaimSignature'];\n};\n\nexport type ClaimsServiceActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type ClaimsServiceEvents = never;\n\nexport type ClaimsServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n ClaimsServiceActions | AllowedActions\n>;\n\nexport type ClaimsServiceConfig = {\n env: Env;\n messenger: ClaimsServiceMessenger;\n fetchFunction: typeof fetch;\n};\n\nexport class ClaimsService {\n readonly name = SERVICE_NAME; // required for Modular Initialization\n\n readonly #env: Env;\n\n readonly #fetch: typeof fetch;\n\n readonly #messenger: ClaimsServiceMessenger;\n\n constructor({ env, messenger, fetchFunction }: ClaimsServiceConfig) {\n this.#env = env;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n this.fetchClaimsConfigurations.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaims`,\n this.getClaims.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimById`,\n this.getClaimById.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getRequestHeaders`,\n this.getRequestHeaders.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimsApiUrl`,\n this.getClaimsApiUrl.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n this.generateMessageForClaimSignature.bind(this),\n );\n }\n\n /**\n * Fetch required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurationsResponse> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/configurations`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const configurations = await response.json();\n return configurations;\n } catch (error) {\n console.error('fetchClaimsConfigurations', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n error as Error,\n ),\n );\n throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n }\n\n /**\n * Get the claims for the current user.\n *\n * @returns The claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const claims = await response.json();\n return claims;\n } catch (error) {\n console.error('getClaims', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS,\n error as Error,\n ),\n );\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\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 */\n async getClaimById(id: string): Promise<Claim> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims/byId/${id}`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const claim = await response.json();\n return claim;\n } catch (error) {\n console.error('getClaimById', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID,\n error as Error,\n ),\n );\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\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 */\n async generateMessageForClaimSignature(\n chainId: number,\n walletAddress: Hex,\n ): Promise<GenerateSignatureMessageResponse> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;\n const response = await this.#fetch(url, {\n method: 'POST',\n headers: {\n ...headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n chainId,\n walletAddress,\n }),\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const message = await response.json();\n return message;\n } catch (error) {\n console.error('generateMessageForClaimSignature', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n error as Error,\n ),\n );\n throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n }\n\n /**\n * Create the headers for the current request.\n *\n * @returns The headers for the current request.\n */\n async getRequestHeaders(): Promise<Record<string, string>> {\n const bearerToken = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return {\n Authorization: `Bearer ${bearerToken}`,\n };\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 */\n getClaimsApiUrl(): string {\n return `${CLAIMS_API_URL_MAP[this.#env]}`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ClaimsService.mjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC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AM,uBAAA,IAAI,gCAAW,CAAC,IAAI,CAC5C,yCAAyC,CAC1C,CAAC;QACF,OAAO;YACL,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,eAAe;QACb,OAAO,GAAG,kBAAkB,CAAC,uBAAA,IAAI,0BAAK,CAAC,EAAE,CAAC;IAC5C,CAAC;CACF","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n CLAIMS_API_URL_MAP,\n ClaimsServiceErrorMessages,\n SERVICE_NAME,\n} from './constants';\nimport type { Env } from './constants';\nimport { createModuleLogger, projectLogger } from './logger';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\nimport { createSentryError, getErrorFromResponse } from './utils';\n\nexport type ClaimsServiceFetchClaimsConfigurationsAction = {\n type: `${typeof SERVICE_NAME}:fetchClaimsConfigurations`;\n handler: ClaimsService['fetchClaimsConfigurations'];\n};\n\nexport type ClaimsServiceGetClaimsAction = {\n type: `${typeof SERVICE_NAME}:getClaims`;\n handler: ClaimsService['getClaims'];\n};\n\nexport type ClaimsServiceGetClaimByIdAction = {\n type: `${typeof SERVICE_NAME}:getClaimById`;\n handler: ClaimsService['getClaimById'];\n};\n\nexport type ClaimsServiceGetRequestHeadersAction = {\n type: `${typeof SERVICE_NAME}:getRequestHeaders`;\n handler: ClaimsService['getRequestHeaders'];\n};\n\nexport type ClaimsServiceGetClaimsApiUrlAction = {\n type: `${typeof SERVICE_NAME}:getClaimsApiUrl`;\n handler: ClaimsService['getClaimsApiUrl'];\n};\n\nexport type ClaimsServiceGenerateMessageForClaimSignatureAction = {\n type: `${typeof SERVICE_NAME}:generateMessageForClaimSignature`;\n handler: ClaimsService['generateMessageForClaimSignature'];\n};\n\nexport type ClaimsServiceActions =\n | ClaimsServiceFetchClaimsConfigurationsAction\n | ClaimsServiceGetClaimsAction\n | ClaimsServiceGetClaimByIdAction\n | ClaimsServiceGetRequestHeadersAction\n | ClaimsServiceGetClaimsApiUrlAction\n | ClaimsServiceGenerateMessageForClaimSignatureAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type ClaimsServiceEvents = never;\n\nexport type ClaimsServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n ClaimsServiceActions | AllowedActions\n>;\n\nexport type ClaimsServiceConfig = {\n env: Env;\n messenger: ClaimsServiceMessenger;\n fetchFunction: typeof fetch;\n};\n\nconst log = createModuleLogger(projectLogger, 'ClaimsService');\n\nexport class ClaimsService {\n readonly name = SERVICE_NAME; // required for Modular Initialization\n\n readonly #env: Env;\n\n readonly #fetch: typeof fetch;\n\n readonly #messenger: ClaimsServiceMessenger;\n\n constructor({ env, messenger, fetchFunction }: ClaimsServiceConfig) {\n this.#env = env;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:fetchClaimsConfigurations`,\n this.fetchClaimsConfigurations.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaims`,\n this.getClaims.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimById`,\n this.getClaimById.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getRequestHeaders`,\n this.getRequestHeaders.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:getClaimsApiUrl`,\n this.getClaimsApiUrl.bind(this),\n );\n this.#messenger.registerActionHandler(\n `${SERVICE_NAME}:generateMessageForClaimSignature`,\n this.generateMessageForClaimSignature.bind(this),\n );\n }\n\n /**\n * Fetch required configurations for the claims service.\n *\n * @returns The required configurations for the claims service.\n */\n async fetchClaimsConfigurations(): Promise<ClaimsConfigurationsResponse> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/configurations`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const configurations = await response.json();\n return configurations;\n } catch (error) {\n log('fetchClaimsConfigurations', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n error as Error,\n ),\n );\n throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n }\n\n /**\n * Get the claims for the current user.\n *\n * @returns The claims for the current user.\n */\n async getClaims(): Promise<Claim[]> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const claims = await response.json();\n return claims;\n } catch (error) {\n log('getClaims', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS,\n error as Error,\n ),\n );\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\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 */\n async getClaimById(id: string): Promise<Claim> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/claims/byId/${id}`;\n const response = await this.#fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const claim = await response.json();\n return claim;\n } catch (error) {\n log('getClaimById', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID,\n error as Error,\n ),\n );\n throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\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 */\n async generateMessageForClaimSignature(\n chainId: number,\n walletAddress: Hex,\n ): Promise<GenerateSignatureMessageResponse> {\n try {\n const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;\n const response = await this.#fetch(url, {\n method: 'POST',\n headers: {\n ...headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n chainId,\n walletAddress,\n }),\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const message = await response.json();\n return message;\n } catch (error) {\n log('generateMessageForClaimSignature', error);\n this.#messenger.captureException?.(\n createSentryError(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n error as Error,\n ),\n );\n throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n }\n\n /**\n * Create the headers for the current request.\n *\n * @returns The headers for the current request.\n */\n async getRequestHeaders(): Promise<Record<string, string>> {\n const bearerToken = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return {\n Authorization: `Bearer ${bearerToken}`,\n };\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 */\n getClaimsApiUrl(): string {\n return `${CLAIMS_API_URL_MAP[this.#env]}`;\n }\n}\n"]}
|
package/dist/logger.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createModuleLogger = exports.projectLogger = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
Object.defineProperty(exports, "createModuleLogger", { enumerable: true, get: function () { return utils_1.createModuleLogger; } });
|
|
6
|
+
const constants_1 = require("./constants.cjs");
|
|
7
|
+
exports.projectLogger = (0, utils_1.createProjectLogger)(constants_1.CONTROLLER_NAME);
|
|
8
|
+
//# sourceMappingURL=logger.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.cjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,2CAA0E;AAMjE,mGANqB,0BAAkB,OAMrB;AAJ3B,+CAA8C;AAEjC,QAAA,aAAa,GAAG,IAAA,2BAAmB,EAAC,2BAAe,CAAC,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nimport { CONTROLLER_NAME } from './constants';\n\nexport const projectLogger = createProjectLogger(CONTROLLER_NAME);\n\nexport { createModuleLogger };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.cts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,OAAO,EAAuB,kBAAkB,EAAE,wBAAwB;AAI1E,eAAO,MAAM,aAAa,0BAAuC,CAAC;AAElE,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.mts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,OAAO,EAAuB,kBAAkB,EAAE,wBAAwB;AAI1E,eAAO,MAAM,aAAa,0BAAuC,CAAC;AAElE,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/logger.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,wBAAwB;AAE1E,OAAO,EAAE,eAAe,EAAE,wBAAoB;AAE9C,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAElE,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nimport { CONTROLLER_NAME } from './constants';\n\nexport const projectLogger = createProjectLogger(CONTROLLER_NAME);\n\nexport { createModuleLogger };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/claims-controller",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Controller handling shield subscription claims logic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@metamask/base-controller": "^9.0.0",
|
|
52
|
-
"@metamask/controller-utils": "^11.
|
|
52
|
+
"@metamask/controller-utils": "^11.18.0",
|
|
53
53
|
"@metamask/messenger": "^0.3.0",
|
|
54
54
|
"@metamask/utils": "^11.9.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@metamask/auto-changelog": "^3.4.4",
|
|
58
|
-
"@metamask/keyring-controller": "^25.
|
|
58
|
+
"@metamask/keyring-controller": "^25.1.0",
|
|
59
59
|
"@metamask/profile-sync-controller": "^27.0.0",
|
|
60
60
|
"@ts-bridge/cli": "^0.6.4",
|
|
61
61
|
"@types/jest": "^27.4.1",
|