@metamask/money-account-mfa-whitelist 0.2.0 → 0.3.0
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 +17 -1
- package/README.md +10 -8
- package/dist/delegation.d.ts.map +1 -1
- package/dist/delegation.js +5 -3
- package/dist/delegation.js.map +1 -1
- package/dist/personal-message.d.ts +3 -3
- package/dist/personal-message.d.ts.map +1 -1
- package/dist/personal-message.js +81 -11
- package/dist/personal-message.js.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Whitelist CHOMP's successor association message for `chompSignInDomain`, so migrating to the MPC Money Account no longer asks for MFA ([#11310](https://github.com/MetaMask/core/pull/11310))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Bump `@metamask/abi-utils` from `^2.0.4` to `^3.0.0` ([#11356](https://github.com/MetaMask/core/pull/11356))
|
|
19
|
+
- Bump `@metamask/utils` from `^12.0.1` to `^12.0.2` ([#11474](https://github.com/MetaMask/core/pull/11474))
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- Whitelist single-use vault deposit delegations that carry a `Redeemer` caveat ([#11310](https://github.com/MetaMask/core/pull/11310))
|
|
24
|
+
|
|
10
25
|
## [0.2.0]
|
|
11
26
|
|
|
12
27
|
### Added
|
|
@@ -31,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
31
46
|
- A whitelisted request must be for the signing account and hash to exactly the given hash (EIP-191, EIP-712 or EIP-7702), so the signer can sign the hash after inspecting the request
|
|
32
47
|
- Whitelist the CHOMP authentication, Rewards binding and Card sign-in messages, the EIP-7702 authorization to `EIP7702StatelessDeleGatorImpl`, standing vault delegations to the CHOMP delegate, and single-use vault deposit delegations
|
|
33
48
|
|
|
34
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/money-account-mfa-whitelist@0.
|
|
49
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/money-account-mfa-whitelist@0.3.0...HEAD
|
|
50
|
+
[0.3.0]: https://github.com/MetaMask/core/compare/@metamask/money-account-mfa-whitelist@0.2.0...@metamask/money-account-mfa-whitelist@0.3.0
|
|
35
51
|
[0.2.0]: https://github.com/MetaMask/core/compare/@metamask/money-account-mfa-whitelist@0.1.0...@metamask/money-account-mfa-whitelist@0.2.0
|
|
36
52
|
[0.1.0]: https://github.com/MetaMask/core/releases/tag/@metamask/money-account-mfa-whitelist@0.1.0
|
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ const config = {
|
|
|
36
36
|
},
|
|
37
37
|
],
|
|
38
38
|
cardSignInDomain: 'link.metamask.io',
|
|
39
|
+
chompSignInDomain: 'chomp.api.cx.metamask.io',
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
const requirement = getMfaRequirement(
|
|
@@ -52,14 +53,15 @@ if (requirement.mfaRequired) {
|
|
|
52
53
|
|
|
53
54
|
### Whitelist rules
|
|
54
55
|
|
|
55
|
-
| Rule
|
|
56
|
-
|
|
|
57
|
-
| `chomp-authentication`
|
|
58
|
-
| `rewards-binding`
|
|
59
|
-
| `card-sign-in`
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `vault-
|
|
56
|
+
| Rule | Method | Payload |
|
|
57
|
+
| ----------------------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
58
|
+
| `chomp-authentication` | `signPersonalMessage` | `CHOMP Authentication <timestamp>`, within `maxMessageAge` of now |
|
|
59
|
+
| `rewards-binding` | `signPersonalMessage` | `metamask-rewards:money-account-binding:<subject>:<address>:<timestamp>` for the signing account, within `maxMessageAge` of now |
|
|
60
|
+
| `card-sign-in` | `signPersonalMessage` | A SIWE message for `cardSignInDomain` and the Money Account chain, signed by the account, that is not expired |
|
|
61
|
+
| `chomp-successor-association` | `signPersonalMessage` | CHOMP's SIWE message for `chompSignInDomain` that links the signing account as successor of one predecessor, on the Money Account chain, that is not expired |
|
|
62
|
+
| `eip7702-authorization` | `signEip7702Authorization` | An authorization to `EIP7702StatelessDeleGatorImpl` on the Money Account chain |
|
|
63
|
+
| `vault-standing-delegation` | `signTypedData` (V4) | A root delegation to the CHOMP delegate with exactly a `ValueLte(0)`, an `ERC20TransferAmount` of mUSD or vault shares, and a `Redeemer` of that vault's adapter |
|
|
64
|
+
| `vault-deposit-delegation` | `signTypedData` (V4) | A single-use root delegation (`LimitedCalls(1)`, optionally with one `Timestamp` deadline and one `Redeemer` allowlist) whose exact executions are `mUSD.approve(boringVault, amount)` followed by `teller.deposit(mUSD, amount, minimumMint, 0x0)` |
|
|
63
65
|
|
|
64
66
|
Every delegation must be signed by the delegator, use the root authority, and be verified by the pinned `DelegationManager` on the Money Account chain.
|
|
65
67
|
|
package/dist/delegation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegation.d.ts","sourceRoot":"","sources":["../src/delegation.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAI3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAQrE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,GAAG,CAAC;IACd,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,kBAAkB,CAAC;CAC5B,CAAC;AAuFF;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,kBAAkB,GACzB,iBAAiB,GAAG,MAAM,CAyD5B;
|
|
1
|
+
{"version":3,"file":"delegation.d.ts","sourceRoot":"","sources":["../src/delegation.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAI3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAQrE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,GAAG,CAAC;IACd,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,kBAAkB,CAAC;CAC5B,CAAC;AAuFF;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,kBAAkB,GACzB,iBAAiB,GAAG,MAAM,CAyD5B;AAsHD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,iBAAiB,EAC7B,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,iBAAiB,GACrC,cAAc,CAoBhB"}
|
package/dist/delegation.js
CHANGED
|
@@ -187,8 +187,9 @@ function getStandingDelegationRequirement(caveats, config) {
|
|
|
187
187
|
/**
|
|
188
188
|
* Checks a single-use transaction delegation: exactly `LimitedCalls(1)`, one
|
|
189
189
|
* exact-execution caveat pinning a vault deposit and, optionally, one
|
|
190
|
-
* `Timestamp` deadline, in any order. A deadline
|
|
191
|
-
* delegation can be
|
|
190
|
+
* `Timestamp` deadline and one `Redeemer` allowlist, in any order. A deadline
|
|
191
|
+
* and a redeemer allowlist only narrow when and by whom the delegation can be
|
|
192
|
+
* redeemed.
|
|
192
193
|
*
|
|
193
194
|
* Withdrawals, payments and Card approvals use the same shape with other
|
|
194
195
|
* calls, so they require MFA.
|
|
@@ -201,7 +202,8 @@ function getStandingDelegationRequirement(caveats, config) {
|
|
|
201
202
|
function getSingleUseDelegationRequirement(caveats, delegator, config) {
|
|
202
203
|
const limitedCalls = findOnlyCaveat(caveats, config.contracts.LimitedCallsEnforcer);
|
|
203
204
|
const timestamp = findOnlyCaveat(caveats, config.contracts.TimestampEnforcer);
|
|
204
|
-
const
|
|
205
|
+
const redeemer = findOnlyCaveat(caveats, config.contracts.RedeemerEnforcer);
|
|
206
|
+
const [exactExecution, ...unexpected] = caveats.filter((caveat) => caveat !== limitedCalls && caveat !== timestamp && caveat !== redeemer);
|
|
205
207
|
if (!limitedCalls || !exactExecution || unexpected.length > 0) {
|
|
206
208
|
return requireMfa('Single-use delegation caveats are not whitelisted');
|
|
207
209
|
}
|
package/dist/delegation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegation.js","sourceRoot":"","sources":["../src/delegation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,8BAA8B,EAC9B,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,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,EAAE,OAAO,EAAE,MAAM,EAAqB;IAEtC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;QAC9C,OAAO,UAAU,CAAC,oCAAoC,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE,CAAC;QACrD,OAAO,UAAU,CAAC,qCAAqC,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,oBAAoB,CAAC,EAAE,CAAC;QAChE,OAAO,gCAAgC,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,eAAe,CAAC,EAAE,CAAC;QACpD,OAAO,iCAAiC,CACtC,UAAU,CAAC,OAAO,EAClB,UAAU,CAAC,SAAS,EACpB,MAAM,CACP,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC,wCAAwC,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import {\n ANY_BENEFICIARY,\n ROOT_AUTHORITY,\n createLimitedCallsTerms,\n createValueLteTerms,\n decodeERC20TransferAmountTerms,\n decodeRedeemerTerms,\n} from '@metamask/delegation-core';\nimport { isObject } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { DELEGATION_TYPES } from './constants.js';\nimport { getExactExecutions, isVaultDeposit } from './executions.js';\nimport type { Caveat } from './executions.js';\nimport type { MfaRequirement, MfaWhitelistConfig } from './types.js';\nimport { isAddress, isSameHex, requireMfa, whitelisted } from './utils.js';\n\nconst BYTES_PATTERN = /^0x(?:[0-9a-fA-F]{2})*$/u;\nconst BYTES32_PATTERN = /^0x[0-9a-fA-F]{64}$/u;\nconst UINT_PATTERN = /^(?:0x[0-9a-fA-F]+|\\d+)$/u;\nconst MAX_UINT256 = 2n ** 256n - 1n;\n\n/**\n * The fields of a delegation that are signed. The domain is not included,\n * because it must equal the pinned one.\n */\nexport type DelegationMessage = {\n delegate: Hex;\n delegator: Hex;\n authority: Hex;\n caveats: Caveat[];\n salt: bigint;\n};\n\ntype DelegationContext = {\n address: Hex;\n config: MfaWhitelistConfig;\n};\n\n/**\n * Checks that an object has exactly the given keys.\n *\n * @param value - The object.\n * @param keys - The expected keys.\n * @returns Whether the object has exactly these keys.\n */\nfunction hasExactKeys(value: Record<string, unknown>, keys: string[]): boolean {\n const actual = Object.keys(value);\n return (\n actual.length === keys.length && keys.every((key) => actual.includes(key))\n );\n}\n\n/**\n * Checks that an EIP-712 type definition matches the expected one exactly,\n * including field order.\n *\n * @param value - The type definition.\n * @param expected - The expected fields.\n * @returns Whether the definitions match.\n */\nfunction isFieldList(\n value: unknown,\n expected: readonly { name: string; type: string }[],\n): boolean {\n return (\n Array.isArray(value) &&\n value.length === expected.length &&\n value.every(\n (field: unknown, index) =>\n isObject(field) &&\n hasExactKeys(field, ['name', 'type']) &&\n field.name === expected[index].name &&\n field.type === expected[index].type,\n )\n );\n}\n\n/**\n * Parses an unsigned integer the way EIP-712 encoders accept it: a number,\n * a bigint, or a decimal or hex string.\n *\n * @param value - The value.\n * @returns The integer, or `undefined` if the value isn't a uint256.\n */\nfunction parseUint256(value: unknown): bigint | undefined {\n let parsed: bigint | undefined;\n if (typeof value === 'bigint') {\n parsed = value;\n } else if (typeof value === 'number' && Number.isSafeInteger(value)) {\n parsed = BigInt(value);\n } else if (typeof value === 'string' && UINT_PATTERN.test(value)) {\n parsed = BigInt(value);\n }\n return parsed !== undefined && parsed >= 0n && parsed <= MAX_UINT256\n ? parsed\n : undefined;\n}\n\n/**\n * Parses the caveats of a delegation message.\n *\n * @param value - The caveats.\n * @returns The caveats, or `undefined` if any is malformed.\n */\nfunction parseCaveats(value: unknown): Caveat[] | undefined {\n if (!Array.isArray(value)) {\n return undefined;\n }\n const caveats: Caveat[] = [];\n for (const caveat of value as unknown[]) {\n if (\n !isObject(caveat) ||\n !isAddress(caveat.enforcer) ||\n typeof caveat.terms !== 'string' ||\n !BYTES_PATTERN.test(caveat.terms)\n ) {\n return undefined;\n }\n caveats.push({ enforcer: caveat.enforcer, terms: caveat.terms as Hex });\n }\n return caveats;\n}\n\n/**\n * Parses and validates EIP-712 typed data as a delegation for the pinned\n * `DelegationManager` on the Money Account chain. Fields the EIP-712 types\n * don't declare (e.g. caveat `args` or an empty `signature`) don't affect\n * the signed digest and are ignored.\n *\n * @param data - The typed data, as an object or a JSON string.\n * @param config - The whitelist config.\n * @returns The delegation message, or the reason it isn't a valid delegation.\n */\nexport function parseDelegationTypedData(\n data: unknown,\n config: MfaWhitelistConfig,\n): DelegationMessage | string {\n const typedData: unknown = typeof data === 'string' ? JSON.parse(data) : data;\n\n if (!isObject(typedData) || typedData.primaryType !== 'Delegation') {\n return 'Typed data is not a delegation';\n }\n\n const { types, domain, message } = typedData;\n if (\n !isObject(types) ||\n !hasExactKeys(types, Object.keys(DELEGATION_TYPES)) ||\n !isFieldList(types.EIP712Domain, DELEGATION_TYPES.EIP712Domain) ||\n !isFieldList(types.Delegation, DELEGATION_TYPES.Delegation) ||\n !isFieldList(types.Caveat, DELEGATION_TYPES.Caveat)\n ) {\n return 'Typed data types are not the delegation types';\n }\n\n if (\n !isObject(domain) ||\n !hasExactKeys(domain, ['name', 'version', 'chainId', 'verifyingContract'])\n ) {\n return 'Typed data domain is malformed';\n }\n if (\n domain.name !== 'DelegationManager' ||\n domain.version !== '1' ||\n parseUint256(domain.chainId) !== BigInt(config.chainId) ||\n !isAddress(domain.verifyingContract) ||\n !isSameHex(domain.verifyingContract, config.contracts.DelegationManager)\n ) {\n return 'Delegation is not for the pinned DelegationManager and chain';\n }\n\n if (!isObject(message)) {\n return 'Delegation message is malformed';\n }\n const caveats = parseCaveats(message.caveats);\n const salt = parseUint256(message.salt);\n if (\n !isAddress(message.delegate) ||\n !isAddress(message.delegator) ||\n typeof message.authority !== 'string' ||\n !BYTES32_PATTERN.test(message.authority) ||\n salt === undefined ||\n !caveats\n ) {\n return 'Delegation message is malformed';\n }\n\n return {\n delegate: message.delegate,\n delegator: message.delegator,\n authority: message.authority as Hex,\n caveats,\n salt,\n };\n}\n\n/**\n * Finds the only caveat with the given enforcer.\n *\n * @param caveats - The caveats.\n * @param enforcer - The enforcer.\n * @returns The caveat, or `undefined` if there is none or more than one.\n */\nfunction findOnlyCaveat(caveats: Caveat[], enforcer: Hex): Caveat | undefined {\n const matches = caveats.filter((caveat) =>\n isSameHex(caveat.enforcer, enforcer),\n );\n return matches.length === 1 ? matches[0] : undefined;\n}\n\n/**\n * Checks a standing vault delegation, signed during the upgrade for CHOMP's\n * auto-deposit: exactly `ValueLte(0)`, `ERC20TransferAmount(token, amount)`\n * and `Redeemer([adapter])`, in any order, where the adapter belongs to a\n * pinned vault and the token is mUSD or that vault's share token.\n *\n * These are standing allowances, so their safety rests entirely on the\n * pinned delegate and adapter.\n *\n * @param caveats - The delegation's caveats.\n * @param config - The whitelist config.\n * @returns Whether MFA is required.\n */\nfunction getStandingDelegationRequirement(\n caveats: Caveat[],\n config: MfaWhitelistConfig,\n): MfaRequirement {\n const { ERC20TransferAmountEnforcer, RedeemerEnforcer, ValueLteEnforcer } =\n config.contracts;\n\n const valueLte = findOnlyCaveat(caveats, ValueLteEnforcer);\n const transferAmount = findOnlyCaveat(caveats, ERC20TransferAmountEnforcer);\n const redeemer = findOnlyCaveat(caveats, RedeemerEnforcer);\n if (caveats.length !== 3 || !valueLte || !transferAmount || !redeemer) {\n return requireMfa('Standing delegation caveats are not whitelisted');\n }\n\n if (!isSameHex(valueLte.terms, createValueLteTerms({ maxValue: 0n }))) {\n return requireMfa('Standing delegation allows native value');\n }\n\n // The packed-terms decoders throw unless the terms have the exact length.\n const { tokenAddress } = decodeERC20TransferAmountTerms(transferAmount.terms);\n const { redeemers } = decodeRedeemerTerms(redeemer.terms);\n if (redeemers.length !== 1) {\n return requireMfa('Standing delegation has more than one redeemer');\n }\n\n const vault = config.vaults.find(({ vedaVaultAdapterAddress }) =>\n isSameHex(vedaVaultAdapterAddress, redeemers[0]),\n );\n if (!vault) {\n return requireMfa('Standing delegation redeemer is not a vault adapter');\n }\n if (\n !isSameHex(tokenAddress, config.musdTokenAddress) &&\n !isSameHex(tokenAddress, vault.boringVault)\n ) {\n return requireMfa('Standing delegation token is not mUSD or vault shares');\n }\n\n return whitelisted('vault-standing-delegation');\n}\n\n/**\n * Checks a single-use transaction delegation: exactly `LimitedCalls(1)`, one\n * exact-execution caveat pinning a vault deposit and, optionally, one\n * `Timestamp` deadline, in any order. A deadline only narrows when the\n * delegation can be redeemed.\n *\n * Withdrawals, payments and Card approvals use the same shape with other\n * calls, so they require MFA.\n *\n * @param caveats - The delegation's caveats.\n * @param delegator - The Money Account.\n * @param config - The whitelist config.\n * @returns Whether MFA is required.\n */\nfunction getSingleUseDelegationRequirement(\n caveats: Caveat[],\n delegator: Hex,\n config: MfaWhitelistConfig,\n): MfaRequirement {\n const limitedCalls = findOnlyCaveat(\n caveats,\n config.contracts.LimitedCallsEnforcer,\n );\n const timestamp = findOnlyCaveat(caveats, config.contracts.TimestampEnforcer);\n const [exactExecution, ...unexpected] = caveats.filter(\n (caveat) => caveat !== limitedCalls && caveat !== timestamp,\n );\n if (!limitedCalls || !exactExecution || unexpected.length > 0) {\n return requireMfa('Single-use delegation caveats are not whitelisted');\n }\n\n if (!isSameHex(limitedCalls.terms, createLimitedCallsTerms({ limit: 1 }))) {\n return requireMfa('Delegation is not limited to a single call');\n }\n\n const executions = getExactExecutions(exactExecution, delegator, config);\n if (!executions) {\n return requireMfa('Delegation does not pin its executions');\n }\n\n return isVaultDeposit(executions, config)\n ? whitelisted('vault-deposit-delegation')\n : requireMfa('Delegation executions are not a vault deposit');\n}\n\n/**\n * Determines whether a delegation requires MFA.\n *\n * The delegation must be a root delegation from the Money Account, parsed\n * with {@link parseDelegationTypedData}. Whitelisted are the standing vault\n * delegations to CHOMP's delegate, and single-use vault deposit delegations\n * redeemable by anyone.\n *\n * @param delegation - The delegation message.\n * @param context - The request context.\n * @param context.address - The Money Account address.\n * @param context.config - The whitelist config.\n * @returns Whether MFA is required.\n */\nexport function getDelegationMfaRequirement(\n delegation: DelegationMessage,\n { address, config }: DelegationContext,\n): MfaRequirement {\n if (!isSameHex(delegation.delegator, address)) {\n return requireMfa('Delegator is not the Money Account');\n }\n if (!isSameHex(delegation.authority, ROOT_AUTHORITY)) {\n return requireMfa('Delegation is not a root delegation');\n }\n\n if (isSameHex(delegation.delegate, config.chompDelegateAddress)) {\n return getStandingDelegationRequirement(delegation.caveats, config);\n }\n if (isSameHex(delegation.delegate, ANY_BENEFICIARY)) {\n return getSingleUseDelegationRequirement(\n delegation.caveats,\n delegation.delegator,\n config,\n );\n }\n\n return requireMfa('Delegation delegate is not whitelisted');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"delegation.js","sourceRoot":"","sources":["../src/delegation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,8BAA8B,EAC9B,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGrE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3E,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,eAAe,GAAG,sBAAsB,CAAC;AAC/C,MAAM,YAAY,GAAG,2BAA2B,CAAC;AACjD,MAAM,WAAW,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC;AAmBpC;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,KAA8B,EAAE,IAAc;IAClE,MAAM,M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,EAAE,CAAC;QACrD,OAAO,UAAU,CAAC,qCAAqC,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,oBAAoB,CAAC,EAAE,CAAC;QAChE,OAAO,gCAAgC,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,eAAe,CAAC,EAAE,CAAC;QACpD,OAAO,iCAAiC,CACtC,UAAU,CAAC,OAAO,EAClB,UAAU,CAAC,SAAS,EACpB,MAAM,CACP,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC,wCAAwC,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import {\n ANY_BENEFICIARY,\n ROOT_AUTHORITY,\n createLimitedCallsTerms,\n createValueLteTerms,\n decodeERC20TransferAmountTerms,\n decodeRedeemerTerms,\n} from '@metamask/delegation-core';\nimport { isObject } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { DELEGATION_TYPES } from './constants.js';\nimport { getExactExecutions, isVaultDeposit } from './executions.js';\nimport type { Caveat } from './executions.js';\nimport type { MfaRequirement, MfaWhitelistConfig } from './types.js';\nimport { isAddress, isSameHex, requireMfa, whitelisted } from './utils.js';\n\nconst BYTES_PATTERN = /^0x(?:[0-9a-fA-F]{2})*$/u;\nconst BYTES32_PATTERN = /^0x[0-9a-fA-F]{64}$/u;\nconst UINT_PATTERN = /^(?:0x[0-9a-fA-F]+|\\d+)$/u;\nconst MAX_UINT256 = 2n ** 256n - 1n;\n\n/**\n * The fields of a delegation that are signed. The domain is not included,\n * because it must equal the pinned one.\n */\nexport type DelegationMessage = {\n delegate: Hex;\n delegator: Hex;\n authority: Hex;\n caveats: Caveat[];\n salt: bigint;\n};\n\ntype DelegationContext = {\n address: Hex;\n config: MfaWhitelistConfig;\n};\n\n/**\n * Checks that an object has exactly the given keys.\n *\n * @param value - The object.\n * @param keys - The expected keys.\n * @returns Whether the object has exactly these keys.\n */\nfunction hasExactKeys(value: Record<string, unknown>, keys: string[]): boolean {\n const actual = Object.keys(value);\n return (\n actual.length === keys.length && keys.every((key) => actual.includes(key))\n );\n}\n\n/**\n * Checks that an EIP-712 type definition matches the expected one exactly,\n * including field order.\n *\n * @param value - The type definition.\n * @param expected - The expected fields.\n * @returns Whether the definitions match.\n */\nfunction isFieldList(\n value: unknown,\n expected: readonly { name: string; type: string }[],\n): boolean {\n return (\n Array.isArray(value) &&\n value.length === expected.length &&\n value.every(\n (field: unknown, index) =>\n isObject(field) &&\n hasExactKeys(field, ['name', 'type']) &&\n field.name === expected[index].name &&\n field.type === expected[index].type,\n )\n );\n}\n\n/**\n * Parses an unsigned integer the way EIP-712 encoders accept it: a number,\n * a bigint, or a decimal or hex string.\n *\n * @param value - The value.\n * @returns The integer, or `undefined` if the value isn't a uint256.\n */\nfunction parseUint256(value: unknown): bigint | undefined {\n let parsed: bigint | undefined;\n if (typeof value === 'bigint') {\n parsed = value;\n } else if (typeof value === 'number' && Number.isSafeInteger(value)) {\n parsed = BigInt(value);\n } else if (typeof value === 'string' && UINT_PATTERN.test(value)) {\n parsed = BigInt(value);\n }\n return parsed !== undefined && parsed >= 0n && parsed <= MAX_UINT256\n ? parsed\n : undefined;\n}\n\n/**\n * Parses the caveats of a delegation message.\n *\n * @param value - The caveats.\n * @returns The caveats, or `undefined` if any is malformed.\n */\nfunction parseCaveats(value: unknown): Caveat[] | undefined {\n if (!Array.isArray(value)) {\n return undefined;\n }\n const caveats: Caveat[] = [];\n for (const caveat of value as unknown[]) {\n if (\n !isObject(caveat) ||\n !isAddress(caveat.enforcer) ||\n typeof caveat.terms !== 'string' ||\n !BYTES_PATTERN.test(caveat.terms)\n ) {\n return undefined;\n }\n caveats.push({ enforcer: caveat.enforcer, terms: caveat.terms as Hex });\n }\n return caveats;\n}\n\n/**\n * Parses and validates EIP-712 typed data as a delegation for the pinned\n * `DelegationManager` on the Money Account chain. Fields the EIP-712 types\n * don't declare (e.g. caveat `args` or an empty `signature`) don't affect\n * the signed digest and are ignored.\n *\n * @param data - The typed data, as an object or a JSON string.\n * @param config - The whitelist config.\n * @returns The delegation message, or the reason it isn't a valid delegation.\n */\nexport function parseDelegationTypedData(\n data: unknown,\n config: MfaWhitelistConfig,\n): DelegationMessage | string {\n const typedData: unknown = typeof data === 'string' ? JSON.parse(data) : data;\n\n if (!isObject(typedData) || typedData.primaryType !== 'Delegation') {\n return 'Typed data is not a delegation';\n }\n\n const { types, domain, message } = typedData;\n if (\n !isObject(types) ||\n !hasExactKeys(types, Object.keys(DELEGATION_TYPES)) ||\n !isFieldList(types.EIP712Domain, DELEGATION_TYPES.EIP712Domain) ||\n !isFieldList(types.Delegation, DELEGATION_TYPES.Delegation) ||\n !isFieldList(types.Caveat, DELEGATION_TYPES.Caveat)\n ) {\n return 'Typed data types are not the delegation types';\n }\n\n if (\n !isObject(domain) ||\n !hasExactKeys(domain, ['name', 'version', 'chainId', 'verifyingContract'])\n ) {\n return 'Typed data domain is malformed';\n }\n if (\n domain.name !== 'DelegationManager' ||\n domain.version !== '1' ||\n parseUint256(domain.chainId) !== BigInt(config.chainId) ||\n !isAddress(domain.verifyingContract) ||\n !isSameHex(domain.verifyingContract, config.contracts.DelegationManager)\n ) {\n return 'Delegation is not for the pinned DelegationManager and chain';\n }\n\n if (!isObject(message)) {\n return 'Delegation message is malformed';\n }\n const caveats = parseCaveats(message.caveats);\n const salt = parseUint256(message.salt);\n if (\n !isAddress(message.delegate) ||\n !isAddress(message.delegator) ||\n typeof message.authority !== 'string' ||\n !BYTES32_PATTERN.test(message.authority) ||\n salt === undefined ||\n !caveats\n ) {\n return 'Delegation message is malformed';\n }\n\n return {\n delegate: message.delegate,\n delegator: message.delegator,\n authority: message.authority as Hex,\n caveats,\n salt,\n };\n}\n\n/**\n * Finds the only caveat with the given enforcer.\n *\n * @param caveats - The caveats.\n * @param enforcer - The enforcer.\n * @returns The caveat, or `undefined` if there is none or more than one.\n */\nfunction findOnlyCaveat(caveats: Caveat[], enforcer: Hex): Caveat | undefined {\n const matches = caveats.filter((caveat) =>\n isSameHex(caveat.enforcer, enforcer),\n );\n return matches.length === 1 ? matches[0] : undefined;\n}\n\n/**\n * Checks a standing vault delegation, signed during the upgrade for CHOMP's\n * auto-deposit: exactly `ValueLte(0)`, `ERC20TransferAmount(token, amount)`\n * and `Redeemer([adapter])`, in any order, where the adapter belongs to a\n * pinned vault and the token is mUSD or that vault's share token.\n *\n * These are standing allowances, so their safety rests entirely on the\n * pinned delegate and adapter.\n *\n * @param caveats - The delegation's caveats.\n * @param config - The whitelist config.\n * @returns Whether MFA is required.\n */\nfunction getStandingDelegationRequirement(\n caveats: Caveat[],\n config: MfaWhitelistConfig,\n): MfaRequirement {\n const { ERC20TransferAmountEnforcer, RedeemerEnforcer, ValueLteEnforcer } =\n config.contracts;\n\n const valueLte = findOnlyCaveat(caveats, ValueLteEnforcer);\n const transferAmount = findOnlyCaveat(caveats, ERC20TransferAmountEnforcer);\n const redeemer = findOnlyCaveat(caveats, RedeemerEnforcer);\n if (caveats.length !== 3 || !valueLte || !transferAmount || !redeemer) {\n return requireMfa('Standing delegation caveats are not whitelisted');\n }\n\n if (!isSameHex(valueLte.terms, createValueLteTerms({ maxValue: 0n }))) {\n return requireMfa('Standing delegation allows native value');\n }\n\n // The packed-terms decoders throw unless the terms have the exact length.\n const { tokenAddress } = decodeERC20TransferAmountTerms(transferAmount.terms);\n const { redeemers } = decodeRedeemerTerms(redeemer.terms);\n if (redeemers.length !== 1) {\n return requireMfa('Standing delegation has more than one redeemer');\n }\n\n const vault = config.vaults.find(({ vedaVaultAdapterAddress }) =>\n isSameHex(vedaVaultAdapterAddress, redeemers[0]),\n );\n if (!vault) {\n return requireMfa('Standing delegation redeemer is not a vault adapter');\n }\n if (\n !isSameHex(tokenAddress, config.musdTokenAddress) &&\n !isSameHex(tokenAddress, vault.boringVault)\n ) {\n return requireMfa('Standing delegation token is not mUSD or vault shares');\n }\n\n return whitelisted('vault-standing-delegation');\n}\n\n/**\n * Checks a single-use transaction delegation: exactly `LimitedCalls(1)`, one\n * exact-execution caveat pinning a vault deposit and, optionally, one\n * `Timestamp` deadline and one `Redeemer` allowlist, in any order. A deadline\n * and a redeemer allowlist only narrow when and by whom the delegation can be\n * redeemed.\n *\n * Withdrawals, payments and Card approvals use the same shape with other\n * calls, so they require MFA.\n *\n * @param caveats - The delegation's caveats.\n * @param delegator - The Money Account.\n * @param config - The whitelist config.\n * @returns Whether MFA is required.\n */\nfunction getSingleUseDelegationRequirement(\n caveats: Caveat[],\n delegator: Hex,\n config: MfaWhitelistConfig,\n): MfaRequirement {\n const limitedCalls = findOnlyCaveat(\n caveats,\n config.contracts.LimitedCallsEnforcer,\n );\n const timestamp = findOnlyCaveat(caveats, config.contracts.TimestampEnforcer);\n const redeemer = findOnlyCaveat(caveats, config.contracts.RedeemerEnforcer);\n const [exactExecution, ...unexpected] = caveats.filter(\n (caveat) =>\n caveat !== limitedCalls && caveat !== timestamp && caveat !== redeemer,\n );\n if (!limitedCalls || !exactExecution || unexpected.length > 0) {\n return requireMfa('Single-use delegation caveats are not whitelisted');\n }\n\n if (!isSameHex(limitedCalls.terms, createLimitedCallsTerms({ limit: 1 }))) {\n return requireMfa('Delegation is not limited to a single call');\n }\n\n const executions = getExactExecutions(exactExecution, delegator, config);\n if (!executions) {\n return requireMfa('Delegation does not pin its executions');\n }\n\n return isVaultDeposit(executions, config)\n ? whitelisted('vault-deposit-delegation')\n : requireMfa('Delegation executions are not a vault deposit');\n}\n\n/**\n * Determines whether a delegation requires MFA.\n *\n * The delegation must be a root delegation from the Money Account, parsed\n * with {@link parseDelegationTypedData}. Whitelisted are the standing vault\n * delegations to CHOMP's delegate, and single-use vault deposit delegations\n * redeemable by anyone.\n *\n * @param delegation - The delegation message.\n * @param context - The request context.\n * @param context.address - The Money Account address.\n * @param context.config - The whitelist config.\n * @returns Whether MFA is required.\n */\nexport function getDelegationMfaRequirement(\n delegation: DelegationMessage,\n { address, config }: DelegationContext,\n): MfaRequirement {\n if (!isSameHex(delegation.delegator, address)) {\n return requireMfa('Delegator is not the Money Account');\n }\n if (!isSameHex(delegation.authority, ROOT_AUTHORITY)) {\n return requireMfa('Delegation is not a root delegation');\n }\n\n if (isSameHex(delegation.delegate, config.chompDelegateAddress)) {\n return getStandingDelegationRequirement(delegation.caveats, config);\n }\n if (isSameHex(delegation.delegate, ANY_BENEFICIARY)) {\n return getSingleUseDelegationRequirement(\n delegation.caveats,\n delegation.delegator,\n config,\n );\n }\n\n return requireMfa('Delegation delegate is not whitelisted');\n}\n"]}
|
|
@@ -9,9 +9,9 @@ type PersonalMessageContext = {
|
|
|
9
9
|
/**
|
|
10
10
|
* Determines whether a personal message requires MFA.
|
|
11
11
|
*
|
|
12
|
-
* Whitelisted are the CHOMP authentication message, the
|
|
13
|
-
* sign-in message and the Rewards
|
|
14
|
-
* timestamp. At worst, signing them without MFA lets someone tie the Money
|
|
12
|
+
* Whitelisted are the CHOMP authentication message, the CHOMP successor
|
|
13
|
+
* association message, the card provider sign-in message and the Rewards
|
|
14
|
+
* binding message, each with a fresh timestamp. At worst, signing them without MFA lets someone tie the Money
|
|
15
15
|
* Account to another CHOMP profile or Rewards subscription, which can deny
|
|
16
16
|
* service but not move funds.
|
|
17
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"personal-message.d.ts","sourceRoot":"","sources":["../src/personal-message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"personal-message.d.ts","sourceRoot":"","sources":["../src/personal-message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AA0DrE,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,kBAAkB,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AA2HF;;;;;;;;;;;;GAYG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,sBAAsB,GAC9B,cAAc,CAoChB"}
|
package/dist/personal-message.js
CHANGED
|
@@ -18,6 +18,25 @@ const CARD_SIGN_IN_PATTERN = new RegExp([
|
|
|
18
18
|
'Issued At: (?<issuedAt>\\S+)',
|
|
19
19
|
'Expiration Time: (?<expirationTime>\\S+)$',
|
|
20
20
|
].join('\n'), 'u');
|
|
21
|
+
/** Signed by `MoneyAccountUpgradeController` to link the MPC Money Account to the account it replaces. */
|
|
22
|
+
const CHOMP_SUCCESSOR_PATTERN = new RegExp([
|
|
23
|
+
'^(?<domain>\\S+) wants you to sign in with your Ethereum account:',
|
|
24
|
+
'(?<address>0x[0-9a-fA-F]{40})',
|
|
25
|
+
'',
|
|
26
|
+
'Associate (?<successor>0x[0-9a-fA-F]{40}) as the successor of (?<predecessor>0x[0-9a-fA-F]{40}) for CHOMP Money Account migration\\.',
|
|
27
|
+
'',
|
|
28
|
+
'URI: (?<uri>\\S+)',
|
|
29
|
+
'Version: 1',
|
|
30
|
+
'Chain ID: (?<chainId>\\d+)',
|
|
31
|
+
'Nonce: \\S+',
|
|
32
|
+
'Issued At: (?<issuedAt>\\S+)',
|
|
33
|
+
'Expiration Time: (?<expirationTime>\\S+)',
|
|
34
|
+
'Request ID: \\S+',
|
|
35
|
+
'Resources:',
|
|
36
|
+
'- urn:chomp:profile:\\S+',
|
|
37
|
+
'- urn:chomp:purpose:ASSOCIATE_SUCCESSOR',
|
|
38
|
+
'- urn:chomp:predecessor:(?<resourcePredecessor>0x[0-9a-fA-F]{40})$',
|
|
39
|
+
].join('\n'), 'u');
|
|
21
40
|
/**
|
|
22
41
|
* Parses an ISO 8601 timestamp in the exact form `Date.prototype.toISOString`
|
|
23
42
|
* produces.
|
|
@@ -33,6 +52,24 @@ function parseIsoTimestamp(value) {
|
|
|
33
52
|
}
|
|
34
53
|
return time;
|
|
35
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Whether a sign-in message was issued recently and has not expired.
|
|
57
|
+
*
|
|
58
|
+
* @param groups - The named groups, with `issuedAt` and `expirationTime`.
|
|
59
|
+
* @param now - The current time in milliseconds.
|
|
60
|
+
* @param maxMessageAge - The maximum message age in milliseconds.
|
|
61
|
+
* @returns Whether the message is fresh.
|
|
62
|
+
*/
|
|
63
|
+
function isFreshSignIn(groups, now, maxMessageAge) {
|
|
64
|
+
const issuedAt = parseIsoTimestamp(groups.issuedAt);
|
|
65
|
+
const expirationTime = parseIsoTimestamp(groups.expirationTime);
|
|
66
|
+
return (issuedAt !== undefined &&
|
|
67
|
+
expirationTime !== undefined &&
|
|
68
|
+
isFresh(issuedAt, now, maxMessageAge) &&
|
|
69
|
+
expirationTime > issuedAt &&
|
|
70
|
+
expirationTime - issuedAt <= maxMessageAge &&
|
|
71
|
+
now <= expirationTime);
|
|
72
|
+
}
|
|
36
73
|
/**
|
|
37
74
|
* Checks the card provider sign-in message. It only proves ownership of the
|
|
38
75
|
* address; funding the card needs a separate approval, which requires MFA.
|
|
@@ -59,24 +96,53 @@ function getCardSignInRequirement(groups, { address, config, maxMessageAge, now
|
|
|
59
96
|
if (groups.chainId !== String(hexToNumber(config.chainId))) {
|
|
60
97
|
return requireMfa('Sign-in message is not for the Money Account chain');
|
|
61
98
|
}
|
|
62
|
-
|
|
63
|
-
const expirationTime = parseIsoTimestamp(groups.expirationTime);
|
|
64
|
-
if (issuedAt === undefined ||
|
|
65
|
-
expirationTime === undefined ||
|
|
66
|
-
!isFresh(issuedAt, now, maxMessageAge) ||
|
|
67
|
-
expirationTime <= issuedAt ||
|
|
68
|
-
expirationTime - issuedAt > maxMessageAge ||
|
|
69
|
-
now > expirationTime) {
|
|
99
|
+
if (!isFreshSignIn(groups, now, maxMessageAge)) {
|
|
70
100
|
return requireMfa('Sign-in message is expired or not fresh');
|
|
71
101
|
}
|
|
72
102
|
return whitelisted('card-sign-in');
|
|
73
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Checks the CHOMP message that links the MPC Money Account, as successor, to
|
|
106
|
+
* the Money Account it replaces. Moving the funds needs the predecessor's own
|
|
107
|
+
* signature, so this only links the two addresses.
|
|
108
|
+
*
|
|
109
|
+
* @param groups - The named groups of {@link CHOMP_SUCCESSOR_PATTERN}.
|
|
110
|
+
* @param context - The request context.
|
|
111
|
+
* @param context.address - The Money Account address.
|
|
112
|
+
* @param context.config - The whitelist config.
|
|
113
|
+
* @param context.maxMessageAge - The maximum message age in milliseconds.
|
|
114
|
+
* @param context.now - The current time in milliseconds.
|
|
115
|
+
* @returns Whether MFA is required.
|
|
116
|
+
*/
|
|
117
|
+
function getChompSuccessorRequirement(groups, { address, config, maxMessageAge, now }) {
|
|
118
|
+
const { chompSignInDomain } = config;
|
|
119
|
+
if (!chompSignInDomain || groups.domain !== chompSignInDomain) {
|
|
120
|
+
return requireMfa('Sign-in message is not for the CHOMP domain');
|
|
121
|
+
}
|
|
122
|
+
if (groups.uri !== `https://${chompSignInDomain}/`) {
|
|
123
|
+
return requireMfa('Sign-in message URI does not match its domain');
|
|
124
|
+
}
|
|
125
|
+
if (!isSameHex(groups.address, address) ||
|
|
126
|
+
!isSameHex(groups.successor, address)) {
|
|
127
|
+
return requireMfa('Sign-in message is not for the Money Account');
|
|
128
|
+
}
|
|
129
|
+
if (!isSameHex(groups.predecessor, groups.resourcePredecessor)) {
|
|
130
|
+
return requireMfa('Sign-in message names two predecessors');
|
|
131
|
+
}
|
|
132
|
+
if (groups.chainId !== String(hexToNumber(config.chainId))) {
|
|
133
|
+
return requireMfa('Sign-in message is not for the Money Account chain');
|
|
134
|
+
}
|
|
135
|
+
if (!isFreshSignIn(groups, now, maxMessageAge)) {
|
|
136
|
+
return requireMfa('Sign-in message is expired or not fresh');
|
|
137
|
+
}
|
|
138
|
+
return whitelisted('chomp-successor-association');
|
|
139
|
+
}
|
|
74
140
|
/**
|
|
75
141
|
* Determines whether a personal message requires MFA.
|
|
76
142
|
*
|
|
77
|
-
* Whitelisted are the CHOMP authentication message, the
|
|
78
|
-
* sign-in message and the Rewards
|
|
79
|
-
* timestamp. At worst, signing them without MFA lets someone tie the Money
|
|
143
|
+
* Whitelisted are the CHOMP authentication message, the CHOMP successor
|
|
144
|
+
* association message, the card provider sign-in message and the Rewards
|
|
145
|
+
* binding message, each with a fresh timestamp. At worst, signing them without MFA lets someone tie the Money
|
|
80
146
|
* Account to another CHOMP profile or Rewards subscription, which can deny
|
|
81
147
|
* service but not move funds.
|
|
82
148
|
*
|
|
@@ -105,6 +171,10 @@ export function getPersonalMessageMfaRequirement(message, context) {
|
|
|
105
171
|
? whitelisted('rewards-binding')
|
|
106
172
|
: requireMfa('Rewards binding timestamp is not fresh');
|
|
107
173
|
}
|
|
174
|
+
const chompSuccessor = CHOMP_SUCCESSOR_PATTERN.exec(text)?.groups;
|
|
175
|
+
if (chompSuccessor) {
|
|
176
|
+
return getChompSuccessorRequirement(chompSuccessor, context);
|
|
177
|
+
}
|
|
108
178
|
const cardSignIn = CARD_SIGN_IN_PATTERN.exec(text)?.groups;
|
|
109
179
|
if (cardSignIn) {
|
|
110
180
|
return getCardSignInRequirement(cardSignIn, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"personal-message.js","sourceRoot":"","sources":["../src/personal-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9C,OAAO,EACL,UAAU,EACV,OAAO,EACP,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,qFAAqF;AACrF,MAAM,4BAA4B,GAChC,8CAA8C,CAAC;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uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAC3D,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;YACzC,OAAO,UAAU,CAAC,8CAA8C,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC;YAC3D,CAAC,CAAC,WAAW,CAAC,iBAAiB,CAAC;YAChC,CAAC,CAAC,UAAU,CAAC,wCAAwC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,UAAU,GAAG,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAC3D,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,wBAAwB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,UAAU,CAAC,6CAA6C,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { hexToNumber } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { MfaRequirement, MfaWhitelistConfig } from './types.js';\nimport {\n decodeUtf8,\n isFresh,\n isSameHex,\n requireMfa,\n whitelisted,\n} from './utils.js';\n\n/** Signed by `MoneyAccountUpgradeController` to associate the address with CHOMP. */\nconst CHOMP_AUTHENTICATION_PATTERN =\n /^CHOMP Authentication (?<timestamp>\\d{13})$/u;\n\n/** Signed by Mobile's `RewardsController.registerMoneyAccountBinding`. */\nconst REWARDS_BINDING_PATTERN =\n /^metamask-rewards:money-account-binding:[^:\\s]+:(?<address>0x[0-9a-f]{40}):(?<timestamp>\\d{13})$/u;\n\n/** Signed by Mobile's `CardController.linkMoneyAccountCard`. */\nconst CARD_SIGN_IN_PATTERN = new RegExp(\n [\n '^(?<domain>\\\\S+) wants you to sign in with your Ethereum account:',\n '(?<address>0x[0-9a-fA-F]{40})',\n '',\n 'Prove address ownership',\n '',\n 'URI: (?<uri>\\\\S+)',\n 'Version: 1',\n 'Chain ID: (?<chainId>\\\\d+)',\n 'Nonce: \\\\S+',\n 'Issued At: (?<issuedAt>\\\\S+)',\n 'Expiration Time: (?<expirationTime>\\\\S+)$',\n ].join('\\n'),\n 'u',\n);\n\ntype PersonalMessageContext = {\n address: Hex;\n config: MfaWhitelistConfig;\n maxMessageAge: number;\n now: number;\n};\n\n/**\n * Parses an ISO 8601 timestamp in the exact form `Date.prototype.toISOString`\n * produces.\n *\n * @param value - The timestamp.\n * @returns The time in milliseconds, or `undefined` if the value isn't in\n * that form.\n */\nfunction parseIsoTimestamp(value: string): number | undefined {\n const time = Date.parse(value);\n if (Number.isNaN(time) || new Date(time).toISOString() !== value) {\n return undefined;\n }\n return time;\n}\n\n/**\n * Checks the card provider sign-in message. It only proves ownership of the\n * address; funding the card needs a separate approval, which requires MFA.\n *\n * @param groups - The named groups of {@link CARD_SIGN_IN_PATTERN}.\n * @param context - The request context.\n * @param context.address - The Money Account address.\n * @param context.config - The whitelist config.\n * @param context.maxMessageAge - The maximum message age in milliseconds.\n * @param context.now - The current time in milliseconds.\n * @returns Whether MFA is required.\n */\nfunction getCardSignInRequirement(\n groups: Record<string, string>,\n { address, config, maxMessageAge, now }: PersonalMessageContext,\n): MfaRequirement {\n const { cardSignInDomain } = config;\n if (!cardSignInDomain || groups.domain !== cardSignInDomain) {\n return requireMfa('Sign-in message is not for the card sign-in domain');\n }\n if (groups.uri !== `https://${cardSignInDomain}`) {\n return requireMfa('Sign-in message URI does not match its domain');\n }\n if (!isSameHex(groups.address, address)) {\n return requireMfa('Sign-in message is not for the Money Account');\n }\n if (groups.chainId !== String(hexToNumber(config.chainId))) {\n return requireMfa('Sign-in message is not for the Money Account chain');\n }\n\n const issuedAt = parseIsoTimestamp(groups.issuedAt);\n const expirationTime = parseIsoTimestamp(groups.expirationTime);\n if (\n issuedAt === undefined ||\n expirationTime === undefined ||\n !isFresh(issuedAt, now, maxMessageAge) ||\n expirationTime <= issuedAt ||\n expirationTime - issuedAt > maxMessageAge ||\n now > expirationTime\n ) {\n return requireMfa('Sign-in message is expired or not fresh');\n }\n\n return whitelisted('card-sign-in');\n}\n\n/**\n * Determines whether a personal message requires MFA.\n *\n * Whitelisted are the CHOMP authentication message, the card provider\n * sign-in message and the Rewards binding message, each with a fresh\n * timestamp. At worst, signing them without MFA lets someone tie the Money\n * Account to another CHOMP profile or Rewards subscription, which can deny\n * service but not move funds.\n *\n * @param message - The message as hex-encoded UTF-8.\n * @param context - The request context.\n * @returns Whether MFA is required.\n */\nexport function getPersonalMessageMfaRequirement(\n message: unknown,\n context: PersonalMessageContext,\n): MfaRequirement {\n const text = decodeUtf8(message);\n if (text === undefined) {\n return requireMfa('Message is not hex-encoded UTF-8');\n }\n\n const { address, maxMessageAge, now } = context;\n\n const chomp = CHOMP_AUTHENTICATION_PATTERN.exec(text)?.groups;\n if (chomp) {\n return isFresh(Number(chomp.timestamp), now, maxMessageAge)\n ? whitelisted('chomp-authentication')\n : requireMfa('CHOMP authentication timestamp is not fresh');\n }\n\n const rewards = REWARDS_BINDING_PATTERN.exec(text)?.groups;\n if (rewards) {\n if (!isSameHex(rewards.address, address)) {\n return requireMfa('Rewards binding is not for the Money Account');\n }\n return isFresh(Number(rewards.timestamp), now, maxMessageAge)\n ? whitelisted('rewards-binding')\n : requireMfa('Rewards binding timestamp is not fresh');\n }\n\n const cardSignIn = CARD_SIGN_IN_PATTERN.exec(text)?.groups;\n if (cardSignIn) {\n return getCardSignInRequirement(cardSignIn, context);\n }\n\n return requireMfa('Message does not match a whitelisted format');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"personal-message.js","sourceRoot":"","sources":["../src/personal-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9C,OAAO,EACL,UAAU,EACV,OAAO,EACP,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CA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AC;IAED,OAAO,UAAU,CAAC,6CAA6C,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { hexToNumber } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { MfaRequirement, MfaWhitelistConfig } from './types.js';\nimport {\n decodeUtf8,\n isFresh,\n isSameHex,\n requireMfa,\n whitelisted,\n} from './utils.js';\n\n/** Signed by `MoneyAccountUpgradeController` to associate the address with CHOMP. */\nconst CHOMP_AUTHENTICATION_PATTERN =\n /^CHOMP Authentication (?<timestamp>\\d{13})$/u;\n\n/** Signed by Mobile's `RewardsController.registerMoneyAccountBinding`. */\nconst REWARDS_BINDING_PATTERN =\n /^metamask-rewards:money-account-binding:[^:\\s]+:(?<address>0x[0-9a-f]{40}):(?<timestamp>\\d{13})$/u;\n\n/** Signed by Mobile's `CardController.linkMoneyAccountCard`. */\nconst CARD_SIGN_IN_PATTERN = new RegExp(\n [\n '^(?<domain>\\\\S+) wants you to sign in with your Ethereum account:',\n '(?<address>0x[0-9a-fA-F]{40})',\n '',\n 'Prove address ownership',\n '',\n 'URI: (?<uri>\\\\S+)',\n 'Version: 1',\n 'Chain ID: (?<chainId>\\\\d+)',\n 'Nonce: \\\\S+',\n 'Issued At: (?<issuedAt>\\\\S+)',\n 'Expiration Time: (?<expirationTime>\\\\S+)$',\n ].join('\\n'),\n 'u',\n);\n\n/** Signed by `MoneyAccountUpgradeController` to link the MPC Money Account to the account it replaces. */\nconst CHOMP_SUCCESSOR_PATTERN = new RegExp(\n [\n '^(?<domain>\\\\S+) wants you to sign in with your Ethereum account:',\n '(?<address>0x[0-9a-fA-F]{40})',\n '',\n 'Associate (?<successor>0x[0-9a-fA-F]{40}) as the successor of (?<predecessor>0x[0-9a-fA-F]{40}) for CHOMP Money Account migration\\\\.',\n '',\n 'URI: (?<uri>\\\\S+)',\n 'Version: 1',\n 'Chain ID: (?<chainId>\\\\d+)',\n 'Nonce: \\\\S+',\n 'Issued At: (?<issuedAt>\\\\S+)',\n 'Expiration Time: (?<expirationTime>\\\\S+)',\n 'Request ID: \\\\S+',\n 'Resources:',\n '- urn:chomp:profile:\\\\S+',\n '- urn:chomp:purpose:ASSOCIATE_SUCCESSOR',\n '- urn:chomp:predecessor:(?<resourcePredecessor>0x[0-9a-fA-F]{40})$',\n ].join('\\n'),\n 'u',\n);\n\ntype PersonalMessageContext = {\n address: Hex;\n config: MfaWhitelistConfig;\n maxMessageAge: number;\n now: number;\n};\n\n/**\n * Parses an ISO 8601 timestamp in the exact form `Date.prototype.toISOString`\n * produces.\n *\n * @param value - The timestamp.\n * @returns The time in milliseconds, or `undefined` if the value isn't in\n * that form.\n */\nfunction parseIsoTimestamp(value: string): number | undefined {\n const time = Date.parse(value);\n if (Number.isNaN(time) || new Date(time).toISOString() !== value) {\n return undefined;\n }\n return time;\n}\n\n/**\n * Whether a sign-in message was issued recently and has not expired.\n *\n * @param groups - The named groups, with `issuedAt` and `expirationTime`.\n * @param now - The current time in milliseconds.\n * @param maxMessageAge - The maximum message age in milliseconds.\n * @returns Whether the message is fresh.\n */\nfunction isFreshSignIn(\n groups: Record<string, string>,\n now: number,\n maxMessageAge: number,\n): boolean {\n const issuedAt = parseIsoTimestamp(groups.issuedAt);\n const expirationTime = parseIsoTimestamp(groups.expirationTime);\n return (\n issuedAt !== undefined &&\n expirationTime !== undefined &&\n isFresh(issuedAt, now, maxMessageAge) &&\n expirationTime > issuedAt &&\n expirationTime - issuedAt <= maxMessageAge &&\n now <= expirationTime\n );\n}\n\n/**\n * Checks the card provider sign-in message. It only proves ownership of the\n * address; funding the card needs a separate approval, which requires MFA.\n *\n * @param groups - The named groups of {@link CARD_SIGN_IN_PATTERN}.\n * @param context - The request context.\n * @param context.address - The Money Account address.\n * @param context.config - The whitelist config.\n * @param context.maxMessageAge - The maximum message age in milliseconds.\n * @param context.now - The current time in milliseconds.\n * @returns Whether MFA is required.\n */\nfunction getCardSignInRequirement(\n groups: Record<string, string>,\n { address, config, maxMessageAge, now }: PersonalMessageContext,\n): MfaRequirement {\n const { cardSignInDomain } = config;\n if (!cardSignInDomain || groups.domain !== cardSignInDomain) {\n return requireMfa('Sign-in message is not for the card sign-in domain');\n }\n if (groups.uri !== `https://${cardSignInDomain}`) {\n return requireMfa('Sign-in message URI does not match its domain');\n }\n if (!isSameHex(groups.address, address)) {\n return requireMfa('Sign-in message is not for the Money Account');\n }\n if (groups.chainId !== String(hexToNumber(config.chainId))) {\n return requireMfa('Sign-in message is not for the Money Account chain');\n }\n\n if (!isFreshSignIn(groups, now, maxMessageAge)) {\n return requireMfa('Sign-in message is expired or not fresh');\n }\n\n return whitelisted('card-sign-in');\n}\n\n/**\n * Checks the CHOMP message that links the MPC Money Account, as successor, to\n * the Money Account it replaces. Moving the funds needs the predecessor's own\n * signature, so this only links the two addresses.\n *\n * @param groups - The named groups of {@link CHOMP_SUCCESSOR_PATTERN}.\n * @param context - The request context.\n * @param context.address - The Money Account address.\n * @param context.config - The whitelist config.\n * @param context.maxMessageAge - The maximum message age in milliseconds.\n * @param context.now - The current time in milliseconds.\n * @returns Whether MFA is required.\n */\nfunction getChompSuccessorRequirement(\n groups: Record<string, string>,\n { address, config, maxMessageAge, now }: PersonalMessageContext,\n): MfaRequirement {\n const { chompSignInDomain } = config;\n if (!chompSignInDomain || groups.domain !== chompSignInDomain) {\n return requireMfa('Sign-in message is not for the CHOMP domain');\n }\n if (groups.uri !== `https://${chompSignInDomain}/`) {\n return requireMfa('Sign-in message URI does not match its domain');\n }\n if (\n !isSameHex(groups.address, address) ||\n !isSameHex(groups.successor, address)\n ) {\n return requireMfa('Sign-in message is not for the Money Account');\n }\n if (!isSameHex(groups.predecessor, groups.resourcePredecessor)) {\n return requireMfa('Sign-in message names two predecessors');\n }\n if (groups.chainId !== String(hexToNumber(config.chainId))) {\n return requireMfa('Sign-in message is not for the Money Account chain');\n }\n if (!isFreshSignIn(groups, now, maxMessageAge)) {\n return requireMfa('Sign-in message is expired or not fresh');\n }\n\n return whitelisted('chomp-successor-association');\n}\n\n/**\n * Determines whether a personal message requires MFA.\n *\n * Whitelisted are the CHOMP authentication message, the CHOMP successor\n * association message, the card provider sign-in message and the Rewards\n * binding message, each with a fresh timestamp. At worst, signing them without MFA lets someone tie the Money\n * Account to another CHOMP profile or Rewards subscription, which can deny\n * service but not move funds.\n *\n * @param message - The message as hex-encoded UTF-8.\n * @param context - The request context.\n * @returns Whether MFA is required.\n */\nexport function getPersonalMessageMfaRequirement(\n message: unknown,\n context: PersonalMessageContext,\n): MfaRequirement {\n const text = decodeUtf8(message);\n if (text === undefined) {\n return requireMfa('Message is not hex-encoded UTF-8');\n }\n\n const { address, maxMessageAge, now } = context;\n\n const chomp = CHOMP_AUTHENTICATION_PATTERN.exec(text)?.groups;\n if (chomp) {\n return isFresh(Number(chomp.timestamp), now, maxMessageAge)\n ? whitelisted('chomp-authentication')\n : requireMfa('CHOMP authentication timestamp is not fresh');\n }\n\n const rewards = REWARDS_BINDING_PATTERN.exec(text)?.groups;\n if (rewards) {\n if (!isSameHex(rewards.address, address)) {\n return requireMfa('Rewards binding is not for the Money Account');\n }\n return isFresh(Number(rewards.timestamp), now, maxMessageAge)\n ? whitelisted('rewards-binding')\n : requireMfa('Rewards binding timestamp is not fresh');\n }\n\n const chompSuccessor = CHOMP_SUCCESSOR_PATTERN.exec(text)?.groups;\n if (chompSuccessor) {\n return getChompSuccessorRequirement(chompSuccessor, context);\n }\n\n const cardSignIn = CARD_SIGN_IN_PATTERN.exec(text)?.groups;\n if (cardSignIn) {\n return getCardSignInRequirement(cardSignIn, context);\n }\n\n return requireMfa('Message does not match a whitelisted format');\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -51,6 +51,11 @@ export type MfaWhitelistConfig = {
|
|
|
51
51
|
* link host). The sign-in message requires MFA when this is not set.
|
|
52
52
|
*/
|
|
53
53
|
cardSignInDomain?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The domain of the CHOMP sign-in message that links the MPC Money Account
|
|
56
|
+
* to the account it replaces. The message requires MFA when this is not set.
|
|
57
|
+
*/
|
|
58
|
+
chompSignInDomain?: string;
|
|
54
59
|
/**
|
|
55
60
|
* How far, in milliseconds, a signed message's timestamp may be from the
|
|
56
61
|
* current time. Defaults to five minutes.
|
|
@@ -92,7 +97,7 @@ export type MoneyAccountSignatureRequest = {
|
|
|
92
97
|
/**
|
|
93
98
|
* The whitelist rule a payload matched.
|
|
94
99
|
*/
|
|
95
|
-
export type MfaWhitelistRule = 'chomp-authentication' | 'card-sign-in' | 'rewards-binding' | 'eip7702-authorization' | 'vault-standing-delegation' | 'vault-deposit-delegation';
|
|
100
|
+
export type MfaWhitelistRule = 'chomp-authentication' | 'card-sign-in' | 'chomp-successor-association' | 'rewards-binding' | 'eip7702-authorization' | 'vault-standing-delegation' | 'vault-deposit-delegation';
|
|
96
101
|
/**
|
|
97
102
|
* Whether a signature request requires MFA. A whitelisted request names the
|
|
98
103
|
* rule it matched; any other request gives the reason it isn't whitelisted.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,2DAA2D;IAC3D,iBAAiB,EAAE,GAAG,CAAC;IACvB,yEAAyE;IACzE,6BAA6B,EAAE,GAAG,CAAC;IACnC,2BAA2B,EAAE,GAAG,CAAC;IACjC,2BAA2B,EAAE,GAAG,CAAC;IACjC,sBAAsB,EAAE,GAAG,CAAC;IAC5B,oBAAoB,EAAE,GAAG,CAAC;IAC1B,gBAAgB,EAAE,GAAG,CAAC;IACtB,iBAAiB,EAAE,GAAG,CAAC;IACvB,gBAAgB,EAAE,GAAG,CAAC;CACvB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,0EAA0E;IAC1E,WAAW,EAAE,GAA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,gBAAgB,CAAA;CAAE,GAC9C;IAAE,WAAW,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,kDAAkD;IAClD,OAAO,EAAE,GAAG,CAAC;IACb,gCAAgC;IAChC,IAAI,EAAE,GAAG,CAAC;IACV,mCAAmC;IACnC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * The Delegation Framework contracts the whitelist pins. The keys match the\n * contract names in `@metamask/delegation-deployments`, so a deployment entry\n * (e.g. `DELEGATOR_CONTRACTS['1.3.0'][143]`) can be passed as is.\n */\nexport type DelegationFrameworkContracts = {\n /** The EIP-712 `verifyingContract` of every delegation. */\n DelegationManager: Hex;\n /** The only implementation an EIP-7702 authorization may delegate to. */\n EIP7702StatelessDeleGatorImpl: Hex;\n ERC20TransferAmountEnforcer: Hex;\n ExactExecutionBatchEnforcer: Hex;\n ExactExecutionEnforcer: Hex;\n LimitedCallsEnforcer: Hex;\n RedeemerEnforcer: Hex;\n TimestampEnforcer: Hex;\n ValueLteEnforcer: Hex;\n};\n\n/**\n * A Money Account vault. The base vault comes from the\n * `moneyAccountVaultConfig` remote feature flag, the premium vault from\n * `moneyAccountPremiumVaultConfig`, and each vault's adapter from the CHOMP\n * service details.\n */\nexport type MoneyAccountVault = {\n /** The boring vault, which is also the vault share token (e.g. vmUSD). */\n boringVault: Hex;\n /** The teller that mints vault shares on deposit. */\n tellerAddress: Hex;\n /** The Veda vault adapter, the only redeemer of standing delegations. */\n vedaVaultAdapterAddress: Hex;\n};\n\n/**\n * The pinned configuration a payload must match to be whitelisted. Anything\n * that doesn't match requires MFA, so a configuration change fails closed.\n */\nexport type MfaWhitelistConfig = {\n /** The Money Account chain, e.g. `0x8f` for Monad. */\n chainId: Hex;\n /** The Delegation Framework contracts on that chain. */\n contracts: DelegationFrameworkContracts;\n /** The mUSD token. */\n musdTokenAddress: Hex;\n /** CHOMP's auto-deposit delegate, the delegate of standing delegations. */\n chompDelegateAddress: Hex;\n /** The vaults deposits may go into. */\n vaults: MoneyAccountVault[];\n /**\n * The domain of the card provider sign-in message (the MetaMask universal\n * link host). The sign-in message requires MFA when this is not set.\n */\n cardSignInDomain?: string;\n /**\n * How far, in milliseconds, a signed message's timestamp may be from the\n * current time. Defaults to five minutes.\n */\n maxMessageAge?: number;\n};\n\n/**\n * An EIP-7702 authorization tuple, as passed to the keyring's\n * `signEip7702Authorization`.\n */\nexport type Eip7702Authorization = [\n chainId: number,\n contractAddress: Hex,\n nonce: number,\n];\n\n/**\n * A signature request for the Money Account, mirroring the three signing\n * methods of the Money keyring.\n */\nexport type MoneyAccountSignatureRequest =\n | {\n method: 'signPersonalMessage';\n /** The Money Account address. */\n address: Hex;\n /** The message as hex-encoded UTF-8, as passed to the keyring. */\n message: Hex;\n }\n | {\n method: 'signTypedData';\n /** The Money Account address. */\n address: Hex;\n version: 'V1' | 'V3' | 'V4';\n /** The typed data, as an object or as a JSON string. */\n data: unknown;\n }\n | {\n method: 'signEip7702Authorization';\n /** The Money Account address. */\n address: Hex;\n authorization: Eip7702Authorization;\n };\n\n/**\n * The whitelist rule a payload matched.\n */\nexport type MfaWhitelistRule =\n | 'chomp-authentication'\n | 'card-sign-in'\n | 'rewards-binding'\n | 'eip7702-authorization'\n | 'vault-standing-delegation'\n | 'vault-deposit-delegation';\n\n/**\n * Whether a signature request requires MFA. A whitelisted request names the\n * rule it matched; any other request gives the reason it isn't whitelisted.\n */\nexport type MfaRequirement =\n | { mfaRequired: false; rule: MfaWhitelistRule }\n | { mfaRequired: true; reason: string };\n\n/**\n * What the signer itself knows about the signature: its key, the hash it is\n * asked to sign, its pinned config and its clock. None of this may be taken\n * from the signature request, which is what is being checked.\n */\nexport type MfaSignerContext = {\n /** The Money Account whose key signs the hash. */\n address: Hex;\n /** The 32-byte hash to sign. */\n hash: Hex;\n /** The pinned whitelist config. */\n config: MfaWhitelistConfig;\n /** The current time in milliseconds. Defaults to `Date.now()`. */\n now?: number;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * The Delegation Framework contracts the whitelist pins. The keys match the\n * contract names in `@metamask/delegation-deployments`, so a deployment entry\n * (e.g. `DELEGATOR_CONTRACTS['1.3.0'][143]`) can be passed as is.\n */\nexport type DelegationFrameworkContracts = {\n /** The EIP-712 `verifyingContract` of every delegation. */\n DelegationManager: Hex;\n /** The only implementation an EIP-7702 authorization may delegate to. */\n EIP7702StatelessDeleGatorImpl: Hex;\n ERC20TransferAmountEnforcer: Hex;\n ExactExecutionBatchEnforcer: Hex;\n ExactExecutionEnforcer: Hex;\n LimitedCallsEnforcer: Hex;\n RedeemerEnforcer: Hex;\n TimestampEnforcer: Hex;\n ValueLteEnforcer: Hex;\n};\n\n/**\n * A Money Account vault. The base vault comes from the\n * `moneyAccountVaultConfig` remote feature flag, the premium vault from\n * `moneyAccountPremiumVaultConfig`, and each vault's adapter from the CHOMP\n * service details.\n */\nexport type MoneyAccountVault = {\n /** The boring vault, which is also the vault share token (e.g. vmUSD). */\n boringVault: Hex;\n /** The teller that mints vault shares on deposit. */\n tellerAddress: Hex;\n /** The Veda vault adapter, the only redeemer of standing delegations. */\n vedaVaultAdapterAddress: Hex;\n};\n\n/**\n * The pinned configuration a payload must match to be whitelisted. Anything\n * that doesn't match requires MFA, so a configuration change fails closed.\n */\nexport type MfaWhitelistConfig = {\n /** The Money Account chain, e.g. `0x8f` for Monad. */\n chainId: Hex;\n /** The Delegation Framework contracts on that chain. */\n contracts: DelegationFrameworkContracts;\n /** The mUSD token. */\n musdTokenAddress: Hex;\n /** CHOMP's auto-deposit delegate, the delegate of standing delegations. */\n chompDelegateAddress: Hex;\n /** The vaults deposits may go into. */\n vaults: MoneyAccountVault[];\n /**\n * The domain of the card provider sign-in message (the MetaMask universal\n * link host). The sign-in message requires MFA when this is not set.\n */\n cardSignInDomain?: string;\n /**\n * The domain of the CHOMP sign-in message that links the MPC Money Account\n * to the account it replaces. The message requires MFA when this is not set.\n */\n chompSignInDomain?: string;\n /**\n * How far, in milliseconds, a signed message's timestamp may be from the\n * current time. Defaults to five minutes.\n */\n maxMessageAge?: number;\n};\n\n/**\n * An EIP-7702 authorization tuple, as passed to the keyring's\n * `signEip7702Authorization`.\n */\nexport type Eip7702Authorization = [\n chainId: number,\n contractAddress: Hex,\n nonce: number,\n];\n\n/**\n * A signature request for the Money Account, mirroring the three signing\n * methods of the Money keyring.\n */\nexport type MoneyAccountSignatureRequest =\n | {\n method: 'signPersonalMessage';\n /** The Money Account address. */\n address: Hex;\n /** The message as hex-encoded UTF-8, as passed to the keyring. */\n message: Hex;\n }\n | {\n method: 'signTypedData';\n /** The Money Account address. */\n address: Hex;\n version: 'V1' | 'V3' | 'V4';\n /** The typed data, as an object or as a JSON string. */\n data: unknown;\n }\n | {\n method: 'signEip7702Authorization';\n /** The Money Account address. */\n address: Hex;\n authorization: Eip7702Authorization;\n };\n\n/**\n * The whitelist rule a payload matched.\n */\nexport type MfaWhitelistRule =\n | 'chomp-authentication'\n | 'card-sign-in'\n | 'chomp-successor-association'\n | 'rewards-binding'\n | 'eip7702-authorization'\n | 'vault-standing-delegation'\n | 'vault-deposit-delegation';\n\n/**\n * Whether a signature request requires MFA. A whitelisted request names the\n * rule it matched; any other request gives the reason it isn't whitelisted.\n */\nexport type MfaRequirement =\n | { mfaRequired: false; rule: MfaWhitelistRule }\n | { mfaRequired: true; reason: string };\n\n/**\n * What the signer itself knows about the signature: its key, the hash it is\n * asked to sign, its pinned config and its clock. None of this may be taken\n * from the signature request, which is what is being checked.\n */\nexport type MfaSignerContext = {\n /** The Money Account whose key signs the hash. */\n address: Hex;\n /** The 32-byte hash to sign. */\n hash: Hex;\n /** The pinned whitelist config. */\n config: MfaWhitelistConfig;\n /** The current time in milliseconds. Defaults to `Date.now()`. */\n now?: number;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/money-account-mfa-whitelist",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Determines which Money Account signature requests can be signed without MFA approval",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"registry": "https://registry.npmjs.org/"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
+
"allow-scripts": "yarn workspace @metamask/core-monorepo run allow-scripts",
|
|
35
36
|
"build": "tsc --project tsconfig.build.json",
|
|
36
37
|
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
37
38
|
"build:clean": "yarn build:only-clean && yarn build",
|
|
@@ -46,13 +47,14 @@
|
|
|
46
47
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
47
48
|
"test": "vitest",
|
|
48
49
|
"test:clean": "vitest --clearCache",
|
|
50
|
+
"test:coverage": "vitest --coverage",
|
|
49
51
|
"test:verbose": "vitest --reporter=verbose",
|
|
50
52
|
"test:watch": "vitest --watch"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
|
-
"@metamask/abi-utils": "^
|
|
55
|
+
"@metamask/abi-utils": "^3.0.0",
|
|
54
56
|
"@metamask/delegation-core": "^2.2.1",
|
|
55
|
-
"@metamask/utils": "^12.0.
|
|
57
|
+
"@metamask/utils": "^12.0.2",
|
|
56
58
|
"@noble/hashes": "^1.8.0"
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {
|
|
@@ -60,8 +62,8 @@
|
|
|
60
62
|
"@metamask/delegation-controller": "^4.0.0",
|
|
61
63
|
"@metamask/delegation-deployments": "^1.4.0",
|
|
62
64
|
"@metamask/messenger": "^3.0.0",
|
|
63
|
-
"@metamask/money-account-utils": "^2.2.
|
|
64
|
-
"@metamask/transaction-controller": "^
|
|
65
|
+
"@metamask/money-account-utils": "^2.2.1",
|
|
66
|
+
"@metamask/transaction-controller": "^74.2.0",
|
|
65
67
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
66
68
|
"ethers": "^6.17.0",
|
|
67
69
|
"rimraf": "^6.1.3",
|