@metamask-previews/chomp-api-service 0.0.0-preview-9fac52d → 1.0.0-preview-42c8fd288
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -2
- package/dist/chomp-api-service-method-action-types.cjs.map +1 -1
- package/dist/chomp-api-service-method-action-types.d.cts +1 -1
- package/dist/chomp-api-service-method-action-types.d.mts +1 -1
- package/dist/chomp-api-service-method-action-types.mjs.map +1 -1
- package/dist/chomp-api-service.cjs +31 -37
- package/dist/chomp-api-service.cjs.map +1 -1
- package/dist/chomp-api-service.d.cts +14 -13
- package/dist/chomp-api-service.d.cts.map +1 -1
- package/dist/chomp-api-service.d.mts +14 -13
- package/dist/chomp-api-service.d.mts.map +1 -1
- package/dist/chomp-api-service.mjs +33 -39
- package/dist/chomp-api-service.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +20 -20
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +20 -20
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,9 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.0.0]
|
|
11
|
+
|
|
10
12
|
### Added
|
|
11
13
|
|
|
12
14
|
- Add `ChompApiService` ([#8413](https://github.com/MetaMask/core/pull/8413))
|
|
13
|
-
- Add `getServiceDetails` method to retrieve delegation redeemer addresses and DeFi contract details for auto-deposit functionality
|
|
14
15
|
|
|
15
|
-
[Unreleased]: https://github.com/MetaMask/core/
|
|
16
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/chomp-api-service@1.0.0...HEAD
|
|
17
|
+
[1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/chomp-api-service@1.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service-method-action-types.cjs","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';\n\n/**\n * Associates an address with a CHOMP profile via POST /v1/auth/address.\n */\nexport type ChompApiServiceAssociateAddressAction = {\n type: `ChompApiService:associateAddress`;\n handler: ChompApiService['associateAddress'];\n};\n\n/**\n * Creates an account upgrade via POST /v1/account-upgrade.\n */\nexport type ChompApiServiceCreateUpgradeAction = {\n type: `ChompApiService:createUpgrade`;\n handler: ChompApiService['createUpgrade'];\n};\n\n/**\n * Fetches the upgrade record for an address via GET /v1/account-upgrade/:address.\n */\nexport type ChompApiServiceGetUpgradeAction = {\n type: `ChompApiService:getUpgrade`;\n handler: ChompApiService['getUpgrade'];\n};\n\n/**\n * Verifies a delegation via POST /v1/intent/verify-delegation.\n */\nexport type ChompApiServiceVerifyDelegationAction = {\n type: `ChompApiService:verifyDelegation`;\n handler: ChompApiService['verifyDelegation'];\n};\n\n/**\n * Submits intents via POST /v1/intent.\n */\nexport type ChompApiServiceCreateIntentsAction = {\n type: `ChompApiService:createIntents`;\n handler: ChompApiService['createIntents'];\n};\n\n/**\n * Fetches intents by address via GET /v1/intent/account/:address.\n */\nexport type ChompApiServiceGetIntentsByAddressAction = {\n type: `ChompApiService:getIntentsByAddress`;\n handler: ChompApiService['getIntentsByAddress'];\n};\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"chomp-api-service-method-action-types.cjs","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';\n\n/**\n * Associates an address with a CHOMP profile via POST /v1/auth/address.\n */\nexport type ChompApiServiceAssociateAddressAction = {\n type: `ChompApiService:associateAddress`;\n handler: ChompApiService['associateAddress'];\n};\n\n/**\n * Creates an account upgrade via POST /v1/account-upgrade.\n */\nexport type ChompApiServiceCreateUpgradeAction = {\n type: `ChompApiService:createUpgrade`;\n handler: ChompApiService['createUpgrade'];\n};\n\n/**\n * Fetches the upgrade record for an address via GET /v1/account-upgrade/:address.\n */\nexport type ChompApiServiceGetUpgradeAction = {\n type: `ChompApiService:getUpgrade`;\n handler: ChompApiService['getUpgrade'];\n};\n\n/**\n * Verifies a delegation via POST /v1/intent/verify-delegation.\n */\nexport type ChompApiServiceVerifyDelegationAction = {\n type: `ChompApiService:verifyDelegation`;\n handler: ChompApiService['verifyDelegation'];\n};\n\n/**\n * Submits intents via POST /v1/intent.\n */\nexport type ChompApiServiceCreateIntentsAction = {\n type: `ChompApiService:createIntents`;\n handler: ChompApiService['createIntents'];\n};\n\n/**\n * Fetches intents by address via GET /v1/intent/account/:address.\n */\nexport type ChompApiServiceGetIntentsByAddressAction = {\n type: `ChompApiService:getIntentsByAddress`;\n handler: ChompApiService['getIntentsByAddress'];\n};\n\n/**\n * Submits a withdrawal request via POST /v1/withdrawal\n */\nexport type ChompApiServiceCreateWithdrawalAction = {\n type: `ChompApiService:createWithdrawal`;\n handler: ChompApiService['createWithdrawal'];\n};\n\n/**\n * Retrieves service details via GET /v1/chomp.\n */\nexport type ChompApiServiceGetServiceDetailsAction = {\n type: `ChompApiService:getServiceDetails`;\n handler: ChompApiService['getServiceDetails'];\n};\n\n/**\n * Union of all ChompApiService action types.\n */\nexport type ChompApiServiceMethodActions =\n | ChompApiServiceAssociateAddressAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetUpgradeAction\n | ChompApiServiceVerifyDelegationAction\n | ChompApiServiceCreateIntentsAction\n | ChompApiServiceGetIntentsByAddressAction\n | ChompApiServiceCreateWithdrawalAction\n | ChompApiServiceGetServiceDetailsAction;\n"]}
|
|
@@ -46,7 +46,7 @@ export type ChompApiServiceGetIntentsByAddressAction = {
|
|
|
46
46
|
handler: ChompApiService['getIntentsByAddress'];
|
|
47
47
|
};
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Submits a withdrawal request via POST /v1/withdrawal
|
|
50
50
|
*/
|
|
51
51
|
export type ChompApiServiceCreateWithdrawalAction = {
|
|
52
52
|
type: `ChompApiService:createWithdrawal`;
|
|
@@ -46,7 +46,7 @@ export type ChompApiServiceGetIntentsByAddressAction = {
|
|
|
46
46
|
handler: ChompApiService['getIntentsByAddress'];
|
|
47
47
|
};
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Submits a withdrawal request via POST /v1/withdrawal
|
|
50
50
|
*/
|
|
51
51
|
export type ChompApiServiceCreateWithdrawalAction = {
|
|
52
52
|
type: `ChompApiService:createWithdrawal`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service-method-action-types.mjs","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';\n\n/**\n * Associates an address with a CHOMP profile via POST /v1/auth/address.\n */\nexport type ChompApiServiceAssociateAddressAction = {\n type: `ChompApiService:associateAddress`;\n handler: ChompApiService['associateAddress'];\n};\n\n/**\n * Creates an account upgrade via POST /v1/account-upgrade.\n */\nexport type ChompApiServiceCreateUpgradeAction = {\n type: `ChompApiService:createUpgrade`;\n handler: ChompApiService['createUpgrade'];\n};\n\n/**\n * Fetches the upgrade record for an address via GET /v1/account-upgrade/:address.\n */\nexport type ChompApiServiceGetUpgradeAction = {\n type: `ChompApiService:getUpgrade`;\n handler: ChompApiService['getUpgrade'];\n};\n\n/**\n * Verifies a delegation via POST /v1/intent/verify-delegation.\n */\nexport type ChompApiServiceVerifyDelegationAction = {\n type: `ChompApiService:verifyDelegation`;\n handler: ChompApiService['verifyDelegation'];\n};\n\n/**\n * Submits intents via POST /v1/intent.\n */\nexport type ChompApiServiceCreateIntentsAction = {\n type: `ChompApiService:createIntents`;\n handler: ChompApiService['createIntents'];\n};\n\n/**\n * Fetches intents by address via GET /v1/intent/account/:address.\n */\nexport type ChompApiServiceGetIntentsByAddressAction = {\n type: `ChompApiService:getIntentsByAddress`;\n handler: ChompApiService['getIntentsByAddress'];\n};\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"chomp-api-service-method-action-types.mjs","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';\n\n/**\n * Associates an address with a CHOMP profile via POST /v1/auth/address.\n */\nexport type ChompApiServiceAssociateAddressAction = {\n type: `ChompApiService:associateAddress`;\n handler: ChompApiService['associateAddress'];\n};\n\n/**\n * Creates an account upgrade via POST /v1/account-upgrade.\n */\nexport type ChompApiServiceCreateUpgradeAction = {\n type: `ChompApiService:createUpgrade`;\n handler: ChompApiService['createUpgrade'];\n};\n\n/**\n * Fetches the upgrade record for an address via GET /v1/account-upgrade/:address.\n */\nexport type ChompApiServiceGetUpgradeAction = {\n type: `ChompApiService:getUpgrade`;\n handler: ChompApiService['getUpgrade'];\n};\n\n/**\n * Verifies a delegation via POST /v1/intent/verify-delegation.\n */\nexport type ChompApiServiceVerifyDelegationAction = {\n type: `ChompApiService:verifyDelegation`;\n handler: ChompApiService['verifyDelegation'];\n};\n\n/**\n * Submits intents via POST /v1/intent.\n */\nexport type ChompApiServiceCreateIntentsAction = {\n type: `ChompApiService:createIntents`;\n handler: ChompApiService['createIntents'];\n};\n\n/**\n * Fetches intents by address via GET /v1/intent/account/:address.\n */\nexport type ChompApiServiceGetIntentsByAddressAction = {\n type: `ChompApiService:getIntentsByAddress`;\n handler: ChompApiService['getIntentsByAddress'];\n};\n\n/**\n * Submits a withdrawal request via POST /v1/withdrawal\n */\nexport type ChompApiServiceCreateWithdrawalAction = {\n type: `ChompApiService:createWithdrawal`;\n handler: ChompApiService['createWithdrawal'];\n};\n\n/**\n * Retrieves service details via GET /v1/chomp.\n */\nexport type ChompApiServiceGetServiceDetailsAction = {\n type: `ChompApiService:getServiceDetails`;\n handler: ChompApiService['getServiceDetails'];\n};\n\n/**\n * Union of all ChompApiService action types.\n */\nexport type ChompApiServiceMethodActions =\n | ChompApiServiceAssociateAddressAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetUpgradeAction\n | ChompApiServiceVerifyDelegationAction\n | ChompApiServiceCreateIntentsAction\n | ChompApiServiceGetIntentsByAddressAction\n | ChompApiServiceCreateWithdrawalAction\n | ChompApiServiceGetServiceDetailsAction;\n"]}
|
|
@@ -39,40 +39,39 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
39
39
|
'getServiceDetails',
|
|
40
40
|
];
|
|
41
41
|
// === RESPONSE VALIDATION ===
|
|
42
|
-
const HexStringStruct = (0, superstruct_1.define)('Hex string', (value) => (0, utils_1.isStrictHexString)(value));
|
|
43
42
|
const AssociateAddressResponseStruct = (0, superstruct_1.type)({
|
|
44
43
|
profileId: (0, superstruct_1.string)(),
|
|
45
|
-
address:
|
|
44
|
+
address: utils_1.StrictHexStruct,
|
|
46
45
|
status: (0, superstruct_1.string)(),
|
|
47
46
|
});
|
|
48
47
|
const UpgradeResponseStruct = (0, superstruct_1.type)({
|
|
49
|
-
signerAddress:
|
|
48
|
+
signerAddress: utils_1.StrictHexStruct,
|
|
50
49
|
status: (0, superstruct_1.string)(),
|
|
51
50
|
createdAt: (0, superstruct_1.string)(),
|
|
52
51
|
});
|
|
53
52
|
const VerifyDelegationResponseStruct = (0, superstruct_1.type)({
|
|
54
53
|
valid: (0, superstruct_1.boolean)(),
|
|
55
|
-
delegationHash: (0, superstruct_1.optional)(
|
|
54
|
+
delegationHash: (0, superstruct_1.optional)(utils_1.StrictHexStruct),
|
|
56
55
|
errors: (0, superstruct_1.optional)((0, superstruct_1.array)((0, superstruct_1.string)())),
|
|
57
56
|
});
|
|
58
57
|
const SendIntentResponseArrayStruct = (0, superstruct_1.array)((0, superstruct_1.type)({
|
|
59
|
-
delegationHash:
|
|
58
|
+
delegationHash: utils_1.StrictHexStruct,
|
|
60
59
|
metadata: (0, superstruct_1.type)({
|
|
61
|
-
allowance:
|
|
60
|
+
allowance: utils_1.StrictHexStruct,
|
|
62
61
|
tokenSymbol: (0, superstruct_1.string)(),
|
|
63
|
-
tokenAddress:
|
|
62
|
+
tokenAddress: utils_1.StrictHexStruct,
|
|
64
63
|
type: (0, superstruct_1.enums)(['cash-deposit', 'cash-withdrawal']),
|
|
65
64
|
}),
|
|
66
65
|
createdAt: (0, superstruct_1.string)(),
|
|
67
66
|
}));
|
|
68
67
|
const IntentEntryArrayStruct = (0, superstruct_1.array)((0, superstruct_1.type)({
|
|
69
|
-
account:
|
|
70
|
-
delegationHash:
|
|
71
|
-
chainId:
|
|
68
|
+
account: utils_1.StrictHexStruct,
|
|
69
|
+
delegationHash: utils_1.StrictHexStruct,
|
|
70
|
+
chainId: utils_1.StrictHexStruct,
|
|
72
71
|
status: (0, superstruct_1.enums)(['active', 'revoked']),
|
|
73
72
|
metadata: (0, superstruct_1.type)({
|
|
74
|
-
allowance:
|
|
75
|
-
tokenAddress:
|
|
73
|
+
allowance: utils_1.StrictHexStruct,
|
|
74
|
+
tokenAddress: utils_1.StrictHexStruct,
|
|
76
75
|
tokenSymbol: (0, superstruct_1.string)(),
|
|
77
76
|
type: (0, superstruct_1.enums)(['deposit', 'withdraw']),
|
|
78
77
|
}),
|
|
@@ -82,18 +81,18 @@ const CreateWithdrawalResponseStruct = (0, superstruct_1.type)({
|
|
|
82
81
|
});
|
|
83
82
|
const ServiceDetailsProtocolStruct = (0, superstruct_1.type)({
|
|
84
83
|
supportedTokens: (0, superstruct_1.array)((0, superstruct_1.type)({
|
|
85
|
-
tokenAddress:
|
|
84
|
+
tokenAddress: utils_1.StrictHexStruct,
|
|
86
85
|
tokenDecimals: (0, superstruct_1.number)(),
|
|
87
86
|
})),
|
|
88
|
-
adapterAddress:
|
|
87
|
+
adapterAddress: utils_1.StrictHexStruct,
|
|
89
88
|
intentTypes: (0, superstruct_1.array)((0, superstruct_1.enums)(['cash-deposit', 'cash-withdrawal'])),
|
|
90
89
|
});
|
|
91
90
|
const ServiceDetailsResponseStruct = (0, superstruct_1.type)({
|
|
92
91
|
auth: (0, superstruct_1.type)({
|
|
93
92
|
message: (0, superstruct_1.string)(),
|
|
94
93
|
}),
|
|
95
|
-
chains: (0, superstruct_1.record)(
|
|
96
|
-
autoDepositDelegate:
|
|
94
|
+
chains: (0, superstruct_1.record)(utils_1.StrictHexStruct, (0, superstruct_1.type)({
|
|
95
|
+
autoDepositDelegate: utils_1.StrictHexStruct,
|
|
97
96
|
protocol: (0, superstruct_1.record)((0, superstruct_1.string)(), ServiceDetailsProtocolStruct),
|
|
98
97
|
})),
|
|
99
98
|
});
|
|
@@ -132,20 +131,20 @@ class ChompApiService extends base_data_service_1.BaseDataService {
|
|
|
132
131
|
*
|
|
133
132
|
* POST /v1/auth/address
|
|
134
133
|
*
|
|
135
|
-
* @param
|
|
134
|
+
* @param params - The association params containing signature, timestamp,
|
|
136
135
|
* and address.
|
|
137
136
|
* @returns The profile association result. Returns on both 201 and 409.
|
|
138
137
|
*/
|
|
139
|
-
async associateAddress(
|
|
138
|
+
async associateAddress(params) {
|
|
140
139
|
const jsonResponse = await this.fetchQuery({
|
|
141
|
-
queryKey: [`${this.name}:associateAddress`,
|
|
140
|
+
queryKey: [`${this.name}:associateAddress`, params],
|
|
142
141
|
staleTime: 0,
|
|
143
142
|
queryFn: async () => {
|
|
144
143
|
const headers = await __classPrivateFieldGet(this, _ChompApiService_instances, "m", _ChompApiService_authHeaders).call(this);
|
|
145
144
|
const response = await fetch(new URL('/v1/auth/address', __classPrivateFieldGet(this, _ChompApiService_baseUrl, "f")), {
|
|
146
145
|
method: 'POST',
|
|
147
146
|
headers,
|
|
148
|
-
body: JSON.stringify(
|
|
147
|
+
body: JSON.stringify(params),
|
|
149
148
|
});
|
|
150
149
|
if (!response.ok && response.status !== 409) {
|
|
151
150
|
throw new controller_utils_1.HttpError(response.status, `POST /v1/auth/address failed with status '${response.status}'`);
|
|
@@ -160,20 +159,20 @@ class ChompApiService extends base_data_service_1.BaseDataService {
|
|
|
160
159
|
*
|
|
161
160
|
* POST /v1/account-upgrade
|
|
162
161
|
*
|
|
163
|
-
* @param
|
|
162
|
+
* @param params - The upgrade params containing signature components and
|
|
164
163
|
* chain details.
|
|
165
164
|
* @returns The upgrade result.
|
|
166
165
|
*/
|
|
167
|
-
async createUpgrade(
|
|
166
|
+
async createUpgrade(params) {
|
|
168
167
|
const jsonResponse = await this.fetchQuery({
|
|
169
|
-
queryKey: [`${this.name}:createUpgrade`,
|
|
168
|
+
queryKey: [`${this.name}:createUpgrade`, params],
|
|
170
169
|
staleTime: 0,
|
|
171
170
|
queryFn: async () => {
|
|
172
171
|
const headers = await __classPrivateFieldGet(this, _ChompApiService_instances, "m", _ChompApiService_authHeaders).call(this);
|
|
173
172
|
const response = await fetch(new URL('/v1/account-upgrade', __classPrivateFieldGet(this, _ChompApiService_baseUrl, "f")), {
|
|
174
173
|
method: 'POST',
|
|
175
174
|
headers,
|
|
176
|
-
body: JSON.stringify(
|
|
175
|
+
body: JSON.stringify(params),
|
|
177
176
|
});
|
|
178
177
|
if (!response.ok) {
|
|
179
178
|
throw new controller_utils_1.HttpError(response.status, `POST /v1/account-upgrade failed with status '${response.status}'`);
|
|
@@ -216,19 +215,19 @@ class ChompApiService extends base_data_service_1.BaseDataService {
|
|
|
216
215
|
*
|
|
217
216
|
* POST /v1/intent/verify-delegation
|
|
218
217
|
*
|
|
219
|
-
* @param
|
|
218
|
+
* @param params - The delegation verification params.
|
|
220
219
|
* @returns The verification result including validity and optional errors.
|
|
221
220
|
*/
|
|
222
|
-
async verifyDelegation(
|
|
221
|
+
async verifyDelegation(params) {
|
|
223
222
|
const jsonResponse = await this.fetchQuery({
|
|
224
|
-
queryKey: [`${this.name}:verifyDelegation`,
|
|
223
|
+
queryKey: [`${this.name}:verifyDelegation`, params],
|
|
225
224
|
staleTime: 0,
|
|
226
225
|
queryFn: async () => {
|
|
227
226
|
const headers = await __classPrivateFieldGet(this, _ChompApiService_instances, "m", _ChompApiService_authHeaders).call(this);
|
|
228
227
|
const response = await fetch(new URL('/v1/intent/verify-delegation', __classPrivateFieldGet(this, _ChompApiService_baseUrl, "f")), {
|
|
229
228
|
method: 'POST',
|
|
230
229
|
headers,
|
|
231
|
-
body: JSON.stringify(
|
|
230
|
+
body: JSON.stringify(params),
|
|
232
231
|
});
|
|
233
232
|
if (!response.ok) {
|
|
234
233
|
throw new controller_utils_1.HttpError(response.status, `POST /v1/intent/verify-delegation failed with status '${response.status}'`);
|
|
@@ -292,20 +291,20 @@ class ChompApiService extends base_data_service_1.BaseDataService {
|
|
|
292
291
|
*
|
|
293
292
|
* POST /v1/withdrawal
|
|
294
293
|
*
|
|
295
|
-
* @param
|
|
294
|
+
* @param params - The withdrawal params containing chainId, amount
|
|
296
295
|
* (decimal or hex string), and account address.
|
|
297
296
|
* @returns The withdrawal result.
|
|
298
297
|
*/
|
|
299
|
-
async createWithdrawal(
|
|
298
|
+
async createWithdrawal(params) {
|
|
300
299
|
const jsonResponse = await this.fetchQuery({
|
|
301
|
-
queryKey: [`${this.name}:createWithdrawal`,
|
|
300
|
+
queryKey: [`${this.name}:createWithdrawal`, params],
|
|
302
301
|
staleTime: 0,
|
|
303
302
|
queryFn: async () => {
|
|
304
303
|
const headers = await __classPrivateFieldGet(this, _ChompApiService_instances, "m", _ChompApiService_authHeaders).call(this);
|
|
305
304
|
const response = await fetch(new URL('/v1/withdrawal', __classPrivateFieldGet(this, _ChompApiService_baseUrl, "f")), {
|
|
306
305
|
method: 'POST',
|
|
307
306
|
headers,
|
|
308
|
-
body: JSON.stringify(
|
|
307
|
+
body: JSON.stringify(params),
|
|
309
308
|
});
|
|
310
309
|
if (!response.ok) {
|
|
311
310
|
throw new controller_utils_1.HttpError(response.status, `POST /v1/withdrawal failed with status '${response.status}'`);
|
|
@@ -326,11 +325,6 @@ class ChompApiService extends base_data_service_1.BaseDataService {
|
|
|
326
325
|
* @returns The service details for the requested chains.
|
|
327
326
|
*/
|
|
328
327
|
async getServiceDetails(chainIds) {
|
|
329
|
-
for (const chainId of chainIds) {
|
|
330
|
-
if (!(0, utils_1.isStrictHexString)(chainId)) {
|
|
331
|
-
throw new Error(`Invalid chainId: expected a 0x-prefixed hex string, got '${chainId}'`);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
328
|
const jsonResponse = await this.fetchQuery({
|
|
335
329
|
queryKey: [`${this.name}:getServiceDetails`, chainIds],
|
|
336
330
|
queryFn: async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service.cjs","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA8D;AAO9D,iEAAuD;AAEvD,uDAY+B;AAC/B,2CAAoD;AAmBpD,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,iBAAiB,CAAC;AAE7C,oBAAoB;AAEpB;;;GAGG;AACH,MAAM,yBAAyB,GAAG;IAChC,kBAAkB;IAClB,eAAe;IACf,YAAY;IACZ,kBAAkB;IAClB,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,mBAAmB;CACX,CAAC;AA0DX,8BAA8B;AAE9B,MAAM,eAAe,GAAG,IAAA,oBAAM,EAAS,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAC7D,IAAA,yBAAiB,EAAC,KAAK,CAAC,CACzB,CAAC;AAEF,MAAM,8BAA8B,GAAG,IAAA,kBAAI,EAAC;IAC1C,SAAS,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AAS,CAAC,IAAI,CACrC,yCAAyC,CAC1C,CAAC;IACF,OAAO;QACL,aAAa,EAAE,UAAU,KAAK,EAAE;QAChC,cAAc,EAAE,kBAAkB;KACnC,CAAC;AACJ,CAAC","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n array,\n boolean,\n create,\n define,\n enums,\n literal,\n number,\n optional,\n record,\n string,\n type,\n} from '@metamask/superstruct';\nimport { isStrictHexString } from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { ChompApiServiceMethodActions } from './chomp-api-service-method-action-types';\nimport type {\n AssociateAddressRequest,\n AssociateAddressResponse,\n CreateUpgradeRequest,\n UpgradeResponse,\n CreateWithdrawalRequest,\n CreateWithdrawalResponse,\n IntentEntry,\n SendIntentRequest,\n SendIntentResponse,\n ServiceDetailsResponse,\n VerifyDelegationRequest,\n VerifyDelegationResponse,\n} from './types';\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 'createUpgrade',\n 'getUpgrade',\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 HexStringStruct = define<string>('Hex string', (value) =>\n isStrictHexString(value),\n);\n\nconst AssociateAddressResponseStruct = type({\n profileId: string(),\n address: string(),\n status: string(),\n});\n\nconst UpgradeResponseStruct = type({\n signerAddress: string(),\n status: string(),\n createdAt: string(),\n});\n\nconst VerifyDelegationResponseStruct = type({\n valid: boolean(),\n delegationHash: optional(string()),\n errors: optional(array(string())),\n});\n\nconst SendIntentResponseArrayStruct = array(\n type({\n delegationHash: string(),\n metadata: type({\n allowance: HexStringStruct,\n tokenSymbol: string(),\n tokenAddress: HexStringStruct,\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n createdAt: string(),\n }),\n);\n\nconst IntentEntryArrayStruct = array(\n type({\n account: HexStringStruct,\n delegationHash: HexStringStruct,\n chainId: HexStringStruct,\n status: enums(['active', 'revoked']),\n metadata: type({\n allowance: HexStringStruct,\n tokenAddress: HexStringStruct,\n tokenSymbol: string(),\n type: enums(['deposit', 'withdraw']),\n }),\n }),\n);\n\nconst CreateWithdrawalResponseStruct = type({\n success: literal(true),\n});\n\nconst ServiceDetailsProtocolStruct = type({\n supportedTokens: array(\n type({\n tokenAddress: string(),\n tokenDecimals: number(),\n }),\n ),\n adapterAddress: string(),\n intentTypes: array(enums(['cash-deposit', 'cash-withdrawal'])),\n});\n\nconst ServiceDetailsResponseStruct = type({\n auth: type({\n message: string(),\n }),\n chains: record(\n string(),\n type({\n autoDepositDelegate: string(),\n protocol: record(string(), ServiceDetailsProtocolStruct),\n }),\n ),\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,\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 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 {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n };\n }\n\n /**\n * Associates an address with a CHOMP profile.\n *\n * POST /v1/auth/address\n *\n * @param request - The association request containing signature, timestamp,\n * and address.\n * @returns The profile association result. Returns on both 201 and 409.\n */\n async associateAddress(\n request: AssociateAddressRequest,\n ): Promise<AssociateAddressResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:associateAddress`, request],\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(request),\n },\n );\n\n if (!response.ok && response.status !== 409) {\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 * Creates an account upgrade request.\n *\n * POST /v1/account-upgrade\n *\n * @param request - The upgrade request containing signature components and\n * chain details.\n * @returns The upgrade result.\n */\n async createUpgrade(request: CreateUpgradeRequest): Promise<UpgradeResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createUpgrade`, request],\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(request),\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, UpgradeResponseStruct);\n }\n\n /**\n * Fetches the upgrade record for a given address.\n *\n * GET /v1/account-upgrade/:address\n *\n * @param address - The address to look up.\n * @returns The upgrade record, or null if not found.\n */\n async getUpgrade(address: string): Promise<UpgradeResponse | null> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getUpgrade`, 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.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get upgrade request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n if (jsonResponse === null) {\n return null;\n }\n\n return create(jsonResponse, UpgradeResponseStruct);\n }\n\n /**\n * Verifies a delegation signature.\n *\n * POST /v1/intent/verify-delegation\n *\n * @param request - The delegation verification request.\n * @returns The verification result including validity and optional errors.\n */\n async verifyDelegation(\n request: VerifyDelegationRequest,\n ): Promise<VerifyDelegationResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:verifyDelegation`, request],\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(request),\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: SendIntentRequest[],\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(\n jsonResponse,\n SendIntentResponseArrayStruct,\n ) as SendIntentResponse[];\n }\n\n /**\n * Fetches intents associated with a given address.\n *\n * GET /v1/intent/account/:address\n *\n * @param address - The address to look up intents for.\n * @returns The array of intents for the address.\n */\n async getIntentsByAddress(address: string): Promise<IntentEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getIntentsByAddress`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/intent/account/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get intents request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, IntentEntryArrayStruct) as IntentEntry[];\n }\n\n /**\n * Creates a withdrawal for card spend flows.\n *\n * POST /v1/withdrawal\n *\n * @param request - The withdrawal request containing chainId, amount\n * (decimal or hex string), and account address.\n * @returns The withdrawal result.\n */\n async createWithdrawal(\n request: CreateWithdrawalRequest,\n ): Promise<CreateWithdrawalResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createWithdrawal`, request],\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(request),\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: string[]): Promise<ServiceDetailsResponse> {\n for (const chainId of chainIds) {\n if (!isStrictHexString(chainId)) {\n throw new Error(\n `Invalid chainId: expected a 0x-prefixed hex string, got '${chainId}'`,\n );\n }\n }\n\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(\n jsonResponse,\n ServiceDetailsResponseStruct,\n ) as ServiceDetailsResponse;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chomp-api-service.cjs","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA8D;AAO9D,iEAAuD;AAEvD,uDAW+B;AAE/B,2CAAkD;AAmBlD,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,iBAAiB,CAAC;AAE7C,oBAAoB;AAEpB;;;GAGG;AACH,MAAM,yBAAyB,GAAG;IAChC,kBAAkB;IAClB,eAAe;IACf,YAAY;IACZ,kBAAkB;IAClB,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,mBAAmB;CACX,CAAC;AA0DX,8BAA8B;AAE9B,MAAM,8BAA8B,GAAG,IAAA,kBAAI,EAAC;IAC1C,SAAS,EAAE,IAAA,oBAAM,GAAE;IACnB,OAAO,EAAE,uBAAe;IACxB,MAAM,EAAE,IAAA,oBAAM,GAAE;CACjB,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,IAAA,kBAAI,EAAC;IACjC,aAAa,EAAE,uBAAe;IAC9B,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,SAAS,EAAE,IAAA,oBAAM,GAAE;CACpB,CAAC,CAAC;AAEH,MAAM,8BAA8B,GAAG,IAAA,kBAAI,EAAC;IAC1C,KAAK,EAAE,IAAA,qBAAO,GAAE;IAChB,cAAc,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;IACzC,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,IAAA,oB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AAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;gBAE/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,4BAAS,CACjB,QAAQ,CAAC,MAAM,EACf,qCAAqC,QAAQ,CAAC,MAAM,GAAG,CACxD,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,IAAA,oBAAM,EAAC,YAAY,EAAE,4BAA4B,CAAC,CAAC;IAC5D,CAAC;CACF;AA/VD,0CA+VC;;AArTC;;;;GAIG;AACH,KAAK;IACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACrC,yCAAyC,CAC1C,CAAC;IACF,OAAO;QACL,aAAa,EAAE,UAAU,KAAK,EAAE;QAChC,cAAc,EAAE,kBAAkB;KACnC,CAAC;AACJ,CAAC","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n array,\n boolean,\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 { StrictHexStruct } from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { ChompApiServiceMethodActions } from './chomp-api-service-method-action-types';\nimport type {\n AssociateAddressParams,\n AssociateAddressResponse,\n CreateUpgradeParams,\n UpgradeResponse,\n CreateWithdrawalParams,\n CreateWithdrawalResponse,\n IntentEntry,\n SendIntentParams,\n SendIntentResponse,\n ServiceDetailsResponse,\n VerifyDelegationParams,\n VerifyDelegationResponse,\n} from './types';\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 'createUpgrade',\n 'getUpgrade',\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: string(),\n address: StrictHexStruct,\n status: string(),\n});\n\nconst UpgradeResponseStruct = type({\n signerAddress: StrictHexStruct,\n status: string(),\n createdAt: string(),\n});\n\nconst VerifyDelegationResponseStruct = type({\n valid: boolean(),\n delegationHash: optional(StrictHexStruct),\n errors: optional(array(string())),\n});\n\nconst SendIntentResponseArrayStruct = array(\n type({\n delegationHash: StrictHexStruct,\n metadata: type({\n allowance: StrictHexStruct,\n tokenSymbol: string(),\n tokenAddress: StrictHexStruct,\n type: enums(['cash-deposit', 'cash-withdrawal']),\n }),\n createdAt: string(),\n }),\n);\n\nconst IntentEntryArrayStruct = array(\n type({\n account: StrictHexStruct,\n delegationHash: StrictHexStruct,\n chainId: StrictHexStruct,\n status: enums(['active', 'revoked']),\n metadata: type({\n allowance: StrictHexStruct,\n tokenAddress: StrictHexStruct,\n tokenSymbol: string(),\n type: enums(['deposit', 'withdraw']),\n }),\n }),\n);\n\nconst CreateWithdrawalResponseStruct = type({\n success: literal(true),\n});\n\nconst ServiceDetailsProtocolStruct = type({\n supportedTokens: array(\n type({\n tokenAddress: StrictHexStruct,\n tokenDecimals: number(),\n }),\n ),\n adapterAddress: StrictHexStruct,\n intentTypes: array(enums(['cash-deposit', 'cash-withdrawal'])),\n});\n\nconst ServiceDetailsResponseStruct = type({\n auth: type({\n message: string(),\n }),\n chains: record(\n StrictHexStruct,\n type({\n autoDepositDelegate: StrictHexStruct,\n protocol: record(string(), ServiceDetailsProtocolStruct),\n }),\n ),\n});\n\n// === 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,\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 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 {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n };\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. Returns on both 201 and 409.\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 && response.status !== 409) {\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 * 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(params: CreateUpgradeParams): Promise<UpgradeResponse> {\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, UpgradeResponseStruct);\n }\n\n /**\n * Fetches the upgrade record for a given address.\n *\n * GET /v1/account-upgrade/:address\n *\n * @param address - The address to look up.\n * @returns The upgrade record, or null if not found.\n */\n async getUpgrade(address: Hex): Promise<UpgradeResponse | null> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getUpgrade`, 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.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get upgrade request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n if (jsonResponse === null) {\n return null;\n }\n\n return create(jsonResponse, UpgradeResponseStruct);\n }\n\n /**\n * Verifies a delegation signature.\n *\n * POST /v1/intent/verify-delegation\n *\n * @param params - The delegation verification params.\n * @returns The verification result including validity and optional errors.\n */\n async verifyDelegation(\n params: VerifyDelegationParams,\n ): Promise<VerifyDelegationResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:verifyDelegation`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL('/v1/intent/verify-delegation', this.#baseUrl),\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent/verify-delegation failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, VerifyDelegationResponseStruct);\n }\n\n /**\n * Submits one or more intents to the CHOMP API.\n *\n * POST /v1/intent\n *\n * @param intents - The array of intents to submit.\n * @returns The array of intent responses.\n */\n async createIntents(\n intents: SendIntentParams[],\n ): Promise<SendIntentResponse[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createIntents`, intents],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/intent', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(intents),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/intent failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, SendIntentResponseArrayStruct);\n }\n\n /**\n * Fetches intents associated with a given address.\n *\n * GET /v1/intent/account/:address\n *\n * @param address - The address to look up intents for.\n * @returns The array of intents for the address.\n */\n async getIntentsByAddress(address: Hex): Promise<IntentEntry[]> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getIntentsByAddress`, address],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(\n new URL(`/v1/intent/account/${address}`, this.#baseUrl),\n { headers },\n );\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Get intents request failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, IntentEntryArrayStruct);\n }\n\n /**\n * Creates a withdrawal for card spend flows.\n *\n * POST /v1/withdrawal\n *\n * @param params - The withdrawal params containing chainId, amount\n * (decimal or hex string), and account address.\n * @returns The withdrawal result.\n */\n async createWithdrawal(\n params: CreateWithdrawalParams,\n ): Promise<CreateWithdrawalResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:createWithdrawal`, params],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const response = await fetch(new URL('/v1/withdrawal', this.#baseUrl), {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `POST /v1/withdrawal failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, CreateWithdrawalResponseStruct);\n }\n\n /**\n * Retrieves service details including delegation redeemer addresses and DeFi\n * contract details for signing delegations for auto-deposit functionality.\n *\n * GET /v1/chomp\n *\n * @param chainIds - Array of chain IDs (0x-prefixed hex strings) to retrieve\n * details for.\n * @returns The service details for the requested chains.\n */\n async getServiceDetails(chainIds: Hex[]): Promise<ServiceDetailsResponse> {\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:getServiceDetails`, chainIds],\n queryFn: async () => {\n const headers = await this.#authHeaders();\n const url = new URL('/v1/chomp', this.#baseUrl);\n url.searchParams.set('chainId', chainIds.join(','));\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `GET /v1/chomp failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n return create(jsonResponse, ServiceDetailsResponseStruct);\n }\n}\n"]}
|
|
@@ -2,9 +2,10 @@ 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
4
|
import type { Messenger } from "@metamask/messenger";
|
|
5
|
+
import type { Hex } from "@metamask/utils";
|
|
5
6
|
import type { QueryClientConfig } from "@tanstack/query-core";
|
|
6
7
|
import type { ChompApiServiceMethodActions } from "./chomp-api-service-method-action-types.cjs";
|
|
7
|
-
import type {
|
|
8
|
+
import type { AssociateAddressParams, AssociateAddressResponse, CreateUpgradeParams, UpgradeResponse, CreateWithdrawalParams, CreateWithdrawalResponse, IntentEntry, SendIntentParams, SendIntentResponse, ServiceDetailsResponse, VerifyDelegationParams, VerifyDelegationResponse } from "./types.cjs";
|
|
8
9
|
/**
|
|
9
10
|
* The name of the {@link ChompApiService}, used to namespace the service's
|
|
10
11
|
* actions and events.
|
|
@@ -75,21 +76,21 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
75
76
|
*
|
|
76
77
|
* POST /v1/auth/address
|
|
77
78
|
*
|
|
78
|
-
* @param
|
|
79
|
+
* @param params - The association params containing signature, timestamp,
|
|
79
80
|
* and address.
|
|
80
81
|
* @returns The profile association result. Returns on both 201 and 409.
|
|
81
82
|
*/
|
|
82
|
-
associateAddress(
|
|
83
|
+
associateAddress(params: AssociateAddressParams): Promise<AssociateAddressResponse>;
|
|
83
84
|
/**
|
|
84
85
|
* Creates an account upgrade request.
|
|
85
86
|
*
|
|
86
87
|
* POST /v1/account-upgrade
|
|
87
88
|
*
|
|
88
|
-
* @param
|
|
89
|
+
* @param params - The upgrade params containing signature components and
|
|
89
90
|
* chain details.
|
|
90
91
|
* @returns The upgrade result.
|
|
91
92
|
*/
|
|
92
|
-
createUpgrade(
|
|
93
|
+
createUpgrade(params: CreateUpgradeParams): Promise<UpgradeResponse>;
|
|
93
94
|
/**
|
|
94
95
|
* Fetches the upgrade record for a given address.
|
|
95
96
|
*
|
|
@@ -98,16 +99,16 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
98
99
|
* @param address - The address to look up.
|
|
99
100
|
* @returns The upgrade record, or null if not found.
|
|
100
101
|
*/
|
|
101
|
-
getUpgrade(address:
|
|
102
|
+
getUpgrade(address: Hex): Promise<UpgradeResponse | null>;
|
|
102
103
|
/**
|
|
103
104
|
* Verifies a delegation signature.
|
|
104
105
|
*
|
|
105
106
|
* POST /v1/intent/verify-delegation
|
|
106
107
|
*
|
|
107
|
-
* @param
|
|
108
|
+
* @param params - The delegation verification params.
|
|
108
109
|
* @returns The verification result including validity and optional errors.
|
|
109
110
|
*/
|
|
110
|
-
verifyDelegation(
|
|
111
|
+
verifyDelegation(params: VerifyDelegationParams): Promise<VerifyDelegationResponse>;
|
|
111
112
|
/**
|
|
112
113
|
* Submits one or more intents to the CHOMP API.
|
|
113
114
|
*
|
|
@@ -116,7 +117,7 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
116
117
|
* @param intents - The array of intents to submit.
|
|
117
118
|
* @returns The array of intent responses.
|
|
118
119
|
*/
|
|
119
|
-
createIntents(intents:
|
|
120
|
+
createIntents(intents: SendIntentParams[]): Promise<SendIntentResponse[]>;
|
|
120
121
|
/**
|
|
121
122
|
* Fetches intents associated with a given address.
|
|
122
123
|
*
|
|
@@ -125,17 +126,17 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
125
126
|
* @param address - The address to look up intents for.
|
|
126
127
|
* @returns The array of intents for the address.
|
|
127
128
|
*/
|
|
128
|
-
getIntentsByAddress(address:
|
|
129
|
+
getIntentsByAddress(address: Hex): Promise<IntentEntry[]>;
|
|
129
130
|
/**
|
|
130
131
|
* Creates a withdrawal for card spend flows.
|
|
131
132
|
*
|
|
132
133
|
* POST /v1/withdrawal
|
|
133
134
|
*
|
|
134
|
-
* @param
|
|
135
|
+
* @param params - The withdrawal params containing chainId, amount
|
|
135
136
|
* (decimal or hex string), and account address.
|
|
136
137
|
* @returns The withdrawal result.
|
|
137
138
|
*/
|
|
138
|
-
createWithdrawal(
|
|
139
|
+
createWithdrawal(params: CreateWithdrawalParams): Promise<CreateWithdrawalResponse>;
|
|
139
140
|
/**
|
|
140
141
|
* Retrieves service details including delegation redeemer addresses and DeFi
|
|
141
142
|
* contract details for signing delegations for auto-deposit functionality.
|
|
@@ -146,7 +147,7 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
146
147
|
* details for.
|
|
147
148
|
* @returns The service details for the requested chains.
|
|
148
149
|
*/
|
|
149
|
-
getServiceDetails(chainIds:
|
|
150
|
+
getServiceDetails(chainIds: Hex[]): Promise<ServiceDetailsResponse>;
|
|
150
151
|
}
|
|
151
152
|
export {};
|
|
152
153
|
//# sourceMappingURL=chomp-api-service.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service.d.cts","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;
|
|
1
|
+
{"version":3,"file":"chomp-api-service.d.cts","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAarD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B;AAE9D,OAAO,KAAK,EAAE,4BAA4B,EAAE,oDAAgD;AAC5F,OAAO,KAAK,EACV,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,eAAe,EACf,sBAAsB,EACtB,wBAAwB,EACxB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACzB,oBAAgB;AAIjB;;;GAGG;AACH,eAAO,MAAM,WAAW,oBAAoB,CAAC;AAmB7C;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAChD,kCAAkC,CAAC,OAAO,WAAW,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAC9B,4BAA4B,GAC5B,sCAAsC,CAAC;AAE3C;;GAEG;AACH,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,CAAC,e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Aa,CACjB,OAAO,EAAE,gBAAgB,EAAE,GAC1B,OAAO,CAAC,kBAAkB,EAAE,CAAC;IA0BhC;;;;;;;OAOG;IACG,mBAAmB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAwB/D;;;;;;;;OAQG;IACG,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,wBAAwB,CAAC;IA0BpC;;;;;;;;;OASG;IACG,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC;CAsB1E"}
|
|
@@ -2,9 +2,10 @@ 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
4
|
import type { Messenger } from "@metamask/messenger";
|
|
5
|
+
import type { Hex } from "@metamask/utils";
|
|
5
6
|
import type { QueryClientConfig } from "@tanstack/query-core";
|
|
6
7
|
import type { ChompApiServiceMethodActions } from "./chomp-api-service-method-action-types.mjs";
|
|
7
|
-
import type {
|
|
8
|
+
import type { AssociateAddressParams, AssociateAddressResponse, CreateUpgradeParams, UpgradeResponse, CreateWithdrawalParams, CreateWithdrawalResponse, IntentEntry, SendIntentParams, SendIntentResponse, ServiceDetailsResponse, VerifyDelegationParams, VerifyDelegationResponse } from "./types.mjs";
|
|
8
9
|
/**
|
|
9
10
|
* The name of the {@link ChompApiService}, used to namespace the service's
|
|
10
11
|
* actions and events.
|
|
@@ -75,21 +76,21 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
75
76
|
*
|
|
76
77
|
* POST /v1/auth/address
|
|
77
78
|
*
|
|
78
|
-
* @param
|
|
79
|
+
* @param params - The association params containing signature, timestamp,
|
|
79
80
|
* and address.
|
|
80
81
|
* @returns The profile association result. Returns on both 201 and 409.
|
|
81
82
|
*/
|
|
82
|
-
associateAddress(
|
|
83
|
+
associateAddress(params: AssociateAddressParams): Promise<AssociateAddressResponse>;
|
|
83
84
|
/**
|
|
84
85
|
* Creates an account upgrade request.
|
|
85
86
|
*
|
|
86
87
|
* POST /v1/account-upgrade
|
|
87
88
|
*
|
|
88
|
-
* @param
|
|
89
|
+
* @param params - The upgrade params containing signature components and
|
|
89
90
|
* chain details.
|
|
90
91
|
* @returns The upgrade result.
|
|
91
92
|
*/
|
|
92
|
-
createUpgrade(
|
|
93
|
+
createUpgrade(params: CreateUpgradeParams): Promise<UpgradeResponse>;
|
|
93
94
|
/**
|
|
94
95
|
* Fetches the upgrade record for a given address.
|
|
95
96
|
*
|
|
@@ -98,16 +99,16 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
98
99
|
* @param address - The address to look up.
|
|
99
100
|
* @returns The upgrade record, or null if not found.
|
|
100
101
|
*/
|
|
101
|
-
getUpgrade(address:
|
|
102
|
+
getUpgrade(address: Hex): Promise<UpgradeResponse | null>;
|
|
102
103
|
/**
|
|
103
104
|
* Verifies a delegation signature.
|
|
104
105
|
*
|
|
105
106
|
* POST /v1/intent/verify-delegation
|
|
106
107
|
*
|
|
107
|
-
* @param
|
|
108
|
+
* @param params - The delegation verification params.
|
|
108
109
|
* @returns The verification result including validity and optional errors.
|
|
109
110
|
*/
|
|
110
|
-
verifyDelegation(
|
|
111
|
+
verifyDelegation(params: VerifyDelegationParams): Promise<VerifyDelegationResponse>;
|
|
111
112
|
/**
|
|
112
113
|
* Submits one or more intents to the CHOMP API.
|
|
113
114
|
*
|
|
@@ -116,7 +117,7 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
116
117
|
* @param intents - The array of intents to submit.
|
|
117
118
|
* @returns The array of intent responses.
|
|
118
119
|
*/
|
|
119
|
-
createIntents(intents:
|
|
120
|
+
createIntents(intents: SendIntentParams[]): Promise<SendIntentResponse[]>;
|
|
120
121
|
/**
|
|
121
122
|
* Fetches intents associated with a given address.
|
|
122
123
|
*
|
|
@@ -125,17 +126,17 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
125
126
|
* @param address - The address to look up intents for.
|
|
126
127
|
* @returns The array of intents for the address.
|
|
127
128
|
*/
|
|
128
|
-
getIntentsByAddress(address:
|
|
129
|
+
getIntentsByAddress(address: Hex): Promise<IntentEntry[]>;
|
|
129
130
|
/**
|
|
130
131
|
* Creates a withdrawal for card spend flows.
|
|
131
132
|
*
|
|
132
133
|
* POST /v1/withdrawal
|
|
133
134
|
*
|
|
134
|
-
* @param
|
|
135
|
+
* @param params - The withdrawal params containing chainId, amount
|
|
135
136
|
* (decimal or hex string), and account address.
|
|
136
137
|
* @returns The withdrawal result.
|
|
137
138
|
*/
|
|
138
|
-
createWithdrawal(
|
|
139
|
+
createWithdrawal(params: CreateWithdrawalParams): Promise<CreateWithdrawalResponse>;
|
|
139
140
|
/**
|
|
140
141
|
* Retrieves service details including delegation redeemer addresses and DeFi
|
|
141
142
|
* contract details for signing delegations for auto-deposit functionality.
|
|
@@ -146,7 +147,7 @@ export declare class ChompApiService extends BaseDataService<typeof serviceName,
|
|
|
146
147
|
* details for.
|
|
147
148
|
* @returns The service details for the requested chains.
|
|
148
149
|
*/
|
|
149
|
-
getServiceDetails(chainIds:
|
|
150
|
+
getServiceDetails(chainIds: Hex[]): Promise<ServiceDetailsResponse>;
|
|
150
151
|
}
|
|
151
152
|
export {};
|
|
152
153
|
//# sourceMappingURL=chomp-api-service.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chomp-api-service.d.mts","sourceRoot":"","sources":["../src/chomp-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;A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