@metamask-previews/chomp-api-service 6.0.1-preview-63902891a → 6.0.1-preview-a0d99e051
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/chomp-api-service-method-action-types.d.ts +85 -13
- 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 +88 -10
- package/dist/chomp-api-service.d.ts.map +1 -1
- package/dist/chomp-api-service.js +259 -25
- package/dist/chomp-api-service.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +99 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,8 +9,27 @@ 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
|
+
- 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
|
+
- 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
|
+
- 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))
|
|
20
|
+
- Submits the signed challenge message to associate the address.
|
|
21
|
+
- Add `ChompApiError`, thrown for non-2xx responses, which exposes the CHOMP error code from the response body as `code` ([#10687](https://github.com/MetaMask/core/pull/10687))
|
|
22
|
+
- Add `AssociationPurpose`, `CreateAddressChallengeParams`, `CreateAddressChallengeResponse`, `AssociateAddressV2Params`, `ChompApiServiceCreateAddressChallengeAction`, and `ChompApiServiceAssociateAddressV2Action` types ([#10687](https://github.com/MetaMask/core/pull/10687))
|
|
12
23
|
- Add support for Node.js 26 ([#10981](https://github.com/MetaMask/core/pull/10981))
|
|
13
24
|
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- **BREAKING:** Widen `ChompIntentType` (used by `SendIntentParams`, intent responses, and service-details `intentTypes`) to include `cash-migration-root` and `cash-migration-transfer` ([#10695](https://github.com/MetaMask/core/pull/10695))
|
|
28
|
+
|
|
29
|
+
### Removed
|
|
30
|
+
|
|
31
|
+
- **BREAKING:** Remove the `associateAddress` method and `ChompApiService:associateAddress` messenger action (`POST /v1/auth/address`), along with the `AssociateAddressParams` and `ChompApiServiceAssociateAddressAction` types ([#10687](https://github.com/MetaMask/core/pull/10687))
|
|
32
|
+
|
|
14
33
|
## [6.0.1]
|
|
15
34
|
|
|
16
35
|
### Changed
|
|
@@ -4,20 +4,57 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ChompApiService } from './chomp-api-service.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Requests a single-use challenge for associating an address through the v2
|
|
8
|
+
* flow. Sign the returned `message` exactly as received, using
|
|
9
|
+
* `personal_sign` with the address being associated, then submit it with
|
|
10
|
+
* {@link ChompApiService.associateAddressV2} before `expiresAt`. Requesting
|
|
11
|
+
* a new challenge for the same address replaces the previous one.
|
|
8
12
|
*
|
|
9
|
-
* POST /
|
|
13
|
+
* POST /v2/auth/address/challenge
|
|
10
14
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
15
|
+
* Each call issues a new challenge, so the result is never cached.
|
|
16
|
+
*
|
|
17
|
+
* @param params - The address to associate and the association purpose.
|
|
18
|
+
* `ASSOCIATE_SUCCESSOR` also requires the predecessor address.
|
|
19
|
+
* @returns The challenge ID, the message to sign, and when it expires.
|
|
20
|
+
*/
|
|
21
|
+
export type ChompApiServiceCreateAddressChallengeAction = {
|
|
22
|
+
type: `ChompApiService:createAddressChallenge`;
|
|
23
|
+
handler: ChompApiService['createAddressChallenge'];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Associates an address with a CHOMP profile by submitting the signature of
|
|
27
|
+
* a challenge from {@link ChompApiService.createAddressChallenge}. The
|
|
28
|
+
* address, purpose and predecessor come from the challenge. For
|
|
29
|
+
* `ASSOCIATE_SUCCESSOR`, the association and the link to the predecessor
|
|
30
|
+
* are written atomically.
|
|
31
|
+
*
|
|
32
|
+
* POST /v2/auth/address
|
|
33
|
+
*
|
|
34
|
+
* @param params - The challenge ID and its signature.
|
|
35
|
+
* @returns The profile association result: `status: 'created'` when the
|
|
36
|
+
* association or link was written, `status: 'active'` when the address was
|
|
37
|
+
* already associated with the authenticated profile. Throws on 400
|
|
38
|
+
* `CHALLENGE_INVALID_OR_EXPIRED` (request a new challenge), on 409 when the
|
|
39
|
+
* address is associated with a different profile, and on link validation
|
|
40
|
+
* errors.
|
|
41
|
+
*/
|
|
42
|
+
export type ChompApiServiceAssociateAddressV2Action = {
|
|
43
|
+
type: `ChompApiService:associateAddressV2`;
|
|
44
|
+
handler: ChompApiService['associateAddressV2'];
|
|
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.
|
|
17
54
|
*/
|
|
18
|
-
export type
|
|
19
|
-
type: `ChompApiService:
|
|
20
|
-
handler: ChompApiService['
|
|
55
|
+
export type ChompApiServiceDisassociateAddressAction = {
|
|
56
|
+
type: `ChompApiService:disassociateAddress`;
|
|
57
|
+
handler: ChompApiService['disassociateAddress'];
|
|
21
58
|
};
|
|
22
59
|
/**
|
|
23
60
|
* Fetches the addresses associated with the authenticated profile.
|
|
@@ -99,7 +136,8 @@ export type ChompApiServiceCreateIntentsAction = {
|
|
|
99
136
|
* is always fetched fresh (`staleTime: 0`).
|
|
100
137
|
*
|
|
101
138
|
* @param address - The address to look up intents for.
|
|
102
|
-
* @returns The array of intents for the address
|
|
139
|
+
* @returns The array of intents for the address, omitting any with an
|
|
140
|
+
* intent type this service does not recognise.
|
|
103
141
|
*/
|
|
104
142
|
export type ChompApiServiceGetIntentsByAddressAction = {
|
|
105
143
|
type: `ChompApiService:getIntentsByAddress`;
|
|
@@ -132,8 +170,42 @@ export type ChompApiServiceGetServiceDetailsAction = {
|
|
|
132
170
|
type: `ChompApiService:getServiceDetails`;
|
|
133
171
|
handler: ChompApiService['getServiceDetails'];
|
|
134
172
|
};
|
|
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
|
+
};
|
|
135
207
|
/**
|
|
136
208
|
* Union of all ChompApiService action types.
|
|
137
209
|
*/
|
|
138
|
-
export type ChompApiServiceMethodActions =
|
|
210
|
+
export type ChompApiServiceMethodActions = ChompApiServiceCreateAddressChallengeAction | ChompApiServiceAssociateAddressV2Action | ChompApiServiceDisassociateAddressAction | ChompApiServiceGetAssociatedAddressesAction | ChompApiServiceCreateUpgradeAction | ChompApiServiceGetUpgradesAction | ChompApiServiceVerifyDelegationAction | ChompApiServiceCreateIntentsAction | ChompApiServiceGetIntentsByAddressAction | ChompApiServiceCreateWithdrawalAction | ChompApiServiceGetServiceDetailsAction | ChompApiServiceGetDerivedIdentitiesAction | ChompApiServiceGetDerivedIdentityByAddressAction;
|
|
139
211
|
//# 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
|
|
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;;;;;;;;GAQG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,eAAe,CAAC,qBAAqB,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,eAAe,CAAC,wBAAwB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAA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,6CAA6C,CAAC;IACpD,OAAO,EAAE,eAAe,CAAC,6BAA6B,CAAC,CAAC;CACzD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACpC,2CAA2C,GAC3C,uCAAuC,GACvC,wCAAwC,GACxC,2CAA2C,GAC3C,kCAAkC,GAClC,gCAAgC,GAChC,qCAAqC,GACrC,kCAAkC,GAClC,wCAAwC,GACxC,qCAAqC,GACrC,sCAAsC,GACtC,yCAAyC,GACzC,gDAAgD,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 *
|
|
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 * 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 */\nexport type ChompApiServiceDisassociateAddressAction = {\n type: `ChompApiService:disassociateAddress`;\n handler: ChompApiService['disassociateAddress'];\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 * 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 */\nexport type ChompApiServiceGetDerivedIdentitiesAction = {\n type: `ChompApiService:getDerivedIdentities`;\n handler: ChompApiService['getDerivedIdentities'];\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 */\nexport type ChompApiServiceGetDerivedIdentityByAddressAction = {\n type: `ChompApiService:getDerivedIdentityByAddress`;\n handler: ChompApiService['getDerivedIdentityByAddress'];\n};\n\n/**\n * Union of all ChompApiService action types.\n */\nexport type ChompApiServiceMethodActions =\n | ChompApiServiceCreateAddressChallengeAction\n | ChompApiServiceAssociateAddressV2Action\n | ChompApiServiceDisassociateAddressAction\n | ChompApiServiceGetAssociatedAddressesAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetUpgradesAction\n | ChompApiServiceVerifyDelegationAction\n | ChompApiServiceCreateIntentsAction\n | ChompApiServiceGetIntentsByAddressAction\n | ChompApiServiceCreateWithdrawalAction\n | ChompApiServiceGetServiceDetailsAction\n | ChompApiServiceGetDerivedIdentitiesAction\n | ChompApiServiceGetDerivedIdentityByAddressAction;\n"]}
|
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
import { BaseDataService } from '@metamask/base-data-service';
|
|
2
2
|
import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from '@metamask/base-data-service';
|
|
3
3
|
import type { CreateServicePolicyOptions } from '@metamask/controller-utils';
|
|
4
|
+
import { HttpError } from '@metamask/controller-utils';
|
|
4
5
|
import type { Messenger } from '@metamask/messenger';
|
|
5
6
|
import type { Hex } from '@metamask/utils';
|
|
6
7
|
import type { QueryClientConfig } from '@tanstack/query-core';
|
|
7
8
|
import type { ChompApiServiceMethodActions } from './chomp-api-service-method-action-types.js';
|
|
8
|
-
import type {
|
|
9
|
+
import type { AddressIdentityResponse, AssociateAddressResponse, AssociateAddressV2Params, CreateAddressChallengeParams, CreateAddressChallengeResponse, ProfileAddressEntry, CreateUpgradeParams, CreateUpgradeResponse, UpgradeEntry, CreateWithdrawalParams, CreateWithdrawalResponse, DerivedIdentitiesResponse, IntentEntry, SendIntentParams, SendIntentResponse, ServiceDetailsResponse, VerifyDelegationParams, VerifyDelegationResponse } from './types.js';
|
|
9
10
|
/**
|
|
10
11
|
* The name of the {@link ChompApiService}, used to namespace the service's
|
|
11
12
|
* actions and events.
|
|
12
13
|
*/
|
|
13
14
|
export declare const serviceName = "ChompApiService";
|
|
15
|
+
/**
|
|
16
|
+
* Thrown when the CHOMP API responds with a non-2xx status.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ChompApiError extends HttpError {
|
|
19
|
+
/**
|
|
20
|
+
* The CHOMP error code from the response body (e.g.
|
|
21
|
+
* `PREDECESSOR_HAS_OPEN_WITHDRAWALS`), if one was provided.
|
|
22
|
+
*/
|
|
23
|
+
readonly code: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Construct a CHOMP API error.
|
|
26
|
+
*
|
|
27
|
+
* @param status - The HTTP response status.
|
|
28
|
+
* @param message - The error message.
|
|
29
|
+
* @param code - The CHOMP error code from the response body.
|
|
30
|
+
*/
|
|
31
|
+
constructor(status: number, message: string, code?: string);
|
|
32
|
+
}
|
|
14
33
|
/**
|
|
15
34
|
* Invalidates cached queries for {@link ChompApiService}.
|
|
16
35
|
*/
|
|
@@ -72,18 +91,49 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
72
91
|
policyOptions?: CreateServicePolicyOptions;
|
|
73
92
|
});
|
|
74
93
|
/**
|
|
75
|
-
*
|
|
94
|
+
* Requests a single-use challenge for associating an address through the v2
|
|
95
|
+
* flow. Sign the returned `message` exactly as received, using
|
|
96
|
+
* `personal_sign` with the address being associated, then submit it with
|
|
97
|
+
* {@link ChompApiService.associateAddressV2} before `expiresAt`. Requesting
|
|
98
|
+
* a new challenge for the same address replaces the previous one.
|
|
76
99
|
*
|
|
77
|
-
* POST /
|
|
100
|
+
* POST /v2/auth/address/challenge
|
|
78
101
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* address is associated with a different profile.
|
|
102
|
+
* Each call issues a new challenge, so the result is never cached.
|
|
103
|
+
*
|
|
104
|
+
* @param params - The address to associate and the association purpose.
|
|
105
|
+
* `ASSOCIATE_SUCCESSOR` also requires the predecessor address.
|
|
106
|
+
* @returns The challenge ID, the message to sign, and when it expires.
|
|
85
107
|
*/
|
|
86
|
-
|
|
108
|
+
createAddressChallenge(params: CreateAddressChallengeParams): Promise<CreateAddressChallengeResponse>;
|
|
109
|
+
/**
|
|
110
|
+
* Associates an address with a CHOMP profile by submitting the signature of
|
|
111
|
+
* a challenge from {@link ChompApiService.createAddressChallenge}. The
|
|
112
|
+
* address, purpose and predecessor come from the challenge. For
|
|
113
|
+
* `ASSOCIATE_SUCCESSOR`, the association and the link to the predecessor
|
|
114
|
+
* are written atomically.
|
|
115
|
+
*
|
|
116
|
+
* POST /v2/auth/address
|
|
117
|
+
*
|
|
118
|
+
* @param params - The challenge ID and its signature.
|
|
119
|
+
* @returns The profile association result: `status: 'created'` when the
|
|
120
|
+
* association or link was written, `status: 'active'` when the address was
|
|
121
|
+
* already associated with the authenticated profile. Throws on 400
|
|
122
|
+
* `CHALLENGE_INVALID_OR_EXPIRED` (request a new challenge), on 409 when the
|
|
123
|
+
* address is associated with a different profile, and on link validation
|
|
124
|
+
* errors.
|
|
125
|
+
*/
|
|
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>;
|
|
87
137
|
/**
|
|
88
138
|
* Fetches the addresses associated with the authenticated profile.
|
|
89
139
|
*
|
|
@@ -174,6 +224,34 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
174
224
|
* @returns The service details for the requested chains.
|
|
175
225
|
*/
|
|
176
226
|
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>;
|
|
177
255
|
}
|
|
178
256
|
export {};
|
|
179
257
|
//# 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;
|
|
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;AAerD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAS3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAC/F,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC5B,8B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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;IAED;;;;;;;;;;;;OAYG;IACG,oBAAoB,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAyB/D;IAED;;;;;;;;;;;;OAYG;IACG,2BAA2B,CAC/B,OAAO,EAAE,GAAG,GACX,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAsCzC;CACF"}
|
|
@@ -1,13 +1,25 @@
|
|
|
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, number, optional, record, string, type, } from '@metamask/superstruct';
|
|
4
|
-
import { bytesToHex, sha256, stringToBytes, StrictHexStruct, } from '@metamask/utils';
|
|
3
|
+
import { array, boolean, coerce, create, enums, literal, nullable, number, optional, record, string, type, } from '@metamask/superstruct';
|
|
4
|
+
import { bytesToHex, hasProperty, isObject, sha256, stringToBytes, StrictHexStruct, } from '@metamask/utils';
|
|
5
5
|
const CHOMP_INTENT_TYPES = [
|
|
6
6
|
'cash-deposit',
|
|
7
7
|
'cash-withdrawal',
|
|
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',
|
|
11
23
|
];
|
|
12
24
|
function isChompIntentType(value) {
|
|
13
25
|
return CHOMP_INTENT_TYPES.includes(value);
|
|
@@ -18,13 +30,53 @@ function isChompIntentType(value) {
|
|
|
18
30
|
* actions and events.
|
|
19
31
|
*/
|
|
20
32
|
export const serviceName = 'ChompApiService';
|
|
33
|
+
// === ERRORS ===
|
|
34
|
+
/**
|
|
35
|
+
* Thrown when the CHOMP API responds with a non-2xx status.
|
|
36
|
+
*/
|
|
37
|
+
export class ChompApiError extends HttpError {
|
|
38
|
+
/**
|
|
39
|
+
* The CHOMP error code from the response body (e.g.
|
|
40
|
+
* `PREDECESSOR_HAS_OPEN_WITHDRAWALS`), if one was provided.
|
|
41
|
+
*/
|
|
42
|
+
code;
|
|
43
|
+
/**
|
|
44
|
+
* Construct a CHOMP API error.
|
|
45
|
+
*
|
|
46
|
+
* @param status - The HTTP response status.
|
|
47
|
+
* @param message - The error message.
|
|
48
|
+
* @param code - The CHOMP error code from the response body.
|
|
49
|
+
*/
|
|
50
|
+
constructor(status, message, code) {
|
|
51
|
+
super(status, message);
|
|
52
|
+
this.name = 'ChompApiError';
|
|
53
|
+
this.code = code;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Builds a {@link ChompApiError} from a non-2xx response, reading the CHOMP
|
|
58
|
+
* error code from the response body when there is one.
|
|
59
|
+
*
|
|
60
|
+
* @param response - The non-2xx response.
|
|
61
|
+
* @param message - The error message.
|
|
62
|
+
* @returns The error to throw.
|
|
63
|
+
*/
|
|
64
|
+
async function createChompApiError(response, message) {
|
|
65
|
+
const body = await response.json().catch(() => undefined);
|
|
66
|
+
const code = isObject(body) && hasProperty(body, 'code') && typeof body.code === 'string'
|
|
67
|
+
? body.code
|
|
68
|
+
: undefined;
|
|
69
|
+
return new ChompApiError(response.status, message, code);
|
|
70
|
+
}
|
|
21
71
|
// === MESSENGER ===
|
|
22
72
|
/**
|
|
23
73
|
* All of the methods within {@link ChompApiService} that are exposed via the
|
|
24
74
|
* messenger.
|
|
25
75
|
*/
|
|
26
76
|
const MESSENGER_EXPOSED_METHODS = [
|
|
27
|
-
'
|
|
77
|
+
'createAddressChallenge',
|
|
78
|
+
'associateAddressV2',
|
|
79
|
+
'disassociateAddress',
|
|
28
80
|
'getAssociatedAddresses',
|
|
29
81
|
'createUpgrade',
|
|
30
82
|
'getUpgrades',
|
|
@@ -33,6 +85,8 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
33
85
|
'getIntentsByAddress',
|
|
34
86
|
'createWithdrawal',
|
|
35
87
|
'getServiceDetails',
|
|
88
|
+
'getDerivedIdentities',
|
|
89
|
+
'getDerivedIdentityByAddress',
|
|
36
90
|
];
|
|
37
91
|
// === RESPONSE VALIDATION ===
|
|
38
92
|
const AssociateAddressResponseStruct = type({
|
|
@@ -40,6 +94,11 @@ const AssociateAddressResponseStruct = type({
|
|
|
40
94
|
address: StrictHexStruct,
|
|
41
95
|
status: enums(['active', 'created']),
|
|
42
96
|
});
|
|
97
|
+
const CreateAddressChallengeResponseStruct = type({
|
|
98
|
+
challengeId: string(),
|
|
99
|
+
message: string(),
|
|
100
|
+
expiresAt: string(),
|
|
101
|
+
});
|
|
43
102
|
/**
|
|
44
103
|
* Parses addresses into canonical lowercase form. CHOMP stores and returns
|
|
45
104
|
* addresses lowercased, but `StrictHexStruct` alone accepts any casing, so
|
|
@@ -52,6 +111,31 @@ const ProfileAddressEntryArrayStruct = array(type({
|
|
|
52
111
|
address: LowercaseHexAddressStruct,
|
|
53
112
|
status: enums(['active']),
|
|
54
113
|
}));
|
|
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
|
+
});
|
|
55
139
|
const AccountUpgradeStatusStruct = enums(['pending', 'upgraded']);
|
|
56
140
|
const AuthorizationDataStruct = type({
|
|
57
141
|
r: StrictHexStruct,
|
|
@@ -195,6 +279,21 @@ export class ChompApiService extends BaseDataService {
|
|
|
195
279
|
'Content-Type': 'application/json',
|
|
196
280
|
};
|
|
197
281
|
}
|
|
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
|
+
}
|
|
198
297
|
/**
|
|
199
298
|
* Builds the standard headers for an authenticated CHOMP API request.
|
|
200
299
|
*
|
|
@@ -205,36 +304,105 @@ export class ChompApiService extends BaseDataService {
|
|
|
205
304
|
return this.#headersForToken(token);
|
|
206
305
|
}
|
|
207
306
|
/**
|
|
208
|
-
*
|
|
307
|
+
* Requests a single-use challenge for associating an address through the v2
|
|
308
|
+
* flow. Sign the returned `message` exactly as received, using
|
|
309
|
+
* `personal_sign` with the address being associated, then submit it with
|
|
310
|
+
* {@link ChompApiService.associateAddressV2} before `expiresAt`. Requesting
|
|
311
|
+
* a new challenge for the same address replaces the previous one.
|
|
209
312
|
*
|
|
210
|
-
* POST /
|
|
313
|
+
* POST /v2/auth/address/challenge
|
|
211
314
|
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* @
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* address is associated with a different profile.
|
|
315
|
+
* Each call issues a new challenge, so the result is never cached.
|
|
316
|
+
*
|
|
317
|
+
* @param params - The address to associate and the association purpose.
|
|
318
|
+
* `ASSOCIATE_SUCCESSOR` also requires the predecessor address.
|
|
319
|
+
* @returns The challenge ID, the message to sign, and when it expires.
|
|
218
320
|
*/
|
|
219
|
-
async
|
|
321
|
+
async createAddressChallenge(params) {
|
|
220
322
|
const jsonResponse = await this.fetchQuery({
|
|
221
|
-
queryKey: [`${this.name}:
|
|
323
|
+
queryKey: [`${this.name}:createAddressChallenge`, params],
|
|
222
324
|
staleTime: 0,
|
|
325
|
+
gcTime: 0,
|
|
223
326
|
queryFn: async () => {
|
|
224
327
|
const headers = await this.#authHeaders();
|
|
225
|
-
const response = await fetch(new URL('/
|
|
328
|
+
const response = await fetch(new URL('/v2/auth/address/challenge', this.#baseUrl), {
|
|
226
329
|
method: 'POST',
|
|
227
330
|
headers,
|
|
228
331
|
body: JSON.stringify(params),
|
|
229
332
|
});
|
|
230
333
|
if (!response.ok) {
|
|
231
|
-
throw
|
|
334
|
+
throw await createChompApiError(response, `POST /v2/auth/address/challenge failed with status '${response.status}'`);
|
|
335
|
+
}
|
|
336
|
+
return response.json();
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
return create(jsonResponse, CreateAddressChallengeResponseStruct);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Associates an address with a CHOMP profile by submitting the signature of
|
|
343
|
+
* a challenge from {@link ChompApiService.createAddressChallenge}. The
|
|
344
|
+
* address, purpose and predecessor come from the challenge. For
|
|
345
|
+
* `ASSOCIATE_SUCCESSOR`, the association and the link to the predecessor
|
|
346
|
+
* are written atomically.
|
|
347
|
+
*
|
|
348
|
+
* POST /v2/auth/address
|
|
349
|
+
*
|
|
350
|
+
* @param params - The challenge ID and its signature.
|
|
351
|
+
* @returns The profile association result: `status: 'created'` when the
|
|
352
|
+
* association or link was written, `status: 'active'` when the address was
|
|
353
|
+
* already associated with the authenticated profile. Throws on 400
|
|
354
|
+
* `CHALLENGE_INVALID_OR_EXPIRED` (request a new challenge), on 409 when the
|
|
355
|
+
* address is associated with a different profile, and on link validation
|
|
356
|
+
* errors.
|
|
357
|
+
*/
|
|
358
|
+
async associateAddressV2(params) {
|
|
359
|
+
const jsonResponse = await this.fetchQuery({
|
|
360
|
+
queryKey: [`${this.name}:associateAddressV2`, params],
|
|
361
|
+
staleTime: 0,
|
|
362
|
+
gcTime: 0,
|
|
363
|
+
queryFn: async () => {
|
|
364
|
+
const headers = await this.#authHeaders();
|
|
365
|
+
const response = await fetch(new URL('/v2/auth/address', this.#baseUrl), {
|
|
366
|
+
method: 'POST',
|
|
367
|
+
headers,
|
|
368
|
+
body: JSON.stringify(params),
|
|
369
|
+
});
|
|
370
|
+
if (!response.ok) {
|
|
371
|
+
throw await createChompApiError(response, `POST /v2/auth/address failed with status '${response.status}'`);
|
|
232
372
|
}
|
|
233
373
|
return response.json();
|
|
234
374
|
},
|
|
235
375
|
});
|
|
236
376
|
return create(jsonResponse, AssociateAddressResponseStruct);
|
|
237
377
|
}
|
|
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
|
+
}
|
|
238
406
|
/**
|
|
239
407
|
* Fetches the addresses associated with the authenticated profile.
|
|
240
408
|
*
|
|
@@ -253,8 +421,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
253
421
|
* Addresses are lowercased.
|
|
254
422
|
*/
|
|
255
423
|
async getAssociatedAddresses() {
|
|
256
|
-
const token = await this
|
|
257
|
-
const profileKey = bytesToHex(await sha256(stringToBytes(token)));
|
|
424
|
+
const { token, profileKey } = await this.#getProfileScopedToken();
|
|
258
425
|
const jsonResponse = await this.fetchQuery({
|
|
259
426
|
queryKey: [`${this.name}:getAssociatedAddresses`, profileKey],
|
|
260
427
|
staleTime: 0,
|
|
@@ -262,7 +429,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
262
429
|
queryFn: async () => {
|
|
263
430
|
const response = await fetch(new URL('/v1/auth/address', this.#baseUrl), { headers: this.#headersForToken(token) });
|
|
264
431
|
if (!response.ok) {
|
|
265
|
-
throw
|
|
432
|
+
throw await createChompApiError(response, `GET /v1/auth/address failed with status '${response.status}'`);
|
|
266
433
|
}
|
|
267
434
|
return response.json();
|
|
268
435
|
},
|
|
@@ -290,7 +457,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
290
457
|
body: JSON.stringify(params),
|
|
291
458
|
});
|
|
292
459
|
if (!response.ok) {
|
|
293
|
-
throw
|
|
460
|
+
throw await createChompApiError(response, `POST /v1/account-upgrade failed with status '${response.status}'`);
|
|
294
461
|
}
|
|
295
462
|
return response.json();
|
|
296
463
|
},
|
|
@@ -313,7 +480,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
313
480
|
const headers = await this.#authHeaders();
|
|
314
481
|
const response = await fetch(new URL(`/v1/account-upgrade/${address}`, this.#baseUrl), { headers });
|
|
315
482
|
if (!response.ok) {
|
|
316
|
-
throw
|
|
483
|
+
throw await createChompApiError(response, `Get upgrades request failed with status '${response.status}'`);
|
|
317
484
|
}
|
|
318
485
|
return response.json();
|
|
319
486
|
},
|
|
@@ -340,7 +507,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
340
507
|
body: JSON.stringify(params),
|
|
341
508
|
});
|
|
342
509
|
if (!response.ok) {
|
|
343
|
-
throw
|
|
510
|
+
throw await createChompApiError(response, `POST /v1/intent/verify-delegation failed with status '${response.status}'`);
|
|
344
511
|
}
|
|
345
512
|
return response.json();
|
|
346
513
|
},
|
|
@@ -367,7 +534,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
367
534
|
body: JSON.stringify(intents),
|
|
368
535
|
});
|
|
369
536
|
if (!response.ok) {
|
|
370
|
-
throw
|
|
537
|
+
throw await createChompApiError(response, `POST /v1/intent failed with status '${response.status}'`);
|
|
371
538
|
}
|
|
372
539
|
return response.json();
|
|
373
540
|
},
|
|
@@ -394,7 +561,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
394
561
|
const headers = await this.#authHeaders();
|
|
395
562
|
const response = await fetch(new URL(`/v1/intent/account/${address}`, this.#baseUrl), { headers });
|
|
396
563
|
if (!response.ok) {
|
|
397
|
-
throw
|
|
564
|
+
throw await createChompApiError(response, `Get intents request failed with status '${response.status}'`);
|
|
398
565
|
}
|
|
399
566
|
return response.json();
|
|
400
567
|
},
|
|
@@ -422,7 +589,7 @@ export class ChompApiService extends BaseDataService {
|
|
|
422
589
|
body: JSON.stringify(params),
|
|
423
590
|
});
|
|
424
591
|
if (!response.ok) {
|
|
425
|
-
throw
|
|
592
|
+
throw await createChompApiError(response, `POST /v1/withdrawal failed with status '${response.status}'`);
|
|
426
593
|
}
|
|
427
594
|
return response.json();
|
|
428
595
|
},
|
|
@@ -448,12 +615,79 @@ export class ChompApiService extends BaseDataService {
|
|
|
448
615
|
url.searchParams.set('chainId', chainIds.join(','));
|
|
449
616
|
const response = await fetch(url, { headers });
|
|
450
617
|
if (!response.ok) {
|
|
451
|
-
throw
|
|
618
|
+
throw await createChompApiError(response, `GET /v1/chomp failed with status '${response.status}'`);
|
|
452
619
|
}
|
|
453
620
|
return response.json();
|
|
454
621
|
},
|
|
455
622
|
});
|
|
456
623
|
return create(jsonResponse, ServiceDetailsResponseStruct);
|
|
457
624
|
}
|
|
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
|
+
}
|
|
458
692
|
}
|
|
459
693
|
//# 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,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,GACL,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,UAAU,EACV,MAAM,EACN,aAAa,EACb,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAsBzB,MAAM,kBAAkB,GAAsB;IAC5C,cAAc;IACd,iBAAiB;IACjB,sBAAsB;IACtB,yBAAyB;IACzB,mBAAmB;CACpB,CAAC;AAEF,SAAS,iBAAiB,CAAC,KAAa;IACtC,OAAQ,kBAA+B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAE7C,oBAAoB;AAEpB;;;GAGG;AACH,MAAM,yBAAyB,GAAG;IAChC,kBAAkB;IAClB,wBAAwB;IACxB,e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ASG;IACH,KAAK,CAAC,iBAAiB,CAAC,QAAe;QACrC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;YACzC,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,oBAAoB,EAAE,QAAQ,CAAC;YACtD,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;gBAC1C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAChD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBACpD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;gBAE/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,SAAS,CACjB,QAAQ,CAAC,MAAM,EACf,qCAAqC,QAAQ,CAAC,MAAM,GAAG,CACxD,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,YAAY,EAAE,4BAA4B,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { handleWhen, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n array,\n boolean,\n coerce,\n create,\n enums,\n literal,\n number,\n optional,\n record,\n string,\n type,\n} from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport {\n bytesToHex,\n sha256,\n stringToBytes,\n StrictHexStruct,\n} from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { ChompApiServiceMethodActions } from './chomp-api-service-method-action-types.js';\nimport type {\n AssociateAddressParams,\n AssociateAddressResponse,\n ProfileAddressEntry,\n 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// === MESSENGER ===\n\n/**\n * All of the methods within {@link ChompApiService} that are exposed via the\n * messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = [\n 'associateAddress',\n 'getAssociatedAddresses',\n 'createUpgrade',\n 'getUpgrades',\n 'verifyDelegation',\n 'createIntents',\n 'getIntentsByAddress',\n 'createWithdrawal',\n 'getServiceDetails',\n] as const;\n\n/**\n * Invalidates cached queries for {@link ChompApiService}.\n */\nexport type ChompApiServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceActions =\n | ChompApiServiceMethodActions\n | ChompApiServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link ChompApiService} calls.\n */\ntype AllowedActions = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\n/**\n * Published when {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<\n typeof serviceName\n>;\n\n/**\n * Published when a key within {@link ChompApiService}'s cache is updated.\n */\nexport type ChompApiServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link ChompApiService} exposes to other consumers.\n */\nexport type ChompApiServiceEvents =\n | ChompApiServiceCacheUpdatedEvent\n | ChompApiServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link ChompApiService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ChompApiService}.\n */\nexport type ChompApiServiceMessenger = Messenger<\n typeof serviceName,\n ChompApiServiceActions | AllowedActions,\n ChompApiServiceEvents | AllowedEvents\n>;\n\n// === RESPONSE VALIDATION ===\n\nconst AssociateAddressResponseStruct = type({\n profileId: optional(string()),\n address: StrictHexStruct,\n status: enums(['active', 'created']),\n});\n\n/**\n * Parses addresses into canonical lowercase form. CHOMP stores and returns\n * addresses lowercased, but `StrictHexStruct` alone accepts any casing, so\n * this makes the canonical form a guarantee of the parsed data rather than a\n * convention consumers must each remember.\n */\nconst LowercaseHexAddressStruct = coerce(StrictHexStruct, string(), (value) =>\n value.toLowerCase(),\n);\n\nconst ProfileAddressEntryArrayStruct = array(\n type({\n profileId: string(),\n address: LowercaseHexAddressStruct,\n status: enums(['active']),\n }),\n);\n\nconst AccountUpgradeStatusStruct = enums(['pending', 'upgraded']);\n\nconst AuthorizationDataStruct = type({\n r: StrictHexStruct,\n s: StrictHexStruct,\n v: number(),\n yParity: number(),\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n});\n\nconst CreateUpgradeResponseStruct = type({\n signerAddress: StrictHexStruct,\n address: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n});\n\nconst UpgradeEntryArrayStruct = array(\n type({\n signerAddress: StrictHexStruct,\n chainId: StrictHexStruct,\n nonce: StrictHexStruct,\n authorization: AuthorizationDataStruct,\n status: AccountUpgradeStatusStruct,\n createdAt: string(),\n }),\n);\n\nconst VerifyDelegationResponseStruct = type({\n valid: boolean(),\n delegationHash: optional(StrictHexStruct),\n errors: optional(array(string())),\n});\n\nconst SendIntentResponseArrayStruct = array(\n type({\n delegationHash: StrictHexStruct,\n metadata: type({\n allowance: StrictHexStruct,\n tokenSymbol: string(),\n tokenAddress: StrictHexStruct,\n type: enums(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 * Associates an address with a CHOMP profile.\n *\n * POST /v1/auth/address\n *\n * @param params - The association params containing signature, timestamp,\n * and address.\n * @returns The profile association result: `status: 'created'` for a new\n * association, `status: 'active'` when the address was already associated\n * with the authenticated profile. Throws on 409, which indicates the\n * address is associated with a different profile.\n */\n async associateAddress(\n params: AssociateAddressParams,\n ): Promise<AssociateAddressResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:associateAddress`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, AssociateAddressResponseStruct);\n }\n\n /**\n * Fetches the addresses associated with the authenticated profile.\n *\n * GET /v1/auth/address\n *\n * The result is scoped to the authenticated profile and consumers use it\n * to decide whether an association already exists, so it is always fetched\n * fresh (`staleTime: 0`) and evicted as soon as the call settles\n * (`gcTime: 0`). The query key carries a SHA-256 digest of the bearer\n * token — the same token the request is made with — so concurrent calls\n * only share an in-flight request when they are for the same profile. The\n * digest, not the token, is used because query keys leave the service via\n * the `cacheUpdated` messenger events.\n *\n * @returns The active address associations; empty array if none exist.\n * Addresses are lowercased.\n */\n async getAssociatedAddresses(): Promise<ProfileAddressEntry[]> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n const profileKey = bytesToHex(await sha256(stringToBytes(token)));\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getAssociatedAddresses`, profileKey],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const response = await fetch(\n new URL('/v1/auth/address', this.#baseUrl),\n { headers: this.#headersForToken(token) },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/auth/address failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ProfileAddressEntryArrayStruct);\n }\n\n /**\n * Creates an account upgrade request.\n *\n * POST /v1/account-upgrade\n *\n * @param params - The upgrade params containing signature components and\n * chain details.\n * @returns The upgrade result.\n */\n async createUpgrade(\n params: CreateUpgradeParams,\n ): Promise<CreateUpgradeResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createUpgrade`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/account-upgrade', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/account-upgrade failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateUpgradeResponseStruct);\n }\n\n /**\n * Fetches all EIP-7702 upgrade authorizations for a given address (one per\n * chain).\n *\n * GET /v1/account-upgrade/:address\n *\n * @param address - The address to look up.\n * @returns The upgrade entries; empty array if none exist.\n */\n async getUpgrades(address: Hex): Promise<UpgradeEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getUpgrades`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/account-upgrade/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get upgrades request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, UpgradeEntryArrayStruct);\n }\n\n /**\n * Verifies a delegation signature.\n *\n * POST /v1/intent/verify-delegation\n *\n * @param params - The delegation verification params.\n * @returns The verification result including validity and optional errors.\n */\n async verifyDelegation(\n params: VerifyDelegationParams,\n ): Promise<VerifyDelegationResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:verifyDelegation`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/intent/verify-delegation', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent/verify-delegation failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, VerifyDelegationResponseStruct);\n }\n\n /**\n * Submits one or more intents to the CHOMP API.\n *\n * POST /v1/intent\n *\n * @param intents - The array of intents to submit.\n * @returns The array of intent responses.\n */\n async createIntents(\n intents: SendIntentParams[],\n ): Promise<SendIntentResponse[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createIntents`, intents],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/intent', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(intents),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, SendIntentResponseArrayStruct);\n }\n\n /**\n * Fetches intents associated with a given address.\n *\n * GET /v1/intent/account/:address\n *\n * 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 new HttpError(\n response.status,\n `Get intents request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, IntentEntryArrayStruct).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 new HttpError(\n response.status,\n `POST /v1/withdrawal failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateWithdrawalResponseStruct);\n }\n\n /**\n * Retrieves service details including delegation redeemer addresses and DeFi\n * contract details for signing delegations for auto-deposit functionality.\n *\n * GET /v1/chomp\n *\n * @param chainIds - Array of chain IDs (0x-prefixed hex strings) to retrieve\n * details for.\n * @returns The service details for the requested chains.\n */\n async getServiceDetails(chainIds: Hex[]): Promise<ServiceDetailsResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getServiceDetails`, chainIds],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const url = new URL('/v1/chomp', this.#baseUrl);\n url.searchParams.set('chainId', chainIds.join(','));\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/chomp failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ServiceDetailsResponseStruct);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chomp-api-service.js","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAO9D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AAC,CAAC;QAEH,OAAO,MAAM,CAAC,YAAY,EAAE,+BAA+B,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,2BAA2B,CAC/B,OAAY;QAEZ,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAElE,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;YACzC,QAAQ,EAAE;gBACR,GAAG,IAAI,CAAC,IAAI,8BAA8B;gBAC1C,UAAU;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"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { ChompApiService } from './chomp-api-service.js';
|
|
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 {
|
|
4
|
-
export type { AccountUpgradeStatus,
|
|
3
|
+
export type { ChompApiServiceAssociateAddressV2Action, ChompApiServiceCreateAddressChallengeAction, ChompApiServiceDisassociateAddressAction, ChompApiServiceGetAssociatedAddressesAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetUpgradesAction, ChompApiServiceVerifyDelegationAction, ChompApiServiceCreateIntentsAction, ChompApiServiceGetIntentsByAddressAction, ChompApiServiceCreateWithdrawalAction, ChompApiServiceGetServiceDetailsAction, ChompApiServiceGetDerivedIdentitiesAction, ChompApiServiceGetDerivedIdentityByAddressAction, } from './chomp-api-service-method-action-types.js';
|
|
4
|
+
export type { AccountUpgradeStatus, AddressIdentityResponse, AssociateAddressResponse, AssociateAddressV2Params, AssociationPurpose, AuthorizationData, ChompIntentType, CreateAddressChallengeParams, CreateAddressChallengeResponse, CreateUpgradeParams, CreateUpgradeResponse, CreateWithdrawalParams, CreateWithdrawalResponse, DelegationCaveat, DerivedIdentitiesResponse, DerivedIdentity, DerivedIdentityAddressRole, DerivedIdentityMigration, DerivedIdentityStatus, UpgradeEntry, IntentEntry, IntentMetadataParams, IntentMetadataResponse, MigrationStep, 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,eAAe,EAAE,MAAM,wBAAwB,CAAC;
|
|
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,wCAAwC,EACxC,2CAA2C,EAC3C,kCAAkC,EAClC,gCAAgC,EAChC,qCAAqC,EACrC,kCAAkC,EAClC,wCAAwC,EACxC,qCAAqC,EACrC,sCAAsC,EACtC,yCAAyC,EACzC,gDAAgD,GACjD,MAAM,4CAA4C,CAAC;AACpD,YAAY,EACV,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,4BAA4B,EAC5B,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EAChB,yBAAyB,EACzB,eAAe,EACf,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,EACb,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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ChompApiService } from './chomp-api-service.js';
|
|
1
|
+
export { ChompApiError, ChompApiService } from './chomp-api-service.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { 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
|
|
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 ChompApiServiceDisassociateAddressAction,\n ChompApiServiceGetAssociatedAddressesAction,\n ChompApiServiceCreateUpgradeAction,\n ChompApiServiceGetUpgradesAction,\n ChompApiServiceVerifyDelegationAction,\n ChompApiServiceCreateIntentsAction,\n ChompApiServiceGetIntentsByAddressAction,\n ChompApiServiceCreateWithdrawalAction,\n ChompApiServiceGetServiceDetailsAction,\n ChompApiServiceGetDerivedIdentitiesAction,\n ChompApiServiceGetDerivedIdentityByAddressAction,\n} from './chomp-api-service-method-action-types.js';\nexport type {\n AccountUpgradeStatus,\n AddressIdentityResponse,\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 DerivedIdentitiesResponse,\n DerivedIdentity,\n DerivedIdentityAddressRole,\n DerivedIdentityMigration,\n DerivedIdentityStatus,\n UpgradeEntry,\n IntentEntry,\n IntentMetadataParams,\n IntentMetadataResponse,\n MigrationStep,\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,10 +2,11 @@ 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`),
|
|
6
|
-
* subscription payment (`cash-subscription`)
|
|
5
|
+
* (`cash-deposit-premium`, `cash-withdrawal-premium`), the recurring
|
|
6
|
+
* subscription payment (`cash-subscription`), and Money Account migration
|
|
7
|
+
* (`cash-migration-root`, `cash-migration-transfer`).
|
|
7
8
|
*/
|
|
8
|
-
export type ChompIntentType = 'cash-deposit' | 'cash-withdrawal' | 'cash-deposit-premium' | 'cash-withdrawal-premium' | 'cash-subscription';
|
|
9
|
+
export type ChompIntentType = 'cash-deposit' | 'cash-withdrawal' | 'cash-deposit-premium' | 'cash-withdrawal-premium' | 'cash-subscription' | 'cash-migration-root' | 'cash-migration-transfer';
|
|
9
10
|
export type DelegationCaveat = {
|
|
10
11
|
enforcer: Hex;
|
|
11
12
|
terms: Hex;
|
|
@@ -19,10 +20,31 @@ export type SignedDelegation = {
|
|
|
19
20
|
salt: Hex;
|
|
20
21
|
signature: Hex;
|
|
21
22
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Why an address is being associated through the v2 flow. `ASSOCIATE` creates
|
|
25
|
+
* a normal association, while `ASSOCIATE_SUCCESSOR` also links the address to
|
|
26
|
+
* its predecessor as the next address in the Money Account identity chain.
|
|
27
|
+
*/
|
|
28
|
+
export type AssociationPurpose = 'ASSOCIATE' | 'ASSOCIATE_SUCCESSOR';
|
|
29
|
+
export type CreateAddressChallengeParams = {
|
|
30
|
+
address: Hex;
|
|
31
|
+
purpose: 'ASSOCIATE';
|
|
32
|
+
} | {
|
|
25
33
|
address: Hex;
|
|
34
|
+
purpose: 'ASSOCIATE_SUCCESSOR';
|
|
35
|
+
/**
|
|
36
|
+
* The current address of the Money Account that `address` succeeds.
|
|
37
|
+
* Must be set before any intents exist on `address`.
|
|
38
|
+
*/
|
|
39
|
+
predecessorAddress: Hex;
|
|
40
|
+
};
|
|
41
|
+
export type AssociateAddressV2Params = {
|
|
42
|
+
challengeId: string;
|
|
43
|
+
/**
|
|
44
|
+
* The `personal_sign` signature of the challenge `message`, signed exactly
|
|
45
|
+
* as returned by CHOMP with the address being associated.
|
|
46
|
+
*/
|
|
47
|
+
signature: Hex;
|
|
26
48
|
};
|
|
27
49
|
export type CreateUpgradeParams = {
|
|
28
50
|
r: Hex;
|
|
@@ -56,19 +78,34 @@ export type CreateWithdrawalParams = {
|
|
|
56
78
|
account: Hex;
|
|
57
79
|
};
|
|
58
80
|
/**
|
|
59
|
-
* Returned by POST /
|
|
81
|
+
* Returned by POST /v2/auth/address.
|
|
60
82
|
*
|
|
61
83
|
* `profileId` is only included when the address was newly associated
|
|
62
84
|
* (`status: 'created'`). When the address was already associated with the
|
|
63
85
|
* authenticated profile (`status: 'active'`), only `address` is returned.
|
|
64
|
-
*
|
|
65
|
-
*
|
|
86
|
+
* An address associated with a different profile responds with 409, which is
|
|
87
|
+
* surfaced as an error.
|
|
66
88
|
*/
|
|
67
89
|
export type AssociateAddressResponse = {
|
|
68
90
|
profileId?: string;
|
|
69
91
|
address: Hex;
|
|
70
92
|
status: 'active' | 'created';
|
|
71
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* Returned by POST /v2/auth/address/challenge.
|
|
96
|
+
*/
|
|
97
|
+
export type CreateAddressChallengeResponse = {
|
|
98
|
+
challengeId: string;
|
|
99
|
+
/**
|
|
100
|
+
* The EIP-4361 (Sign-In with Ethereum) message to sign, bound to the
|
|
101
|
+
* profile, chain, purpose, address and predecessor.
|
|
102
|
+
*/
|
|
103
|
+
message: string;
|
|
104
|
+
/**
|
|
105
|
+
* When the challenge expires, as an ISO 8601 timestamp.
|
|
106
|
+
*/
|
|
107
|
+
expiresAt: string;
|
|
108
|
+
};
|
|
72
109
|
/**
|
|
73
110
|
* One entry returned by GET /v1/auth/address. The endpoint returns an array
|
|
74
111
|
* of these — the active address associations of the authenticated profile
|
|
@@ -147,6 +184,59 @@ export type IntentEntry = {
|
|
|
147
184
|
export type CreateWithdrawalResponse = {
|
|
148
185
|
success: true;
|
|
149
186
|
};
|
|
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
|
+
};
|
|
150
240
|
export type ServiceDetailsSupportedToken = {
|
|
151
241
|
tokenAddress: Hex;
|
|
152
242
|
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.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EAAE,eAAe,CAAC;IAC1B,OAAO,EAAE;QACP,OAAO,EAAE,GAAG,CAAC;QACb,IAAI,EAAE,0BAA0B,CAAC;QACjC,WAAW,EAAE,GAAG,GAAG,IAAI,CAAC;QACxB,SAAS,EAAE,GAAG,GAAG,IAAI,CAAC;KACvB,CAAC;CACH,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`),
|
|
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`), and Money Account migration\n * (`cash-migration-root`, `cash-migration-transfer`).\n */\nexport type 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\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// === DERIVED IDENTITY TYPES ===\n\n/**\n * A step that must exist before a migration link counts as complete.\n * `SUCCESSOR_SUBSCRIPTION_INTENT` and `TRANSFER_INTENT_PVMUSD` are only\n * required for premium subscribers.\n */\nexport type 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/**\n * The settlement status of a Money Account identity chain. `NONE` is never\n * returned as an entry: a profile with no Money Account has no identities.\n */\nexport type DerivedIdentityStatus = 'NONE' | 'MIGRATING' | 'DONE';\n\n/**\n * The latest link of an identity chain while it is migrating.\n */\nexport type DerivedIdentityMigration = {\n from: Hex;\n to: Hex;\n requiredSteps: MigrationStep[];\n completedSteps: MigrationStep[];\n missingSteps: MigrationStep[];\n};\n\n/**\n * One Money Account over time: a chain of addresses joined by links.\n * Addresses are lowercased.\n */\nexport type DerivedIdentity = {\n /** The tip of the chain. Stays on the old address while migrating. */\n currentAddress: Hex;\n /** Earlier addresses, from the immediate predecessor backwards. */\n previousAddresses: Hex[];\n status: DerivedIdentityStatus;\n migration: DerivedIdentityMigration | null;\n};\n\n/**\n * Returned by GET /v1/money-account/identities.\n */\nexport type DerivedIdentitiesResponse = {\n identities: DerivedIdentity[];\n};\n\nexport type DerivedIdentityAddressRole =\n | 'CURRENT'\n | 'PREVIOUS'\n | 'PENDING_SUCCESSOR';\n\n/**\n * Returned by GET /v1/money-account/identities/address/:address. Addresses\n * are lowercased.\n */\nexport type AddressIdentityResponse = {\n identity: DerivedIdentity;\n address: {\n address: Hex;\n role: DerivedIdentityAddressRole;\n predecessor: Hex | null;\n successor: Hex | null;\n };\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"]}
|