@metamask-previews/subscription-controller 9.0.1-preview-2b92c5a1c → 9.0.1-preview-e8a256c39
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 +18 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -0
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.d.ts +44 -0
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.d.ts.map +1 -0
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.js +6 -0
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.js.map +1 -0
- package/dist/subscription-delegation/SubscriptionDelegationService.d.ts +93 -0
- package/dist/subscription-delegation/SubscriptionDelegationService.d.ts.map +1 -0
- package/dist/subscription-delegation/SubscriptionDelegationService.js +290 -0
- package/dist/subscription-delegation/SubscriptionDelegationService.js.map +1 -0
- package/dist/subscription-delegation/amount.d.ts +49 -0
- package/dist/subscription-delegation/amount.d.ts.map +1 -0
- package/dist/subscription-delegation/amount.js +84 -0
- package/dist/subscription-delegation/amount.js.map +1 -0
- package/dist/subscription-delegation/caveats.d.ts +41 -0
- package/dist/subscription-delegation/caveats.d.ts.map +1 -0
- package/dist/subscription-delegation/caveats.js +59 -0
- package/dist/subscription-delegation/caveats.js.map +1 -0
- package/dist/subscription-delegation/fingerprint.d.ts +42 -0
- package/dist/subscription-delegation/fingerprint.d.ts.map +1 -0
- package/dist/subscription-delegation/fingerprint.js +80 -0
- package/dist/subscription-delegation/fingerprint.js.map +1 -0
- package/dist/subscription-delegation/types.d.ts +73 -0
- package/dist/subscription-delegation/types.d.ts.map +1 -0
- package/dist/subscription-delegation/types.js +10 -0
- package/dist/subscription-delegation/types.js.map +1 -0
- package/package.json +11 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { DelegationResponse } from '@metamask/authenticated-user-storage';
|
|
2
|
+
import type { Hex } from '@metamask/utils';
|
|
3
|
+
import type { SubscriptionDelegationEnforcers } from './types.js';
|
|
4
|
+
export type SubscriptionDelegationFingerprint = {
|
|
5
|
+
delegatorAddress: Hex;
|
|
6
|
+
delegateAddress: Hex;
|
|
7
|
+
chainId: Hex;
|
|
8
|
+
tokenAddress: Hex;
|
|
9
|
+
periodAmount: bigint;
|
|
10
|
+
periodDuration: number;
|
|
11
|
+
/**
|
|
12
|
+
* Current unix timestamp in seconds. Used to classify a stored period
|
|
13
|
+
* `startDate` as immediately redeemable (`<= now`) vs trial-deferred (`> now`).
|
|
14
|
+
*/
|
|
15
|
+
nowSeconds: number;
|
|
16
|
+
/**
|
|
17
|
+
* When true, only a still-deferred period start (`> nowSeconds`) matches.
|
|
18
|
+
* When false, only an immediately redeemable start (`<= nowSeconds`) matches.
|
|
19
|
+
*/
|
|
20
|
+
isTrialDeferred: boolean;
|
|
21
|
+
enforcers: SubscriptionDelegationEnforcers;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Case-insensitive hex equality.
|
|
25
|
+
*
|
|
26
|
+
* @param left - First hex value.
|
|
27
|
+
* @param right - Second hex value.
|
|
28
|
+
* @returns Whether the values are equal ignoring case.
|
|
29
|
+
*/
|
|
30
|
+
export declare function equalsIgnoreCase(left: string, right: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Builds a predicate that matches a stored AUS delegation to the semantic
|
|
33
|
+
* cash-subscription fingerprint. Salt is ignored so a previously signed
|
|
34
|
+
* equivalent permission can be reused. Period `startDate` is compared only
|
|
35
|
+
* as trial-deferred (`> nowSeconds`) vs immediately redeemable (`<= nowSeconds`)
|
|
36
|
+
* so a positive-length trial cannot reuse a live permission and vice versa.
|
|
37
|
+
*
|
|
38
|
+
* @param expected - Semantic fields that must match.
|
|
39
|
+
* @returns Predicate over {@link DelegationResponse}.
|
|
40
|
+
*/
|
|
41
|
+
export declare function makeMatchesSubscriptionDelegation(expected: SubscriptionDelegationFingerprint): (entry: DelegationResponse) => boolean;
|
|
42
|
+
//# sourceMappingURL=fingerprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../../src/subscription-delegation/fingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAK/E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,YAAY,CAAC;AAGlE,MAAM,MAAM,iCAAiC,GAAG;IAC9C,gBAAgB,EAAE,GAAG,CAAC;IACtB,eAAe,EAAE,GAAG,CAAC;IACrB,OAAO,EAAE,GAAG,CAAC;IACb,YAAY,EAAE,GAAG,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,+BAA+B,CAAC;CAC5C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAErE;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,iCAAiC,GAC1C,CAAC,KAAK,EAAE,kBAAkB,KAAK,OAAO,CAkFxC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { decodeERC20TokenPeriodTransferTerms, decodeValueLteTerms, } from '@metamask/delegation-core';
|
|
2
|
+
import { CASH_SUBSCRIPTION_DELEGATION_TYPE } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Case-insensitive hex equality.
|
|
5
|
+
*
|
|
6
|
+
* @param left - First hex value.
|
|
7
|
+
* @param right - Second hex value.
|
|
8
|
+
* @returns Whether the values are equal ignoring case.
|
|
9
|
+
*/
|
|
10
|
+
export function equalsIgnoreCase(left, right) {
|
|
11
|
+
return left.toLowerCase() === right.toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Builds a predicate that matches a stored AUS delegation to the semantic
|
|
15
|
+
* cash-subscription fingerprint. Salt is ignored so a previously signed
|
|
16
|
+
* equivalent permission can be reused. Period `startDate` is compared only
|
|
17
|
+
* as trial-deferred (`> nowSeconds`) vs immediately redeemable (`<= nowSeconds`)
|
|
18
|
+
* so a positive-length trial cannot reuse a live permission and vice versa.
|
|
19
|
+
*
|
|
20
|
+
* @param expected - Semantic fields that must match.
|
|
21
|
+
* @returns Predicate over {@link DelegationResponse}.
|
|
22
|
+
*/
|
|
23
|
+
export function makeMatchesSubscriptionDelegation(expected) {
|
|
24
|
+
// const expectedRedeemerTerms = createRedeemerTerms({
|
|
25
|
+
// redeemers: [expected.delegateAddress],
|
|
26
|
+
// });
|
|
27
|
+
return (entry) => {
|
|
28
|
+
if (entry.metadata.type !== CASH_SUBSCRIPTION_DELEGATION_TYPE) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (!equalsIgnoreCase(entry.signedDelegation.delegator, expected.delegatorAddress)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (!equalsIgnoreCase(entry.signedDelegation.delegate, expected.delegateAddress)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (!equalsIgnoreCase(entry.metadata.chainIdHex, expected.chainId)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (!equalsIgnoreCase(entry.metadata.tokenAddress, expected.tokenAddress)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const { caveats } = entry.signedDelegation;
|
|
44
|
+
if (caveats.length < 2) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const valueLteCaveat = caveats.find((caveat) => equalsIgnoreCase(caveat.enforcer, expected.enforcers.valueLte));
|
|
48
|
+
const periodCaveat = caveats.find((caveat) => equalsIgnoreCase(caveat.enforcer, expected.enforcers.erc20TokenPeriodTransfer));
|
|
49
|
+
// TODO: recheck with CHOMP team if we should set redeemer to subscirption payment address
|
|
50
|
+
// or use allowed call data
|
|
51
|
+
// const redeemerCaveat = caveats.find((caveat) =>
|
|
52
|
+
// equalsIgnoreCase(caveat.enforcer, expected.enforcers.redeemer),
|
|
53
|
+
// );
|
|
54
|
+
if (!valueLteCaveat || !periodCaveat) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// if (!equalsIgnoreCase(redeemerCaveat.terms, expectedRedeemerTerms)) {
|
|
58
|
+
// return false;
|
|
59
|
+
// }
|
|
60
|
+
try {
|
|
61
|
+
const valueTerms = decodeValueLteTerms(valueLteCaveat.terms);
|
|
62
|
+
if (valueTerms.maxValue !== 0n) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const periodTerms = decodeERC20TokenPeriodTransferTerms(periodCaveat.terms);
|
|
66
|
+
const storedStartDate = Number(periodTerms.startDate);
|
|
67
|
+
const isStoredDeferred = storedStartDate > expected.nowSeconds;
|
|
68
|
+
if (expected.isTrialDeferred !== isStoredDeferred) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return (equalsIgnoreCase(periodTerms.tokenAddress, expected.tokenAddress) &&
|
|
72
|
+
periodTerms.periodAmount === expected.periodAmount &&
|
|
73
|
+
Number(periodTerms.periodDuration) === expected.periodDuration);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=fingerprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["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AC,cAAc,CAC/D,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { DelegationResponse } from '@metamask/authenticated-user-storage';\nimport {\n decodeERC20TokenPeriodTransferTerms,\n decodeValueLteTerms,\n} from '@metamask/delegation-core';\nimport type { Hex } from '@metamask/utils';\n\nimport type { SubscriptionDelegationEnforcers } from './types.js';\nimport { CASH_SUBSCRIPTION_DELEGATION_TYPE } from './types.js';\n\nexport type SubscriptionDelegationFingerprint = {\n delegatorAddress: Hex;\n delegateAddress: Hex;\n chainId: Hex;\n tokenAddress: Hex;\n periodAmount: bigint;\n periodDuration: number;\n /**\n * Current unix timestamp in seconds. Used to classify a stored period\n * `startDate` as immediately redeemable (`<= now`) vs trial-deferred (`> now`).\n */\n nowSeconds: number;\n /**\n * When true, only a still-deferred period start (`> nowSeconds`) matches.\n * When false, only an immediately redeemable start (`<= nowSeconds`) matches.\n */\n isTrialDeferred: boolean;\n enforcers: SubscriptionDelegationEnforcers;\n};\n\n/**\n * Case-insensitive hex equality.\n *\n * @param left - First hex value.\n * @param right - Second hex value.\n * @returns Whether the values are equal ignoring case.\n */\nexport function equalsIgnoreCase(left: string, right: string): boolean {\n return left.toLowerCase() === right.toLowerCase();\n}\n\n/**\n * Builds a predicate that matches a stored AUS delegation to the semantic\n * cash-subscription fingerprint. Salt is ignored so a previously signed\n * equivalent permission can be reused. Period `startDate` is compared only\n * as trial-deferred (`> nowSeconds`) vs immediately redeemable (`<= nowSeconds`)\n * so a positive-length trial cannot reuse a live permission and vice versa.\n *\n * @param expected - Semantic fields that must match.\n * @returns Predicate over {@link DelegationResponse}.\n */\nexport function makeMatchesSubscriptionDelegation(\n expected: SubscriptionDelegationFingerprint,\n): (entry: DelegationResponse) => boolean {\n // const expectedRedeemerTerms = createRedeemerTerms({\n // redeemers: [expected.delegateAddress],\n // });\n\n return (entry) => {\n if (entry.metadata.type !== CASH_SUBSCRIPTION_DELEGATION_TYPE) {\n return false;\n }\n if (\n !equalsIgnoreCase(\n entry.signedDelegation.delegator,\n expected.delegatorAddress,\n )\n ) {\n return false;\n }\n if (\n !equalsIgnoreCase(\n entry.signedDelegation.delegate,\n expected.delegateAddress,\n )\n ) {\n return false;\n }\n if (!equalsIgnoreCase(entry.metadata.chainIdHex, expected.chainId)) {\n return false;\n }\n if (!equalsIgnoreCase(entry.metadata.tokenAddress, expected.tokenAddress)) {\n return false;\n }\n\n const { caveats } = entry.signedDelegation;\n if (caveats.length < 2) {\n return false;\n }\n\n const valueLteCaveat = caveats.find((caveat) =>\n equalsIgnoreCase(caveat.enforcer, expected.enforcers.valueLte),\n );\n const periodCaveat = caveats.find((caveat) =>\n equalsIgnoreCase(\n caveat.enforcer,\n expected.enforcers.erc20TokenPeriodTransfer,\n ),\n );\n // TODO: recheck with CHOMP team if we should set redeemer to subscirption payment address\n // or use allowed call data\n // const redeemerCaveat = caveats.find((caveat) =>\n // equalsIgnoreCase(caveat.enforcer, expected.enforcers.redeemer),\n // );\n if (!valueLteCaveat || !periodCaveat) {\n return false;\n }\n // if (!equalsIgnoreCase(redeemerCaveat.terms, expectedRedeemerTerms)) {\n // return false;\n // }\n\n try {\n const valueTerms = decodeValueLteTerms(valueLteCaveat.terms);\n if (valueTerms.maxValue !== 0n) {\n return false;\n }\n\n const periodTerms = decodeERC20TokenPeriodTransferTerms(\n periodCaveat.terms,\n );\n const storedStartDate = Number(periodTerms.startDate);\n const isStoredDeferred = storedStartDate > expected.nowSeconds;\n if (expected.isTrialDeferred !== isStoredDeferred) {\n return false;\n }\n\n return (\n equalsIgnoreCase(periodTerms.tokenAddress, expected.tokenAddress) &&\n periodTerms.periodAmount === expected.periodAmount &&\n Number(periodTerms.periodDuration) === expected.periodDuration\n );\n } catch {\n return false;\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Hex } from '@metamask/utils';
|
|
2
|
+
import { PRODUCT_TYPES } from '../types.js';
|
|
3
|
+
import type { RecurringInterval } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Storage / CHOMP metadata type for cash-subscription delegations.
|
|
6
|
+
*
|
|
7
|
+
* Defined locally so this package does not depend on an unreleased
|
|
8
|
+
* `@metamask/chomp-api-service` intent type. Production CHOMP intent
|
|
9
|
+
* registration still requires a follow-up chomp-api-service release that
|
|
10
|
+
* accepts `'cash-subscription'`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CASH_SUBSCRIPTION_DELEGATION_TYPE: 'cash-subscription';
|
|
13
|
+
/**
|
|
14
|
+
* Request to prepare a cash-subscription delegation.
|
|
15
|
+
*
|
|
16
|
+
* The service resolves all amount, token, delegate, and trial-duration fields
|
|
17
|
+
* from authoritative pricing held by `SubscriptionController`.
|
|
18
|
+
*
|
|
19
|
+
* Only Money Account Plus is supported; Shield continues to use ERC-20
|
|
20
|
+
* approval rather than delegation.
|
|
21
|
+
*/
|
|
22
|
+
export type PrepareSubscriptionDelegationRequest = {
|
|
23
|
+
product: typeof PRODUCT_TYPES.MONEY_ACCOUNT_PLUS;
|
|
24
|
+
recurringInterval: RecurringInterval;
|
|
25
|
+
payerAddress: Hex;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the user selected the pricing trial. Pricing `trialPeriodDays`
|
|
28
|
+
* only affects the delegation start date when this is true.
|
|
29
|
+
*/
|
|
30
|
+
isTrialRequested: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* When true, gates preparation on a sufficient Money Account balance
|
|
33
|
+
* (`unitAmount × minBillingCyclesForBalance` in mUSD) before side effects.
|
|
34
|
+
*/
|
|
35
|
+
checkBalance?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* When true, skips CHOMP verify/intent interactions. Required for alpha
|
|
38
|
+
* until `@metamask/chomp-api-service` accepts `'cash-subscription'` intent
|
|
39
|
+
* metadata. Defaults to false (production path; unsupported until that
|
|
40
|
+
* follow-up release).
|
|
41
|
+
*/
|
|
42
|
+
skipChompInteractions?: boolean;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Result of {@link SubscriptionDelegationService.prepareDelegation}.
|
|
46
|
+
*/
|
|
47
|
+
export type PreparedSubscriptionDelegation = {
|
|
48
|
+
delegationHash: Hex;
|
|
49
|
+
disposition: 'created' | 'reused';
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Request to check whether a Money Account holds enough convertible mUSD value
|
|
53
|
+
* to cover the subscription funding requirement.
|
|
54
|
+
*/
|
|
55
|
+
export type MoneyAccountBalanceCheckRequest = Pick<PrepareSubscriptionDelegationRequest, 'product' | 'recurringInterval' | 'payerAddress'>;
|
|
56
|
+
/**
|
|
57
|
+
* Result of {@link SubscriptionDelegationService.checkMoneyAccountBalance}.
|
|
58
|
+
* `balance` and `requiredBalance` are mUSD base units (6 decimals).
|
|
59
|
+
*/
|
|
60
|
+
export type MoneyAccountBalanceCheckResult = {
|
|
61
|
+
hasSufficientBalance: boolean;
|
|
62
|
+
balance: string;
|
|
63
|
+
requiredBalance: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Delegation Framework enforcers used by cash-subscription delegations.
|
|
67
|
+
*/
|
|
68
|
+
export type SubscriptionDelegationEnforcers = {
|
|
69
|
+
valueLte: Hex;
|
|
70
|
+
erc20TokenPeriodTransfer: Hex;
|
|
71
|
+
redeemer: Hex;
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/subscription-delegation/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,EAAG,mBAA4B,CAAC;AAE9E;;;;;;;;GAQG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,OAAO,EAAE,OAAO,aAAa,CAAC,kBAAkB,CAAC;IACjD,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,YAAY,EAAE,GAAG,CAAC;IAClB;;;OAGG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,cAAc,EAAE,GAAG,CAAC;IACpB,WAAW,EAAE,SAAS,GAAG,QAAQ,CAAC;CACnC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAChD,oCAAoC,EACpC,SAAS,GAAG,mBAAmB,GAAG,cAAc,CACjD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,oBAAoB,EAAE,OAAO,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,QAAQ,EAAE,GAAG,CAAC;IACd,wBAAwB,EAAE,GAAG,CAAC;IAC9B,QAAQ,EAAE,GAAG,CAAC;CACf,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage / CHOMP metadata type for cash-subscription delegations.
|
|
3
|
+
*
|
|
4
|
+
* Defined locally so this package does not depend on an unreleased
|
|
5
|
+
* `@metamask/chomp-api-service` intent type. Production CHOMP intent
|
|
6
|
+
* registration still requires a follow-up chomp-api-service release that
|
|
7
|
+
* accepts `'cash-subscription'`.
|
|
8
|
+
*/
|
|
9
|
+
export const CASH_SUBSCRIPTION_DELEGATION_TYPE = 'cash-subscription';
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/subscription-delegation/types.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,mBAA4B,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport { PRODUCT_TYPES } from '../types.js';\nimport type { RecurringInterval } from '../types.js';\n\n/**\n * Storage / CHOMP metadata type for cash-subscription delegations.\n *\n * Defined locally so this package does not depend on an unreleased\n * `@metamask/chomp-api-service` intent type. Production CHOMP intent\n * registration still requires a follow-up chomp-api-service release that\n * accepts `'cash-subscription'`.\n */\nexport const CASH_SUBSCRIPTION_DELEGATION_TYPE = 'cash-subscription' as const;\n\n/**\n * Request to prepare a cash-subscription delegation.\n *\n * The service resolves all amount, token, delegate, and trial-duration fields\n * from authoritative pricing held by `SubscriptionController`.\n *\n * Only Money Account Plus is supported; Shield continues to use ERC-20\n * approval rather than delegation.\n */\nexport type PrepareSubscriptionDelegationRequest = {\n product: typeof PRODUCT_TYPES.MONEY_ACCOUNT_PLUS;\n recurringInterval: RecurringInterval;\n payerAddress: Hex;\n /**\n * Whether the user selected the pricing trial. Pricing `trialPeriodDays`\n * only affects the delegation start date when this is true.\n */\n isTrialRequested: boolean;\n /**\n * When true, gates preparation on a sufficient Money Account balance\n * (`unitAmount × minBillingCyclesForBalance` in mUSD) before side effects.\n */\n checkBalance?: boolean;\n /**\n * When true, skips CHOMP verify/intent interactions. Required for alpha\n * until `@metamask/chomp-api-service` accepts `'cash-subscription'` intent\n * metadata. Defaults to false (production path; unsupported until that\n * follow-up release).\n */\n skipChompInteractions?: boolean;\n};\n\n/**\n * Result of {@link SubscriptionDelegationService.prepareDelegation}.\n */\nexport type PreparedSubscriptionDelegation = {\n delegationHash: Hex;\n disposition: 'created' | 'reused';\n};\n\n/**\n * Request to check whether a Money Account holds enough convertible mUSD value\n * to cover the subscription funding requirement.\n */\nexport type MoneyAccountBalanceCheckRequest = Pick<\n PrepareSubscriptionDelegationRequest,\n 'product' | 'recurringInterval' | 'payerAddress'\n>;\n\n/**\n * Result of {@link SubscriptionDelegationService.checkMoneyAccountBalance}.\n * `balance` and `requiredBalance` are mUSD base units (6 decimals).\n */\nexport type MoneyAccountBalanceCheckResult = {\n hasSufficientBalance: boolean;\n balance: string;\n requiredBalance: string;\n};\n\n/**\n * Delegation Framework enforcers used by cash-subscription delegations.\n */\nexport type SubscriptionDelegationEnforcers = {\n valueLte: Hex;\n erc20TokenPeriodTransfer: Hex;\n redeemer: Hex;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/subscription-controller",
|
|
3
|
-
"version": "9.0.1-preview-
|
|
3
|
+
"version": "9.0.1-preview-e8a256c39",
|
|
4
4
|
"description": "Handle user subscription",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -50,12 +50,20 @@
|
|
|
50
50
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
+
"@metamask/authenticated-user-storage": "^4.0.0",
|
|
53
54
|
"@metamask/base-controller": "^10.0.0",
|
|
54
55
|
"@metamask/base-data-service": "^2.0.0",
|
|
56
|
+
"@metamask/chomp-api-service": "^5.0.0",
|
|
55
57
|
"@metamask/controller-utils": "^13.0.0",
|
|
58
|
+
"@metamask/delegation-controller": "^4.0.0",
|
|
59
|
+
"@metamask/delegation-core": "^2.2.1",
|
|
60
|
+
"@metamask/delegation-deployments": "^1.4.0",
|
|
56
61
|
"@metamask/messenger": "^3.0.0",
|
|
62
|
+
"@metamask/money-account-balance-service": "^3.0.0",
|
|
63
|
+
"@metamask/money-account-utils": "^2.0.0",
|
|
57
64
|
"@metamask/polling-controller": "^17.0.0",
|
|
58
|
-
"@metamask/profile-sync-controller": "^32.
|
|
65
|
+
"@metamask/profile-sync-controller": "^32.1.0",
|
|
66
|
+
"@metamask/remote-feature-flag-controller": "^7.0.0",
|
|
59
67
|
"@metamask/superstruct": "^3.4.1",
|
|
60
68
|
"@metamask/transaction-controller": "^70.0.0",
|
|
61
69
|
"@metamask/utils": "^11.12.0",
|
|
@@ -69,6 +77,7 @@
|
|
|
69
77
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
70
78
|
"deepmerge": "^4.2.2",
|
|
71
79
|
"jest": "^30.4.2",
|
|
80
|
+
"jest-environment-node": "^30.4.1",
|
|
72
81
|
"rimraf": "^5.0.5",
|
|
73
82
|
"ts-jest": "^29.4.11",
|
|
74
83
|
"tsx": "^4.20.5",
|