@metamask-previews/chomp-api-service 6.0.1-preview-a0d99e051 → 6.0.1-preview-060b37d94
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 +1 -6
- package/dist/chomp-api-service-method-action-types.d.ts +1 -48
- package/dist/chomp-api-service-method-action-types.d.ts.map +1 -1
- package/dist/chomp-api-service-method-action-types.js.map +1 -1
- package/dist/chomp-api-service.d.ts +1 -39
- package/dist/chomp-api-service.d.ts.map +1 -1
- package/dist/chomp-api-service.js +3 -152
- package/dist/chomp-api-service.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +3 -57
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -9,11 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
-
- Add `getDerivedIdentities` method, also expose it through the messenger as `ChompApiService:getDerivedIdentities` ([#10695](https://github.com/MetaMask/core/pull/10695))
|
|
13
|
-
- Add `getDerivedIdentityByAddress` method, and expose it through the messenger as `ChompApiService:getDerivedIdentityByAddress` ([#10695](https://github.com/MetaMask/core/pull/10695))
|
|
14
|
-
- Add `disassociateAddress` method for `DELETE /v1/auth/address`, and expose it through the messenger as `ChompApiService:disassociateAddress` ([#10695](https://github.com/MetaMask/core/pull/10695))
|
|
15
|
-
- For an address linked as a successor, this cancels the Money Account migration and unfreezes its predecessor, which CHOMP only allows while the migration is not `DONE`.
|
|
16
|
-
- Add `AddressIdentityResponse`, `DerivedIdentitiesResponse`, `DerivedIdentity`, `DerivedIdentityAddressRole`, `DerivedIdentityMigration`, `DerivedIdentityStatus`, `MigrationStep`, `ChompApiServiceDisassociateAddressAction`, `ChompApiServiceGetDerivedIdentitiesAction`, and `ChompApiServiceGetDerivedIdentityByAddressAction` types ([#10695](https://github.com/MetaMask/core/pull/10695))
|
|
17
12
|
- Add `createAddressChallenge` method for `POST /v2/auth/address/challenge`, and expose it through the messenger as `ChompApiService:createAddressChallenge` ([#10687](https://github.com/MetaMask/core/pull/10687))
|
|
18
13
|
- Returns a single-use SIWE message bound to the profile, chain, purpose and address. The `ASSOCIATE_SUCCESSOR` purpose takes a `predecessorAddress` to link the address as the successor of an existing Money Account.
|
|
19
14
|
- Add `associateAddressV2` method for `POST /v2/auth/address`, and expose it through the messenger as `ChompApiService:associateAddressV2` ([#10687](https://github.com/MetaMask/core/pull/10687))
|
|
@@ -24,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
24
19
|
|
|
25
20
|
### Changed
|
|
26
21
|
|
|
27
|
-
-
|
|
22
|
+
- Bump `@metamask/utils` from `^12.0.0` to `^12.0.1` ([#11107](https://github.com/MetaMask/core/pull/11107))
|
|
28
23
|
|
|
29
24
|
### Removed
|
|
30
25
|
|
|
@@ -43,19 +43,6 @@ export type ChompApiServiceAssociateAddressV2Action = {
|
|
|
43
43
|
type: `ChompApiService:associateAddressV2`;
|
|
44
44
|
handler: ChompApiService['associateAddressV2'];
|
|
45
45
|
};
|
|
46
|
-
/**
|
|
47
|
-
* Removes an address association from the authenticated profile. For an
|
|
48
|
-
* address linked as a successor, this cancels the migration and unfreezes
|
|
49
|
-
* its predecessor, which is only allowed while the migration is not `DONE`.
|
|
50
|
-
*
|
|
51
|
-
* DELETE /v1/auth/address
|
|
52
|
-
*
|
|
53
|
-
* @param address - The address to disassociate.
|
|
54
|
-
*/
|
|
55
|
-
export type ChompApiServiceDisassociateAddressAction = {
|
|
56
|
-
type: `ChompApiService:disassociateAddress`;
|
|
57
|
-
handler: ChompApiService['disassociateAddress'];
|
|
58
|
-
};
|
|
59
46
|
/**
|
|
60
47
|
* Fetches the addresses associated with the authenticated profile.
|
|
61
48
|
*
|
|
@@ -170,42 +157,8 @@ export type ChompApiServiceGetServiceDetailsAction = {
|
|
|
170
157
|
type: `ChompApiService:getServiceDetails`;
|
|
171
158
|
handler: ChompApiService['getServiceDetails'];
|
|
172
159
|
};
|
|
173
|
-
/**
|
|
174
|
-
* Fetches the Money Account identities of the authenticated profile, with
|
|
175
|
-
* the status and migration steps CHOMP derives on every read.
|
|
176
|
-
*
|
|
177
|
-
* GET /v1/money-account/identities
|
|
178
|
-
*
|
|
179
|
-
* Profile-scoped and used to drive migrations, so it is always fetched
|
|
180
|
-
* fresh and keyed by a digest of the bearer token, like
|
|
181
|
-
* {@link ChompApiService.getAssociatedAddresses}.
|
|
182
|
-
*
|
|
183
|
-
* @returns The identities; empty when the profile has no Money Account.
|
|
184
|
-
* Addresses are lowercased.
|
|
185
|
-
*/
|
|
186
|
-
export type ChompApiServiceGetDerivedIdentitiesAction = {
|
|
187
|
-
type: `ChompApiService:getDerivedIdentities`;
|
|
188
|
-
handler: ChompApiService['getDerivedIdentities'];
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* Fetches the identity containing an address, along with where the address
|
|
192
|
-
* sits in it. The identity's `status` describes the whole chain.
|
|
193
|
-
*
|
|
194
|
-
* GET /v1/money-account/identities/address/:address
|
|
195
|
-
*
|
|
196
|
-
* Always fetched fresh and keyed by a digest of the bearer token, like
|
|
197
|
-
* {@link ChompApiService.getDerivedIdentities}.
|
|
198
|
-
*
|
|
199
|
-
* @param address - The address to look up.
|
|
200
|
-
* @returns The identity and address details, or `null` when the address is
|
|
201
|
-
* not associated with the authenticated profile. Addresses are lowercased.
|
|
202
|
-
*/
|
|
203
|
-
export type ChompApiServiceGetDerivedIdentityByAddressAction = {
|
|
204
|
-
type: `ChompApiService:getDerivedIdentityByAddress`;
|
|
205
|
-
handler: ChompApiService['getDerivedIdentityByAddress'];
|
|
206
|
-
};
|
|
207
160
|
/**
|
|
208
161
|
* Union of all ChompApiService action types.
|
|
209
162
|
*/
|
|
210
|
-
export type ChompApiServiceMethodActions = ChompApiServiceCreateAddressChallengeAction | ChompApiServiceAssociateAddressV2Action |
|
|
163
|
+
export type ChompApiServiceMethodActions = ChompApiServiceCreateAddressChallengeAction | ChompApiServiceAssociateAddressV2Action | ChompApiServiceGetAssociatedAddressesAction | ChompApiServiceCreateUpgradeAction | ChompApiServiceGetUpgradesAction | ChompApiServiceVerifyDelegationAction | ChompApiServiceCreateIntentsAction | ChompApiServiceGetIntentsByAddressAction | ChompApiServiceCreateWithdrawalAction | ChompApiServiceGetServiceDetailsAction;
|
|
211
164
|
//# sourceMappingURL=chomp-api-service-method-action-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service-method-action-types.d.ts","sourceRoot":"","sources":["../src/chomp-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,eAAe,CAAC,wBAAwB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,eAAe,CAAC,oBAAoB,CAAC,CAAC;CAChD,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"chomp-api-service-method-action-types.d.ts","sourceRoot":"","sources":["../src/chomp-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,eAAe,CAAC,wBAAwB,CAAC,CAAC;CACpD,CAAC;AA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AAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,eAAe,CAAC,mBAAmB,CAAC,CAAC;CAC/C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACpC,2CAA2C,GAC3C,uCAAuC,GACvC,2CAA2C,GAC3C,kCAAkC,GAClC,gCAAgC,GAChC,qCAAqC,GACrC,kCAAkC,GAClC,wCAAwC,GACxC,qCAAqC,GACrC,sCAAsC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service-method-action-types.js","sourceRoot":"","sources":["../src/chomp-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ChompApiService } from './chomp-api-service.js';\n\n/**\n * Requests a single-use challenge for associating an address through the v2\n * flow. Sign the returned `message` exactly as received, using\n * `personal_sign` with the address being associated, then submit it with\n * {@link ChompApiService.associateAddressV2} before `expiresAt`. Requesting\n * a new challenge for the same address replaces the previous one.\n *\n * POST /v2/auth/address/challenge\n *\n * Each call issues a new challenge, so the result is never cached.\n *\n * @param params - The address to associate and the association purpose.\n * `ASSOCIATE_SUCCESSOR` also requires the predecessor address.\n * @returns The challenge ID, the message to sign, and when it expires.\n */\nexport type ChompApiServiceCreateAddressChallengeAction = {\n type: `ChompApiService:createAddressChallenge`;\n handler: ChompApiService['createAddressChallenge'];\n};\n\n/**\n * Associates an address with a CHOMP profile by submitting the signature of\n * a challenge from {@link ChompApiService.createAddressChallenge}. The\n * address, purpose and predecessor come from the challenge. For\n * `ASSOCIATE_SUCCESSOR`, the association and the link to the predecessor\n * are written atomically.\n *\n * POST /v2/auth/address\n *\n * @param params - The challenge ID and its signature.\n * @returns The profile association result: `status: 'created'` when the\n * association or link was written, `status: 'active'` when the address was\n * already associated with the authenticated profile. Throws on 400\n * `CHALLENGE_INVALID_OR_EXPIRED` (request a new challenge), on 409 when the\n * address is associated with a different profile, and on link validation\n * errors.\n */\nexport type ChompApiServiceAssociateAddressV2Action = {\n type: `ChompApiService:associateAddressV2`;\n handler: ChompApiService['associateAddressV2'];\n};\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"chomp-api-service-method-action-types.js","sourceRoot":"","sources":["../src/chomp-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ChompApiService } from './chomp-api-service.js';\n\n/**\n * Requests a single-use challenge for associating an address through the v2\n * flow. Sign the returned `message` exactly as received, using\n * `personal_sign` with the address being associated, then submit it with\n * {@link ChompApiService.associateAddressV2} before `expiresAt`. Requesting\n * a new challenge for the same address replaces the previous one.\n *\n * POST /v2/auth/address/challenge\n *\n * Each call issues a new challenge, so the result is never cached.\n *\n * @param params - The address to associate and the association purpose.\n * `ASSOCIATE_SUCCESSOR` also requires the predecessor address.\n * @returns The challenge ID, the message to sign, and when it expires.\n */\nexport type ChompApiServiceCreateAddressChallengeAction = {\n type: `ChompApiService:createAddressChallenge`;\n handler: ChompApiService['createAddressChallenge'];\n};\n\n/**\n * Associates an address with a CHOMP profile by submitting the signature of\n * a challenge from {@link ChompApiService.createAddressChallenge}. The\n * address, purpose and predecessor come from the challenge. For\n * `ASSOCIATE_SUCCESSOR`, the association and the link to the predecessor\n * are written atomically.\n *\n * POST /v2/auth/address\n *\n * @param params - The challenge ID and its signature.\n * @returns The profile association result: `status: 'created'` when the\n * association or link was written, `status: 'active'` when the address was\n * already associated with the authenticated profile. Throws on 400\n * `CHALLENGE_INVALID_OR_EXPIRED` (request a new challenge), on 409 when the\n * address is associated with a different profile, and on link validation\n * errors.\n */\nexport type ChompApiServiceAssociateAddressV2Action = {\n type: `ChompApiService:associateAddressV2`;\n handler: ChompApiService['associateAddressV2'];\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 */\nexport type ChompApiServiceGetAssociatedAddressesAction = {\n type: `ChompApiService:getAssociatedAddresses`;\n handler: ChompApiService['getAssociatedAddresses'];\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 */\nexport type ChompApiServiceCreateUpgradeAction = {\n type: `ChompApiService:createUpgrade`;\n handler: ChompApiService['createUpgrade'];\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 */\nexport type ChompApiServiceGetUpgradesAction = {\n type: `ChompApiService:getUpgrades`;\n handler: ChompApiService['getUpgrades'];\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 */\nexport type ChompApiServiceVerifyDelegationAction = {\n type: `ChompApiService:verifyDelegation`;\n handler: ChompApiService['verifyDelegation'];\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 */\nexport type ChompApiServiceCreateIntentsAction = {\n type: `ChompApiService:createIntents`;\n handler: ChompApiService['createIntents'];\n};\n\n/**\n * Fetches intents associated with a given address.\n *\n * GET /v1/intent/account/:address\n *\n * Callers use the result to decide whether an intent already exists, so it\n * is always fetched fresh (`staleTime: 0`).\n *\n * @param address - The address to look up intents for.\n * @returns The array of intents for the address, omitting any with an\n * intent type this service does not recognise.\n */\nexport type ChompApiServiceGetIntentsByAddressAction = {\n type: `ChompApiService:getIntentsByAddress`;\n handler: ChompApiService['getIntentsByAddress'];\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 */\nexport type ChompApiServiceCreateWithdrawalAction = {\n type: `ChompApiService:createWithdrawal`;\n handler: ChompApiService['createWithdrawal'];\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 */\nexport type ChompApiServiceGetServiceDetailsAction = {\n type: `ChompApiService:getServiceDetails`;\n handler: ChompApiService['getServiceDetails'];\n};\n\n/**\n * Union of all ChompApiService action types.\n */\nexport type ChompApiServiceMethodActions =\n | ChompApiServiceCreateAddressChallengeAction\n | ChompApiServiceAssociateAddressV2Action\n | ChompApiServiceGetAssociatedAddressesAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetUpgradesAction\n | ChompApiServiceVerifyDelegationAction\n | ChompApiServiceCreateIntentsAction\n | ChompApiServiceGetIntentsByAddressAction\n | ChompApiServiceCreateWithdrawalAction\n | ChompApiServiceGetServiceDetailsAction;\n"]}
|
|
@@ -6,7 +6,7 @@ import type { Messenger } from '@metamask/messenger';
|
|
|
6
6
|
import type { Hex } from '@metamask/utils';
|
|
7
7
|
import type { QueryClientConfig } from '@tanstack/query-core';
|
|
8
8
|
import type { ChompApiServiceMethodActions } from './chomp-api-service-method-action-types.js';
|
|
9
|
-
import type {
|
|
9
|
+
import type { AssociateAddressResponse, AssociateAddressV2Params, CreateAddressChallengeParams, CreateAddressChallengeResponse, ProfileAddressEntry, CreateUpgradeParams, CreateUpgradeResponse, UpgradeEntry, CreateWithdrawalParams, CreateWithdrawalResponse, IntentEntry, SendIntentParams, SendIntentResponse, ServiceDetailsResponse, VerifyDelegationParams, VerifyDelegationResponse } from './types.js';
|
|
10
10
|
/**
|
|
11
11
|
* The name of the {@link ChompApiService}, used to namespace the service's
|
|
12
12
|
* actions and events.
|
|
@@ -124,16 +124,6 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
124
124
|
* errors.
|
|
125
125
|
*/
|
|
126
126
|
associateAddressV2(params: AssociateAddressV2Params): Promise<AssociateAddressResponse>;
|
|
127
|
-
/**
|
|
128
|
-
* Removes an address association from the authenticated profile. For an
|
|
129
|
-
* address linked as a successor, this cancels the migration and unfreezes
|
|
130
|
-
* its predecessor, which is only allowed while the migration is not `DONE`.
|
|
131
|
-
*
|
|
132
|
-
* DELETE /v1/auth/address
|
|
133
|
-
*
|
|
134
|
-
* @param address - The address to disassociate.
|
|
135
|
-
*/
|
|
136
|
-
disassociateAddress(address: Hex): Promise<void>;
|
|
137
127
|
/**
|
|
138
128
|
* Fetches the addresses associated with the authenticated profile.
|
|
139
129
|
*
|
|
@@ -224,34 +214,6 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
224
214
|
* @returns The service details for the requested chains.
|
|
225
215
|
*/
|
|
226
216
|
getServiceDetails(chainIds: Hex[]): Promise<ServiceDetailsResponse>;
|
|
227
|
-
/**
|
|
228
|
-
* Fetches the Money Account identities of the authenticated profile, with
|
|
229
|
-
* the status and migration steps CHOMP derives on every read.
|
|
230
|
-
*
|
|
231
|
-
* GET /v1/money-account/identities
|
|
232
|
-
*
|
|
233
|
-
* Profile-scoped and used to drive migrations, so it is always fetched
|
|
234
|
-
* fresh and keyed by a digest of the bearer token, like
|
|
235
|
-
* {@link ChompApiService.getAssociatedAddresses}.
|
|
236
|
-
*
|
|
237
|
-
* @returns The identities; empty when the profile has no Money Account.
|
|
238
|
-
* Addresses are lowercased.
|
|
239
|
-
*/
|
|
240
|
-
getDerivedIdentities(): Promise<DerivedIdentitiesResponse>;
|
|
241
|
-
/**
|
|
242
|
-
* Fetches the identity containing an address, along with where the address
|
|
243
|
-
* sits in it. The identity's `status` describes the whole chain.
|
|
244
|
-
*
|
|
245
|
-
* GET /v1/money-account/identities/address/:address
|
|
246
|
-
*
|
|
247
|
-
* Always fetched fresh and keyed by a digest of the bearer token, like
|
|
248
|
-
* {@link ChompApiService.getDerivedIdentities}.
|
|
249
|
-
*
|
|
250
|
-
* @param address - The address to look up.
|
|
251
|
-
* @returns The identity and address details, or `null` when the address is
|
|
252
|
-
* not associated with the authenticated profile. Addresses are lowercased.
|
|
253
|
-
*/
|
|
254
|
-
getDerivedIdentityByAddress(address: Hex): Promise<AddressIdentityResponse | null>;
|
|
255
217
|
}
|
|
256
218
|
export {};
|
|
257
219
|
//# sourceMappingURL=chomp-api-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service.d.ts","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAc,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"chomp-api-service.d.ts","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAc,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,EAAE,sBAAsB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,CA2BnC;IAED;;;;;;;OAOG;IACG,aAAa,CACjB,OAAO,EAAE,gBAAgB,EAAE,GAC1B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAwB/B;IAED;;;;;;;;;;;OAWG;IACG,mBAAmB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CA0B9D;IAED;;;;;;;;OAQG;IACG,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,CAwBnC;IAED;;;;;;;;;OASG;IACG,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAqBxE;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseDataService } from '@metamask/base-data-service';
|
|
2
2
|
import { handleWhen, HttpError } from '@metamask/controller-utils';
|
|
3
|
-
import { array, boolean, coerce, create, enums, literal,
|
|
3
|
+
import { array, boolean, coerce, create, enums, literal, number, optional, record, string, type, } from '@metamask/superstruct';
|
|
4
4
|
import { bytesToHex, hasProperty, isObject, sha256, stringToBytes, StrictHexStruct, } from '@metamask/utils';
|
|
5
5
|
const CHOMP_INTENT_TYPES = [
|
|
6
6
|
'cash-deposit',
|
|
@@ -8,18 +8,6 @@ const CHOMP_INTENT_TYPES = [
|
|
|
8
8
|
'cash-deposit-premium',
|
|
9
9
|
'cash-withdrawal-premium',
|
|
10
10
|
'cash-subscription',
|
|
11
|
-
'cash-migration-root',
|
|
12
|
-
'cash-migration-transfer',
|
|
13
|
-
];
|
|
14
|
-
const MIGRATION_STEPS = [
|
|
15
|
-
'SUCCESSOR_DEPOSIT_INTENT',
|
|
16
|
-
'SUCCESSOR_WITHDRAWAL_INTENT',
|
|
17
|
-
'SUCCESSOR_SUBSCRIPTION_INTENT',
|
|
18
|
-
'SUCCESSOR_MONITORED',
|
|
19
|
-
'ROOT_DELEGATION',
|
|
20
|
-
'TRANSFER_INTENT_MUSD',
|
|
21
|
-
'TRANSFER_INTENT_VMUSD',
|
|
22
|
-
'TRANSFER_INTENT_PVMUSD',
|
|
23
11
|
];
|
|
24
12
|
function isChompIntentType(value) {
|
|
25
13
|
return CHOMP_INTENT_TYPES.includes(value);
|
|
@@ -76,7 +64,6 @@ async function createChompApiError(response, message) {
|
|
|
76
64
|
const MESSENGER_EXPOSED_METHODS = [
|
|
77
65
|
'createAddressChallenge',
|
|
78
66
|
'associateAddressV2',
|
|
79
|
-
'disassociateAddress',
|
|
80
67
|
'getAssociatedAddresses',
|
|
81
68
|
'createUpgrade',
|
|
82
69
|
'getUpgrades',
|
|
@@ -85,8 +72,6 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
85
72
|
'getIntentsByAddress',
|
|
86
73
|
'createWithdrawal',
|
|
87
74
|
'getServiceDetails',
|
|
88
|
-
'getDerivedIdentities',
|
|
89
|
-
'getDerivedIdentityByAddress',
|
|
90
75
|
];
|
|
91
76
|
// === RESPONSE VALIDATION ===
|
|
92
77
|
const AssociateAddressResponseStruct = type({
|
|
@@ -111,31 +96,6 @@ const ProfileAddressEntryArrayStruct = array(type({
|
|
|
111
96
|
address: LowercaseHexAddressStruct,
|
|
112
97
|
status: enums(['active']),
|
|
113
98
|
}));
|
|
114
|
-
const MigrationStepArrayStruct = array(enums(MIGRATION_STEPS));
|
|
115
|
-
const DerivedIdentityStruct = type({
|
|
116
|
-
currentAddress: LowercaseHexAddressStruct,
|
|
117
|
-
previousAddresses: array(LowercaseHexAddressStruct),
|
|
118
|
-
status: enums(['NONE', 'MIGRATING', 'DONE']),
|
|
119
|
-
migration: nullable(type({
|
|
120
|
-
from: LowercaseHexAddressStruct,
|
|
121
|
-
to: LowercaseHexAddressStruct,
|
|
122
|
-
requiredSteps: MigrationStepArrayStruct,
|
|
123
|
-
completedSteps: MigrationStepArrayStruct,
|
|
124
|
-
missingSteps: MigrationStepArrayStruct,
|
|
125
|
-
})),
|
|
126
|
-
});
|
|
127
|
-
const DerivedIdentitiesResponseStruct = type({
|
|
128
|
-
identities: array(DerivedIdentityStruct),
|
|
129
|
-
});
|
|
130
|
-
const AddressIdentityResponseStruct = type({
|
|
131
|
-
identity: DerivedIdentityStruct,
|
|
132
|
-
address: type({
|
|
133
|
-
address: LowercaseHexAddressStruct,
|
|
134
|
-
role: enums(['CURRENT', 'PREVIOUS', 'PENDING_SUCCESSOR']),
|
|
135
|
-
predecessor: nullable(LowercaseHexAddressStruct),
|
|
136
|
-
successor: nullable(LowercaseHexAddressStruct),
|
|
137
|
-
}),
|
|
138
|
-
});
|
|
139
99
|
const AccountUpgradeStatusStruct = enums(['pending', 'upgraded']);
|
|
140
100
|
const AuthorizationDataStruct = type({
|
|
141
101
|
r: StrictHexStruct,
|
|
@@ -279,21 +239,6 @@ export class ChompApiService extends BaseDataService {
|
|
|
279
239
|
'Content-Type': 'application/json',
|
|
280
240
|
};
|
|
281
241
|
}
|
|
282
|
-
/**
|
|
283
|
-
* Fetches the bearer token along with a SHA-256 digest of it, for query
|
|
284
|
-
* keys of profile-scoped requests. The digest, not the token, goes in the
|
|
285
|
-
* key because query keys leave the service via the `cacheUpdated`
|
|
286
|
-
* messenger events.
|
|
287
|
-
*
|
|
288
|
-
* @returns The bearer token and its digest.
|
|
289
|
-
*/
|
|
290
|
-
async #getProfileScopedToken() {
|
|
291
|
-
const token = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
292
|
-
return {
|
|
293
|
-
token,
|
|
294
|
-
profileKey: bytesToHex(await sha256(stringToBytes(token))),
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
242
|
/**
|
|
298
243
|
* Builds the standard headers for an authenticated CHOMP API request.
|
|
299
244
|
*
|
|
@@ -375,34 +320,6 @@ export class ChompApiService extends BaseDataService {
|
|
|
375
320
|
});
|
|
376
321
|
return create(jsonResponse, AssociateAddressResponseStruct);
|
|
377
322
|
}
|
|
378
|
-
/**
|
|
379
|
-
* Removes an address association from the authenticated profile. For an
|
|
380
|
-
* address linked as a successor, this cancels the migration and unfreezes
|
|
381
|
-
* its predecessor, which is only allowed while the migration is not `DONE`.
|
|
382
|
-
*
|
|
383
|
-
* DELETE /v1/auth/address
|
|
384
|
-
*
|
|
385
|
-
* @param address - The address to disassociate.
|
|
386
|
-
*/
|
|
387
|
-
async disassociateAddress(address) {
|
|
388
|
-
await this.fetchQuery({
|
|
389
|
-
queryKey: [`${this.name}:disassociateAddress`, address],
|
|
390
|
-
staleTime: 0,
|
|
391
|
-
gcTime: 0,
|
|
392
|
-
queryFn: async () => {
|
|
393
|
-
const headers = await this.#authHeaders();
|
|
394
|
-
const response = await fetch(new URL('/v1/auth/address', this.#baseUrl), {
|
|
395
|
-
method: 'DELETE',
|
|
396
|
-
headers,
|
|
397
|
-
body: JSON.stringify({ address }),
|
|
398
|
-
});
|
|
399
|
-
if (!response.ok) {
|
|
400
|
-
throw await createChompApiError(response, `DELETE /v1/auth/address failed with status '${response.status}'`);
|
|
401
|
-
}
|
|
402
|
-
return null;
|
|
403
|
-
},
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
323
|
/**
|
|
407
324
|
* Fetches the addresses associated with the authenticated profile.
|
|
408
325
|
*
|
|
@@ -421,7 +338,8 @@ export class ChompApiService extends BaseDataService {
|
|
|
421
338
|
* Addresses are lowercased.
|
|
422
339
|
*/
|
|
423
340
|
async getAssociatedAddresses() {
|
|
424
|
-
const
|
|
341
|
+
const token = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
342
|
+
const profileKey = bytesToHex(await sha256(stringToBytes(token)));
|
|
425
343
|
const jsonResponse = await this.fetchQuery({
|
|
426
344
|
queryKey: [`${this.name}:getAssociatedAddresses`, profileKey],
|
|
427
345
|
staleTime: 0,
|
|
@@ -622,72 +540,5 @@ export class ChompApiService extends BaseDataService {
|
|
|
622
540
|
});
|
|
623
541
|
return create(jsonResponse, ServiceDetailsResponseStruct);
|
|
624
542
|
}
|
|
625
|
-
/**
|
|
626
|
-
* Fetches the Money Account identities of the authenticated profile, with
|
|
627
|
-
* the status and migration steps CHOMP derives on every read.
|
|
628
|
-
*
|
|
629
|
-
* GET /v1/money-account/identities
|
|
630
|
-
*
|
|
631
|
-
* Profile-scoped and used to drive migrations, so it is always fetched
|
|
632
|
-
* fresh and keyed by a digest of the bearer token, like
|
|
633
|
-
* {@link ChompApiService.getAssociatedAddresses}.
|
|
634
|
-
*
|
|
635
|
-
* @returns The identities; empty when the profile has no Money Account.
|
|
636
|
-
* Addresses are lowercased.
|
|
637
|
-
*/
|
|
638
|
-
async getDerivedIdentities() {
|
|
639
|
-
const { token, profileKey } = await this.#getProfileScopedToken();
|
|
640
|
-
const jsonResponse = await this.fetchQuery({
|
|
641
|
-
queryKey: [`${this.name}:getDerivedIdentities`, profileKey],
|
|
642
|
-
staleTime: 0,
|
|
643
|
-
gcTime: 0,
|
|
644
|
-
queryFn: async () => {
|
|
645
|
-
const response = await fetch(new URL('/v1/money-account/identities', this.#baseUrl), { headers: this.#headersForToken(token) });
|
|
646
|
-
if (!response.ok) {
|
|
647
|
-
throw await createChompApiError(response, `GET /v1/money-account/identities failed with status '${response.status}'`);
|
|
648
|
-
}
|
|
649
|
-
return response.json();
|
|
650
|
-
},
|
|
651
|
-
});
|
|
652
|
-
return create(jsonResponse, DerivedIdentitiesResponseStruct);
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Fetches the identity containing an address, along with where the address
|
|
656
|
-
* sits in it. The identity's `status` describes the whole chain.
|
|
657
|
-
*
|
|
658
|
-
* GET /v1/money-account/identities/address/:address
|
|
659
|
-
*
|
|
660
|
-
* Always fetched fresh and keyed by a digest of the bearer token, like
|
|
661
|
-
* {@link ChompApiService.getDerivedIdentities}.
|
|
662
|
-
*
|
|
663
|
-
* @param address - The address to look up.
|
|
664
|
-
* @returns The identity and address details, or `null` when the address is
|
|
665
|
-
* not associated with the authenticated profile. Addresses are lowercased.
|
|
666
|
-
*/
|
|
667
|
-
async getDerivedIdentityByAddress(address) {
|
|
668
|
-
const { token, profileKey } = await this.#getProfileScopedToken();
|
|
669
|
-
const jsonResponse = await this.fetchQuery({
|
|
670
|
-
queryKey: [
|
|
671
|
-
`${this.name}:getDerivedIdentityByAddress`,
|
|
672
|
-
profileKey,
|
|
673
|
-
address,
|
|
674
|
-
],
|
|
675
|
-
staleTime: 0,
|
|
676
|
-
gcTime: 0,
|
|
677
|
-
queryFn: async () => {
|
|
678
|
-
const response = await fetch(new URL(`/v1/money-account/identities/address/${address}`, this.#baseUrl), { headers: this.#headersForToken(token) });
|
|
679
|
-
if (response.status === 404) {
|
|
680
|
-
return null;
|
|
681
|
-
}
|
|
682
|
-
if (!response.ok) {
|
|
683
|
-
throw await createChompApiError(response, `GET /v1/money-account/identities/address/${address} failed with status '${response.status}'`);
|
|
684
|
-
}
|
|
685
|
-
return response.json();
|
|
686
|
-
},
|
|
687
|
-
});
|
|
688
|
-
return jsonResponse === null
|
|
689
|
-
? null
|
|
690
|
-
: create(jsonResponse, AddressIdentityResponseStruct);
|
|
691
|
-
}
|
|
692
543
|
}
|
|
693
544
|
//# sourceMappingURL=chomp-api-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service.js","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAO9D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,KAAK,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,GACL,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,UAAU,EACV,WAAW,EACX,QAAQ,EACR,MAAM,EACN,aAAa,EACb,eAAe,GAChB,MAAM,iBAAiB,CAAC;AA2BzB,MAAM,kBAAk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U;gBACV,OAAO;aACR;YACD,SAAS,EAAE,CAAC;YACZ,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,IAAI,GAAG,CACL,wCAAwC,OAAO,EAAE,EACjD,IAAI,CAAC,QAAQ,CACd,EACD,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAC1C,CAAC;gBAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;oBAC5B,OAAO,IAAI,CAAC;gBACd,CAAC;gBAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,MAAM,mBAAmB,CAC7B,QAAQ,EACR,4CAA4C,OAAO,wBAAwB,QAAQ,CAAC,MAAM,GAAG,CAC9F,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,YAAY,KAAK,IAAI;YAC1B,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,6BAA6B,CAAC,CAAC;IAC1D,CAAC;CACF","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 nullable,\n number,\n optional,\n record,\n string,\n type,\n} from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport {\n bytesToHex,\n hasProperty,\n isObject,\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 AddressIdentityResponse,\n AssociateAddressResponse,\n AssociateAddressV2Params,\n CreateAddressChallengeParams,\n CreateAddressChallengeResponse,\n ProfileAddressEntry,\n ChompIntentType,\n CreateUpgradeParams,\n CreateUpgradeResponse,\n UpgradeEntry,\n CreateWithdrawalParams,\n CreateWithdrawalResponse,\n DerivedIdentitiesResponse,\n IntentEntry,\n MigrationStep,\n SendIntentParams,\n SendIntentResponse,\n ServiceDetailsResponse,\n VerifyDelegationParams,\n VerifyDelegationResponse,\n} from './types.js';\n\nconst CHOMP_INTENT_TYPES: ChompIntentType[] = [\n 'cash-deposit',\n 'cash-withdrawal',\n 'cash-deposit-premium',\n 'cash-withdrawal-premium',\n 'cash-subscription',\n 'cash-migration-root',\n 'cash-migration-transfer',\n];\n\nconst MIGRATION_STEPS: MigrationStep[] = [\n 'SUCCESSOR_DEPOSIT_INTENT',\n 'SUCCESSOR_WITHDRAWAL_INTENT',\n 'SUCCESSOR_SUBSCRIPTION_INTENT',\n 'SUCCESSOR_MONITORED',\n 'ROOT_DELEGATION',\n 'TRANSFER_INTENT_MUSD',\n 'TRANSFER_INTENT_VMUSD',\n 'TRANSFER_INTENT_PVMUSD',\n];\n\nfunction isChompIntentType(value: string): value is ChompIntentType {\n return (CHOMP_INTENT_TYPES as string[]).includes(value);\n}\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// === ERRORS ===\n\n/**\n * Thrown when the CHOMP API responds with a non-2xx status.\n */\nexport class ChompApiError extends HttpError {\n /**\n * The CHOMP error code from the response body (e.g.\n * `PREDECESSOR_HAS_OPEN_WITHDRAWALS`), if one was provided.\n */\n readonly code: string | undefined;\n\n /**\n * Construct a CHOMP API error.\n *\n * @param status - The HTTP response status.\n * @param message - The error message.\n * @param code - The CHOMP error code from the response body.\n */\n constructor(status: number, message: string, code?: string) {\n super(status, message);\n this.name = 'ChompApiError';\n this.code = code;\n }\n}\n\n/**\n * Builds a {@link ChompApiError} from a non-2xx response, reading the CHOMP\n * error code from the response body when there is one.\n *\n * @param response - The non-2xx response.\n * @param message - The error message.\n * @returns The error to throw.\n */\nasync function createChompApiError(\n response: Response,\n message: string,\n): Promise<ChompApiError> {\n const body: unknown = await response.json().catch(() => undefined);\n const code =\n isObject(body) && hasProperty(body, 'code') && typeof body.code === 'string'\n ? body.code\n : undefined;\n return new ChompApiError(response.status, message, code);\n}\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 'createAddressChallenge',\n 'associateAddressV2',\n 'disassociateAddress',\n 'getAssociatedAddresses',\n 'createUpgrade',\n 'getUpgrades',\n 'verifyDelegation',\n 'createIntents',\n 'getIntentsByAddress',\n 'createWithdrawal',\n 'getServiceDetails',\n 'getDerivedIdentities',\n 'getDerivedIdentityByAddress',\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\nconst CreateAddressChallengeResponseStruct = type({\n challengeId: string(),\n message: string(),\n expiresAt: string(),\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 MigrationStepArrayStruct = array(enums(MIGRATION_STEPS));\n\nconst DerivedIdentityStruct = type({\n currentAddress: LowercaseHexAddressStruct,\n previousAddresses: array(LowercaseHexAddressStruct),\n status: enums(['NONE', 'MIGRATING', 'DONE']),\n migration: nullable(\n type({\n from: LowercaseHexAddressStruct,\n to: LowercaseHexAddressStruct,\n requiredSteps: MigrationStepArrayStruct,\n completedSteps: MigrationStepArrayStruct,\n missingSteps: MigrationStepArrayStruct,\n }),\n ),\n});\n\nconst DerivedIdentitiesResponseStruct = type({\n identities: array(DerivedIdentityStruct),\n});\n\nconst AddressIdentityResponseStruct = type({\n identity: DerivedIdentityStruct,\n address: type({\n address: LowercaseHexAddressStruct,\n role: enums(['CURRENT', 'PREVIOUS', 'PENDING_SUCCESSOR']),\n predecessor: nullable(LowercaseHexAddressStruct),\n successor: nullable(LowercaseHexAddressStruct),\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(CHOMP_INTENT_TYPES),\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: string(),\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: coerce(\n array(enums(CHOMP_INTENT_TYPES)),\n array(string()),\n (intentTypes) => intentTypes.filter(isChompIntentType),\n ),\n});\n\nconst ServiceDetailsResponseStruct = type({\n auth: type({\n message: string(),\n }),\n chains: record(\n StrictHexStruct,\n type({\n autoDepositDelegate: StrictHexStruct,\n protocol: type({\n vedaProtocol: ServiceDetailsProtocolStruct,\n vedaPremiumProtocol: optional(ServiceDetailsProtocolStruct),\n }),\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 * Fetches the bearer token along with a SHA-256 digest of it, for query\n * keys of profile-scoped requests. The digest, not the token, goes in the\n * key because query keys leave the service via the `cacheUpdated`\n * messenger events.\n *\n * @returns The bearer token and its digest.\n */\n async #getProfileScopedToken(): Promise<{\n token: string;\n profileKey: Hex;\n }> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return {\n token,\n profileKey: bytesToHex(await sha256(stringToBytes(token))),\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 * Requests a single-use challenge for associating an address through the v2\n * flow. Sign the returned `message` exactly as received, using\n * `personal_sign` with the address being associated, then submit it with\n * {@link ChompApiService.associateAddressV2} before `expiresAt`. Requesting\n * a new challenge for the same address replaces the previous one.\n *\n * POST /v2/auth/address/challenge\n *\n * Each call issues a new challenge, so the result is never cached.\n *\n * @param params - The address to associate and the association purpose.\n * `ASSOCIATE_SUCCESSOR` also requires the predecessor address.\n * @returns The challenge ID, the message to sign, and when it expires.\n */\n async createAddressChallenge(\n params: CreateAddressChallengeParams,\n ): Promise<CreateAddressChallengeResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createAddressChallenge`, params],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v2/auth/address/challenge', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw await createChompApiError(\n response,\n `POST /v2/auth/address/challenge failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateAddressChallengeResponseStruct);\n }\n\n /**\n * Associates an address with a CHOMP profile by submitting the signature of\n * a challenge from {@link ChompApiService.createAddressChallenge}. The\n * address, purpose and predecessor come from the challenge. For\n * `ASSOCIATE_SUCCESSOR`, the association and the link to the predecessor\n * are written atomically.\n *\n * POST /v2/auth/address\n *\n * @param params - The challenge ID and its signature.\n * @returns The profile association result: `status: 'created'` when the\n * association or link was written, `status: 'active'` when the address was\n * already associated with the authenticated profile. Throws on 400\n * `CHALLENGE_INVALID_OR_EXPIRED` (request a new challenge), on 409 when the\n * address is associated with a different profile, and on link validation\n * errors.\n */\n async associateAddressV2(\n params: AssociateAddressV2Params,\n ): Promise<AssociateAddressResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:associateAddressV2`, params],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v2/auth/address', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw await createChompApiError(\n response,\n `POST /v2/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 * Removes an address association from the authenticated profile. For an\n * address linked as a successor, this cancels the migration and unfreezes\n * its predecessor, which is only allowed while the migration is not `DONE`.\n *\n * DELETE /v1/auth/address\n *\n * @param address - The address to disassociate.\n */\n async disassociateAddress(address: Hex): Promise<void> {\n await this.fetchQuery({\n queryKey: [`${this.name}:disassociateAddress`, address],\n staleTime: 0,\n gcTime: 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: 'DELETE',\n headers,\n body: JSON.stringify({ address }),\n },\n );\n\n if (!response.ok) {\n throw await createChompApiError(\n response,\n `DELETE /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return null;\n },\n });\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, profileKey } = await this.#getProfileScopedToken();\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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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 * Callers use the result to decide whether an intent already exists, so it\n * is always fetched fresh (`staleTime: 0`).\n *\n * @param address - The address to look up intents for.\n * @returns The array of intents for the address, omitting any with an\n * intent type this service does not recognise.\n */\n async getIntentsByAddress(address: Hex): Promise<IntentEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getIntentsByAddress`, address],\n staleTime: 0,\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 await createChompApiError(\n response,\n `Get intents request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, IntentEntryArrayStruct).filter(\n (intent): intent is IntentEntry =>\n isChompIntentType(intent.metadata.type),\n );\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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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 /**\n * Fetches the Money Account identities of the authenticated profile, with\n * the status and migration steps CHOMP derives on every read.\n *\n * GET /v1/money-account/identities\n *\n * Profile-scoped and used to drive migrations, so it is always fetched\n * fresh and keyed by a digest of the bearer token, like\n * {@link ChompApiService.getAssociatedAddresses}.\n *\n * @returns The identities; empty when the profile has no Money Account.\n * Addresses are lowercased.\n */\n async getDerivedIdentities(): Promise<DerivedIdentitiesResponse> {\n const { token, profileKey } = await this.#getProfileScopedToken();\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getDerivedIdentities`, profileKey],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const response = await fetch(\n new URL('/v1/money-account/identities', this.#baseUrl),\n { headers: this.#headersForToken(token) },\n );\n\n if (!response.ok) {\n throw await createChompApiError(\n response,\n `GET /v1/money-account/identities failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, DerivedIdentitiesResponseStruct);\n }\n\n /**\n * Fetches the identity containing an address, along with where the address\n * sits in it. The identity's `status` describes the whole chain.\n *\n * GET /v1/money-account/identities/address/:address\n *\n * Always fetched fresh and keyed by a digest of the bearer token, like\n * {@link ChompApiService.getDerivedIdentities}.\n *\n * @param address - The address to look up.\n * @returns The identity and address details, or `null` when the address is\n * not associated with the authenticated profile. Addresses are lowercased.\n */\n async getDerivedIdentityByAddress(\n address: Hex,\n ): Promise<AddressIdentityResponse | null> {\n const { token, profileKey } = await this.#getProfileScopedToken();\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [\n `${this.name}:getDerivedIdentityByAddress`,\n profileKey,\n address,\n ],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const response = await fetch(\n new URL(\n `/v1/money-account/identities/address/${address}`,\n this.#baseUrl,\n ),\n { headers: this.#headersForToken(token) },\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw await createChompApiError(\n response,\n `GET /v1/money-account/identities/address/${address} failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return jsonResponse === null\n ? null\n : create(jsonResponse, AddressIdentityResponseStruct);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chomp-api-service.js","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAO9D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,GACL,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,UAAU,EACV,WAAW,EACX,QAAQ,EACR,MAAM,EACN,aAAa,EACb,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAwBzB,MAAM,kBAAkB,GAAsB;IAC5C,cAAc;IACd,iBAAiB;IACjB,sBAAsB;IACtB,yBAAyB;IACzB,mBAA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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,MAAM,mBAAmB,CAC7B,QAAQ,EACR,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","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 hasProperty,\n isObject,\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 AssociateAddressResponse,\n AssociateAddressV2Params,\n CreateAddressChallengeParams,\n CreateAddressChallengeResponse,\n ProfileAddressEntry,\n ChompIntentType,\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\nconst CHOMP_INTENT_TYPES: ChompIntentType[] = [\n 'cash-deposit',\n 'cash-withdrawal',\n 'cash-deposit-premium',\n 'cash-withdrawal-premium',\n 'cash-subscription',\n];\n\nfunction isChompIntentType(value: string): value is ChompIntentType {\n return (CHOMP_INTENT_TYPES as string[]).includes(value);\n}\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// === ERRORS ===\n\n/**\n * Thrown when the CHOMP API responds with a non-2xx status.\n */\nexport class ChompApiError extends HttpError {\n /**\n * The CHOMP error code from the response body (e.g.\n * `PREDECESSOR_HAS_OPEN_WITHDRAWALS`), if one was provided.\n */\n readonly code: string | undefined;\n\n /**\n * Construct a CHOMP API error.\n *\n * @param status - The HTTP response status.\n * @param message - The error message.\n * @param code - The CHOMP error code from the response body.\n */\n constructor(status: number, message: string, code?: string) {\n super(status, message);\n this.name = 'ChompApiError';\n this.code = code;\n }\n}\n\n/**\n * Builds a {@link ChompApiError} from a non-2xx response, reading the CHOMP\n * error code from the response body when there is one.\n *\n * @param response - The non-2xx response.\n * @param message - The error message.\n * @returns The error to throw.\n */\nasync function createChompApiError(\n response: Response,\n message: string,\n): Promise<ChompApiError> {\n const body: unknown = await response.json().catch(() => undefined);\n const code =\n isObject(body) && hasProperty(body, 'code') && typeof body.code === 'string'\n ? body.code\n : undefined;\n return new ChompApiError(response.status, message, code);\n}\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 'createAddressChallenge',\n 'associateAddressV2',\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\nconst CreateAddressChallengeResponseStruct = type({\n challengeId: string(),\n message: string(),\n expiresAt: string(),\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(CHOMP_INTENT_TYPES),\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: string(),\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: coerce(\n array(enums(CHOMP_INTENT_TYPES)),\n array(string()),\n (intentTypes) => intentTypes.filter(isChompIntentType),\n ),\n});\n\nconst ServiceDetailsResponseStruct = type({\n auth: type({\n message: string(),\n }),\n chains: record(\n StrictHexStruct,\n type({\n autoDepositDelegate: StrictHexStruct,\n protocol: type({\n vedaProtocol: ServiceDetailsProtocolStruct,\n vedaPremiumProtocol: optional(ServiceDetailsProtocolStruct),\n }),\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 * Requests a single-use challenge for associating an address through the v2\n * flow. Sign the returned `message` exactly as received, using\n * `personal_sign` with the address being associated, then submit it with\n * {@link ChompApiService.associateAddressV2} before `expiresAt`. Requesting\n * a new challenge for the same address replaces the previous one.\n *\n * POST /v2/auth/address/challenge\n *\n * Each call issues a new challenge, so the result is never cached.\n *\n * @param params - The address to associate and the association purpose.\n * `ASSOCIATE_SUCCESSOR` also requires the predecessor address.\n * @returns The challenge ID, the message to sign, and when it expires.\n */\n async createAddressChallenge(\n params: CreateAddressChallengeParams,\n ): Promise<CreateAddressChallengeResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createAddressChallenge`, params],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v2/auth/address/challenge', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw await createChompApiError(\n response,\n `POST /v2/auth/address/challenge failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateAddressChallengeResponseStruct);\n }\n\n /**\n * Associates an address with a CHOMP profile by submitting the signature of\n * a challenge from {@link ChompApiService.createAddressChallenge}. The\n * address, purpose and predecessor come from the challenge. For\n * `ASSOCIATE_SUCCESSOR`, the association and the link to the predecessor\n * are written atomically.\n *\n * POST /v2/auth/address\n *\n * @param params - The challenge ID and its signature.\n * @returns The profile association result: `status: 'created'` when the\n * association or link was written, `status: 'active'` when the address was\n * already associated with the authenticated profile. Throws on 400\n * `CHALLENGE_INVALID_OR_EXPIRED` (request a new challenge), on 409 when the\n * address is associated with a different profile, and on link validation\n * errors.\n */\n async associateAddressV2(\n params: AssociateAddressV2Params,\n ): Promise<AssociateAddressResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:associateAddressV2`, params],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v2/auth/address', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw await createChompApiError(\n response,\n `POST /v2/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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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 * Callers use the result to decide whether an intent already exists, so it\n * is always fetched fresh (`staleTime: 0`).\n *\n * @param address - The address to look up intents for.\n * @returns The array of intents for the address, omitting any with an\n * intent type this service does not recognise.\n */\n async getIntentsByAddress(address: Hex): Promise<IntentEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getIntentsByAddress`, address],\n staleTime: 0,\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 await createChompApiError(\n response,\n `Get intents request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, IntentEntryArrayStruct).filter(\n (intent): intent is IntentEntry =>\n isChompIntentType(intent.metadata.type),\n );\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 await createChompApiError(\n response,\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 await createChompApiError(\n response,\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/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ChompApiError, ChompApiService } from './chomp-api-service.js';
|
|
2
2
|
export type { ChompApiServiceMessenger, ChompApiServiceActions, ChompApiServiceEvents, ChompApiServiceInvalidateQueriesAction, ChompApiServiceCacheUpdatedEvent, ChompApiServiceGranularCacheUpdatedEvent, } from './chomp-api-service.js';
|
|
3
|
-
export type { ChompApiServiceAssociateAddressV2Action, ChompApiServiceCreateAddressChallengeAction,
|
|
4
|
-
export type { AccountUpgradeStatus,
|
|
3
|
+
export type { ChompApiServiceAssociateAddressV2Action, ChompApiServiceCreateAddressChallengeAction, ChompApiServiceGetAssociatedAddressesAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetUpgradesAction, ChompApiServiceVerifyDelegationAction, ChompApiServiceCreateIntentsAction, ChompApiServiceGetIntentsByAddressAction, ChompApiServiceCreateWithdrawalAction, ChompApiServiceGetServiceDetailsAction, } from './chomp-api-service-method-action-types.js';
|
|
4
|
+
export type { AccountUpgradeStatus, AssociateAddressResponse, AssociateAddressV2Params, AssociationPurpose, AuthorizationData, ChompIntentType, CreateAddressChallengeParams, CreateAddressChallengeResponse, CreateUpgradeParams, CreateUpgradeResponse, CreateWithdrawalParams, CreateWithdrawalResponse, DelegationCaveat, UpgradeEntry, IntentEntry, IntentMetadataParams, IntentMetadataResponse, ProfileAddressEntry, SendIntentParams, SendIntentResponse, ServiceDetailsChain, ServiceDetailsProtocol, ServiceDetailsResponse, ServiceDetailsSupportedToken, SignedDelegation, VerifyDelegationParams, VerifyDelegationResponse, } from './types.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACxE,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,sCAAsC,EACtC,gCAAgC,EAChC,wCAAwC,GACzC,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,uCAAuC,EACvC,2CAA2C,EAC3C,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACxE,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,sCAAsC,EACtC,gCAAgC,EAChC,wCAAwC,GACzC,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,uCAAuC,EACvC,2CAA2C,EAC3C,2CAA2C,EAC3C,kCAAkC,EAClC,gCAAgC,EAChC,qCAAqC,EACrC,kCAAkC,EAClC,wCAAwC,EACxC,qCAAqC,EACrC,sCAAsC,GACvC,MAAM,4CAA4C,CAAC;AACpD,YAAY,EACV,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,4BAA4B,EAC5B,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,gBAAgB,EAChB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { ChompApiError, ChompApiService } from './chomp-api-service.js';\nexport type {\n ChompApiServiceMessenger,\n ChompApiServiceActions,\n ChompApiServiceEvents,\n ChompApiServiceInvalidateQueriesAction,\n ChompApiServiceCacheUpdatedEvent,\n ChompApiServiceGranularCacheUpdatedEvent,\n} from './chomp-api-service.js';\nexport type {\n ChompApiServiceAssociateAddressV2Action,\n ChompApiServiceCreateAddressChallengeAction,\n
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { ChompApiError, ChompApiService } from './chomp-api-service.js';\nexport type {\n ChompApiServiceMessenger,\n ChompApiServiceActions,\n ChompApiServiceEvents,\n ChompApiServiceInvalidateQueriesAction,\n ChompApiServiceCacheUpdatedEvent,\n ChompApiServiceGranularCacheUpdatedEvent,\n} from './chomp-api-service.js';\nexport type {\n ChompApiServiceAssociateAddressV2Action,\n ChompApiServiceCreateAddressChallengeAction,\n ChompApiServiceGetAssociatedAddressesAction,\n ChompApiServiceCreateUpgradeAction,\n ChompApiServiceGetUpgradesAction,\n ChompApiServiceVerifyDelegationAction,\n ChompApiServiceCreateIntentsAction,\n ChompApiServiceGetIntentsByAddressAction,\n ChompApiServiceCreateWithdrawalAction,\n ChompApiServiceGetServiceDetailsAction,\n} from './chomp-api-service-method-action-types.js';\nexport type {\n AccountUpgradeStatus,\n AssociateAddressResponse,\n AssociateAddressV2Params,\n AssociationPurpose,\n AuthorizationData,\n ChompIntentType,\n CreateAddressChallengeParams,\n CreateAddressChallengeResponse,\n CreateUpgradeParams,\n CreateUpgradeResponse,\n CreateWithdrawalParams,\n CreateWithdrawalResponse,\n DelegationCaveat,\n UpgradeEntry,\n IntentEntry,\n IntentMetadataParams,\n IntentMetadataResponse,\n ProfileAddressEntry,\n SendIntentParams,\n SendIntentResponse,\n ServiceDetailsChain,\n ServiceDetailsProtocol,\n ServiceDetailsResponse,\n ServiceDetailsSupportedToken,\n SignedDelegation,\n VerifyDelegationParams,\n VerifyDelegationResponse,\n} from './types.js';\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ import type { Hex } from '@metamask/utils';
|
|
|
2
2
|
/**
|
|
3
3
|
* The CHOMP intent metadata `type` discriminator, covering the base vault
|
|
4
4
|
* (`cash-deposit`, `cash-withdrawal`), the premium vault
|
|
5
|
-
* (`cash-deposit-premium`, `cash-withdrawal-premium`), the recurring
|
|
6
|
-
* subscription payment (`cash-subscription`)
|
|
7
|
-
* (`cash-migration-root`, `cash-migration-transfer`).
|
|
5
|
+
* (`cash-deposit-premium`, `cash-withdrawal-premium`), and the recurring
|
|
6
|
+
* subscription payment (`cash-subscription`).
|
|
8
7
|
*/
|
|
9
|
-
export type ChompIntentType = 'cash-deposit' | 'cash-withdrawal' | 'cash-deposit-premium' | 'cash-withdrawal-premium' | 'cash-subscription'
|
|
8
|
+
export type ChompIntentType = 'cash-deposit' | 'cash-withdrawal' | 'cash-deposit-premium' | 'cash-withdrawal-premium' | 'cash-subscription';
|
|
10
9
|
export type DelegationCaveat = {
|
|
11
10
|
enforcer: Hex;
|
|
12
11
|
terms: Hex;
|
|
@@ -184,59 +183,6 @@ export type IntentEntry = {
|
|
|
184
183
|
export type CreateWithdrawalResponse = {
|
|
185
184
|
success: true;
|
|
186
185
|
};
|
|
187
|
-
/**
|
|
188
|
-
* A step that must exist before a migration link counts as complete.
|
|
189
|
-
* `SUCCESSOR_SUBSCRIPTION_INTENT` and `TRANSFER_INTENT_PVMUSD` are only
|
|
190
|
-
* required for premium subscribers.
|
|
191
|
-
*/
|
|
192
|
-
export type MigrationStep = 'SUCCESSOR_DEPOSIT_INTENT' | 'SUCCESSOR_WITHDRAWAL_INTENT' | 'SUCCESSOR_SUBSCRIPTION_INTENT' | 'SUCCESSOR_MONITORED' | 'ROOT_DELEGATION' | 'TRANSFER_INTENT_MUSD' | 'TRANSFER_INTENT_VMUSD' | 'TRANSFER_INTENT_PVMUSD';
|
|
193
|
-
/**
|
|
194
|
-
* The settlement status of a Money Account identity chain. `NONE` is never
|
|
195
|
-
* returned as an entry: a profile with no Money Account has no identities.
|
|
196
|
-
*/
|
|
197
|
-
export type DerivedIdentityStatus = 'NONE' | 'MIGRATING' | 'DONE';
|
|
198
|
-
/**
|
|
199
|
-
* The latest link of an identity chain while it is migrating.
|
|
200
|
-
*/
|
|
201
|
-
export type DerivedIdentityMigration = {
|
|
202
|
-
from: Hex;
|
|
203
|
-
to: Hex;
|
|
204
|
-
requiredSteps: MigrationStep[];
|
|
205
|
-
completedSteps: MigrationStep[];
|
|
206
|
-
missingSteps: MigrationStep[];
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* One Money Account over time: a chain of addresses joined by links.
|
|
210
|
-
* Addresses are lowercased.
|
|
211
|
-
*/
|
|
212
|
-
export type DerivedIdentity = {
|
|
213
|
-
/** The tip of the chain. Stays on the old address while migrating. */
|
|
214
|
-
currentAddress: Hex;
|
|
215
|
-
/** Earlier addresses, from the immediate predecessor backwards. */
|
|
216
|
-
previousAddresses: Hex[];
|
|
217
|
-
status: DerivedIdentityStatus;
|
|
218
|
-
migration: DerivedIdentityMigration | null;
|
|
219
|
-
};
|
|
220
|
-
/**
|
|
221
|
-
* Returned by GET /v1/money-account/identities.
|
|
222
|
-
*/
|
|
223
|
-
export type DerivedIdentitiesResponse = {
|
|
224
|
-
identities: DerivedIdentity[];
|
|
225
|
-
};
|
|
226
|
-
export type DerivedIdentityAddressRole = 'CURRENT' | 'PREVIOUS' | 'PENDING_SUCCESSOR';
|
|
227
|
-
/**
|
|
228
|
-
* Returned by GET /v1/money-account/identities/address/:address. Addresses
|
|
229
|
-
* are lowercased.
|
|
230
|
-
*/
|
|
231
|
-
export type AddressIdentityResponse = {
|
|
232
|
-
identity: DerivedIdentity;
|
|
233
|
-
address: {
|
|
234
|
-
address: Hex;
|
|
235
|
-
role: DerivedIdentityAddressRole;
|
|
236
|
-
predecessor: Hex | null;
|
|
237
|
-
successor: Hex | null;
|
|
238
|
-
};
|
|
239
|
-
};
|
|
240
186
|
export type ServiceDetailsSupportedToken = {
|
|
241
187
|
tokenAddress: Hex;
|
|
242
188
|
tokenDecimals: number;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAI3C
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAI3C;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GACvB,cAAc,GACd,iBAAiB,GACjB,sBAAsB,GACtB,yBAAyB,GACzB,mBAAmB,CAAC;AAExB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,GAAG,CAAC;IACd,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,IAAI,EAAE,GAAG,CAAC;IACV,SAAS,EAAE,GAAG,CAAC;CAChB,CAAC;AAIF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,qBAAqB,CAAC;AAErE,MAAM,MAAM,4BAA4B,GACpC;IACE,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,WAAW,CAAC;CACtB,GACD;IACE,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,qBAAqB,CAAC;IAC/B;;;OAGG;IACH,kBAAkB,EAAE,GAAG,CAAC;CACzB,CAAC;AAEN,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,SAAS,EAAE,GAAG,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,G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C;IACpB,QAAQ,EAAE,sBAAsB,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,GAAG,CAAC;IACb,cAAc,EAAE,GAAG,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE;QACR,SAAS,EAAE,GAAG,CAAC;QACf,YAAY,EAAE,GAAG,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,EAAE,eAAe,CAAC;KACvB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,IAAI,CAAC;CACf,CAAC;AAIF,MAAM,MAAM,4BAA4B,GAAG;IACzC,YAAY,EAAE,GAAG,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,eAAe,EAAE,4BAA4B,EAAE,CAAC;IAChD,cAAc,EAAE,GAAG,CAAC;IACpB,WAAW,EAAE,eAAe,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,mBAAmB,EAAE,GAAG,CAAC;IACzB,QAAQ,EAAE;QACR,YAAY,EAAE,sBAAsB,CAAC;QACrC,mBAAmB,CAAC,EAAE,sBAAsB,CAAC;KAC9C,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;CAC1C,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n// === COMMON TYPES ===\n\n/**\n * The CHOMP intent metadata `type` discriminator, covering the base vault\n * (`cash-deposit`, `cash-withdrawal`), the premium vault\n * (`cash-deposit-premium`, `cash-withdrawal-premium`), the recurring\n * subscription payment (`cash-subscription`)
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n// === COMMON TYPES ===\n\n/**\n * The CHOMP intent metadata `type` discriminator, covering the base vault\n * (`cash-deposit`, `cash-withdrawal`), the premium vault\n * (`cash-deposit-premium`, `cash-withdrawal-premium`), and the recurring\n * subscription payment (`cash-subscription`).\n */\nexport type ChompIntentType =\n | 'cash-deposit'\n | 'cash-withdrawal'\n | 'cash-deposit-premium'\n | 'cash-withdrawal-premium'\n | 'cash-subscription';\n\nexport type DelegationCaveat = {\n enforcer: Hex;\n terms: Hex;\n args: Hex;\n};\n\nexport type SignedDelegation = {\n delegate: Hex;\n delegator: Hex;\n authority: Hex;\n caveats: DelegationCaveat[];\n salt: Hex;\n signature: Hex;\n};\n\n// === PARAMS TYPES ===\n\n/**\n * Why an address is being associated through the v2 flow. `ASSOCIATE` creates\n * a normal association, while `ASSOCIATE_SUCCESSOR` also links the address to\n * its predecessor as the next address in the Money Account identity chain.\n */\nexport type AssociationPurpose = 'ASSOCIATE' | 'ASSOCIATE_SUCCESSOR';\n\nexport type CreateAddressChallengeParams =\n | {\n address: Hex;\n purpose: 'ASSOCIATE';\n }\n | {\n address: Hex;\n purpose: 'ASSOCIATE_SUCCESSOR';\n /**\n * The current address of the Money Account that `address` succeeds.\n * Must be set before any intents exist on `address`.\n */\n predecessorAddress: Hex;\n };\n\nexport type AssociateAddressV2Params = {\n challengeId: string;\n /**\n * The `personal_sign` signature of the challenge `message`, signed exactly\n * as returned by CHOMP with the address being associated.\n */\n signature: Hex;\n};\n\nexport type CreateUpgradeParams = {\n r: Hex;\n s: Hex;\n v: number;\n yParity: number;\n address: Hex;\n chainId: string;\n nonce: string;\n};\n\nexport type VerifyDelegationParams = {\n signedDelegation: SignedDelegation;\n chainId: Hex;\n};\n\nexport type IntentMetadataParams = {\n allowance: Hex;\n tokenSymbol: string;\n tokenAddress: Hex;\n type: ChompIntentType;\n};\n\nexport type SendIntentParams = {\n account: Hex;\n delegationHash: Hex;\n chainId: Hex;\n metadata: IntentMetadataParams;\n};\n\nexport type CreateWithdrawalParams = {\n chainId: Hex;\n /** Decimal integer or 0x-prefixed hex string representing the amount. */\n amount: string;\n account: Hex;\n};\n\n// === RESPONSE TYPES ===\n\n/**\n * Returned by POST /v2/auth/address.\n *\n * `profileId` is only included when the address was newly associated\n * (`status: 'created'`). When the address was already associated with the\n * authenticated profile (`status: 'active'`), only `address` is returned.\n * An address associated with a different profile responds with 409, which is\n * surfaced as an error.\n */\nexport type AssociateAddressResponse = {\n profileId?: string;\n address: Hex;\n status: 'active' | 'created';\n};\n\n/**\n * Returned by POST /v2/auth/address/challenge.\n */\nexport type CreateAddressChallengeResponse = {\n challengeId: string;\n /**\n * The EIP-4361 (Sign-In with Ethereum) message to sign, bound to the\n * profile, chain, purpose, address and predecessor.\n */\n message: string;\n /**\n * When the challenge expires, as an ISO 8601 timestamp.\n */\n expiresAt: string;\n};\n\n/**\n * One entry returned by GET /v1/auth/address. The endpoint returns an array\n * of these — the active address associations of the authenticated profile\n * (the API filters out soft-deleted associations, so `status` is always\n * `'active'`). Addresses are lowercased.\n */\nexport type ProfileAddressEntry = {\n profileId: string;\n address: Hex;\n status: 'active';\n};\n\nexport type AccountUpgradeStatus = 'pending' | 'upgraded';\n\nexport type AuthorizationData = {\n r: Hex;\n s: Hex;\n v: number;\n yParity: number;\n address: Hex;\n chainId: Hex;\n nonce: Hex;\n};\n\n/**\n * Returned by POST /v1/account-upgrade.\n */\nexport type CreateUpgradeResponse = {\n signerAddress: Hex;\n address: Hex;\n chainId: Hex;\n nonce: Hex;\n status: AccountUpgradeStatus;\n createdAt: string;\n};\n\n/**\n * One entry returned by GET /v1/account-upgrade/:address. The endpoint returns\n * an array of these (one per chain).\n */\nexport type UpgradeEntry = {\n signerAddress: Hex;\n chainId: Hex;\n nonce: Hex;\n authorization: AuthorizationData;\n status: AccountUpgradeStatus;\n createdAt: string;\n};\n\nexport type VerifyDelegationResponse = {\n valid: boolean;\n delegationHash?: Hex;\n errors?: string[];\n};\n\nexport type IntentMetadataResponse = {\n allowance: Hex;\n tokenSymbol: string;\n tokenAddress: Hex;\n type: ChompIntentType;\n};\n\nexport type SendIntentResponse = {\n delegationHash: Hex;\n metadata: IntentMetadataResponse;\n createdAt: string;\n};\n\n/**\n * The shape returned by GET /v1/intent/account/:address for each intent.\n */\nexport type IntentEntry = {\n account: Hex;\n delegationHash: Hex;\n chainId: Hex;\n status: 'active' | 'revoked';\n metadata: {\n allowance: Hex;\n tokenAddress: Hex;\n tokenSymbol: string;\n type: ChompIntentType;\n };\n};\n\nexport type CreateWithdrawalResponse = {\n success: true;\n};\n\n// === SERVICE DETAILS TYPES ===\n\nexport type ServiceDetailsSupportedToken = {\n tokenAddress: Hex;\n tokenDecimals: number;\n};\n\nexport type ServiceDetailsProtocol = {\n supportedTokens: ServiceDetailsSupportedToken[];\n adapterAddress: Hex;\n intentTypes: ChompIntentType[];\n};\n\nexport type ServiceDetailsChain = {\n autoDepositDelegate: Hex;\n protocol: {\n vedaProtocol: ServiceDetailsProtocol;\n vedaPremiumProtocol?: ServiceDetailsProtocol;\n };\n};\n\nexport type ServiceDetailsResponse = {\n auth: {\n message: string;\n };\n chains: Record<Hex, ServiceDetailsChain>;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/chomp-api-service",
|
|
3
|
-
"version": "6.0.1-preview-
|
|
3
|
+
"version": "6.0.1-preview-060b37d94",
|
|
4
4
|
"description": "Data service for the Chomp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@metamask/controller-utils": "^13.0.0",
|
|
53
53
|
"@metamask/messenger": "^3.0.0",
|
|
54
54
|
"@metamask/superstruct": "^3.4.1",
|
|
55
|
-
"@metamask/utils": "^12.0.
|
|
55
|
+
"@metamask/utils": "^12.0.1",
|
|
56
56
|
"@tanstack/query-core": "^5.103.2"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|