@metamask-previews/claims-controller 0.1.0-preview-bf3ab7d → 0.1.0-preview-7b698bb

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 CHANGED
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
  - Added new states fields, `validSubmissionWindowDays` and `supportedNetworks` to the controller state. ([#7109](https://github.com/MetaMask/core/pull/7109))
14
14
  - `validSubmissionWindowDays` - number of days the claim is valid for submission.
15
15
  - `supportedNetworks` - supported networks for the claim submission.
16
+ - Exported `CreateClaimRequest` and `SubmitClaimConfig` types from the controller. ([#7109](https://github.com/MetaMask/core/pull/7109))
16
17
 
17
18
  ## [0.1.0]
18
19
 
@@ -93,8 +93,11 @@ class ClaimsService {
93
93
  const headers = await this.getRequestHeaders();
94
94
  const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;
95
95
  const response = await __classPrivateFieldGet(this, _ClaimsService_fetch, "f").call(this, url, {
96
- headers,
97
96
  method: 'POST',
97
+ headers: {
98
+ ...headers,
99
+ 'Content-Type': 'application/json',
100
+ },
98
101
  body: JSON.stringify({
99
102
  chainId,
100
103
  walletAddress,
@@ -1 +1 @@
1
- {"version":3,"file":"ClaimsService.cjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,+CAKqB;AA6DrB,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,C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,GAAG,GAAG,GAAG,IAAI,CAAC,eAAe,EAAE,4BAA4B,CAAC;QAClE,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,4BAAO,MAAX,IAAI,EAAQ,GAAG,EAAE;YACtC,OAAO;YACP,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,OAAO;gBACP,aAAa;aACd,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,sCAA0B,CAAC,mCAAmC,CAC/D,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,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;AA7JD,sCA6JC","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 type Env,\n SERVICE_NAME,\n} from './constants';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\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 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 throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n\n const configurations = await response.json();\n return configurations;\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 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 throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\n\n const claims = await response.json();\n return claims;\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 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 throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\n\n const claim = await response.json();\n return claim;\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 const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;\n const response = await this.#fetch(url, {\n headers,\n method: 'POST',\n body: JSON.stringify({\n chainId,\n walletAddress,\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n\n const message = await response.json();\n return message;\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,+CAKqB;AA6DrB,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,E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;YACd,OAAO,EAAE;gBACP,GAAG,OAAO;gBACV,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,OAAO;gBACP,aAAa;aACd,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,sCAA0B,CAAC,mCAAmC,CAC/D,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,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;AAhKD,sCAgKC","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 type Env,\n SERVICE_NAME,\n} from './constants';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\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 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 throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n\n const configurations = await response.json();\n return configurations;\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 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 throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\n\n const claims = await response.json();\n return claims;\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 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 throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\n\n const claim = await response.json();\n return claim;\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 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 throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n\n const message = await response.json();\n return message;\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,KAAK,GAAG,EACR,YAAY,EACb,wBAAoB;AACrB,OAAO,KAAK,EACV,KAAK,EACL,4BAA4B,EAC5B,gCAAgC,EACjC,oBAAgB;AAEjB,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,GAAG,OAAO,YAAY,4BAA4B,CAAC;IACzD,OAAO,EAAE,aAAa,CAAC,2BAA2B,CAAC,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,GAAG,OAAO,YAAY,YAAY,CAAC;IACzC,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAA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A4B,GAC5B,+BAA+B,GAC/B,oCAAoC,GACpC,kCAAkC,GAClC,mDAAmD,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;AAEF,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;IAiBxE;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAenC;;;;;OAKG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAe9C;;;;;;OAMG;IACG,gCAAgC,CACpC,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,GAAG,GACjB,OAAO,CAAC,gCAAgC,CAAC;IAyB5C;;;;OAIG;IACG,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAS1D;;;;OAIG;IACH,eAAe,IAAI,MAAM;CAG1B"}
@@ -90,8 +90,11 @@ export class ClaimsService {
90
90
  const headers = await this.getRequestHeaders();
91
91
  const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;
92
92
  const response = await __classPrivateFieldGet(this, _ClaimsService_fetch, "f").call(this, url, {
93
- headers,
94
93
  method: 'POST',
94
+ headers: {
95
+ ...headers,
96
+ 'Content-Type': 'application/json',
97
+ },
95
98
  body: JSON.stringify({
96
99
  chainId,
97
100
  walletAddress,
@@ -1 +1 @@
1
- {"version":3,"file":"ClaimsService.mjs","sourceRoot":"","sources":["../src/ClaimsService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAE1B,YAAY,EACb,wBAAoB;AA6DrB,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,qBAAqB,CACnC,GAAG,YAAY,oBAAoB,EACnC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CACnC,GAAG,YAAY,kBAAkB,EACjC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAChC,CAAC;QACF,uBAAA,IAAI,gCAAW,CAAC,qBAAqB,CAC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AC;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 type Env,\n SERVICE_NAME,\n} from './constants';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\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 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 throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n\n const configurations = await response.json();\n return configurations;\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 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 throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\n\n const claims = await response.json();\n return claims;\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 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 throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\n\n const claim = await response.json();\n return claim;\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 const headers = await this.getRequestHeaders();\n const url = `${this.getClaimsApiUrl()}/signature/generateMessage`;\n const response = await this.#fetch(url, {\n headers,\n method: 'POST',\n body: JSON.stringify({\n chainId,\n walletAddress,\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n\n const message = await response.json();\n return message;\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":";;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A,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 type Env,\n SERVICE_NAME,\n} from './constants';\nimport type {\n Claim,\n ClaimsConfigurationsResponse,\n GenerateSignatureMessageResponse,\n} from './types';\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 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 throw new Error(\n ClaimsServiceErrorMessages.FAILED_TO_FETCH_CONFIGURATIONS,\n );\n }\n\n const configurations = await response.json();\n return configurations;\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 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 throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIMS);\n }\n\n const claims = await response.json();\n return claims;\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 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 throw new Error(ClaimsServiceErrorMessages.FAILED_TO_GET_CLAIM_BY_ID);\n }\n\n const claim = await response.json();\n return claim;\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 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 throw new Error(\n ClaimsServiceErrorMessages.SIGNATURE_MESSAGE_GENERATION_FAILED,\n );\n }\n\n const message = await response.json();\n return message;\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":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAG4B;AAF1B,oHAAA,gBAAgB,OAAA;AAChB,mIAAA,+BAA+B,OAAA;AAiBjC,qDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAatB,6CAOqB;AANnB,4GAAA,eAAe,OAAA;AACf,gGAAA,GAAG,OAAA;AACH,0HAAA,6BAA6B,OAAA;AAC7B,0HAAA,6BAA6B,OAAA;AAC7B,uHAAA,0BAA0B,OAAA;AAC1B,+GAAA,kBAAkB,OAAA","sourcesContent":["export {\n ClaimsController,\n getDefaultClaimsControllerState,\n} from './ClaimsController';\n\nexport type {\n ClaimsControllerGetStateAction,\n ClaimsControllerActions,\n ClaimsControllerStateChangeEvent,\n ClaimsControllerMessenger,\n} from './ClaimsController';\n\nexport type {\n Claim,\n ClaimsControllerState,\n Attachment,\n ClaimsConfigurations,\n} from './types';\n\nexport { ClaimsService } from './ClaimsService';\n\nexport type {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetRequestHeadersAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceActions,\n ClaimsServiceMessenger,\n} from './ClaimsService';\n\nexport {\n ClaimStatusEnum,\n Env,\n ClaimsControllerErrorMessages,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n ClaimsServiceErrorMessages,\n CLAIMS_API_URL_MAP,\n} from './constants';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAG4B;AAF1B,oHAAA,gBAAgB,OAAA;AAChB,mIAAA,+BAA+B,OAAA;AAmBjC,qDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAatB,6CAOqB;AANnB,4GAAA,eAAe,OAAA;AACf,gGAAA,GAAG,OAAA;AACH,0HAAA,6BAA6B,OAAA;AAC7B,0HAAA,6BAA6B,OAAA;AAC7B,uHAAA,0BAA0B,OAAA;AAC1B,+GAAA,kBAAkB,OAAA","sourcesContent":["export {\n ClaimsController,\n getDefaultClaimsControllerState,\n} from './ClaimsController';\n\nexport type {\n ClaimsControllerGetStateAction,\n ClaimsControllerActions,\n ClaimsControllerStateChangeEvent,\n ClaimsControllerMessenger,\n} from './ClaimsController';\n\nexport type {\n Claim,\n ClaimsControllerState,\n Attachment,\n ClaimsConfigurations,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types';\n\nexport { ClaimsService } from './ClaimsService';\n\nexport type {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetRequestHeadersAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceActions,\n ClaimsServiceMessenger,\n} from './ClaimsService';\n\nexport {\n ClaimStatusEnum,\n Env,\n ClaimsControllerErrorMessages,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n ClaimsServiceErrorMessages,\n CLAIMS_API_URL_MAP,\n} from './constants';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { ClaimsController, getDefaultClaimsControllerState, } from "./ClaimsController.cjs";
2
2
  export type { ClaimsControllerGetStateAction, ClaimsControllerActions, ClaimsControllerStateChangeEvent, ClaimsControllerMessenger, } from "./ClaimsController.cjs";
3
- export type { Claim, ClaimsControllerState, Attachment, ClaimsConfigurations, } from "./types.cjs";
3
+ export type { Claim, ClaimsControllerState, Attachment, ClaimsConfigurations, CreateClaimRequest, SubmitClaimConfig, } from "./types.cjs";
4
4
  export { ClaimsService } from "./ClaimsService.cjs";
5
5
  export type { ClaimsServiceFetchClaimsConfigurationsAction, ClaimsServiceGetClaimsAction, ClaimsServiceGetRequestHeadersAction, ClaimsServiceGetClaimsApiUrlAction, ClaimsServiceGetClaimByIdAction, ClaimsServiceGenerateMessageForClaimSignatureAction, ClaimsServiceActions, ClaimsServiceMessenger, } from "./ClaimsService.cjs";
6
6
  export { ClaimStatusEnum, Env, ClaimsControllerErrorMessages, DEFAULT_CLAIMS_CONFIGURATIONS, ClaimsServiceErrorMessages, CLAIMS_API_URL_MAP, } from "./constants.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAE5B,YAAY,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,yBAAyB,GAC1B,+BAA2B;AAE5B,YAAY,EACV,KAAK,EACL,qBAAqB,EACrB,UAAU,EACV,oBAAoB,GACrB,oBAAgB;AAEjB,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,YAAY,EACV,4CAA4C,EAC5C,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EAClC,+BAA+B,EAC/B,mDAAmD,EACnD,oBAAoB,EACpB,sBAAsB,GACvB,4BAAwB;AAEzB,OAAO,EACL,eAAe,EACf,GAAG,EACH,6BAA6B,EAC7B,6BAA6B,EAC7B,0BAA0B,EAC1B,kBAAkB,GACnB,wBAAoB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAE5B,YAAY,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,yBAAyB,GAC1B,+BAA2B;AAE5B,YAAY,EACV,KAAK,EACL,qBAAqB,EACrB,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,oBAAgB;AAEjB,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,YAAY,EACV,4CAA4C,EAC5C,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EAClC,+BAA+B,EAC/B,mDAAmD,EACnD,oBAAoB,EACpB,sBAAsB,GACvB,4BAAwB;AAEzB,OAAO,EACL,eAAe,EACf,GAAG,EACH,6BAA6B,EAC7B,6BAA6B,EAC7B,0BAA0B,EAC1B,kBAAkB,GACnB,wBAAoB"}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { ClaimsController, getDefaultClaimsControllerState, } from "./ClaimsController.mjs";
2
2
  export type { ClaimsControllerGetStateAction, ClaimsControllerActions, ClaimsControllerStateChangeEvent, ClaimsControllerMessenger, } from "./ClaimsController.mjs";
3
- export type { Claim, ClaimsControllerState, Attachment, ClaimsConfigurations, } from "./types.mjs";
3
+ export type { Claim, ClaimsControllerState, Attachment, ClaimsConfigurations, CreateClaimRequest, SubmitClaimConfig, } from "./types.mjs";
4
4
  export { ClaimsService } from "./ClaimsService.mjs";
5
5
  export type { ClaimsServiceFetchClaimsConfigurationsAction, ClaimsServiceGetClaimsAction, ClaimsServiceGetRequestHeadersAction, ClaimsServiceGetClaimsApiUrlAction, ClaimsServiceGetClaimByIdAction, ClaimsServiceGenerateMessageForClaimSignatureAction, ClaimsServiceActions, ClaimsServiceMessenger, } from "./ClaimsService.mjs";
6
6
  export { ClaimStatusEnum, Env, ClaimsControllerErrorMessages, DEFAULT_CLAIMS_CONFIGURATIONS, ClaimsServiceErrorMessages, CLAIMS_API_URL_MAP, } from "./constants.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAE5B,YAAY,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,yBAAyB,GAC1B,+BAA2B;AAE5B,YAAY,EACV,KAAK,EACL,qBAAqB,EACrB,UAAU,EACV,oBAAoB,GACrB,oBAAgB;AAEjB,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,YAAY,EACV,4CAA4C,EAC5C,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EAClC,+BAA+B,EAC/B,mDAAmD,EACnD,oBAAoB,EACpB,sBAAsB,GACvB,4BAAwB;AAEzB,OAAO,EACL,eAAe,EACf,GAAG,EACH,6BAA6B,EAC7B,6BAA6B,EAC7B,0BAA0B,EAC1B,kBAAkB,GACnB,wBAAoB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAE5B,YAAY,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,yBAAyB,GAC1B,+BAA2B;AAE5B,YAAY,EACV,KAAK,EACL,qBAAqB,EACrB,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,oBAAgB;AAEjB,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,YAAY,EACV,4CAA4C,EAC5C,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EAClC,+BAA+B,EAC/B,mDAAmD,EACnD,oBAAoB,EACpB,sBAAsB,GACvB,4BAAwB;AAEzB,OAAO,EACL,eAAe,EACf,GAAG,EACH,6BAA6B,EAC7B,6BAA6B,EAC7B,0BAA0B,EAC1B,kBAAkB,GACnB,wBAAoB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAChC,+BAA2B;AAgB5B,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAahD,OAAO,EACL,eAAe,EACf,GAAG,EACH,6BAA6B,EAC7B,6BAA6B,EAC7B,0BAA0B,EAC1B,kBAAkB,EACnB,wBAAoB","sourcesContent":["export {\n ClaimsController,\n getDefaultClaimsControllerState,\n} from './ClaimsController';\n\nexport type {\n ClaimsControllerGetStateAction,\n ClaimsControllerActions,\n ClaimsControllerStateChangeEvent,\n ClaimsControllerMessenger,\n} from './ClaimsController';\n\nexport type {\n Claim,\n ClaimsControllerState,\n Attachment,\n ClaimsConfigurations,\n} from './types';\n\nexport { ClaimsService } from './ClaimsService';\n\nexport type {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetRequestHeadersAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceActions,\n ClaimsServiceMessenger,\n} from './ClaimsService';\n\nexport {\n ClaimStatusEnum,\n Env,\n ClaimsControllerErrorMessages,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n ClaimsServiceErrorMessages,\n CLAIMS_API_URL_MAP,\n} from './constants';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAChC,+BAA2B;AAkB5B,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAahD,OAAO,EACL,eAAe,EACf,GAAG,EACH,6BAA6B,EAC7B,6BAA6B,EAC7B,0BAA0B,EAC1B,kBAAkB,EACnB,wBAAoB","sourcesContent":["export {\n ClaimsController,\n getDefaultClaimsControllerState,\n} from './ClaimsController';\n\nexport type {\n ClaimsControllerGetStateAction,\n ClaimsControllerActions,\n ClaimsControllerStateChangeEvent,\n ClaimsControllerMessenger,\n} from './ClaimsController';\n\nexport type {\n Claim,\n ClaimsControllerState,\n Attachment,\n ClaimsConfigurations,\n CreateClaimRequest,\n SubmitClaimConfig,\n} from './types';\n\nexport { ClaimsService } from './ClaimsService';\n\nexport type {\n ClaimsServiceFetchClaimsConfigurationsAction,\n ClaimsServiceGetClaimsAction,\n ClaimsServiceGetRequestHeadersAction,\n ClaimsServiceGetClaimsApiUrlAction,\n ClaimsServiceGetClaimByIdAction,\n ClaimsServiceGenerateMessageForClaimSignatureAction,\n ClaimsServiceActions,\n ClaimsServiceMessenger,\n} from './ClaimsService';\n\nexport {\n ClaimStatusEnum,\n Env,\n ClaimsControllerErrorMessages,\n DEFAULT_CLAIMS_CONFIGURATIONS,\n ClaimsServiceErrorMessages,\n CLAIMS_API_URL_MAP,\n} from './constants';\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 CreateClaimRequest = Omit<\n Claim,\n 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'\n>;\n\nexport type ClaimsControllerState = ClaimsConfigurations & {\n /**\n * List of claims.\n */\n claims: Claim[];\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\nexport type VerifyClaimSignatureResponse = {\n message: string;\n success: boolean;\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 CreateClaimRequest = Omit<\n Claim,\n 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'\n>;\n\nexport type ClaimsControllerState = ClaimsConfigurations & {\n /**\n * List of claims.\n */\n claims: Claim[];\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
@@ -67,8 +67,4 @@ export type GenerateSignatureMessageResponse = {
67
67
  message: string;
68
68
  nonce: string;
69
69
  };
70
- export type VerifyClaimSignatureResponse = {
71
- message: string;
72
- success: boolean;
73
- };
74
70
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types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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,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,IAAI,CACnC,KAAK,EACL,IAAI,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,QAAQ,CACvE,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,GAAG;IACzD;;OAEG;IACH,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,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
@@ -67,8 +67,4 @@ export type GenerateSignatureMessageResponse = {
67
67
  message: string;
68
68
  nonce: string;
69
69
  };
70
- export type VerifyClaimSignatureResponse = {
71
- message: string;
72
- success: boolean;
73
- };
74
70
  //# sourceMappingURL=types.d.mts.map
@@ -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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CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,GAAG,CAAC;IACf,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,IAAI,CACnC,KAAK,EACL,IAAI,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,QAAQ,CACvE,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,GAAG;IACzD;;OAEG;IACH,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,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"}
@@ -1 +1 @@
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 CreateClaimRequest = Omit<\n Claim,\n 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'\n>;\n\nexport type ClaimsControllerState = ClaimsConfigurations & {\n /**\n * List of claims.\n */\n claims: Claim[];\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\nexport type VerifyClaimSignatureResponse = {\n message: string;\n success: boolean;\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 CreateClaimRequest = Omit<\n Claim,\n 'id' | 'shortId' | 'createdAt' | 'updatedAt' | 'intercomId' | 'status'\n>;\n\nexport type ClaimsControllerState = ClaimsConfigurations & {\n /**\n * List of claims.\n */\n claims: Claim[];\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.1.0-preview-bf3ab7d",
3
+ "version": "0.1.0-preview-7b698bb",
4
4
  "description": "Controller handling shield subscription claims logic",
5
5
  "keywords": [
6
6
  "MetaMask",