@metamask-previews/subscription-controller 10.0.1-preview-c4f7eb130 → 10.0.1-preview-d518059
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 +0 -10
- package/dist/SubscriptionController.d.ts.map +1 -1
- package/dist/SubscriptionController.js +3 -9
- package/dist/SubscriptionController.js.map +1 -1
- package/dist/constants.d.ts +1 -8
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +0 -7
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.d.ts +1 -23
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.d.ts.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.js.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService.d.ts +3 -29
- package/dist/subscription-delegation/SubscriptionDelegationService.d.ts.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService.js +3 -294
- package/dist/subscription-delegation/SubscriptionDelegationService.js.map +1 -1
- package/dist/subscription-delegation/caveats.d.ts +0 -1
- package/dist/subscription-delegation/caveats.d.ts.map +1 -1
- package/dist/subscription-delegation/caveats.js.map +1 -1
- package/dist/subscription-delegation/fingerprint.d.ts.map +1 -1
- package/dist/subscription-delegation/fingerprint.js.map +1 -1
- package/dist/subscription-delegation/types.d.ts +2 -99
- package/dist/subscription-delegation/types.d.ts.map +1 -1
- package/dist/subscription-delegation/types.js +0 -2
- package/dist/subscription-delegation/types.js.map +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -3
- package/dist/subscription-delegation/typed-data.d.ts +0 -23
- package/dist/subscription-delegation/typed-data.d.ts.map +0 -1
- package/dist/subscription-delegation/typed-data.js +0 -75
- package/dist/subscription-delegation/typed-data.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmCA,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,MAAM,6BAA6B,CAAC;AA0ErC,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,GAAG,EACH,kCAAkC,EAClC,+BAA+B,EAC/B,yCAAyC,GAC1C,MAAM,gBAAgB,CAAC;AAUxB,OAAO,EACL,mBAAmB,EACnB,WAAW,IAAI,uBAAuB,EACtC,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAyBlC,OAAO,EACL,6BAA6B,EAC7B,WAAW,IAAI,iCAAiC,GACjD,MAAM,4DAA4D,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmCA,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,MAAM,6BAA6B,CAAC;AA0ErC,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,GAAG,EACH,kCAAkC,EAClC,+BAA+B,EAC/B,yCAAyC,GAC1C,MAAM,gBAAgB,CAAC;AAUxB,OAAO,EACL,mBAAmB,EACnB,WAAW,IAAI,uBAAuB,EACtC,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAyBlC,OAAO,EACL,6BAA6B,EAC7B,WAAW,IAAI,iCAAiC,GACjD,MAAM,4DAA4D,CAAC;AASpE,OAAO,EAAE,iCAAiC,EAAE,MAAM,oCAAoC,CAAC","sourcesContent":["export type {\n SubscriptionControllerActions,\n SubscriptionControllerState,\n SubscriptionControllerEvents,\n SubscriptionControllerGetStateAction,\n SubscriptionControllerMessenger,\n SubscriptionControllerOptions,\n SubscriptionControllerStateChangeEvent,\n} from './SubscriptionController.js';\nexport type {\n SubscriptionControllerGetPricingAction,\n SubscriptionControllerGetSubscriptionsAction,\n SubscriptionControllerGetBenefitsAction,\n SubscriptionControllerGetSubscriptionByProductAction,\n SubscriptionControllerGetSubscriptionsEligibilitiesAction,\n SubscriptionControllerCancelSubscriptionAction,\n SubscriptionControllerUnCancelSubscriptionAction,\n SubscriptionControllerStartSubscriptionWithCardAction,\n SubscriptionControllerStartSubscriptionWithCryptoAction,\n SubscriptionControllerSubmitSubscriptionCryptoApprovalAction,\n SubscriptionControllerGetCryptoApproveTransactionParamsAction,\n SubscriptionControllerUpdatePaymentMethodAction,\n SubscriptionControllerGetBillingPortalUrlAction,\n SubscriptionControllerCacheLastSelectedPaymentMethodAction,\n SubscriptionControllerClearLastSelectedPaymentMethodAction,\n SubscriptionControllerSubmitSponsorshipIntentsAction,\n SubscriptionControllerSubmitUserEventAction,\n SubscriptionControllerAssignUserToCohortAction,\n SubscriptionControllerLinkRewardsAction,\n SubscriptionControllerGetTokenApproveAmountAction,\n SubscriptionControllerGetTokenMinimumBalanceAmountAction,\n SubscriptionControllerClearStateAction,\n SubscriptionControllerTriggerAccessTokenRefreshAction,\n SubscriptionControllerStopAllPollingAction,\n} from './SubscriptionController-method-action-types.js';\nexport {\n SubscriptionController,\n getDefaultSubscriptionControllerState,\n} from './SubscriptionController.js';\nexport type {\n SubscriptionApiError,\n Subscription,\n PerpsBenefitUsage,\n PredictBenefitUsage,\n SubscriptionBenefitsResponse,\n SubscriptionBenefitsState,\n SwapsBenefitUsage,\n AuthUtils,\n CancelSubscriptionRequest,\n CancelType,\n CancellationReasonCode,\n ISubscriptionService,\n StartCryptoSubscriptionRequest,\n StartDelegationCryptoSubscriptionRequest,\n StartErc20CryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n GetCryptoApproveTransactionRequest,\n GetCryptoApproveTransactionResponse,\n SubmitSubscriptionCryptoApprovalRequest,\n SubscriptionCardPaymentMethod,\n SubscriptionCryptoPaymentMethod,\n SubscriptionPaymentMethod,\n SubscriptionInvoice,\n InvoicePaymentStatus,\n SubmitUserEventRequest,\n SubmitSponsorshipIntentsRequest,\n SubscriptionEligibility,\n SubscriptionUserEventType,\n RecurringInterval,\n SubscriptionStatus,\n PaymentType,\n Product,\n ProductType,\n ProductPrice,\n ProductPricing,\n TokenPaymentInfo,\n SpotTokenPaymentInfo,\n VaultTokenPaymentInfo,\n VaultName,\n ChainPaymentInfo,\n Currency,\n CryptoAuthMethod,\n PricingPaymentMethod,\n PricingCardPaymentMethod,\n PricingCryptoPaymentMethod,\n PricingResponse,\n UpdatePaymentMethodOpts,\n BillingPortalResponse,\n CryptoPaymentMethodError,\n CryptoPaymentError,\n UpdateErc20PaymentMethodCryptoRequest,\n UpdateDelegationPaymentMethodCryptoRequest,\n UpdatePaymentMethodCryptoRequest,\n UpdatePaymentMethodCardRequest,\n UpdatePaymentMethodCardResponse,\n CachedLastSelectedPaymentMethod,\n CacheLastSelectedPaymentMethodRequest,\n SubmitSponsorshipIntentsMethodParams,\n Cohort,\n CohortName,\n BalanceCategory,\n AssignCohortRequest,\n GetSubscriptionsEligibilitiesRequest,\n ModalType,\n MoneyAccountEntitlements,\n MoneyAccountPlusClaim,\n ProductEntitlementFeatureMap,\n ProductEntitlements,\n ShieldEntitlements,\n} from './types.js';\nexport {\n CANCEL_TYPES,\n CRYPTO_PAYMENT_METHOD_ERRORS,\n CRYPTO_PAYMENT_ERRORS,\n INVOICE_PAYMENT_STATUSES,\n SUBSCRIPTION_STATUSES,\n PRODUCT_TYPES,\n RECURRING_INTERVALS,\n PAYMENT_TYPES,\n CRYPTO_AUTH_METHODS,\n VAULT_NAMES,\n isVaultShareToken,\n SubscriptionUserEvent,\n COHORT_NAMES,\n BALANCE_CATEGORIES,\n MODAL_TYPE,\n MoneyAccountFeature,\n ShieldFeature,\n} from './types.js';\nexport { CANCELLATION_REASONS } from './constants.js';\nexport {\n selectHasEntitlement,\n selectIsActiveSubscriber,\n selectIsUsageAvailable,\n selectIsPaymentFailed,\n selectPaymentFailureReason,\n selectIsRenewalNeeded,\n selectIsDelegationExhausted,\n} from './selectors.js';\nexport { SubscriptionServiceError } from './errors.js';\nexport {\n Env,\n SubscriptionControllerErrorMessage,\n SubscriptionServiceErrorMessage,\n SubscriptionDelegationServiceErrorMessage,\n} from './constants.js';\nexport type {\n SubscriptionServiceOptions,\n SubscriptionServiceMessenger,\n SubscriptionServiceActions,\n SubscriptionServiceEvents,\n SubscriptionServiceCacheUpdatedEvent,\n SubscriptionServiceGranularCacheUpdatedEvent,\n SubscriptionServiceInvalidateQueriesAction,\n} from './SubscriptionService.js';\nexport {\n SubscriptionService,\n serviceName as subscriptionServiceName,\n SUBSCRIPTION_URL,\n} from './SubscriptionService.js';\nexport type {\n SubscriptionServiceGetSubscriptionsAction,\n SubscriptionServiceGetBenefitsAction,\n SubscriptionServiceCancelSubscriptionAction,\n SubscriptionServiceUnCancelSubscriptionAction,\n SubscriptionServiceStartSubscriptionWithCardAction,\n SubscriptionServiceStartSubscriptionWithCryptoAction,\n SubscriptionServiceUpdatePaymentMethodCardAction,\n SubscriptionServiceUpdatePaymentMethodCryptoAction,\n SubscriptionServiceGetSubscriptionsEligibilitiesAction,\n SubscriptionServiceSubmitUserEventAction,\n SubscriptionServiceAssignUserToCohortAction,\n SubscriptionServiceSubmitSponsorshipIntentsAction,\n SubscriptionServiceLinkRewardsAction,\n SubscriptionServiceGetPricingAction,\n SubscriptionServiceGetBillingPortalUrlAction,\n} from './SubscriptionService-method-action-types.js';\n\nexport type {\n SubscriptionDelegationServiceActions,\n SubscriptionDelegationServiceEvents,\n SubscriptionDelegationServiceMessenger,\n SubscriptionDelegationServiceOptions,\n} from './subscription-delegation/SubscriptionDelegationService.js';\nexport {\n SubscriptionDelegationService,\n serviceName as subscriptionDelegationServiceName,\n} from './subscription-delegation/SubscriptionDelegationService.js';\nexport type { SubscriptionDelegationServicePrepareDelegationAction } from './subscription-delegation/SubscriptionDelegationService-method-action-types.js';\nexport type { SubscriptionDelegationServiceCheckMoneyAccountBalanceAction } from './subscription-delegation/SubscriptionDelegationService-method-action-types.js';\nexport type {\n MoneyAccountBalanceCheckRequest,\n MoneyAccountBalanceCheckResult,\n PrepareSubscriptionDelegationRequest,\n PreparedSubscriptionDelegation,\n} from './subscription-delegation/types.js';\nexport { CASH_SUBSCRIPTION_DELEGATION_TYPE } from './subscription-delegation/types.js';\n"]}
|
|
@@ -14,28 +14,6 @@ export type SubscriptionDelegationServiceCheckMoneyAccountBalanceAction = {
|
|
|
14
14
|
type: `SubscriptionDelegationService:checkMoneyAccountBalance`;
|
|
15
15
|
handler: SubscriptionDelegationService['checkMoneyAccountBalance'];
|
|
16
16
|
};
|
|
17
|
-
/**
|
|
18
|
-
* Runs the complete Money Account subscription checkout authorization flow.
|
|
19
|
-
*
|
|
20
|
-
* Before the approval, `MoneyAccountUpgradeController` is asked to ensure
|
|
21
|
-
* the Money Account vault delegations and CHOMP intents exist; the
|
|
22
|
-
* Subscription API validates them server-side. The custom approval is the
|
|
23
|
-
* sole consent and funding boundary for the payment permission. No payment
|
|
24
|
-
* delegation signing, persistence, or intent mutation occurs before it
|
|
25
|
-
* returns a funding transaction hash.
|
|
26
|
-
*
|
|
27
|
-
* When `request.skipApproval` is `true`, the approval request and its
|
|
28
|
-
* result validation are skipped and the flow proceeds directly to signing.
|
|
29
|
-
* The caller is then responsible for consent and funding.
|
|
30
|
-
*
|
|
31
|
-
* @param request - Product selection, Money Account identity, and optional
|
|
32
|
-
* `skipApproval` flag.
|
|
33
|
-
* @returns The result from `SubscriptionController:startSubscriptionWithCrypto`.
|
|
34
|
-
*/
|
|
35
|
-
export type SubscriptionDelegationServiceStartSubscriptionWithDelegationAction = {
|
|
36
|
-
type: `SubscriptionDelegationService:startSubscriptionWithDelegation`;
|
|
37
|
-
handler: SubscriptionDelegationService['startSubscriptionWithDelegation'];
|
|
38
|
-
};
|
|
39
17
|
/**
|
|
40
18
|
* Prepares a cash-subscription delegation and returns its hash.
|
|
41
19
|
*
|
|
@@ -67,5 +45,5 @@ export type SubscriptionDelegationServicePrepareDelegationAction = {
|
|
|
67
45
|
/**
|
|
68
46
|
* Union of all SubscriptionDelegationService action types.
|
|
69
47
|
*/
|
|
70
|
-
export type SubscriptionDelegationServiceMethodActions = SubscriptionDelegationServiceCheckMoneyAccountBalanceAction |
|
|
48
|
+
export type SubscriptionDelegationServiceMethodActions = SubscriptionDelegationServiceCheckMoneyAccountBalanceAction | SubscriptionDelegationServicePrepareDelegationAction;
|
|
71
49
|
//# sourceMappingURL=SubscriptionDelegationService-method-action-types.d.ts.map
|
package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionDelegationService-method-action-types.d.ts","sourceRoot":"","sources":["../../src/subscription-delegation/SubscriptionDelegationService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAExF;;;;;;GAMG;AACH,MAAM,MAAM,2DAA2D,GAAG;IACxE,IAAI,EAAE,wDAAwD,CAAC;IAC/D,OAAO,EAAE,6BAA6B,CAAC,0BAA0B,CAAC,CAAC;CACpE,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"SubscriptionDelegationService-method-action-types.d.ts","sourceRoot":"","sources":["../../src/subscription-delegation/SubscriptionDelegationService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAExF;;;;;;GAMG;AACH,MAAM,MAAM,2DAA2D,GAAG;IACxE,IAAI,EAAE,wDAAwD,CAAC;IAC/D,OAAO,EAAE,6BAA6B,CAAC,0BAA0B,CAAC,CAAC;CACpE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,6BAA6B,CAAC,mBAAmB,CAAC,CAAC;CAC7D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0CAA0C,GAClD,2DAA2D,GAC3D,oDAAoD,CAAC"}
|
package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionDelegationService-method-action-types.js","sourceRoot":"","sources":["../../src/subscription-delegation/SubscriptionDelegationService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SubscriptionDelegationService } from './SubscriptionDelegationService.js';\n\n/**\n * Checks whether the Money Account holds enough convertible mUSD value to\n * cover pricing `unitAmount × minBillingCyclesForBalance`.\n *\n * @param request - Payer address and pricing amount fields.\n * @returns Balance comparison in mUSD base units (6 decimals).\n */\nexport type SubscriptionDelegationServiceCheckMoneyAccountBalanceAction = {\n type: `SubscriptionDelegationService:checkMoneyAccountBalance`;\n handler: SubscriptionDelegationService['checkMoneyAccountBalance'];\n};\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"SubscriptionDelegationService-method-action-types.js","sourceRoot":"","sources":["../../src/subscription-delegation/SubscriptionDelegationService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SubscriptionDelegationService } from './SubscriptionDelegationService.js';\n\n/**\n * Checks whether the Money Account holds enough convertible mUSD value to\n * cover pricing `unitAmount × minBillingCyclesForBalance`.\n *\n * @param request - Payer address and pricing amount fields.\n * @returns Balance comparison in mUSD base units (6 decimals).\n */\nexport type SubscriptionDelegationServiceCheckMoneyAccountBalanceAction = {\n type: `SubscriptionDelegationService:checkMoneyAccountBalance`;\n handler: SubscriptionDelegationService['checkMoneyAccountBalance'];\n};\n\n/**\n * Prepares a cash-subscription delegation and returns its hash.\n *\n * Reuses a stored AUS delegation that matches the semantic fingerprint when\n * one exists (ensuring a CHOMP intent is active for its hash, unless\n * `skipChompInteractions` is true). Reuse classifies period `startDate` as\n * trial-deferred (`> now`) vs immediately redeemable, matching creation.\n * When several records match, the latest period `startDate` is reused\n * so a `forceNew` replacement is preferred over an older equivalent\n * permission.\n * If there is no match, builds, signs, optionally verifies with CHOMP,\n * persists, and optionally registers a new delegation.\n *\n * When `skipChompInteractions` is true (required for alpha), CHOMP verify\n * and intent calls are skipped; the returned hash is computed locally. The\n * default CHOMP-enabled path requires a follow-up chomp-api-service release\n * that accepts `'cash-subscription'` intent metadata.\n *\n * @param request - Authoritative pricing and payer details for the delegation.\n * @param forceNew - Whether to create a replacement instead of reusing a\n * matching stored delegation.\n * @returns The delegation hash (CHOMP-verified unless skipped) and whether it\n * was created or reused.\n */\nexport type SubscriptionDelegationServicePrepareDelegationAction = {\n type: `SubscriptionDelegationService:prepareDelegation`;\n handler: SubscriptionDelegationService['prepareDelegation'];\n};\n\n/**\n * Union of all SubscriptionDelegationService action types.\n */\nexport type SubscriptionDelegationServiceMethodActions =\n | SubscriptionDelegationServiceCheckMoneyAccountBalanceAction\n | SubscriptionDelegationServicePrepareDelegationAction;\n"]}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import type { ApprovalControllerAddRequestAction } from '@metamask/approval-controller';
|
|
2
1
|
import type { AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceListDelegationsAction } from '@metamask/authenticated-user-storage';
|
|
3
2
|
import type { ChompApiServiceCreateIntentsAction, ChompApiServiceGetIntentsByAddressAction, ChompApiServiceVerifyDelegationAction } from '@metamask/chomp-api-service';
|
|
4
3
|
import type { DelegationControllerSignDelegationAction } from '@metamask/delegation-controller';
|
|
5
4
|
import type { Messenger } from '@metamask/messenger';
|
|
6
5
|
import type { MoneyAccountBalanceServiceFetchBalanceWithFallbackAction } from '@metamask/money-account-balance-service';
|
|
7
|
-
import type { MoneyAccountUpgradeControllerForceUpgradeAccountAction } from '@metamask/money-account-upgrade-controller';
|
|
8
6
|
import type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';
|
|
9
|
-
import type { SubscriptionControllerGetPricingAction
|
|
10
|
-
import type { SubscriptionControllerGetStateAction } from '../SubscriptionController.js';
|
|
7
|
+
import type { SubscriptionControllerGetPricingAction } from '../SubscriptionController-method-action-types.js';
|
|
11
8
|
import type { SubscriptionDelegationServiceMethodActions } from './SubscriptionDelegationService-method-action-types.js';
|
|
12
|
-
import type { MoneyAccountBalanceCheckRequest, MoneyAccountBalanceCheckResult, PrepareSubscriptionDelegationRequest, PreparedSubscriptionDelegation
|
|
9
|
+
import type { MoneyAccountBalanceCheckRequest, MoneyAccountBalanceCheckResult, PrepareSubscriptionDelegationRequest, PreparedSubscriptionDelegation } from './types.js';
|
|
13
10
|
/**
|
|
14
11
|
* The name of the {@link SubscriptionDelegationService}, used to namespace the
|
|
15
12
|
* service's actions and events.
|
|
@@ -22,7 +19,7 @@ export type SubscriptionDelegationServiceActions = SubscriptionDelegationService
|
|
|
22
19
|
/**
|
|
23
20
|
* Actions from other messengers that {@link SubscriptionDelegationServiceMessenger} calls.
|
|
24
21
|
*/
|
|
25
|
-
type AllowedActions = AuthenticatedUserStorageServiceListDelegationsAction | AuthenticatedUserStorageServiceCreateDelegationAction | ChompApiServiceVerifyDelegationAction | ChompApiServiceCreateIntentsAction | ChompApiServiceGetIntentsByAddressAction | DelegationControllerSignDelegationAction |
|
|
22
|
+
type AllowedActions = AuthenticatedUserStorageServiceListDelegationsAction | AuthenticatedUserStorageServiceCreateDelegationAction | ChompApiServiceVerifyDelegationAction | ChompApiServiceCreateIntentsAction | ChompApiServiceGetIntentsByAddressAction | DelegationControllerSignDelegationAction | MoneyAccountBalanceServiceFetchBalanceWithFallbackAction | RemoteFeatureFlagControllerGetStateAction | SubscriptionControllerGetPricingAction;
|
|
26
23
|
/**
|
|
27
24
|
* Events that {@link SubscriptionDelegationService} exposes to other consumers.
|
|
28
25
|
*/
|
|
@@ -70,29 +67,6 @@ export declare class SubscriptionDelegationService {
|
|
|
70
67
|
* @returns Balance comparison in mUSD base units (6 decimals).
|
|
71
68
|
*/
|
|
72
69
|
checkMoneyAccountBalance(request: MoneyAccountBalanceCheckRequest): Promise<MoneyAccountBalanceCheckResult>;
|
|
73
|
-
/**
|
|
74
|
-
* Runs the complete Money Account subscription checkout authorization flow.
|
|
75
|
-
*
|
|
76
|
-
* Subscriptions are refreshed first. An active subscription for the product
|
|
77
|
-
* is rejected before Money Account upgrade, approval, delegation signing,
|
|
78
|
-
* persistence, or CHOMP registration.
|
|
79
|
-
*
|
|
80
|
-
* Before the approval, `MoneyAccountUpgradeController` is asked to ensure
|
|
81
|
-
* the Money Account vault delegations and CHOMP intents exist; the
|
|
82
|
-
* Subscription API validates them server-side. The custom approval is the
|
|
83
|
-
* sole consent and funding boundary for the payment permission. No payment
|
|
84
|
-
* delegation signing, persistence, or intent mutation occurs before it
|
|
85
|
-
* returns a funding transaction hash.
|
|
86
|
-
*
|
|
87
|
-
* When `request.skipApproval` is `true`, the approval request and its
|
|
88
|
-
* result validation are skipped and the flow proceeds directly to signing.
|
|
89
|
-
* The caller is then responsible for consent and funding.
|
|
90
|
-
*
|
|
91
|
-
* @param request - Product selection, Money Account identity, and optional
|
|
92
|
-
* `skipApproval` flag.
|
|
93
|
-
* @returns The result from `SubscriptionController:startSubscriptionWithCrypto`.
|
|
94
|
-
*/
|
|
95
|
-
startSubscriptionWithDelegation(request: StartSubscriptionWithDelegationRequest): Promise<StartSubscriptionWithDelegationResult>;
|
|
96
70
|
/**
|
|
97
71
|
* Prepares a cash-subscription delegation and returns its hash.
|
|
98
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionDelegationService.d.ts","sourceRoot":"","sources":["../../src/subscription-delegation/SubscriptionDelegationService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,
|
|
1
|
+
{"version":3,"file":"SubscriptionDelegationService.d.ts","sourceRoot":"","sources":["../../src/subscription-delegation/SubscriptionDelegationService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,qDAAqD,EACrD,oDAAoD,EACrD,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EACV,kCAAkC,EAClC,wCAAwC,EACxC,qCAAqC,EACtC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,wCAAwC,EAAE,MAAM,iCAAiC,CAAC;AAGhG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,wDAAwD,EAAE,MAAM,yCAAyC,CAAC;AAKxH,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,0CAA0C,CAAC;AAK1G,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,kDAAkD,CAAC;AAqB/G,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,wDAAwD,CAAC;AACzH,OAAO,KAAK,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,oCAAoC,EACpC,8BAA8B,EAE/B,MAAM,YAAY,CAAC;AAGpB;;;GAGG;AACH,eAAO,MAAM,WAAW,kCAAkC,CAAC;AA4B3D;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAC9C,0CAA0C,CAAC;AAE7C;;GAEG;AACH,KAAK,cAAc,GACf,oDAAoD,GACpD,qDAAqD,GACrD,qCAAqC,GACrC,kCAAkC,GAClC,wCAAwC,GACxC,wCAAwC,GACxC,wDAAwD,GACxD,yCAAyC,GACzC,sCAAsC,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAAG,KAAK,CAAC;AAExD,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,sCAAsC,GAAG,SAAS,CAC5D,OAAO,WAAW,EAClB,oCAAoC,GAAG,cAAc,EACrD,mCAAmC,GAAG,aAAa,CACpD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,SAAS,EAAE,sCAAsC,CAAC;CACnD,CAAC;AAoBF;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,6BAA6B;;IACxC,QAAQ,CAAC,IAAI,EAAE,OAAO,WAAW,CAAe;IAIhD,YAAY,OAAO,EAAE,oCAAoC,EAOxD;IAED;;;;;;OAMG;IACG,wBAAwB,CAC5B,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,8BAA8B,CAAC,CAMzC;IA+BD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,iBAAiB,CACrB,OAAO,EAAE,oCAAoC,EAC7C,QAAQ,UAAQ,GACf,OAAO,CAAC,8BAA8B,CAAC,CAoKzC;CAsJF"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { ORIGIN_METAMASK } from '@metamask/controller-utils';
|
|
2
1
|
import { hashDelegation } from '@metamask/delegation-core';
|
|
3
2
|
import { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';
|
|
4
3
|
import { getMoneyAccountVaultConfig, MUSD_DECIMALS, } from '@metamask/money-account-utils';
|
|
5
|
-
import { add0x, hexToNumber
|
|
6
|
-
import {
|
|
4
|
+
import { add0x, hexToNumber } from '@metamask/utils';
|
|
5
|
+
import { SubscriptionDelegationServiceErrorMessage } from '../constants.js';
|
|
7
6
|
import { CRYPTO_AUTH_METHODS, PAYMENT_TYPES, PRODUCT_TYPES } from '../types.js';
|
|
8
7
|
import { assertPositiveInteger, calculatePeriodAmount, getDelegationStartDate, getPeriodDuration, } from './amount.js';
|
|
9
8
|
import { buildUnsignedSubscriptionDelegation } from './caveats.js';
|
|
10
9
|
import { equalsIgnoreCase, makeMatchesSubscriptionDelegation, pickLatestMatchingSubscriptionDelegation, } from './fingerprint.js';
|
|
11
|
-
import {
|
|
12
|
-
import { CASH_SUBSCRIPTION_DELEGATION_TYPE, SUBSCRIPTION_DELEGATION_APPROVAL_TYPE, SUBSCRIPTION_DELEGATION_POLICY_VERSION, } from './types.js';
|
|
10
|
+
import { CASH_SUBSCRIPTION_DELEGATION_TYPE } from './types.js';
|
|
13
11
|
/**
|
|
14
12
|
* The name of the {@link SubscriptionDelegationService}, used to namespace the
|
|
15
13
|
* service's actions and events.
|
|
@@ -18,7 +16,6 @@ export const serviceName = 'SubscriptionDelegationService';
|
|
|
18
16
|
const MESSENGER_EXPOSED_METHODS = [
|
|
19
17
|
'prepareDelegation',
|
|
20
18
|
'checkMoneyAccountBalance',
|
|
21
|
-
'startSubscriptionWithDelegation',
|
|
22
19
|
];
|
|
23
20
|
const DELEGATION_FRAMEWORK_VERSION = '1.3.0';
|
|
24
21
|
function resolveEnforcers(chainId) {
|
|
@@ -32,10 +29,6 @@ function resolveEnforcers(chainId) {
|
|
|
32
29
|
allowedCalldata: contracts.AllowedCalldataEnforcer,
|
|
33
30
|
};
|
|
34
31
|
}
|
|
35
|
-
function removeDelegationSignature(delegation) {
|
|
36
|
-
const { signature: _signature, ...unsignedDelegation } = delegation;
|
|
37
|
-
return unsignedDelegation;
|
|
38
|
-
}
|
|
39
32
|
/**
|
|
40
33
|
* Stateless orchestrator for cash-subscription delegation setup.
|
|
41
34
|
*
|
|
@@ -88,287 +81,6 @@ export class SubscriptionDelegationService {
|
|
|
88
81
|
requiredBalance: requiredBalance.toString(),
|
|
89
82
|
};
|
|
90
83
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Runs the complete Money Account subscription checkout authorization flow.
|
|
93
|
-
*
|
|
94
|
-
* Subscriptions are refreshed first. An active subscription for the product
|
|
95
|
-
* is rejected before Money Account upgrade, approval, delegation signing,
|
|
96
|
-
* persistence, or CHOMP registration.
|
|
97
|
-
*
|
|
98
|
-
* Before the approval, `MoneyAccountUpgradeController` is asked to ensure
|
|
99
|
-
* the Money Account vault delegations and CHOMP intents exist; the
|
|
100
|
-
* Subscription API validates them server-side. The custom approval is the
|
|
101
|
-
* sole consent and funding boundary for the payment permission. No payment
|
|
102
|
-
* delegation signing, persistence, or intent mutation occurs before it
|
|
103
|
-
* returns a funding transaction hash.
|
|
104
|
-
*
|
|
105
|
-
* When `request.skipApproval` is `true`, the approval request and its
|
|
106
|
-
* result validation are skipped and the flow proceeds directly to signing.
|
|
107
|
-
* The caller is then responsible for consent and funding.
|
|
108
|
-
*
|
|
109
|
-
* @param request - Product selection, Money Account identity, and optional
|
|
110
|
-
* `skipApproval` flag.
|
|
111
|
-
* @returns The result from `SubscriptionController:startSubscriptionWithCrypto`.
|
|
112
|
-
*/
|
|
113
|
-
async startSubscriptionWithDelegation(request) {
|
|
114
|
-
if (request.product !== PRODUCT_TYPES.MONEY_ACCOUNT_PLUS) {
|
|
115
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.UnsupportedProduct);
|
|
116
|
-
}
|
|
117
|
-
const config = await this.#resolveConfiguration(request.product, request.recurringInterval);
|
|
118
|
-
if (!equalsIgnoreCase(request.chainId, config.chainId)) {
|
|
119
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.ChainMismatch);
|
|
120
|
-
}
|
|
121
|
-
if (!config.musdAddress) {
|
|
122
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.MissingMusdTokenAddress);
|
|
123
|
-
}
|
|
124
|
-
const subscriptions = await this.#messenger.call('SubscriptionController:getSubscriptions');
|
|
125
|
-
this.#assertUserNotSubscribed(subscriptions, request.product);
|
|
126
|
-
const { trialedProducts } = this.#messenger.call('SubscriptionController:getState');
|
|
127
|
-
const isTrialRequested = config.price.trialPeriodDays > 0 &&
|
|
128
|
-
!trialedProducts.includes(request.product);
|
|
129
|
-
await this.#messenger.call('MoneyAccountUpgradeController:forceUpgradeAccount', request.payerAddress);
|
|
130
|
-
const paymentPermission = await this.#preparePaymentPermission(request, config, isTrialRequested);
|
|
131
|
-
const bundle = {
|
|
132
|
-
policyVersion: SUBSCRIPTION_DELEGATION_POLICY_VERSION,
|
|
133
|
-
account: request.payerAddress,
|
|
134
|
-
chainId: request.chainId,
|
|
135
|
-
permissions: [paymentPermission],
|
|
136
|
-
};
|
|
137
|
-
const approval = request.skipApproval
|
|
138
|
-
? undefined
|
|
139
|
-
: await this.#requestApproval({
|
|
140
|
-
request,
|
|
141
|
-
price: config.price,
|
|
142
|
-
musdAddress: config.musdAddress,
|
|
143
|
-
bundle,
|
|
144
|
-
});
|
|
145
|
-
try {
|
|
146
|
-
if (approval) {
|
|
147
|
-
this.#validateApprovalResult(approval);
|
|
148
|
-
}
|
|
149
|
-
const paymentDelegation = await this.#signPaymentPermissionIfRequired(paymentPermission, config);
|
|
150
|
-
const paymentDelegationHash = await this.#commitPaymentPermission({
|
|
151
|
-
request,
|
|
152
|
-
paymentPermission,
|
|
153
|
-
paymentDelegation,
|
|
154
|
-
config,
|
|
155
|
-
});
|
|
156
|
-
const result = await this.#messenger.call('SubscriptionController:startSubscriptionWithCrypto', {
|
|
157
|
-
products: [request.product],
|
|
158
|
-
isTrialRequested,
|
|
159
|
-
recurringInterval: request.recurringInterval,
|
|
160
|
-
billingCycles: config.price.minBillingCycles,
|
|
161
|
-
chainId: request.chainId,
|
|
162
|
-
payerAddress: request.payerAddress,
|
|
163
|
-
tokenSymbol: config.token.symbol,
|
|
164
|
-
cryptoAuthMethod: CRYPTO_AUTH_METHODS.DELEGATION,
|
|
165
|
-
delegationHash: paymentDelegationHash,
|
|
166
|
-
// Reject if eligibility changed during approval, because the signed
|
|
167
|
-
// delegation start date was derived from the original trial state.
|
|
168
|
-
// This local guard is removed before the backend request.
|
|
169
|
-
assertTrialEligibility: true,
|
|
170
|
-
});
|
|
171
|
-
approval?.resultCallbacks?.success();
|
|
172
|
-
return result;
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
approval?.resultCallbacks?.error(error);
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Rejects when the refreshed list already contains an active subscription
|
|
181
|
-
* for the product. Active includes `active`, `trialing`, and `provisional`.
|
|
182
|
-
*
|
|
183
|
-
* @param subscriptions - Subscriptions returned by the latest refresh.
|
|
184
|
-
* @param product - Product the caller is trying to start.
|
|
185
|
-
*/
|
|
186
|
-
#assertUserNotSubscribed(subscriptions, product) {
|
|
187
|
-
const alreadySubscribed = subscriptions.some((subscription) => ACTIVE_SUBSCRIPTION_STATUSES.includes(subscription.status) &&
|
|
188
|
-
subscription.products.some((entry) => entry.name === product));
|
|
189
|
-
if (alreadySubscribed) {
|
|
190
|
-
throw new Error(SubscriptionControllerErrorMessage.UserAlreadySubscribed);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
async #requestApproval({ request, price, musdAddress, bundle, }) {
|
|
194
|
-
const targetAmount = calculatePeriodAmount({
|
|
195
|
-
unitAmount: price.unitAmount,
|
|
196
|
-
unitDecimals: price.unitDecimals,
|
|
197
|
-
tokenDecimals: MUSD_DECIMALS,
|
|
198
|
-
}) * BigInt(price.minBillingCyclesForBalance);
|
|
199
|
-
return (await this.#messenger.call('ApprovalController:addRequest', {
|
|
200
|
-
origin: ORIGIN_METAMASK,
|
|
201
|
-
type: SUBSCRIPTION_DELEGATION_APPROVAL_TYPE,
|
|
202
|
-
expectsResult: true,
|
|
203
|
-
requestData: {
|
|
204
|
-
bundle,
|
|
205
|
-
funding: {
|
|
206
|
-
useCase: 'subscription',
|
|
207
|
-
destinationAccount: request.payerAddress,
|
|
208
|
-
chainId: request.chainId,
|
|
209
|
-
targetToken: {
|
|
210
|
-
symbol: 'mUSD',
|
|
211
|
-
address: musdAddress,
|
|
212
|
-
},
|
|
213
|
-
targetAmount: targetAmount.toString(),
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
}, true));
|
|
217
|
-
}
|
|
218
|
-
async #preparePaymentPermission(request, config, isTrialRequested) {
|
|
219
|
-
const periodAmount = calculatePeriodAmount({
|
|
220
|
-
unitAmount: config.price.unitAmount,
|
|
221
|
-
unitDecimals: config.price.unitDecimals,
|
|
222
|
-
tokenDecimals: config.token.decimals,
|
|
223
|
-
});
|
|
224
|
-
const periodDuration = getPeriodDuration(request.recurringInterval);
|
|
225
|
-
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
226
|
-
const startDate = getDelegationStartDate({
|
|
227
|
-
nowSeconds,
|
|
228
|
-
trialPeriodDays: isTrialRequested
|
|
229
|
-
? config.price.trialPeriodDays
|
|
230
|
-
: undefined,
|
|
231
|
-
});
|
|
232
|
-
const matches = makeMatchesSubscriptionDelegation({
|
|
233
|
-
delegatorAddress: request.payerAddress,
|
|
234
|
-
delegateAddress: config.delegateAddress,
|
|
235
|
-
chainId: request.chainId,
|
|
236
|
-
recipientAddress: config.paymentAddress,
|
|
237
|
-
tokenAddress: config.token.address,
|
|
238
|
-
periodAmount,
|
|
239
|
-
periodDuration,
|
|
240
|
-
nowSeconds,
|
|
241
|
-
isTrialDeferred: startDate > nowSeconds,
|
|
242
|
-
enforcers: config.enforcers,
|
|
243
|
-
});
|
|
244
|
-
const reusable = pickLatestMatchingSubscriptionDelegation((await this.#messenger.call('AuthenticatedUserStorageService:listDelegations')).filter(matches), config.enforcers);
|
|
245
|
-
const delegation = reusable
|
|
246
|
-
? removeDelegationSignature(reusable.signedDelegation)
|
|
247
|
-
: buildUnsignedSubscriptionDelegation({
|
|
248
|
-
delegateAddress: config.delegateAddress,
|
|
249
|
-
delegatorAddress: request.payerAddress,
|
|
250
|
-
enforcers: config.enforcers,
|
|
251
|
-
recipientAddress: config.paymentAddress,
|
|
252
|
-
tokenAddress: config.token.address,
|
|
253
|
-
periodAmount,
|
|
254
|
-
periodDuration,
|
|
255
|
-
startDate,
|
|
256
|
-
});
|
|
257
|
-
const typedData = buildDelegationTypedData({
|
|
258
|
-
delegation,
|
|
259
|
-
chainId: request.chainId,
|
|
260
|
-
delegationManager: config.delegationManager,
|
|
261
|
-
});
|
|
262
|
-
return {
|
|
263
|
-
id: CASH_SUBSCRIPTION_DELEGATION_TYPE,
|
|
264
|
-
owner: 'subscription',
|
|
265
|
-
disposition: reusable ? 'reused' : 'new',
|
|
266
|
-
delegation,
|
|
267
|
-
typedData,
|
|
268
|
-
decodedAuthority: decodeSubscriptionAuthority(delegation, config.enforcers),
|
|
269
|
-
...(reusable
|
|
270
|
-
? { existingDelegationHash: reusable.metadata.delegationHash }
|
|
271
|
-
: {}),
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
#validateApprovalResult(approval) {
|
|
275
|
-
if (!approval?.value || typeof approval.value !== 'object') {
|
|
276
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.ApprovalResultMissing);
|
|
277
|
-
}
|
|
278
|
-
const value = approval.value;
|
|
279
|
-
if (typeof value.fundingTransactionHash !== 'string' ||
|
|
280
|
-
!isStrictHexString(value.fundingTransactionHash) ||
|
|
281
|
-
value.fundingTransactionHash.length !== 66) {
|
|
282
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.InvalidFundingTransactionHash);
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
fundingTransactionHash: value.fundingTransactionHash,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
async #signPaymentPermissionIfRequired(permission, config) {
|
|
289
|
-
if (permission.disposition === 'reused') {
|
|
290
|
-
return undefined;
|
|
291
|
-
}
|
|
292
|
-
const signature = (await this.#messenger.call('DelegationController:signDelegation', {
|
|
293
|
-
delegation: permission.delegation,
|
|
294
|
-
chainId: config.chainId,
|
|
295
|
-
}));
|
|
296
|
-
return { ...permission.delegation, signature };
|
|
297
|
-
}
|
|
298
|
-
async #commitPaymentPermission({ request, paymentPermission, paymentDelegation, config, }) {
|
|
299
|
-
if (paymentPermission.disposition === 'reused') {
|
|
300
|
-
const delegationHash = paymentPermission.existingDelegationHash;
|
|
301
|
-
const storedDelegation = (await this.#messenger.call('AuthenticatedUserStorageService:listDelegations')).find(({ metadata }) => equalsIgnoreCase(metadata.delegationHash, delegationHash));
|
|
302
|
-
if (!storedDelegation) {
|
|
303
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.ReusableDelegationInvalid);
|
|
304
|
-
}
|
|
305
|
-
await this.#verifySignedPaymentDelegation(storedDelegation.signedDelegation, delegationHash, request.chainId);
|
|
306
|
-
await this.#ensureIntent({
|
|
307
|
-
account: request.payerAddress,
|
|
308
|
-
chainId: request.chainId,
|
|
309
|
-
delegationHash,
|
|
310
|
-
allowance: add0x(BigInt(paymentPermission.decodedAuthority.periodAmount).toString(16)),
|
|
311
|
-
tokenSymbol: config.token.symbol,
|
|
312
|
-
tokenAddress: config.token.address,
|
|
313
|
-
});
|
|
314
|
-
await this.#assertIntentActive(request.payerAddress, delegationHash);
|
|
315
|
-
return delegationHash;
|
|
316
|
-
}
|
|
317
|
-
const signedDelegation = paymentDelegation;
|
|
318
|
-
const delegationHash = hashDelegation({
|
|
319
|
-
...signedDelegation,
|
|
320
|
-
salt: BigInt(signedDelegation.salt),
|
|
321
|
-
});
|
|
322
|
-
await this.#verifySignedPaymentDelegation(signedDelegation, delegationHash, request.chainId);
|
|
323
|
-
const allowance = add0x(BigInt(paymentPermission.decodedAuthority.periodAmount).toString(16));
|
|
324
|
-
await this.#messenger.call('AuthenticatedUserStorageService:createDelegation', {
|
|
325
|
-
signedDelegation,
|
|
326
|
-
metadata: {
|
|
327
|
-
delegationHash,
|
|
328
|
-
chainIdHex: request.chainId,
|
|
329
|
-
allowance,
|
|
330
|
-
tokenSymbol: config.token.symbol,
|
|
331
|
-
tokenAddress: config.token.address,
|
|
332
|
-
type: CASH_SUBSCRIPTION_DELEGATION_TYPE,
|
|
333
|
-
},
|
|
334
|
-
});
|
|
335
|
-
await this.#createIntent({
|
|
336
|
-
account: request.payerAddress,
|
|
337
|
-
chainId: request.chainId,
|
|
338
|
-
delegationHash,
|
|
339
|
-
allowance,
|
|
340
|
-
tokenSymbol: config.token.symbol,
|
|
341
|
-
tokenAddress: config.token.address,
|
|
342
|
-
});
|
|
343
|
-
await this.#assertIntentActive(request.payerAddress, delegationHash);
|
|
344
|
-
return delegationHash;
|
|
345
|
-
}
|
|
346
|
-
async #assertIntentActive(account, delegationHash) {
|
|
347
|
-
const intents = await this.#messenger.call('ChompApiService:getIntentsByAddress', account);
|
|
348
|
-
const intent = intents.find((candidate) => equalsIgnoreCase(candidate.delegationHash, delegationHash));
|
|
349
|
-
if (intent?.status !== 'active') {
|
|
350
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.ChompIntentNotActive);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
async #verifySignedPaymentDelegation(signedDelegation, expectedDelegationHash, chainId) {
|
|
354
|
-
const localHash = hashDelegation({
|
|
355
|
-
...signedDelegation,
|
|
356
|
-
salt: BigInt(signedDelegation.salt),
|
|
357
|
-
});
|
|
358
|
-
if (!equalsIgnoreCase(localHash, expectedDelegationHash)) {
|
|
359
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.ReusableDelegationInvalid);
|
|
360
|
-
}
|
|
361
|
-
const verifyResult = await this.#messenger.call('ChompApiService:verifyDelegation', { signedDelegation, chainId });
|
|
362
|
-
if (!verifyResult.valid) {
|
|
363
|
-
throw new Error(`${SubscriptionDelegationServiceErrorMessage.ChompRejectedDelegation}: ${verifyResult.errors?.join(', ') ?? 'unknown error'}`);
|
|
364
|
-
}
|
|
365
|
-
if (!verifyResult.delegationHash) {
|
|
366
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.ChompMissingDelegationHash);
|
|
367
|
-
}
|
|
368
|
-
if (!equalsIgnoreCase(verifyResult.delegationHash, expectedDelegationHash)) {
|
|
369
|
-
throw new Error(SubscriptionDelegationServiceErrorMessage.ChompDelegationHashMismatch);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
84
|
/**
|
|
373
85
|
* Prepares a cash-subscription delegation and returns its hash.
|
|
374
86
|
*
|
|
@@ -547,11 +259,8 @@ export class SubscriptionDelegationService {
|
|
|
547
259
|
return {
|
|
548
260
|
chainId,
|
|
549
261
|
delegateAddress: chain.delegateAddress,
|
|
550
|
-
delegationManager: DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION][hexToNumber(chainId)]
|
|
551
|
-
.DelegationManager,
|
|
552
262
|
paymentAddress: chain.paymentAddress,
|
|
553
263
|
enforcers,
|
|
554
|
-
musdAddress: vaultConfig.underlyingToken,
|
|
555
264
|
price,
|
|
556
265
|
token,
|
|
557
266
|
};
|