@metamask/ramps-controller 20.0.0 → 20.2.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 +36 -1
- package/dist/RampsController-method-action-types.cjs.map +1 -1
- package/dist/RampsController-method-action-types.d.cts +44 -1
- package/dist/RampsController-method-action-types.d.cts.map +1 -1
- package/dist/RampsController-method-action-types.d.mts +44 -1
- package/dist/RampsController-method-action-types.d.mts.map +1 -1
- package/dist/RampsController-method-action-types.mjs.map +1 -1
- package/dist/RampsController.cjs +225 -18
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +76 -7
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +76 -7
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +224 -17
- package/dist/RampsController.mjs.map +1 -1
- package/dist/RampsService.cjs +18 -4
- package/dist/RampsService.cjs.map +1 -1
- package/dist/RampsService.d.cts +20 -4
- package/dist/RampsService.d.cts.map +1 -1
- package/dist/RampsService.d.mts +20 -4
- package/dist/RampsService.d.mts.map +1 -1
- package/dist/RampsService.mjs +18 -4
- package/dist/RampsService.mjs.map +1 -1
- package/dist/TransakService.cjs +15 -3
- package/dist/TransakService.cjs.map +1 -1
- package/dist/TransakService.d.cts +3 -1
- package/dist/TransakService.d.cts.map +1 -1
- package/dist/TransakService.d.mts +3 -1
- package/dist/TransakService.d.mts.map +1 -1
- package/dist/TransakService.mjs +15 -3
- package/dist/TransakService.mjs.map +1 -1
- package/dist/client-identity.cjs +28 -0
- package/dist/client-identity.cjs.map +1 -0
- package/dist/client-identity.d.cts +24 -0
- package/dist/client-identity.d.cts.map +1 -0
- package/dist/client-identity.d.mts +24 -0
- package/dist/client-identity.d.mts.map +1 -0
- package/dist/client-identity.mjs +24 -0
- package/dist/client-identity.mjs.map +1 -0
- package/dist/index.cjs +9 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/index.mjs.map +1 -1
- package/dist/orderStatus.cjs +34 -0
- package/dist/orderStatus.cjs.map +1 -0
- package/dist/orderStatus.d.cts +18 -0
- package/dist/orderStatus.d.cts.map +1 -0
- package/dist/orderStatus.d.mts +18 -0
- package/dist/orderStatus.d.mts.map +1 -0
- package/dist/orderStatus.mjs +30 -0
- package/dist/orderStatus.mjs.map +1 -0
- package/dist/paymentMethodMerge.cjs +51 -0
- package/dist/paymentMethodMerge.cjs.map +1 -0
- package/dist/paymentMethodMerge.d.cts +26 -0
- package/dist/paymentMethodMerge.d.cts.map +1 -0
- package/dist/paymentMethodMerge.d.mts +26 -0
- package/dist/paymentMethodMerge.d.mts.map +1 -0
- package/dist/paymentMethodMerge.mjs +46 -0
- package/dist/paymentMethodMerge.mjs.map +1 -0
- package/dist/providerAvailability.cjs +39 -8
- package/dist/providerAvailability.cjs.map +1 -1
- package/dist/providerAvailability.d.cts +30 -5
- package/dist/providerAvailability.d.cts.map +1 -1
- package/dist/providerAvailability.d.mts +30 -5
- package/dist/providerAvailability.d.mts.map +1 -1
- package/dist/providerAvailability.mjs +37 -7
- package/dist/providerAvailability.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providerAvailability.d.mts","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,2BAA0B;AAElD
|
|
1
|
+
{"version":3,"file":"providerAvailability.d.mts","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,2BAA0B;AAElD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAK7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAST;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,QAAQ,EAAE,EACrB,OAAO,EAAE,MAAM,GACd,QAAQ,EAAE,CAEZ;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,SAAS,EACT,OAAO,EACP,mBAAmB,GACpB,EAAE;IACD,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,OAAO,CAAC;CAC9B,GAAG,OAAO,CAYV;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GACpB,EAAE;IACD,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,gBAAgB,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IACnC,mBAAmB,EAAE,OAAO,CAAC;CAC9B,GAAG,OAAO,CAQV"}
|
|
@@ -1,13 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonicalizes a CAIP-19 asset id for comparison against Ramps API values.
|
|
3
|
+
*
|
|
4
|
+
* CAIP-19 does not constrain the case of the asset reference, and the Ramps API
|
|
5
|
+
* is not consistent about it. Every `eip155` key in `regions/{region}/providers`
|
|
6
|
+
* `supportedCryptoCurrencies` is lowercase, while `regions/{region}/topTokens`
|
|
7
|
+
* returns four mainnet `assetId` values EIP-55 checksummed (USDT, USDC, WBTC,
|
|
8
|
+
* LINK) in both its `topTokens` and `allTokens` lists, with no lowercase
|
|
9
|
+
* duplicate. Callers also supply checksummed ids of their own from other
|
|
10
|
+
* controllers, so the two sides of a comparison can disagree on case for the
|
|
11
|
+
* same asset.
|
|
12
|
+
*
|
|
13
|
+
* Non-EVM references are case-sensitive (Solana base58, Tron base58, bitcoin
|
|
14
|
+
* bech32), so lowercasing is restricted to `eip155` rather than applied to the
|
|
15
|
+
* whole string. This is a tightening: for EVM ids a plain `toLowerCase()` on
|
|
16
|
+
* both sides already matched. Current API data carries non-EVM ids in identical
|
|
17
|
+
* case on both endpoints, so the passthrough guards against future drift rather
|
|
18
|
+
* than fixing an observed mismatch.
|
|
19
|
+
*
|
|
20
|
+
* The namespace itself is matched case-insensitively, so an `EIP155:` prefix
|
|
21
|
+
* is treated as EVM even though CAIP-19 defines namespaces as lowercase.
|
|
22
|
+
*
|
|
23
|
+
* @param assetId - CAIP-19 asset id, in either case form.
|
|
24
|
+
* @returns The asset id in the form the Ramps API uses.
|
|
25
|
+
*/
|
|
26
|
+
export function normalizeRampsAssetId(assetId) {
|
|
27
|
+
const trimmedAssetId = assetId.trim();
|
|
28
|
+
return /^eip155:/iu.test(trimmedAssetId)
|
|
29
|
+
? trimmedAssetId.toLowerCase()
|
|
30
|
+
: trimmedAssetId;
|
|
31
|
+
}
|
|
1
32
|
/**
|
|
2
33
|
* Whether a provider serves the given deposit asset.
|
|
3
34
|
*
|
|
4
35
|
* Mirrors the region-provider matching the controller performs internally: a
|
|
5
36
|
* provider serves the asset when its `supportedCryptoCurrencies` map (keyed by
|
|
6
|
-
* CAIP-19 asset id) contains the asset id
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* serving the asset.
|
|
37
|
+
* CAIP-19 asset id) contains the asset id. Both sides are canonicalized with
|
|
38
|
+
* {@link normalizeRampsAssetId}, so EVM ids match regardless of checksum
|
|
39
|
+
* casing while non-EVM references stay case-sensitive. A provider without a
|
|
40
|
+
* `supportedCryptoCurrencies` map is treated as not serving the asset.
|
|
11
41
|
*
|
|
12
42
|
* @param provider - The provider to test.
|
|
13
43
|
* @param assetId - CAIP-19 asset id of the deposit asset.
|
|
@@ -18,8 +48,8 @@ export function providerServesAsset(provider, assetId) {
|
|
|
18
48
|
if (!map) {
|
|
19
49
|
return false;
|
|
20
50
|
}
|
|
21
|
-
const target = assetId
|
|
22
|
-
return Object.keys(map).some((key) => key
|
|
51
|
+
const target = normalizeRampsAssetId(assetId);
|
|
52
|
+
return Object.keys(map).some((key) => normalizeRampsAssetId(key) === target && map[key]);
|
|
23
53
|
}
|
|
24
54
|
/**
|
|
25
55
|
* Filters a provider list down to those serving the given deposit asset.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providerAvailability.mjs","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"providerAvailability.mjs","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IACtC,OAAO,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC;QACtC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE;QAC9B,CAAC,CAAC,cAAc,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAkB,EAClB,OAAe;IAEf,MAAM,GAAG,GAAG,QAAQ,EAAE,yBAAyB,CAAC;IAChD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,MAAM,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAC1B,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAC3D,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAAqB,EACrB,OAAe;IAEf,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAChF,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,yBAAyB,CAAC,EACxC,SAAS,EACT,OAAO,EACP,mBAAmB,GAKpB;IACC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,OAAO,GAAG,wBAAwB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC7D,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GAKpB;IACC,IAAI,gBAAgB,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import type { Provider } from './RampsService.js';\n\n/**\n * Canonicalizes a CAIP-19 asset id for comparison against Ramps API values.\n *\n * CAIP-19 does not constrain the case of the asset reference, and the Ramps API\n * is not consistent about it. Every `eip155` key in `regions/{region}/providers`\n * `supportedCryptoCurrencies` is lowercase, while `regions/{region}/topTokens`\n * returns four mainnet `assetId` values EIP-55 checksummed (USDT, USDC, WBTC,\n * LINK) in both its `topTokens` and `allTokens` lists, with no lowercase\n * duplicate. Callers also supply checksummed ids of their own from other\n * controllers, so the two sides of a comparison can disagree on case for the\n * same asset.\n *\n * Non-EVM references are case-sensitive (Solana base58, Tron base58, bitcoin\n * bech32), so lowercasing is restricted to `eip155` rather than applied to the\n * whole string. This is a tightening: for EVM ids a plain `toLowerCase()` on\n * both sides already matched. Current API data carries non-EVM ids in identical\n * case on both endpoints, so the passthrough guards against future drift rather\n * than fixing an observed mismatch.\n *\n * The namespace itself is matched case-insensitively, so an `EIP155:` prefix\n * is treated as EVM even though CAIP-19 defines namespaces as lowercase.\n *\n * @param assetId - CAIP-19 asset id, in either case form.\n * @returns The asset id in the form the Ramps API uses.\n */\nexport function normalizeRampsAssetId(assetId: string): string {\n const trimmedAssetId = assetId.trim();\n return /^eip155:/iu.test(trimmedAssetId)\n ? trimmedAssetId.toLowerCase()\n : trimmedAssetId;\n}\n\n/**\n * Whether a provider serves the given deposit asset.\n *\n * Mirrors the region-provider matching the controller performs internally: a\n * provider serves the asset when its `supportedCryptoCurrencies` map (keyed by\n * CAIP-19 asset id) contains the asset id. Both sides are canonicalized with\n * {@link normalizeRampsAssetId}, so EVM ids match regardless of checksum\n * casing while non-EVM references stay case-sensitive. A provider without a\n * `supportedCryptoCurrencies` map is treated as not serving the asset.\n *\n * @param provider - The provider to test.\n * @param assetId - CAIP-19 asset id of the deposit asset.\n * @returns Whether the provider serves the asset.\n */\nexport function providerServesAsset(\n provider: Provider,\n assetId: string,\n): boolean {\n const map = provider?.supportedCryptoCurrencies;\n if (!map) {\n return false;\n }\n const target = normalizeRampsAssetId(assetId);\n return Object.keys(map).some(\n (key) => normalizeRampsAssetId(key) === target && map[key],\n );\n}\n\n/**\n * Filters a provider list down to those serving the given deposit asset.\n *\n * @param providers - The providers to filter.\n * @param assetId - CAIP-19 asset id of the deposit asset.\n * @returns The subset of providers serving the asset.\n */\nexport function getProvidersServingAsset(\n providers: Provider[],\n assetId: string,\n): Provider[] {\n return providers.filter((provider) => providerServesAsset(provider, assetId));\n}\n\n/**\n * Whether a region offers a usable on-ramp provider that serves the given\n * deposit asset, under the all-providers feature flag. This is the pure,\n * asset-aware region gate shared between the controller and headless-buy\n * consumers so the two never disagree about eligibility.\n *\n * With `allProvidersEnabled` false the gate is native-only: the region must\n * offer a native provider (e.g. Transak Native) that serves the asset. With\n * `allProvidersEnabled` true the region is supported when any provider\n * (native or aggregator) serves the asset; the controller's flag-aware\n * `getQuotes` performs the precise provider selection at quote time. Fails\n * closed: an empty or missing `assetId` returns `false`.\n *\n * @param options - The options.\n * @param options.providers - The region's providers (native and aggregator).\n * @param options.assetId - CAIP-19 asset id of the deposit asset.\n * @param options.allProvidersEnabled - Whether the all-providers feature flag\n * is enabled (see `isHeadlessAllProvidersEnabled`).\n * @returns Whether the region has a provider serving the asset.\n */\nexport function regionHasProviderForAsset({\n providers,\n assetId,\n allProvidersEnabled,\n}: {\n providers: Provider[];\n assetId: string;\n allProvidersEnabled: boolean;\n}): boolean {\n if (!assetId) {\n return false;\n }\n const serving = getProvidersServingAsset(providers, assetId);\n if (serving.some((provider) => provider.type === 'native')) {\n return true;\n }\n if (!allProvidersEnabled) {\n return false;\n }\n return serving.length > 0;\n}\n\n/**\n * Whether headless fiat deposit is available for the current region, under\n * the all-providers feature flag. Flag-aware and independent of which single\n * provider is currently selected once widened, so the availability gate\n * cannot disagree with the controller's own flag-aware provider pick.\n *\n * With `allProvidersEnabled` false the check keeps the native-only behaviour:\n * a native provider must be the currently selected (preferred) one, since the\n * controller resolves the selected provider first and an aggregator preferred\n * provider would otherwise run a non-native deposit. With\n * `allProvidersEnabled` true the flow is available whenever the region has\n * any provider.\n *\n * @param options - The options.\n * @param options.providers - The region's providers.\n * @param options.selectedProvider - The currently selected provider, if any.\n * @param options.allProvidersEnabled - Whether the all-providers feature flag\n * is enabled (see `isHeadlessAllProvidersEnabled`).\n * @returns Whether headless fiat deposit is available.\n */\nexport function isFiatDepositAvailable({\n providers,\n selectedProvider,\n allProvidersEnabled,\n}: {\n providers: Provider[];\n selectedProvider?: Provider | null;\n allProvidersEnabled: boolean;\n}): boolean {\n if (selectedProvider?.type === 'native') {\n return true;\n }\n if (!allProvidersEnabled) {\n return false;\n }\n return providers.length > 0;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/ramps-controller",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.2.0",
|
|
4
4
|
"description": "A controller for managing cryptocurrency on/off ramps functionality",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@metamask/controller-utils": "^12.3.0",
|
|
61
61
|
"@metamask/messenger": "^2.0.0",
|
|
62
62
|
"@metamask/profile-sync-controller": "^29.0.0",
|
|
63
|
-
"@metamask/remote-feature-flag-controller": "^
|
|
63
|
+
"@metamask/remote-feature-flag-controller": "^6.1.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@metamask/auto-changelog": "^6.1.0",
|