@metamask-previews/chomp-api-service 4.0.0-preview-0efc7ef01 → 4.0.0-preview-7b60eca
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 +4 -0
- package/dist/chomp-api-service.cjs +2 -2
- package/dist/chomp-api-service.cjs.map +1 -1
- package/dist/chomp-api-service.d.cts +1 -1
- package/dist/chomp-api-service.d.mts +1 -1
- package/dist/chomp-api-service.mjs +2 -2
- package/dist/chomp-api-service.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Bump `@tanstack/query-core` from `^4.43.0` to `^5.62.16` ([#9712](https://github.com/MetaMask/core/pull/9712))
|
|
13
|
+
|
|
10
14
|
## [4.0.0]
|
|
11
15
|
|
|
12
16
|
### Added
|
|
@@ -224,7 +224,7 @@ class ChompApiService extends base_data_service_1.BaseDataService {
|
|
|
224
224
|
* The result is scoped to the authenticated profile and consumers use it
|
|
225
225
|
* to decide whether an association already exists, so it is always fetched
|
|
226
226
|
* fresh (`staleTime: 0`) and evicted as soon as the call settles
|
|
227
|
-
* (`
|
|
227
|
+
* (`gcTime: 0`). The query key carries a SHA-256 digest of the bearer
|
|
228
228
|
* token — the same token the request is made with — so concurrent calls
|
|
229
229
|
* only share an in-flight request when they are for the same profile. The
|
|
230
230
|
* digest, not the token, is used because query keys leave the service via
|
|
@@ -239,7 +239,7 @@ class ChompApiService extends base_data_service_1.BaseDataService {
|
|
|
239
239
|
const jsonResponse = await this.fetchQuery({
|
|
240
240
|
queryKey: [`${this.name}:getAssociatedAddresses`, profileKey],
|
|
241
241
|
staleTime: 0,
|
|
242
|
-
|
|
242
|
+
gcTime: 0,
|
|
243
243
|
queryFn: async () => {
|
|
244
244
|
const response = await fetch(new URL('/v1/auth/address', __classPrivateFieldGet(this, _ChompApiService_baseUrl, "f")), { headers: __classPrivateFieldGet(this, _ChompApiService_instances, "m", _ChompApiService_headersForToken).call(this, token) });
|
|
245
245
|
if (!response.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service.cjs","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA8D;AAO9D,iEAAmE;AAEnE,uDAY+B;AAE/B,2CAKyB;AAqBzB,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,iBAAiB,CAAC;AAE7C,oBAAoB;AAEpB;;;GAGG;AACH,MAAM,yBAAyB,GAAG;IAChC,kBAAkB;IAClB,wBAAwB;IACxB,eAAe;IACf,aAAa;IACb,kBAAkB;IAClB,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,mBAAmB;CACX,CAAC;AA0DX,8BAA8B;AAE9B,MAAM,8BAA8B,GAAG,IAAA,kBAAI,EAAC;IAC1C,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC7B,OAAO,EAAE,uBAAe;IACxB,MAAM,EAAE,IAAA,mBAAK,EAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;CACrC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,IAAA,oBAAM,EAAC,uBAAe,EAAE,IAAA,oBAAM,GAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAC5E,KAAK,CAAC,WAAW,EAAE,CACpB,CAAC;AAEF,MAAM,8BAA8B,GAAG,IAAA,mBAAK,EAC1C,IAAA,kBAAI,EAAC;IACH,SAAS,EAAE,IAAA,oBAAM,GAAE;IACnB,OAAO,EAAE,yBAAyB;IAClC,MAAM,EAAE,IAAA,mBAAK,EAAC,CAAC,QAAQ,CAAC,CAAC;CAC1B,CAAC,C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4BAAS,CACjB,QAAQ,CAAC,MAAM,EACf,qCAAqC,QAAQ,CAAC,MAAM,GAAG,CACxD,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,IAAA,oBAAM,EAAC,YAAY,EAAE,4BAA4B,CAAC,CAAC;IAC5D,CAAC;CACF;AAvZD,0CAuZC;mKAtWkB,KAAa;IAC5B,OAAO;QACL,aAAa,EAAE,UAAU,KAAK,EAAE;QAChC,cAAc,EAAE,kBAAkB;KACnC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK;IACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACrC,yCAAyC,CAC1C,CAAC;IACF,OAAO,uBAAA,IAAI,oEAAiB,MAArB,IAAI,EAAkB,KAAK,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { handleWhen, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n array,\n boolean,\n coerce,\n create,\n enums,\n literal,\n number,\n optional,\n record,\n string,\n type,\n} from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport {\n bytesToHex,\n sha256,\n stringToBytes,\n StrictHexStruct,\n} from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { ChompApiServiceMethodActions } from './chomp-api-service-method-action-types.js';\nimport type {\n AssociateAddressParams,\n AssociateAddressResponse,\n ProfileAddressEntry,\n CreateUpgradeParams,\n CreateUpgradeResponse,\n UpgradeEntry,\n CreateWithdrawalParams,\n CreateWithdrawalResponse,\n IntentEntry,\n SendIntentParams,\n SendIntentResponse,\n ServiceDetailsResponse,\n VerifyDelegationParams,\n VerifyDelegationResponse,\n} from './types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ChompApiService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'ChompApiService';\n\n// === MESSENGER ===\n\n/**\n * All of the methods within {@link ChompApiService} that are exposed via the\n * messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = [\n 'associateAddress',\n 'getAssociatedAddresses',\n 'createUpgrade',\n 'getUpgrades',\n 'verifyDelegation',\n 'createIntents',\n 'getIntentsByAddress',\n 'createWithdrawal',\n 'getServiceDetails',\n] as const;\n\n/**\n * Invalidates cached queries for {@link ChompApiService}.\n */\nexport type ChompApiServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceActions =\n | ChompApiServiceMethodActions\n | ChompApiServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link ChompApiService} calls.\n */\ntype AllowedActions = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\n/**\n * Published when {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<\n typeof serviceName\n>;\n\n/**\n * Published when a key within {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceEvents =\n | ChompApiServiceCacheUpdatedEvent\n | ChompApiServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link ChompApiService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ChompApiService}.\n */\nexport type ChompApiServiceMessenger = Messenger<\n typeof serviceName,\n ChompApiServiceActions | AllowedActions,\n ChompApiServiceEvents | AllowedEvents\n>;\n\n// === RESPONSE VALIDATION ===\n\nconst AssociateAddressResponseStruct = type({\n profileId: optional(string()),\n address: StrictHexStruct,\n status: enums(['active', 'created']),\n});\n\n/**\n * Parses addresses into canonical lowercase form. CHOMP stores and returns\n * addresses lowercased, but `StrictHexStruct` alone accepts any casing, so\n * this makes the canonical form a guarantee of the parsed data rather than a\n * convention consumers must each remember.\n */\nconst LowercaseHexAddressStruct = coerce(StrictHexStruct, string(), (value) =>\n value.toLowerCase(),\n);\n\nconst ProfileAddressEntryArrayStruct = array(\n type({\n profileId: string(),\n address: LowercaseHexAddressStruct,\n status: enums(['active']),\n }),\n);\n\nconst AccountUpgradeStatusStruct = enums(['pending', 'upgraded']);\n\nconst AuthorizationDataStruct = type({\n r: StrictHexStruct,\n s: StrictHexStruct,\n v: number(),\n yParity: number(),\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n});\n\nconst CreateUpgradeResponseStruct = type({\n signerAddress: StrictHexStruct,\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n});\n\nconst UpgradeEntryArrayStruct = array(\n type({\n signerAddress: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n authorization: AuthorizationDataStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n }),\n);\n\nconst VerifyDelegationResponseStruct = type({\n valid: boolean(),\n delegationHash: optional(StrictHexStruct),\n errors: optional(array(string())),\n});\n\nconst SendIntentResponseArrayStruct = array(\n type({\n delegationHash: StrictHexStruct,\n metadata: type({\n allowance: StrictHexStruct,\n tokenSymbol: string(),\n tokenAddress: StrictHexStruct,\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n createdAt: string(),\n }),\n);\n\nconst IntentEntryArrayStruct = array(\n type({\n account: StrictHexStruct,\n delegationHash: StrictHexStruct,\n chainId: StrictHexStruct,\n status: enums(['active', 'revoked']),\n metadata: type({\n allowance: StrictHexStruct,\n tokenAddress: StrictHexStruct,\n tokenSymbol: string(),\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n }),\n);\n\nconst CreateWithdrawalResponseStruct = type({\n success: literal(true),\n});\n\nconst ServiceDetailsProtocolStruct = type({\n supportedTokens: array(\n type({\n tokenAddress: StrictHexStruct,\n tokenDecimals: number(),\n }),\n ),\n adapterAddress: StrictHexStruct,\n intentTypes: array(enums(['cash-deposit', 'cash-withdrawal'])),\n});\n\nconst ServiceDetailsResponseStruct = type({\n auth: type({\n message: string(),\n }),\n chains: record(\n StrictHexStruct,\n type({\n autoDepositDelegate: StrictHexStruct,\n protocol: record(string(), ServiceDetailsProtocolStruct),\n }),\n ),\n});\n\n// === RETRY POLICY ===\n\n/**\n * Determines whether an error from a CHOMP API call is worth retrying.\n *\n * 4xx responses (e.g. 409 \"already exists\", 400 validation, 401/403 auth) are\n * caused by the request itself and will not be resolved by re-issuing the same\n * request, so they bypass the retry loop. 429 is treated as transient and\n * retried alongside 5xx server errors. Non-HTTP errors (network/timeout) fall\n * through to the default \"retry\" behaviour.\n *\n * @param error - The error thrown by the query function.\n * @returns `true` when the error is worth retrying.\n */\nfunction isRetryableError(error: unknown): boolean {\n if (error instanceof HttpError) {\n if (error.httpStatus === 429) {\n return true;\n }\n return error.httpStatus < 400 || error.httpStatus >= 500;\n }\n return true;\n}\n\nconst DEFAULT_POLICY_OPTIONS: CreateServicePolicyOptions = {\n retryFilterPolicy: handleWhen(isRetryableError),\n};\n\n// === SERVICE DEFINITION ===\n\n/**\n * This service is responsible for communicating with the CHOMP API.\n *\n * All requests are authenticated via JWT Bearer tokens obtained from the\n * `AuthenticationController:getBearerToken` messenger action.\n */\nexport class ChompApiService extends BaseDataService<\n typeof serviceName,\n ChompApiServiceMessenger\n> {\n readonly #baseUrl: string;\n\n /**\n * Constructs a new ChompApiService.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.baseUrl - The base URL of the CHOMP API.\n * @param args.queryClientConfig - Configuration for the underlying TanStack\n * Query client.\n * @param args.policyOptions - Options to pass to `createServicePolicy`.\n */\n constructor({\n messenger,\n baseUrl,\n queryClientConfig = {},\n policyOptions = {},\n }: {\n messenger: ChompApiServiceMessenger;\n baseUrl: string;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions: { ...DEFAULT_POLICY_OPTIONS, ...policyOptions },\n });\n\n this.#baseUrl = baseUrl;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Builds the standard headers for a CHOMP API request authenticated with\n * the given bearer token.\n *\n * @param token - The bearer token to authenticate with.\n * @returns Headers including Authorization and Content-Type.\n */\n #headersForToken(token: string): Record<string, string> {\n return {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n };\n }\n\n /**\n * Builds the standard headers for an authenticated CHOMP API request.\n *\n * @returns Headers including Authorization and Content-Type.\n */\n async #authHeaders(): Promise<Record<string, string>> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return this.#headersForToken(token);\n }\n\n /**\n * Associates an address with a CHOMP profile.\n *\n * POST /v1/auth/address\n *\n * @param params - The association params containing signature, timestamp,\n * and address.\n * @returns The profile association result: `status: 'created'` for a new\n * association, `status: 'active'` when the address was already associated\n * with the authenticated profile. Throws on 409, which indicates the\n * address is associated with a different profile.\n */\n async associateAddress(\n params: AssociateAddressParams,\n ): Promise<AssociateAddressResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:associateAddress`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, AssociateAddressResponseStruct);\n }\n\n /**\n * Fetches the addresses associated with the authenticated profile.\n *\n * GET /v1/auth/address\n *\n * The result is scoped to the authenticated profile and consumers use it\n * to decide whether an association already exists, so it is always fetched\n * fresh (`staleTime: 0`) and evicted as soon as the call settles\n * (`cacheTime: 0`). The query key carries a SHA-256 digest of the bearer\n * token — the same token the request is made with — so concurrent calls\n * only share an in-flight request when they are for the same profile. The\n * digest, not the token, is used because query keys leave the service via\n * the `cacheUpdated` messenger events.\n *\n * @returns The active address associations; empty array if none exist.\n * Addresses are lowercased.\n */\n async getAssociatedAddresses(): Promise<ProfileAddressEntry[]> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n const profileKey = bytesToHex(await sha256(stringToBytes(token)));\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getAssociatedAddresses`, profileKey],\n staleTime: 0,\n cacheTime: 0,\n queryFn: async () => {\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n { headers: this.#headersForToken(token) },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ProfileAddressEntryArrayStruct);\n }\n\n /**\n * Creates an account upgrade request.\n *\n * POST /v1/account-upgrade\n *\n * @param params - The upgrade params containing signature components and\n * chain details.\n * @returns The upgrade result.\n */\n async createUpgrade(\n params: CreateUpgradeParams,\n ): Promise<CreateUpgradeResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createUpgrade`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/account-upgrade', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/account-upgrade failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateUpgradeResponseStruct);\n }\n\n /**\n * Fetches all EIP-7702 upgrade authorizations for a given address (one per\n * chain).\n *\n * GET /v1/account-upgrade/:address\n *\n * @param address - The address to look up.\n * @returns The upgrade entries; empty array if none exist.\n */\n async getUpgrades(address: Hex): Promise<UpgradeEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getUpgrades`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/account-upgrade/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get upgrades request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, UpgradeEntryArrayStruct);\n }\n\n /**\n * Verifies a delegation signature.\n *\n * POST /v1/intent/verify-delegation\n *\n * @param params - The delegation verification params.\n * @returns The verification result including validity and optional errors.\n */\n async verifyDelegation(\n params: VerifyDelegationParams,\n ): Promise<VerifyDelegationResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:verifyDelegation`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/intent/verify-delegation', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent/verify-delegation failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, VerifyDelegationResponseStruct);\n }\n\n /**\n * Submits one or more intents to the CHOMP API.\n *\n * POST /v1/intent\n *\n * @param intents - The array of intents to submit.\n * @returns The array of intent responses.\n */\n async createIntents(\n intents: SendIntentParams[],\n ): Promise<SendIntentResponse[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createIntents`, intents],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/intent', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(intents),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, SendIntentResponseArrayStruct);\n }\n\n /**\n * Fetches intents associated with a given address.\n *\n * GET /v1/intent/account/:address\n *\n * @param address - The address to look up intents for.\n * @returns The array of intents for the address.\n */\n async getIntentsByAddress(address: Hex): Promise<IntentEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getIntentsByAddress`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/intent/account/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get intents request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, IntentEntryArrayStruct);\n }\n\n /**\n * Creates a withdrawal for card spend flows.\n *\n * POST /v1/withdrawal\n *\n * @param params - The withdrawal params containing chainId, amount\n * (decimal or hex string), and account address.\n * @returns The withdrawal result.\n */\n async createWithdrawal(\n params: CreateWithdrawalParams,\n ): Promise<CreateWithdrawalResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createWithdrawal`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/withdrawal', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/withdrawal failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateWithdrawalResponseStruct);\n }\n\n /**\n * Retrieves service details including delegation redeemer addresses and DeFi\n * contract details for signing delegations for auto-deposit functionality.\n *\n * GET /v1/chomp\n *\n * @param chainIds - Array of chain IDs (0x-prefixed hex strings) to retrieve\n * details for.\n * @returns The service details for the requested chains.\n */\n async getServiceDetails(chainIds: Hex[]): Promise<ServiceDetailsResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getServiceDetails`, chainIds],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const url = new URL('/v1/chomp', this.#baseUrl);\n url.searchParams.set('chainId', chainIds.join(','));\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/chomp failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ServiceDetailsResponseStruct);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chomp-api-service.cjs","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA8D;AAO9D,iEAAmE;AAEnE,uDAY+B;AAE/B,2CAKyB;AAqBzB,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,iBAAiB,CAAC;AAE7C,oBAAoB;AAEpB;;;GAGG;AACH,MAAM,yBAAyB,GAAG;IAChC,kBAAkB;IAClB,wBAAwB;IACxB,eAAe;IACf,aAAa;IACb,kBAAkB;IAClB,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,mBAAmB;CACX,CAAC;AA0DX,8BAA8B;AAE9B,MAAM,8BAA8B,GAAG,IAAA,kBAAI,EAAC;IAC1C,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC7B,OAAO,EAAE,uBAAe;IACxB,MAAM,EAAE,IAAA,mBAAK,EAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;CACrC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,IAAA,oBAAM,EAAC,uBAAe,EAAE,IAAA,oBAAM,GAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAC5E,KAAK,CAAC,WAAW,EAAE,CACpB,CAAC;AAEF,MAAM,8BA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,CAAC,GAAG,CAAC,CAAC,CAAC;gBACpD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;gBAE/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,4BAAS,CACjB,QAAQ,CAAC,MAAM,EACf,qCAAqC,QAAQ,CAAC,MAAM,GAAG,CACxD,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,IAAA,oBAAM,EAAC,YAAY,EAAE,4BAA4B,CAAC,CAAC;IAC5D,CAAC;CACF;AAvZD,0CAuZC;mKAtWkB,KAAa;IAC5B,OAAO;QACL,aAAa,EAAE,UAAU,KAAK,EAAE;QAChC,cAAc,EAAE,kBAAkB;KACnC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK;IACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACrC,yCAAyC,CAC1C,CAAC;IACF,OAAO,uBAAA,IAAI,oEAAiB,MAArB,IAAI,EAAkB,KAAK,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { handleWhen, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n array,\n boolean,\n coerce,\n create,\n enums,\n literal,\n number,\n optional,\n record,\n string,\n type,\n} from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport {\n bytesToHex,\n sha256,\n stringToBytes,\n StrictHexStruct,\n} from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { ChompApiServiceMethodActions } from './chomp-api-service-method-action-types.js';\nimport type {\n AssociateAddressParams,\n AssociateAddressResponse,\n ProfileAddressEntry,\n CreateUpgradeParams,\n CreateUpgradeResponse,\n UpgradeEntry,\n CreateWithdrawalParams,\n CreateWithdrawalResponse,\n IntentEntry,\n SendIntentParams,\n SendIntentResponse,\n ServiceDetailsResponse,\n VerifyDelegationParams,\n VerifyDelegationResponse,\n} from './types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ChompApiService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'ChompApiService';\n\n// === MESSENGER ===\n\n/**\n * All of the methods within {@link ChompApiService} that are exposed via the\n * messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = [\n 'associateAddress',\n 'getAssociatedAddresses',\n 'createUpgrade',\n 'getUpgrades',\n 'verifyDelegation',\n 'createIntents',\n 'getIntentsByAddress',\n 'createWithdrawal',\n 'getServiceDetails',\n] as const;\n\n/**\n * Invalidates cached queries for {@link ChompApiService}.\n */\nexport type ChompApiServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceActions =\n | ChompApiServiceMethodActions\n | ChompApiServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link ChompApiService} calls.\n */\ntype AllowedActions = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\n/**\n * Published when {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<\n typeof serviceName\n>;\n\n/**\n * Published when a key within {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceEvents =\n | ChompApiServiceCacheUpdatedEvent\n | ChompApiServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link ChompApiService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ChompApiService}.\n */\nexport type ChompApiServiceMessenger = Messenger<\n typeof serviceName,\n ChompApiServiceActions | AllowedActions,\n ChompApiServiceEvents | AllowedEvents\n>;\n\n// === RESPONSE VALIDATION ===\n\nconst AssociateAddressResponseStruct = type({\n profileId: optional(string()),\n address: StrictHexStruct,\n status: enums(['active', 'created']),\n});\n\n/**\n * Parses addresses into canonical lowercase form. CHOMP stores and returns\n * addresses lowercased, but `StrictHexStruct` alone accepts any casing, so\n * this makes the canonical form a guarantee of the parsed data rather than a\n * convention consumers must each remember.\n */\nconst LowercaseHexAddressStruct = coerce(StrictHexStruct, string(), (value) =>\n value.toLowerCase(),\n);\n\nconst ProfileAddressEntryArrayStruct = array(\n type({\n profileId: string(),\n address: LowercaseHexAddressStruct,\n status: enums(['active']),\n }),\n);\n\nconst AccountUpgradeStatusStruct = enums(['pending', 'upgraded']);\n\nconst AuthorizationDataStruct = type({\n r: StrictHexStruct,\n s: StrictHexStruct,\n v: number(),\n yParity: number(),\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n});\n\nconst CreateUpgradeResponseStruct = type({\n signerAddress: StrictHexStruct,\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n});\n\nconst UpgradeEntryArrayStruct = array(\n type({\n signerAddress: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n authorization: AuthorizationDataStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n }),\n);\n\nconst VerifyDelegationResponseStruct = type({\n valid: boolean(),\n delegationHash: optional(StrictHexStruct),\n errors: optional(array(string())),\n});\n\nconst SendIntentResponseArrayStruct = array(\n type({\n delegationHash: StrictHexStruct,\n metadata: type({\n allowance: StrictHexStruct,\n tokenSymbol: string(),\n tokenAddress: StrictHexStruct,\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n createdAt: string(),\n }),\n);\n\nconst IntentEntryArrayStruct = array(\n type({\n account: StrictHexStruct,\n delegationHash: StrictHexStruct,\n chainId: StrictHexStruct,\n status: enums(['active', 'revoked']),\n metadata: type({\n allowance: StrictHexStruct,\n tokenAddress: StrictHexStruct,\n tokenSymbol: string(),\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n }),\n);\n\nconst CreateWithdrawalResponseStruct = type({\n success: literal(true),\n});\n\nconst ServiceDetailsProtocolStruct = type({\n supportedTokens: array(\n type({\n tokenAddress: StrictHexStruct,\n tokenDecimals: number(),\n }),\n ),\n adapterAddress: StrictHexStruct,\n intentTypes: array(enums(['cash-deposit', 'cash-withdrawal'])),\n});\n\nconst ServiceDetailsResponseStruct = type({\n auth: type({\n message: string(),\n }),\n chains: record(\n StrictHexStruct,\n type({\n autoDepositDelegate: StrictHexStruct,\n protocol: record(string(), ServiceDetailsProtocolStruct),\n }),\n ),\n});\n\n// === RETRY POLICY ===\n\n/**\n * Determines whether an error from a CHOMP API call is worth retrying.\n *\n * 4xx responses (e.g. 409 \"already exists\", 400 validation, 401/403 auth) are\n * caused by the request itself and will not be resolved by re-issuing the same\n * request, so they bypass the retry loop. 429 is treated as transient and\n * retried alongside 5xx server errors. Non-HTTP errors (network/timeout) fall\n * through to the default \"retry\" behaviour.\n *\n * @param error - The error thrown by the query function.\n * @returns `true` when the error is worth retrying.\n */\nfunction isRetryableError(error: unknown): boolean {\n if (error instanceof HttpError) {\n if (error.httpStatus === 429) {\n return true;\n }\n return error.httpStatus < 400 || error.httpStatus >= 500;\n }\n return true;\n}\n\nconst DEFAULT_POLICY_OPTIONS: CreateServicePolicyOptions = {\n retryFilterPolicy: handleWhen(isRetryableError),\n};\n\n// === SERVICE DEFINITION ===\n\n/**\n * This service is responsible for communicating with the CHOMP API.\n *\n * All requests are authenticated via JWT Bearer tokens obtained from the\n * `AuthenticationController:getBearerToken` messenger action.\n */\nexport class ChompApiService extends BaseDataService<\n typeof serviceName,\n ChompApiServiceMessenger\n> {\n readonly #baseUrl: string;\n\n /**\n * Constructs a new ChompApiService.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.baseUrl - The base URL of the CHOMP API.\n * @param args.queryClientConfig - Configuration for the underlying TanStack\n * Query client.\n * @param args.policyOptions - Options to pass to `createServicePolicy`.\n */\n constructor({\n messenger,\n baseUrl,\n queryClientConfig = {},\n policyOptions = {},\n }: {\n messenger: ChompApiServiceMessenger;\n baseUrl: string;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions: { ...DEFAULT_POLICY_OPTIONS, ...policyOptions },\n });\n\n this.#baseUrl = baseUrl;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Builds the standard headers for a CHOMP API request authenticated with\n * the given bearer token.\n *\n * @param token - The bearer token to authenticate with.\n * @returns Headers including Authorization and Content-Type.\n */\n #headersForToken(token: string): Record<string, string> {\n return {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n };\n }\n\n /**\n * Builds the standard headers for an authenticated CHOMP API request.\n *\n * @returns Headers including Authorization and Content-Type.\n */\n async #authHeaders(): Promise<Record<string, string>> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return this.#headersForToken(token);\n }\n\n /**\n * Associates an address with a CHOMP profile.\n *\n * POST /v1/auth/address\n *\n * @param params - The association params containing signature, timestamp,\n * and address.\n * @returns The profile association result: `status: 'created'` for a new\n * association, `status: 'active'` when the address was already associated\n * with the authenticated profile. Throws on 409, which indicates the\n * address is associated with a different profile.\n */\n async associateAddress(\n params: AssociateAddressParams,\n ): Promise<AssociateAddressResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:associateAddress`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, AssociateAddressResponseStruct);\n }\n\n /**\n * Fetches the addresses associated with the authenticated profile.\n *\n * GET /v1/auth/address\n *\n * The result is scoped to the authenticated profile and consumers use it\n * to decide whether an association already exists, so it is always fetched\n * fresh (`staleTime: 0`) and evicted as soon as the call settles\n * (`gcTime: 0`). The query key carries a SHA-256 digest of the bearer\n * token — the same token the request is made with — so concurrent calls\n * only share an in-flight request when they are for the same profile. The\n * digest, not the token, is used because query keys leave the service via\n * the `cacheUpdated` messenger events.\n *\n * @returns The active address associations; empty array if none exist.\n * Addresses are lowercased.\n */\n async getAssociatedAddresses(): Promise<ProfileAddressEntry[]> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n const profileKey = bytesToHex(await sha256(stringToBytes(token)));\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getAssociatedAddresses`, profileKey],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n { headers: this.#headersForToken(token) },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ProfileAddressEntryArrayStruct);\n }\n\n /**\n * Creates an account upgrade request.\n *\n * POST /v1/account-upgrade\n *\n * @param params - The upgrade params containing signature components and\n * chain details.\n * @returns The upgrade result.\n */\n async createUpgrade(\n params: CreateUpgradeParams,\n ): Promise<CreateUpgradeResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createUpgrade`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/account-upgrade', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/account-upgrade failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateUpgradeResponseStruct);\n }\n\n /**\n * Fetches all EIP-7702 upgrade authorizations for a given address (one per\n * chain).\n *\n * GET /v1/account-upgrade/:address\n *\n * @param address - The address to look up.\n * @returns The upgrade entries; empty array if none exist.\n */\n async getUpgrades(address: Hex): Promise<UpgradeEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getUpgrades`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/account-upgrade/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get upgrades request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, UpgradeEntryArrayStruct);\n }\n\n /**\n * Verifies a delegation signature.\n *\n * POST /v1/intent/verify-delegation\n *\n * @param params - The delegation verification params.\n * @returns The verification result including validity and optional errors.\n */\n async verifyDelegation(\n params: VerifyDelegationParams,\n ): Promise<VerifyDelegationResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:verifyDelegation`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/intent/verify-delegation', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent/verify-delegation failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, VerifyDelegationResponseStruct);\n }\n\n /**\n * Submits one or more intents to the CHOMP API.\n *\n * POST /v1/intent\n *\n * @param intents - The array of intents to submit.\n * @returns The array of intent responses.\n */\n async createIntents(\n intents: SendIntentParams[],\n ): Promise<SendIntentResponse[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createIntents`, intents],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/intent', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(intents),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, SendIntentResponseArrayStruct);\n }\n\n /**\n * Fetches intents associated with a given address.\n *\n * GET /v1/intent/account/:address\n *\n * @param address - The address to look up intents for.\n * @returns The array of intents for the address.\n */\n async getIntentsByAddress(address: Hex): Promise<IntentEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getIntentsByAddress`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/intent/account/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get intents request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, IntentEntryArrayStruct);\n }\n\n /**\n * Creates a withdrawal for card spend flows.\n *\n * POST /v1/withdrawal\n *\n * @param params - The withdrawal params containing chainId, amount\n * (decimal or hex string), and account address.\n * @returns The withdrawal result.\n */\n async createWithdrawal(\n params: CreateWithdrawalParams,\n ): Promise<CreateWithdrawalResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createWithdrawal`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/withdrawal', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/withdrawal failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateWithdrawalResponseStruct);\n }\n\n /**\n * Retrieves service details including delegation redeemer addresses and DeFi\n * contract details for signing delegations for auto-deposit functionality.\n *\n * GET /v1/chomp\n *\n * @param chainIds - Array of chain IDs (0x-prefixed hex strings) to retrieve\n * details for.\n * @returns The service details for the requested chains.\n */\n async getServiceDetails(chainIds: Hex[]): Promise<ServiceDetailsResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getServiceDetails`, chainIds],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const url = new URL('/v1/chomp', this.#baseUrl);\n url.searchParams.set('chainId', chainIds.join(','));\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/chomp failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ServiceDetailsResponseStruct);\n }\n}\n"]}
|
|
@@ -92,7 +92,7 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
92
92
|
* The result is scoped to the authenticated profile and consumers use it
|
|
93
93
|
* to decide whether an association already exists, so it is always fetched
|
|
94
94
|
* fresh (`staleTime: 0`) and evicted as soon as the call settles
|
|
95
|
-
* (`
|
|
95
|
+
* (`gcTime: 0`). The query key carries a SHA-256 digest of the bearer
|
|
96
96
|
* token — the same token the request is made with — so concurrent calls
|
|
97
97
|
* only share an in-flight request when they are for the same profile. The
|
|
98
98
|
* digest, not the token, is used because query keys leave the service via
|
|
@@ -92,7 +92,7 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
92
92
|
* The result is scoped to the authenticated profile and consumers use it
|
|
93
93
|
* to decide whether an association already exists, so it is always fetched
|
|
94
94
|
* fresh (`staleTime: 0`) and evicted as soon as the call settles
|
|
95
|
-
* (`
|
|
95
|
+
* (`gcTime: 0`). The query key carries a SHA-256 digest of the bearer
|
|
96
96
|
* token — the same token the request is made with — so concurrent calls
|
|
97
97
|
* only share an in-flight request when they are for the same profile. The
|
|
98
98
|
* digest, not the token, is used because query keys leave the service via
|
|
@@ -221,7 +221,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
221
221
|
* The result is scoped to the authenticated profile and consumers use it
|
|
222
222
|
* to decide whether an association already exists, so it is always fetched
|
|
223
223
|
* fresh (`staleTime: 0`) and evicted as soon as the call settles
|
|
224
|
-
* (`
|
|
224
|
+
* (`gcTime: 0`). The query key carries a SHA-256 digest of the bearer
|
|
225
225
|
* token — the same token the request is made with — so concurrent calls
|
|
226
226
|
* only share an in-flight request when they are for the same profile. The
|
|
227
227
|
* digest, not the token, is used because query keys leave the service via
|
|
@@ -236,7 +236,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
236
236
|
const jsonResponse = await this.fetchQuery({
|
|
237
237
|
queryKey: [`${this.name}:getAssociatedAddresses`, profileKey],
|
|
238
238
|
staleTime: 0,
|
|
239
|
-
|
|
239
|
+
gcTime: 0,
|
|
240
240
|
queryFn: async () => {
|
|
241
241
|
const response = await fetch(new URL('/v1/auth/address', __classPrivateFieldGet(this, _ChompApiService_baseUrl, "f")), { headers: __classPrivateFieldGet(this, _ChompApiService_instances, "m", _ChompApiService_headersForToken).call(this, token) });
|
|
242
242
|
if (!response.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service.mjs","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAO9D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,mCAAmC;AAEnE,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,EACL,8BAA8B;AAE/B,OAAO,EACL,UAAU,EACV,MAAM,EACN,aAAa,EACb,eAAe,EAChB,wBAAwB;AAqBzB,kBAAkB;AAElB;;;GAGG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AAC;gBAC1C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,uBAAA,IAAI,gCAAS,CAAC,CAAC;gBAChD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBACpD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;gBAE/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,SAAS,CACjB,QAAQ,CAAC,MAAM,EACf,qCAAqC,QAAQ,CAAC,MAAM,GAAG,CACxD,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,YAAY,EAAE,4BAA4B,CAAC,CAAC;IAC5D,CAAC;CACF;mKAtWkB,KAAa;IAC5B,OAAO;QACL,aAAa,EAAE,UAAU,KAAK,EAAE;QAChC,cAAc,EAAE,kBAAkB;KACnC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK;IACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACrC,yCAAyC,CAC1C,CAAC;IACF,OAAO,uBAAA,IAAI,oEAAiB,MAArB,IAAI,EAAkB,KAAK,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { handleWhen, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n array,\n boolean,\n coerce,\n create,\n enums,\n literal,\n number,\n optional,\n record,\n string,\n type,\n} from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport {\n bytesToHex,\n sha256,\n stringToBytes,\n StrictHexStruct,\n} from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { ChompApiServiceMethodActions } from './chomp-api-service-method-action-types.js';\nimport type {\n AssociateAddressParams,\n AssociateAddressResponse,\n ProfileAddressEntry,\n CreateUpgradeParams,\n CreateUpgradeResponse,\n UpgradeEntry,\n CreateWithdrawalParams,\n CreateWithdrawalResponse,\n IntentEntry,\n SendIntentParams,\n SendIntentResponse,\n ServiceDetailsResponse,\n VerifyDelegationParams,\n VerifyDelegationResponse,\n} from './types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ChompApiService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'ChompApiService';\n\n// === MESSENGER ===\n\n/**\n * All of the methods within {@link ChompApiService} that are exposed via the\n * messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = [\n 'associateAddress',\n 'getAssociatedAddresses',\n 'createUpgrade',\n 'getUpgrades',\n 'verifyDelegation',\n 'createIntents',\n 'getIntentsByAddress',\n 'createWithdrawal',\n 'getServiceDetails',\n] as const;\n\n/**\n * Invalidates cached queries for {@link ChompApiService}.\n */\nexport type ChompApiServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceActions =\n | ChompApiServiceMethodActions\n | ChompApiServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link ChompApiService} calls.\n */\ntype AllowedActions = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\n/**\n * Published when {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<\n typeof serviceName\n>;\n\n/**\n * Published when a key within {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceEvents =\n | ChompApiServiceCacheUpdatedEvent\n | ChompApiServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link ChompApiService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ChompApiService}.\n */\nexport type ChompApiServiceMessenger = Messenger<\n typeof serviceName,\n ChompApiServiceActions | AllowedActions,\n ChompApiServiceEvents | AllowedEvents\n>;\n\n// === RESPONSE VALIDATION ===\n\nconst AssociateAddressResponseStruct = type({\n profileId: optional(string()),\n address: StrictHexStruct,\n status: enums(['active', 'created']),\n});\n\n/**\n * Parses addresses into canonical lowercase form. CHOMP stores and returns\n * addresses lowercased, but `StrictHexStruct` alone accepts any casing, so\n * this makes the canonical form a guarantee of the parsed data rather than a\n * convention consumers must each remember.\n */\nconst LowercaseHexAddressStruct = coerce(StrictHexStruct, string(), (value) =>\n value.toLowerCase(),\n);\n\nconst ProfileAddressEntryArrayStruct = array(\n type({\n profileId: string(),\n address: LowercaseHexAddressStruct,\n status: enums(['active']),\n }),\n);\n\nconst AccountUpgradeStatusStruct = enums(['pending', 'upgraded']);\n\nconst AuthorizationDataStruct = type({\n r: StrictHexStruct,\n s: StrictHexStruct,\n v: number(),\n yParity: number(),\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n});\n\nconst CreateUpgradeResponseStruct = type({\n signerAddress: StrictHexStruct,\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n});\n\nconst UpgradeEntryArrayStruct = array(\n type({\n signerAddress: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n authorization: AuthorizationDataStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n }),\n);\n\nconst VerifyDelegationResponseStruct = type({\n valid: boolean(),\n delegationHash: optional(StrictHexStruct),\n errors: optional(array(string())),\n});\n\nconst SendIntentResponseArrayStruct = array(\n type({\n delegationHash: StrictHexStruct,\n metadata: type({\n allowance: StrictHexStruct,\n tokenSymbol: string(),\n tokenAddress: StrictHexStruct,\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n createdAt: string(),\n }),\n);\n\nconst IntentEntryArrayStruct = array(\n type({\n account: StrictHexStruct,\n delegationHash: StrictHexStruct,\n chainId: StrictHexStruct,\n status: enums(['active', 'revoked']),\n metadata: type({\n allowance: StrictHexStruct,\n tokenAddress: StrictHexStruct,\n tokenSymbol: string(),\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n }),\n);\n\nconst CreateWithdrawalResponseStruct = type({\n success: literal(true),\n});\n\nconst ServiceDetailsProtocolStruct = type({\n supportedTokens: array(\n type({\n tokenAddress: StrictHexStruct,\n tokenDecimals: number(),\n }),\n ),\n adapterAddress: StrictHexStruct,\n intentTypes: array(enums(['cash-deposit', 'cash-withdrawal'])),\n});\n\nconst ServiceDetailsResponseStruct = type({\n auth: type({\n message: string(),\n }),\n chains: record(\n StrictHexStruct,\n type({\n autoDepositDelegate: StrictHexStruct,\n protocol: record(string(), ServiceDetailsProtocolStruct),\n }),\n ),\n});\n\n// === RETRY POLICY ===\n\n/**\n * Determines whether an error from a CHOMP API call is worth retrying.\n *\n * 4xx responses (e.g. 409 \"already exists\", 400 validation, 401/403 auth) are\n * caused by the request itself and will not be resolved by re-issuing the same\n * request, so they bypass the retry loop. 429 is treated as transient and\n * retried alongside 5xx server errors. Non-HTTP errors (network/timeout) fall\n * through to the default \"retry\" behaviour.\n *\n * @param error - The error thrown by the query function.\n * @returns `true` when the error is worth retrying.\n */\nfunction isRetryableError(error: unknown): boolean {\n if (error instanceof HttpError) {\n if (error.httpStatus === 429) {\n return true;\n }\n return error.httpStatus < 400 || error.httpStatus >= 500;\n }\n return true;\n}\n\nconst DEFAULT_POLICY_OPTIONS: CreateServicePolicyOptions = {\n retryFilterPolicy: handleWhen(isRetryableError),\n};\n\n// === SERVICE DEFINITION ===\n\n/**\n * This service is responsible for communicating with the CHOMP API.\n *\n * All requests are authenticated via JWT Bearer tokens obtained from the\n * `AuthenticationController:getBearerToken` messenger action.\n */\nexport class ChompApiService extends BaseDataService<\n typeof serviceName,\n ChompApiServiceMessenger\n> {\n readonly #baseUrl: string;\n\n /**\n * Constructs a new ChompApiService.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.baseUrl - The base URL of the CHOMP API.\n * @param args.queryClientConfig - Configuration for the underlying TanStack\n * Query client.\n * @param args.policyOptions - Options to pass to `createServicePolicy`.\n */\n constructor({\n messenger,\n baseUrl,\n queryClientConfig = {},\n policyOptions = {},\n }: {\n messenger: ChompApiServiceMessenger;\n baseUrl: string;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions: { ...DEFAULT_POLICY_OPTIONS, ...policyOptions },\n });\n\n this.#baseUrl = baseUrl;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Builds the standard headers for a CHOMP API request authenticated with\n * the given bearer token.\n *\n * @param token - The bearer token to authenticate with.\n * @returns Headers including Authorization and Content-Type.\n */\n #headersForToken(token: string): Record<string, string> {\n return {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n };\n }\n\n /**\n * Builds the standard headers for an authenticated CHOMP API request.\n *\n * @returns Headers including Authorization and Content-Type.\n */\n async #authHeaders(): Promise<Record<string, string>> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return this.#headersForToken(token);\n }\n\n /**\n * Associates an address with a CHOMP profile.\n *\n * POST /v1/auth/address\n *\n * @param params - The association params containing signature, timestamp,\n * and address.\n * @returns The profile association result: `status: 'created'` for a new\n * association, `status: 'active'` when the address was already associated\n * with the authenticated profile. Throws on 409, which indicates the\n * address is associated with a different profile.\n */\n async associateAddress(\n params: AssociateAddressParams,\n ): Promise<AssociateAddressResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:associateAddress`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, AssociateAddressResponseStruct);\n }\n\n /**\n * Fetches the addresses associated with the authenticated profile.\n *\n * GET /v1/auth/address\n *\n * The result is scoped to the authenticated profile and consumers use it\n * to decide whether an association already exists, so it is always fetched\n * fresh (`staleTime: 0`) and evicted as soon as the call settles\n * (`cacheTime: 0`). The query key carries a SHA-256 digest of the bearer\n * token — the same token the request is made with — so concurrent calls\n * only share an in-flight request when they are for the same profile. The\n * digest, not the token, is used because query keys leave the service via\n * the `cacheUpdated` messenger events.\n *\n * @returns The active address associations; empty array if none exist.\n * Addresses are lowercased.\n */\n async getAssociatedAddresses(): Promise<ProfileAddressEntry[]> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n const profileKey = bytesToHex(await sha256(stringToBytes(token)));\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getAssociatedAddresses`, profileKey],\n staleTime: 0,\n cacheTime: 0,\n queryFn: async () => {\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n { headers: this.#headersForToken(token) },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ProfileAddressEntryArrayStruct);\n }\n\n /**\n * Creates an account upgrade request.\n *\n * POST /v1/account-upgrade\n *\n * @param params - The upgrade params containing signature components and\n * chain details.\n * @returns The upgrade result.\n */\n async createUpgrade(\n params: CreateUpgradeParams,\n ): Promise<CreateUpgradeResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createUpgrade`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/account-upgrade', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/account-upgrade failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateUpgradeResponseStruct);\n }\n\n /**\n * Fetches all EIP-7702 upgrade authorizations for a given address (one per\n * chain).\n *\n * GET /v1/account-upgrade/:address\n *\n * @param address - The address to look up.\n * @returns The upgrade entries; empty array if none exist.\n */\n async getUpgrades(address: Hex): Promise<UpgradeEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getUpgrades`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/account-upgrade/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get upgrades request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, UpgradeEntryArrayStruct);\n }\n\n /**\n * Verifies a delegation signature.\n *\n * POST /v1/intent/verify-delegation\n *\n * @param params - The delegation verification params.\n * @returns The verification result including validity and optional errors.\n */\n async verifyDelegation(\n params: VerifyDelegationParams,\n ): Promise<VerifyDelegationResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:verifyDelegation`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/intent/verify-delegation', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent/verify-delegation failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, VerifyDelegationResponseStruct);\n }\n\n /**\n * Submits one or more intents to the CHOMP API.\n *\n * POST /v1/intent\n *\n * @param intents - The array of intents to submit.\n * @returns The array of intent responses.\n */\n async createIntents(\n intents: SendIntentParams[],\n ): Promise<SendIntentResponse[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createIntents`, intents],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/intent', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(intents),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, SendIntentResponseArrayStruct);\n }\n\n /**\n * Fetches intents associated with a given address.\n *\n * GET /v1/intent/account/:address\n *\n * @param address - The address to look up intents for.\n * @returns The array of intents for the address.\n */\n async getIntentsByAddress(address: Hex): Promise<IntentEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getIntentsByAddress`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/intent/account/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get intents request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, IntentEntryArrayStruct);\n }\n\n /**\n * Creates a withdrawal for card spend flows.\n *\n * POST /v1/withdrawal\n *\n * @param params - The withdrawal params containing chainId, amount\n * (decimal or hex string), and account address.\n * @returns The withdrawal result.\n */\n async createWithdrawal(\n params: CreateWithdrawalParams,\n ): Promise<CreateWithdrawalResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createWithdrawal`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/withdrawal', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/withdrawal failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateWithdrawalResponseStruct);\n }\n\n /**\n * Retrieves service details including delegation redeemer addresses and DeFi\n * contract details for signing delegations for auto-deposit functionality.\n *\n * GET /v1/chomp\n *\n * @param chainIds - Array of chain IDs (0x-prefixed hex strings) to retrieve\n * details for.\n * @returns The service details for the requested chains.\n */\n async getServiceDetails(chainIds: Hex[]): Promise<ServiceDetailsResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getServiceDetails`, chainIds],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const url = new URL('/v1/chomp', this.#baseUrl);\n url.searchParams.set('chainId', chainIds.join(','));\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/chomp failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ServiceDetailsResponseStruct);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chomp-api-service.mjs","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAO9D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,mCAAmC;AAEnE,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,EACL,8BAA8B;AAE/B,OAAO,EACL,UAAU,EACV,MAAM,EACN,aAAa,EACb,eAAe,EAChB,wBAAwB;AAqBzB,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAE7C,oBAAoB;AAEpB;;;GAG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,CAAC,CAAC;gBAChD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBACpD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;gBAE/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,SAAS,CACjB,QAAQ,CAAC,MAAM,EACf,qCAAqC,QAAQ,CAAC,MAAM,GAAG,CACxD,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,YAAY,EAAE,4BAA4B,CAAC,CAAC;IAC5D,CAAC;CACF;mKAtWkB,KAAa;IAC5B,OAAO;QACL,aAAa,EAAE,UAAU,KAAK,EAAE;QAChC,cAAc,EAAE,kBAAkB;KACnC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK;IACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACrC,yCAAyC,CAC1C,CAAC;IACF,OAAO,uBAAA,IAAI,oEAAiB,MAArB,IAAI,EAAkB,KAAK,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { handleWhen, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n array,\n boolean,\n coerce,\n create,\n enums,\n literal,\n number,\n optional,\n record,\n string,\n type,\n} from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport {\n bytesToHex,\n sha256,\n stringToBytes,\n StrictHexStruct,\n} from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { ChompApiServiceMethodActions } from './chomp-api-service-method-action-types.js';\nimport type {\n AssociateAddressParams,\n AssociateAddressResponse,\n ProfileAddressEntry,\n CreateUpgradeParams,\n CreateUpgradeResponse,\n UpgradeEntry,\n CreateWithdrawalParams,\n CreateWithdrawalResponse,\n IntentEntry,\n SendIntentParams,\n SendIntentResponse,\n ServiceDetailsResponse,\n VerifyDelegationParams,\n VerifyDelegationResponse,\n} from './types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ChompApiService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'ChompApiService';\n\n// === MESSENGER ===\n\n/**\n * All of the methods within {@link ChompApiService} that are exposed via the\n * messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = [\n 'associateAddress',\n 'getAssociatedAddresses',\n 'createUpgrade',\n 'getUpgrades',\n 'verifyDelegation',\n 'createIntents',\n 'getIntentsByAddress',\n 'createWithdrawal',\n 'getServiceDetails',\n] as const;\n\n/**\n * Invalidates cached queries for {@link ChompApiService}.\n */\nexport type ChompApiServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceActions =\n | ChompApiServiceMethodActions\n | ChompApiServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link ChompApiService} calls.\n */\ntype AllowedActions = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\n/**\n * Published when {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<\n typeof serviceName\n>;\n\n/**\n * Published when a key within {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceEvents =\n | ChompApiServiceCacheUpdatedEvent\n | ChompApiServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link ChompApiService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ChompApiService}.\n */\nexport type ChompApiServiceMessenger = Messenger<\n typeof serviceName,\n ChompApiServiceActions | AllowedActions,\n ChompApiServiceEvents | AllowedEvents\n>;\n\n// === RESPONSE VALIDATION ===\n\nconst AssociateAddressResponseStruct = type({\n profileId: optional(string()),\n address: StrictHexStruct,\n status: enums(['active', 'created']),\n});\n\n/**\n * Parses addresses into canonical lowercase form. CHOMP stores and returns\n * addresses lowercased, but `StrictHexStruct` alone accepts any casing, so\n * this makes the canonical form a guarantee of the parsed data rather than a\n * convention consumers must each remember.\n */\nconst LowercaseHexAddressStruct = coerce(StrictHexStruct, string(), (value) =>\n value.toLowerCase(),\n);\n\nconst ProfileAddressEntryArrayStruct = array(\n type({\n profileId: string(),\n address: LowercaseHexAddressStruct,\n status: enums(['active']),\n }),\n);\n\nconst AccountUpgradeStatusStruct = enums(['pending', 'upgraded']);\n\nconst AuthorizationDataStruct = type({\n r: StrictHexStruct,\n s: StrictHexStruct,\n v: number(),\n yParity: number(),\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n});\n\nconst CreateUpgradeResponseStruct = type({\n signerAddress: StrictHexStruct,\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n});\n\nconst UpgradeEntryArrayStruct = array(\n type({\n signerAddress: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n authorization: AuthorizationDataStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n }),\n);\n\nconst VerifyDelegationResponseStruct = type({\n valid: boolean(),\n delegationHash: optional(StrictHexStruct),\n errors: optional(array(string())),\n});\n\nconst SendIntentResponseArrayStruct = array(\n type({\n delegationHash: StrictHexStruct,\n metadata: type({\n allowance: StrictHexStruct,\n tokenSymbol: string(),\n tokenAddress: StrictHexStruct,\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n createdAt: string(),\n }),\n);\n\nconst IntentEntryArrayStruct = array(\n type({\n account: StrictHexStruct,\n delegationHash: StrictHexStruct,\n chainId: StrictHexStruct,\n status: enums(['active', 'revoked']),\n metadata: type({\n allowance: StrictHexStruct,\n tokenAddress: StrictHexStruct,\n tokenSymbol: string(),\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n }),\n);\n\nconst CreateWithdrawalResponseStruct = type({\n success: literal(true),\n});\n\nconst ServiceDetailsProtocolStruct = type({\n supportedTokens: array(\n type({\n tokenAddress: StrictHexStruct,\n tokenDecimals: number(),\n }),\n ),\n adapterAddress: StrictHexStruct,\n intentTypes: array(enums(['cash-deposit', 'cash-withdrawal'])),\n});\n\nconst ServiceDetailsResponseStruct = type({\n auth: type({\n message: string(),\n }),\n chains: record(\n StrictHexStruct,\n type({\n autoDepositDelegate: StrictHexStruct,\n protocol: record(string(), ServiceDetailsProtocolStruct),\n }),\n ),\n});\n\n// === RETRY POLICY ===\n\n/**\n * Determines whether an error from a CHOMP API call is worth retrying.\n *\n * 4xx responses (e.g. 409 \"already exists\", 400 validation, 401/403 auth) are\n * caused by the request itself and will not be resolved by re-issuing the same\n * request, so they bypass the retry loop. 429 is treated as transient and\n * retried alongside 5xx server errors. Non-HTTP errors (network/timeout) fall\n * through to the default \"retry\" behaviour.\n *\n * @param error - The error thrown by the query function.\n * @returns `true` when the error is worth retrying.\n */\nfunction isRetryableError(error: unknown): boolean {\n if (error instanceof HttpError) {\n if (error.httpStatus === 429) {\n return true;\n }\n return error.httpStatus < 400 || error.httpStatus >= 500;\n }\n return true;\n}\n\nconst DEFAULT_POLICY_OPTIONS: CreateServicePolicyOptions = {\n retryFilterPolicy: handleWhen(isRetryableError),\n};\n\n// === SERVICE DEFINITION ===\n\n/**\n * This service is responsible for communicating with the CHOMP API.\n *\n * All requests are authenticated via JWT Bearer tokens obtained from the\n * `AuthenticationController:getBearerToken` messenger action.\n */\nexport class ChompApiService extends BaseDataService<\n typeof serviceName,\n ChompApiServiceMessenger\n> {\n readonly #baseUrl: string;\n\n /**\n * Constructs a new ChompApiService.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.baseUrl - The base URL of the CHOMP API.\n * @param args.queryClientConfig - Configuration for the underlying TanStack\n * Query client.\n * @param args.policyOptions - Options to pass to `createServicePolicy`.\n */\n constructor({\n messenger,\n baseUrl,\n queryClientConfig = {},\n policyOptions = {},\n }: {\n messenger: ChompApiServiceMessenger;\n baseUrl: string;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions: { ...DEFAULT_POLICY_OPTIONS, ...policyOptions },\n });\n\n this.#baseUrl = baseUrl;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Builds the standard headers for a CHOMP API request authenticated with\n * the given bearer token.\n *\n * @param token - The bearer token to authenticate with.\n * @returns Headers including Authorization and Content-Type.\n */\n #headersForToken(token: string): Record<string, string> {\n return {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n };\n }\n\n /**\n * Builds the standard headers for an authenticated CHOMP API request.\n *\n * @returns Headers including Authorization and Content-Type.\n */\n async #authHeaders(): Promise<Record<string, string>> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return this.#headersForToken(token);\n }\n\n /**\n * Associates an address with a CHOMP profile.\n *\n * POST /v1/auth/address\n *\n * @param params - The association params containing signature, timestamp,\n * and address.\n * @returns The profile association result: `status: 'created'` for a new\n * association, `status: 'active'` when the address was already associated\n * with the authenticated profile. Throws on 409, which indicates the\n * address is associated with a different profile.\n */\n async associateAddress(\n params: AssociateAddressParams,\n ): Promise<AssociateAddressResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:associateAddress`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, AssociateAddressResponseStruct);\n }\n\n /**\n * Fetches the addresses associated with the authenticated profile.\n *\n * GET /v1/auth/address\n *\n * The result is scoped to the authenticated profile and consumers use it\n * to decide whether an association already exists, so it is always fetched\n * fresh (`staleTime: 0`) and evicted as soon as the call settles\n * (`gcTime: 0`). The query key carries a SHA-256 digest of the bearer\n * token — the same token the request is made with — so concurrent calls\n * only share an in-flight request when they are for the same profile. The\n * digest, not the token, is used because query keys leave the service via\n * the `cacheUpdated` messenger events.\n *\n * @returns The active address associations; empty array if none exist.\n * Addresses are lowercased.\n */\n async getAssociatedAddresses(): Promise<ProfileAddressEntry[]> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n const profileKey = bytesToHex(await sha256(stringToBytes(token)));\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getAssociatedAddresses`, profileKey],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n { headers: this.#headersForToken(token) },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ProfileAddressEntryArrayStruct);\n }\n\n /**\n * Creates an account upgrade request.\n *\n * POST /v1/account-upgrade\n *\n * @param params - The upgrade params containing signature components and\n * chain details.\n * @returns The upgrade result.\n */\n async createUpgrade(\n params: CreateUpgradeParams,\n ): Promise<CreateUpgradeResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createUpgrade`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/account-upgrade', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/account-upgrade failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateUpgradeResponseStruct);\n }\n\n /**\n * Fetches all EIP-7702 upgrade authorizations for a given address (one per\n * chain).\n *\n * GET /v1/account-upgrade/:address\n *\n * @param address - The address to look up.\n * @returns The upgrade entries; empty array if none exist.\n */\n async getUpgrades(address: Hex): Promise<UpgradeEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getUpgrades`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/account-upgrade/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get upgrades request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, UpgradeEntryArrayStruct);\n }\n\n /**\n * Verifies a delegation signature.\n *\n * POST /v1/intent/verify-delegation\n *\n * @param params - The delegation verification params.\n * @returns The verification result including validity and optional errors.\n */\n async verifyDelegation(\n params: VerifyDelegationParams,\n ): Promise<VerifyDelegationResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:verifyDelegation`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/intent/verify-delegation', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent/verify-delegation failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, VerifyDelegationResponseStruct);\n }\n\n /**\n * Submits one or more intents to the CHOMP API.\n *\n * POST /v1/intent\n *\n * @param intents - The array of intents to submit.\n * @returns The array of intent responses.\n */\n async createIntents(\n intents: SendIntentParams[],\n ): Promise<SendIntentResponse[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createIntents`, intents],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/intent', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(intents),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, SendIntentResponseArrayStruct);\n }\n\n /**\n * Fetches intents associated with a given address.\n *\n * GET /v1/intent/account/:address\n *\n * @param address - The address to look up intents for.\n * @returns The array of intents for the address.\n */\n async getIntentsByAddress(address: Hex): Promise<IntentEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getIntentsByAddress`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/intent/account/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get intents request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, IntentEntryArrayStruct);\n }\n\n /**\n * Creates a withdrawal for card spend flows.\n *\n * POST /v1/withdrawal\n *\n * @param params - The withdrawal params containing chainId, amount\n * (decimal or hex string), and account address.\n * @returns The withdrawal result.\n */\n async createWithdrawal(\n params: CreateWithdrawalParams,\n ): Promise<CreateWithdrawalResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createWithdrawal`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/withdrawal', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/withdrawal failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateWithdrawalResponseStruct);\n }\n\n /**\n * Retrieves service details including delegation redeemer addresses and DeFi\n * contract details for signing delegations for auto-deposit functionality.\n *\n * GET /v1/chomp\n *\n * @param chainIds - Array of chain IDs (0x-prefixed hex strings) to retrieve\n * details for.\n * @returns The service details for the requested chains.\n */\n async getServiceDetails(chainIds: Hex[]): Promise<ServiceDetailsResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getServiceDetails`, chainIds],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const url = new URL('/v1/chomp', this.#baseUrl);\n url.searchParams.set('chainId', chainIds.join(','));\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/chomp failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ServiceDetailsResponseStruct);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/chomp-api-service",
|
|
3
|
-
"version": "4.0.0-preview-
|
|
3
|
+
"version": "4.0.0-preview-7b60eca",
|
|
4
4
|
"description": "Data service for the Chomp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@metamask/messenger": "^2.0.0",
|
|
59
59
|
"@metamask/superstruct": "^3.1.0",
|
|
60
60
|
"@metamask/utils": "^11.11.0",
|
|
61
|
-
"@tanstack/query-core": "^
|
|
61
|
+
"@tanstack/query-core": "^5.62.16"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@metamask/auto-changelog": "^6.1.0",
|