@metamask/ramps-controller 19.0.0 → 20.1.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/dist/RampsController-method-action-types.cjs.map +1 -1
  3. package/dist/RampsController-method-action-types.d.cts +45 -2
  4. package/dist/RampsController-method-action-types.d.cts.map +1 -1
  5. package/dist/RampsController-method-action-types.d.mts +45 -2
  6. package/dist/RampsController-method-action-types.d.mts.map +1 -1
  7. package/dist/RampsController-method-action-types.mjs.map +1 -1
  8. package/dist/RampsController.cjs +230 -20
  9. package/dist/RampsController.cjs.map +1 -1
  10. package/dist/RampsController.d.cts +78 -9
  11. package/dist/RampsController.d.cts.map +1 -1
  12. package/dist/RampsController.d.mts +78 -9
  13. package/dist/RampsController.d.mts.map +1 -1
  14. package/dist/RampsController.mjs +229 -19
  15. package/dist/RampsController.mjs.map +1 -1
  16. package/dist/RampsService.cjs +4 -1
  17. package/dist/RampsService.cjs.map +1 -1
  18. package/dist/RampsService.d.cts +15 -3
  19. package/dist/RampsService.d.cts.map +1 -1
  20. package/dist/RampsService.d.mts +15 -3
  21. package/dist/RampsService.d.mts.map +1 -1
  22. package/dist/RampsService.mjs +4 -1
  23. package/dist/RampsService.mjs.map +1 -1
  24. package/dist/index.cjs +5 -1
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +5 -4
  27. package/dist/index.d.cts.map +1 -1
  28. package/dist/index.d.mts +5 -4
  29. package/dist/index.d.mts.map +1 -1
  30. package/dist/index.mjs +2 -1
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/orderStatus.cjs +34 -0
  33. package/dist/orderStatus.cjs.map +1 -0
  34. package/dist/orderStatus.d.cts +18 -0
  35. package/dist/orderStatus.d.cts.map +1 -0
  36. package/dist/orderStatus.d.mts +18 -0
  37. package/dist/orderStatus.d.mts.map +1 -0
  38. package/dist/orderStatus.mjs +30 -0
  39. package/dist/orderStatus.mjs.map +1 -0
  40. package/dist/paymentMethodMerge.cjs +51 -0
  41. package/dist/paymentMethodMerge.cjs.map +1 -0
  42. package/dist/paymentMethodMerge.d.cts +26 -0
  43. package/dist/paymentMethodMerge.d.cts.map +1 -0
  44. package/dist/paymentMethodMerge.d.mts +26 -0
  45. package/dist/paymentMethodMerge.d.mts.map +1 -0
  46. package/dist/paymentMethodMerge.mjs +46 -0
  47. package/dist/paymentMethodMerge.mjs.map +1 -0
  48. package/dist/providerAvailability.cjs +39 -8
  49. package/dist/providerAvailability.cjs.map +1 -1
  50. package/dist/providerAvailability.d.cts +30 -5
  51. package/dist/providerAvailability.d.cts.map +1 -1
  52. package/dist/providerAvailability.d.mts +30 -5
  53. package/dist/providerAvailability.d.mts.map +1 -1
  54. package/dist/providerAvailability.mjs +37 -7
  55. package/dist/providerAvailability.mjs.map +1 -1
  56. package/package.json +3 -3
@@ -0,0 +1,18 @@
1
+ import { RampsOrderStatus } from "./RampsService.cjs";
2
+ /**
3
+ * Order statuses that no longer require polling or in-flow navigation.
4
+ * Shared by the controller and consuming clients so terminal checks stay in sync.
5
+ */
6
+ export declare const TERMINAL_ORDER_STATUSES: ReadonlySet<RampsOrderStatus>;
7
+ /**
8
+ * Whether a ramps order has reached a terminal status.
9
+ *
10
+ * @param status - The order status to test.
11
+ * @returns Whether the status is terminal.
12
+ */
13
+ export declare function isTerminalOrderStatus(status: RampsOrderStatus): boolean;
14
+ /**
15
+ * Order statuses that are still in progress and may be polled.
16
+ */
17
+ export declare const PENDING_ORDER_STATUSES: ReadonlySet<RampsOrderStatus>;
18
+ //# sourceMappingURL=orderStatus.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orderStatus.d.cts","sourceRoot":"","sources":["../src/orderStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2BAA0B;AAErD;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,gBAAgB,CAKhE,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAEvE;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAAC,gBAAgB,CAK/D,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { RampsOrderStatus } from "./RampsService.mjs";
2
+ /**
3
+ * Order statuses that no longer require polling or in-flow navigation.
4
+ * Shared by the controller and consuming clients so terminal checks stay in sync.
5
+ */
6
+ export declare const TERMINAL_ORDER_STATUSES: ReadonlySet<RampsOrderStatus>;
7
+ /**
8
+ * Whether a ramps order has reached a terminal status.
9
+ *
10
+ * @param status - The order status to test.
11
+ * @returns Whether the status is terminal.
12
+ */
13
+ export declare function isTerminalOrderStatus(status: RampsOrderStatus): boolean;
14
+ /**
15
+ * Order statuses that are still in progress and may be polled.
16
+ */
17
+ export declare const PENDING_ORDER_STATUSES: ReadonlySet<RampsOrderStatus>;
18
+ //# sourceMappingURL=orderStatus.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orderStatus.d.mts","sourceRoot":"","sources":["../src/orderStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2BAA0B;AAErD;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,gBAAgB,CAKhE,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAEvE;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAAC,gBAAgB,CAK/D,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { RampsOrderStatus } from "./RampsService.mjs";
2
+ /**
3
+ * Order statuses that no longer require polling or in-flow navigation.
4
+ * Shared by the controller and consuming clients so terminal checks stay in sync.
5
+ */
6
+ export const TERMINAL_ORDER_STATUSES = new Set([
7
+ RampsOrderStatus.Completed,
8
+ RampsOrderStatus.Failed,
9
+ RampsOrderStatus.Cancelled,
10
+ RampsOrderStatus.IdExpired,
11
+ ]);
12
+ /**
13
+ * Whether a ramps order has reached a terminal status.
14
+ *
15
+ * @param status - The order status to test.
16
+ * @returns Whether the status is terminal.
17
+ */
18
+ export function isTerminalOrderStatus(status) {
19
+ return TERMINAL_ORDER_STATUSES.has(status);
20
+ }
21
+ /**
22
+ * Order statuses that are still in progress and may be polled.
23
+ */
24
+ export const PENDING_ORDER_STATUSES = new Set([
25
+ RampsOrderStatus.Pending,
26
+ RampsOrderStatus.Created,
27
+ RampsOrderStatus.Unknown,
28
+ RampsOrderStatus.Precreated,
29
+ ]);
30
+ //# sourceMappingURL=orderStatus.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orderStatus.mjs","sourceRoot":"","sources":["../src/orderStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2BAA0B;AAErD;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAkC,IAAI,GAAG,CAAC;IAC5E,gBAAgB,CAAC,SAAS;IAC1B,gBAAgB,CAAC,MAAM;IACvB,gBAAgB,CAAC,SAAS;IAC1B,gBAAgB,CAAC,SAAS;CAC3B,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAwB;IAC5D,OAAO,uBAAuB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAkC,IAAI,GAAG,CAAC;IAC3E,gBAAgB,CAAC,OAAO;IACxB,gBAAgB,CAAC,OAAO;IACxB,gBAAgB,CAAC,OAAO;IACxB,gBAAgB,CAAC,UAAU;CAC5B,CAAC,CAAC","sourcesContent":["import { RampsOrderStatus } from './RampsService.js';\n\n/**\n * Order statuses that no longer require polling or in-flow navigation.\n * Shared by the controller and consuming clients so terminal checks stay in sync.\n */\nexport const TERMINAL_ORDER_STATUSES: ReadonlySet<RampsOrderStatus> = new Set([\n RampsOrderStatus.Completed,\n RampsOrderStatus.Failed,\n RampsOrderStatus.Cancelled,\n RampsOrderStatus.IdExpired,\n]);\n\n/**\n * Whether a ramps order has reached a terminal status.\n *\n * @param status - The order status to test.\n * @returns Whether the status is terminal.\n */\nexport function isTerminalOrderStatus(status: RampsOrderStatus): boolean {\n return TERMINAL_ORDER_STATUSES.has(status);\n}\n\n/**\n * Order statuses that are still in progress and may be polled.\n */\nexport const PENDING_ORDER_STATUSES: ReadonlySet<RampsOrderStatus> = new Set([\n RampsOrderStatus.Pending,\n RampsOrderStatus.Created,\n RampsOrderStatus.Unknown,\n RampsOrderStatus.Precreated,\n]);\n"]}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergePaymentMethodsById = exports.pickPaymentMethod = void 0;
4
+ /**
5
+ * Merges payment-method lists from multiple providers into one list keyed by
6
+ * canonical payment method `id`.
7
+ *
8
+ * First seen wins on collision. Payment metadata is provider-invariant: the
9
+ * API serves it from a per-region catalog and the `provider` query narrows
10
+ * that catalog by id-set membership without rewriting fields, so colliding
11
+ * entries carry identical values.
12
+ *
13
+ * Encounter order of first-seen ids is preserved (provider fan-out order).
14
+ *
15
+ * @param lists - Payment method arrays in provider contribution order.
16
+ * @returns Deduped payment methods.
17
+ */
18
+ /**
19
+ * Picks the payment method to select: the first `preferredIds` entry still
20
+ * present in `methods`, otherwise the first method.
21
+ *
22
+ * @param methods - Candidate payment methods, in display order.
23
+ * @param preferredIds - Preferred ids in priority order; falsy ids are skipped.
24
+ * @returns The selection, or null when `methods` is empty.
25
+ */
26
+ function pickPaymentMethod(methods, preferredIds) {
27
+ for (const id of preferredIds) {
28
+ const match = id ? methods.find((method) => method.id === id) : undefined;
29
+ if (match) {
30
+ return match;
31
+ }
32
+ }
33
+ return methods[0] ?? null;
34
+ }
35
+ exports.pickPaymentMethod = pickPaymentMethod;
36
+ function mergePaymentMethodsById(lists) {
37
+ if (lists.length === 1) {
38
+ return lists[0];
39
+ }
40
+ const byId = new Map();
41
+ for (const list of lists) {
42
+ for (const method of list) {
43
+ if (!byId.has(method.id)) {
44
+ byId.set(method.id, { ...method });
45
+ }
46
+ }
47
+ }
48
+ return [...byId.values()];
49
+ }
50
+ exports.mergePaymentMethodsById = mergePaymentMethodsById;
51
+ //# sourceMappingURL=paymentMethodMerge.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paymentMethodMerge.cjs","sourceRoot":"","sources":["../src/paymentMethodMerge.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;GAaG;AACH;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAC/B,OAAwB,EACxB,YAAoC;IAEpC,KAAK,MAAM,EAAE,IAAI,YAAY,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1E,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC5B,CAAC;AAXD,8CAWC;AAED,SAAgB,uBAAuB,CACrC,KAAwB;IAExB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,GAAG,EAAyB,CAAC;IAE9C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,MAAM,MAAM,IAAI,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;gBACzB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAC5B,CAAC;AAlBD,0DAkBC","sourcesContent":["import type { PaymentMethod } from './RampsService.js';\n\n/**\n * Merges payment-method lists from multiple providers into one list keyed by\n * canonical payment method `id`.\n *\n * First seen wins on collision. Payment metadata is provider-invariant: the\n * API serves it from a per-region catalog and the `provider` query narrows\n * that catalog by id-set membership without rewriting fields, so colliding\n * entries carry identical values.\n *\n * Encounter order of first-seen ids is preserved (provider fan-out order).\n *\n * @param lists - Payment method arrays in provider contribution order.\n * @returns Deduped payment methods.\n */\n/**\n * Picks the payment method to select: the first `preferredIds` entry still\n * present in `methods`, otherwise the first method.\n *\n * @param methods - Candidate payment methods, in display order.\n * @param preferredIds - Preferred ids in priority order; falsy ids are skipped.\n * @returns The selection, or null when `methods` is empty.\n */\nexport function pickPaymentMethod(\n methods: PaymentMethod[],\n preferredIds: (string | undefined)[],\n): PaymentMethod | null {\n for (const id of preferredIds) {\n const match = id ? methods.find((method) => method.id === id) : undefined;\n if (match) {\n return match;\n }\n }\n return methods[0] ?? null;\n}\n\nexport function mergePaymentMethodsById(\n lists: PaymentMethod[][],\n): PaymentMethod[] {\n if (lists.length === 1) {\n return lists[0];\n }\n\n const byId = new Map<string, PaymentMethod>();\n\n for (const list of lists) {\n for (const method of list) {\n if (!byId.has(method.id)) {\n byId.set(method.id, { ...method });\n }\n }\n }\n\n return [...byId.values()];\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import type { PaymentMethod } from "./RampsService.cjs";
2
+ /**
3
+ * Merges payment-method lists from multiple providers into one list keyed by
4
+ * canonical payment method `id`.
5
+ *
6
+ * First seen wins on collision. Payment metadata is provider-invariant: the
7
+ * API serves it from a per-region catalog and the `provider` query narrows
8
+ * that catalog by id-set membership without rewriting fields, so colliding
9
+ * entries carry identical values.
10
+ *
11
+ * Encounter order of first-seen ids is preserved (provider fan-out order).
12
+ *
13
+ * @param lists - Payment method arrays in provider contribution order.
14
+ * @returns Deduped payment methods.
15
+ */
16
+ /**
17
+ * Picks the payment method to select: the first `preferredIds` entry still
18
+ * present in `methods`, otherwise the first method.
19
+ *
20
+ * @param methods - Candidate payment methods, in display order.
21
+ * @param preferredIds - Preferred ids in priority order; falsy ids are skipped.
22
+ * @returns The selection, or null when `methods` is empty.
23
+ */
24
+ export declare function pickPaymentMethod(methods: PaymentMethod[], preferredIds: (string | undefined)[]): PaymentMethod | null;
25
+ export declare function mergePaymentMethodsById(lists: PaymentMethod[][]): PaymentMethod[];
26
+ //# sourceMappingURL=paymentMethodMerge.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paymentMethodMerge.d.cts","sourceRoot":"","sources":["../src/paymentMethodMerge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,2BAA0B;AAEvD;;;;;;;;;;;;;GAaG;AACH;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,aAAa,EAAE,EACxB,YAAY,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GACnC,aAAa,GAAG,IAAI,CAQtB;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,aAAa,EAAE,EAAE,GACvB,aAAa,EAAE,CAgBjB"}
@@ -0,0 +1,26 @@
1
+ import type { PaymentMethod } from "./RampsService.mjs";
2
+ /**
3
+ * Merges payment-method lists from multiple providers into one list keyed by
4
+ * canonical payment method `id`.
5
+ *
6
+ * First seen wins on collision. Payment metadata is provider-invariant: the
7
+ * API serves it from a per-region catalog and the `provider` query narrows
8
+ * that catalog by id-set membership without rewriting fields, so colliding
9
+ * entries carry identical values.
10
+ *
11
+ * Encounter order of first-seen ids is preserved (provider fan-out order).
12
+ *
13
+ * @param lists - Payment method arrays in provider contribution order.
14
+ * @returns Deduped payment methods.
15
+ */
16
+ /**
17
+ * Picks the payment method to select: the first `preferredIds` entry still
18
+ * present in `methods`, otherwise the first method.
19
+ *
20
+ * @param methods - Candidate payment methods, in display order.
21
+ * @param preferredIds - Preferred ids in priority order; falsy ids are skipped.
22
+ * @returns The selection, or null when `methods` is empty.
23
+ */
24
+ export declare function pickPaymentMethod(methods: PaymentMethod[], preferredIds: (string | undefined)[]): PaymentMethod | null;
25
+ export declare function mergePaymentMethodsById(lists: PaymentMethod[][]): PaymentMethod[];
26
+ //# sourceMappingURL=paymentMethodMerge.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paymentMethodMerge.d.mts","sourceRoot":"","sources":["../src/paymentMethodMerge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,2BAA0B;AAEvD;;;;;;;;;;;;;GAaG;AACH;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,aAAa,EAAE,EACxB,YAAY,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GACnC,aAAa,GAAG,IAAI,CAQtB;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,aAAa,EAAE,EAAE,GACvB,aAAa,EAAE,CAgBjB"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Merges payment-method lists from multiple providers into one list keyed by
3
+ * canonical payment method `id`.
4
+ *
5
+ * First seen wins on collision. Payment metadata is provider-invariant: the
6
+ * API serves it from a per-region catalog and the `provider` query narrows
7
+ * that catalog by id-set membership without rewriting fields, so colliding
8
+ * entries carry identical values.
9
+ *
10
+ * Encounter order of first-seen ids is preserved (provider fan-out order).
11
+ *
12
+ * @param lists - Payment method arrays in provider contribution order.
13
+ * @returns Deduped payment methods.
14
+ */
15
+ /**
16
+ * Picks the payment method to select: the first `preferredIds` entry still
17
+ * present in `methods`, otherwise the first method.
18
+ *
19
+ * @param methods - Candidate payment methods, in display order.
20
+ * @param preferredIds - Preferred ids in priority order; falsy ids are skipped.
21
+ * @returns The selection, or null when `methods` is empty.
22
+ */
23
+ export function pickPaymentMethod(methods, preferredIds) {
24
+ for (const id of preferredIds) {
25
+ const match = id ? methods.find((method) => method.id === id) : undefined;
26
+ if (match) {
27
+ return match;
28
+ }
29
+ }
30
+ return methods[0] ?? null;
31
+ }
32
+ export function mergePaymentMethodsById(lists) {
33
+ if (lists.length === 1) {
34
+ return lists[0];
35
+ }
36
+ const byId = new Map();
37
+ for (const list of lists) {
38
+ for (const method of list) {
39
+ if (!byId.has(method.id)) {
40
+ byId.set(method.id, { ...method });
41
+ }
42
+ }
43
+ }
44
+ return [...byId.values()];
45
+ }
46
+ //# sourceMappingURL=paymentMethodMerge.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paymentMethodMerge.mjs","sourceRoot":"","sources":["../src/paymentMethodMerge.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAwB,EACxB,YAAoC;IAEpC,KAAK,MAAM,EAAE,IAAI,YAAY,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1E,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,KAAwB;IAExB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,GAAG,EAAyB,CAAC;IAE9C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,MAAM,MAAM,IAAI,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;gBACzB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type { PaymentMethod } from './RampsService.js';\n\n/**\n * Merges payment-method lists from multiple providers into one list keyed by\n * canonical payment method `id`.\n *\n * First seen wins on collision. Payment metadata is provider-invariant: the\n * API serves it from a per-region catalog and the `provider` query narrows\n * that catalog by id-set membership without rewriting fields, so colliding\n * entries carry identical values.\n *\n * Encounter order of first-seen ids is preserved (provider fan-out order).\n *\n * @param lists - Payment method arrays in provider contribution order.\n * @returns Deduped payment methods.\n */\n/**\n * Picks the payment method to select: the first `preferredIds` entry still\n * present in `methods`, otherwise the first method.\n *\n * @param methods - Candidate payment methods, in display order.\n * @param preferredIds - Preferred ids in priority order; falsy ids are skipped.\n * @returns The selection, or null when `methods` is empty.\n */\nexport function pickPaymentMethod(\n methods: PaymentMethod[],\n preferredIds: (string | undefined)[],\n): PaymentMethod | null {\n for (const id of preferredIds) {\n const match = id ? methods.find((method) => method.id === id) : undefined;\n if (match) {\n return match;\n }\n }\n return methods[0] ?? null;\n}\n\nexport function mergePaymentMethodsById(\n lists: PaymentMethod[][],\n): PaymentMethod[] {\n if (lists.length === 1) {\n return lists[0];\n }\n\n const byId = new Map<string, PaymentMethod>();\n\n for (const list of lists) {\n for (const method of list) {\n if (!byId.has(method.id)) {\n byId.set(method.id, { ...method });\n }\n }\n }\n\n return [...byId.values()];\n}\n"]}
@@ -1,16 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFiatDepositAvailable = exports.regionHasProviderForAsset = exports.getProvidersServingAsset = exports.providerServesAsset = void 0;
3
+ exports.isFiatDepositAvailable = exports.regionHasProviderForAsset = exports.getProvidersServingAsset = exports.providerServesAsset = exports.normalizeRampsAssetId = void 0;
4
+ /**
5
+ * Canonicalizes a CAIP-19 asset id for comparison against Ramps API values.
6
+ *
7
+ * CAIP-19 does not constrain the case of the asset reference, and the Ramps API
8
+ * is not consistent about it. Every `eip155` key in `regions/{region}/providers`
9
+ * `supportedCryptoCurrencies` is lowercase, while `regions/{region}/topTokens`
10
+ * returns four mainnet `assetId` values EIP-55 checksummed (USDT, USDC, WBTC,
11
+ * LINK) in both its `topTokens` and `allTokens` lists, with no lowercase
12
+ * duplicate. Callers also supply checksummed ids of their own from other
13
+ * controllers, so the two sides of a comparison can disagree on case for the
14
+ * same asset.
15
+ *
16
+ * Non-EVM references are case-sensitive (Solana base58, Tron base58, bitcoin
17
+ * bech32), so lowercasing is restricted to `eip155` rather than applied to the
18
+ * whole string. This is a tightening: for EVM ids a plain `toLowerCase()` on
19
+ * both sides already matched. Current API data carries non-EVM ids in identical
20
+ * case on both endpoints, so the passthrough guards against future drift rather
21
+ * than fixing an observed mismatch.
22
+ *
23
+ * The namespace itself is matched case-insensitively, so an `EIP155:` prefix
24
+ * is treated as EVM even though CAIP-19 defines namespaces as lowercase.
25
+ *
26
+ * @param assetId - CAIP-19 asset id, in either case form.
27
+ * @returns The asset id in the form the Ramps API uses.
28
+ */
29
+ function normalizeRampsAssetId(assetId) {
30
+ const trimmedAssetId = assetId.trim();
31
+ return /^eip155:/iu.test(trimmedAssetId)
32
+ ? trimmedAssetId.toLowerCase()
33
+ : trimmedAssetId;
34
+ }
35
+ exports.normalizeRampsAssetId = normalizeRampsAssetId;
4
36
  /**
5
37
  * Whether a provider serves the given deposit asset.
6
38
  *
7
39
  * Mirrors the region-provider matching the controller performs internally: a
8
40
  * provider serves the asset when its `supportedCryptoCurrencies` map (keyed by
9
- * CAIP-19 asset id) contains the asset id, compared case-insensitively on both
10
- * sides. EVM CAIP-19 asset ids may arrive checksummed or lowercased and the
11
- * providers API returns both forms, so only the lowercased forms are compared.
12
- * A provider without a `supportedCryptoCurrencies` map is treated as not
13
- * serving the asset.
41
+ * CAIP-19 asset id) contains the asset id. Both sides are canonicalized with
42
+ * {@link normalizeRampsAssetId}, so EVM ids match regardless of checksum
43
+ * casing while non-EVM references stay case-sensitive. A provider without a
44
+ * `supportedCryptoCurrencies` map is treated as not serving the asset.
14
45
  *
15
46
  * @param provider - The provider to test.
16
47
  * @param assetId - CAIP-19 asset id of the deposit asset.
@@ -21,8 +52,8 @@ function providerServesAsset(provider, assetId) {
21
52
  if (!map) {
22
53
  return false;
23
54
  }
24
- const target = assetId.toLowerCase();
25
- return Object.keys(map).some((key) => key.toLowerCase() === target && map[key]);
55
+ const target = normalizeRampsAssetId(assetId);
56
+ return Object.keys(map).some((key) => normalizeRampsAssetId(key) === target && map[key]);
26
57
  }
27
58
  exports.providerServesAsset = providerServesAsset;
28
59
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"providerAvailability.cjs","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;GAcG;AACH,SAAgB,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,OAAO,CAAC,WAAW,EAAE,CAAC;IACrC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAC1B,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAClD,CAAC;AACJ,CAAC;AAZD,kDAYC;AAED;;;;;;GAMG;AACH,SAAgB,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;AALD,4DAKC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,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;AApBD,8DAoBC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,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;AAhBD,wDAgBC","sourcesContent":["import type { Provider } from './RampsService.js';\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, compared case-insensitively on both\n * sides. EVM CAIP-19 asset ids may arrive checksummed or lowercased and the\n * providers API returns both forms, so only the lowercased forms are compared.\n * A provider without a `supportedCryptoCurrencies` map is treated as not\n * 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 = assetId.toLowerCase();\n return Object.keys(map).some(\n (key) => key.toLowerCase() === 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"]}
1
+ {"version":3,"file":"providerAvailability.cjs","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,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;AALD,sDAKC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,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;AAZD,kDAYC;AAED;;;;;;GAMG;AACH,SAAgB,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;AALD,4DAKC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,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;AApBD,8DAoBC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,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;AAhBD,wDAgBC","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"]}
@@ -1,14 +1,39 @@
1
1
  import type { Provider } from "./RampsService.cjs";
2
+ /**
3
+ * Canonicalizes a CAIP-19 asset id for comparison against Ramps API values.
4
+ *
5
+ * CAIP-19 does not constrain the case of the asset reference, and the Ramps API
6
+ * is not consistent about it. Every `eip155` key in `regions/{region}/providers`
7
+ * `supportedCryptoCurrencies` is lowercase, while `regions/{region}/topTokens`
8
+ * returns four mainnet `assetId` values EIP-55 checksummed (USDT, USDC, WBTC,
9
+ * LINK) in both its `topTokens` and `allTokens` lists, with no lowercase
10
+ * duplicate. Callers also supply checksummed ids of their own from other
11
+ * controllers, so the two sides of a comparison can disagree on case for the
12
+ * same asset.
13
+ *
14
+ * Non-EVM references are case-sensitive (Solana base58, Tron base58, bitcoin
15
+ * bech32), so lowercasing is restricted to `eip155` rather than applied to the
16
+ * whole string. This is a tightening: for EVM ids a plain `toLowerCase()` on
17
+ * both sides already matched. Current API data carries non-EVM ids in identical
18
+ * case on both endpoints, so the passthrough guards against future drift rather
19
+ * than fixing an observed mismatch.
20
+ *
21
+ * The namespace itself is matched case-insensitively, so an `EIP155:` prefix
22
+ * is treated as EVM even though CAIP-19 defines namespaces as lowercase.
23
+ *
24
+ * @param assetId - CAIP-19 asset id, in either case form.
25
+ * @returns The asset id in the form the Ramps API uses.
26
+ */
27
+ export declare function normalizeRampsAssetId(assetId: string): string;
2
28
  /**
3
29
  * Whether a provider serves the given deposit asset.
4
30
  *
5
31
  * Mirrors the region-provider matching the controller performs internally: a
6
32
  * provider serves the asset when its `supportedCryptoCurrencies` map (keyed by
7
- * CAIP-19 asset id) contains the asset id, compared case-insensitively on both
8
- * sides. EVM CAIP-19 asset ids may arrive checksummed or lowercased and the
9
- * providers API returns both forms, so only the lowercased forms are compared.
10
- * A provider without a `supportedCryptoCurrencies` map is treated as not
11
- * serving the asset.
33
+ * CAIP-19 asset id) contains the asset id. Both sides are canonicalized with
34
+ * {@link normalizeRampsAssetId}, so EVM ids match regardless of checksum
35
+ * casing while non-EVM references stay case-sensitive. A provider without a
36
+ * `supportedCryptoCurrencies` map is treated as not serving the asset.
12
37
  *
13
38
  * @param provider - The provider to test.
14
39
  * @param assetId - CAIP-19 asset id of the deposit asset.
@@ -1 +1 @@
1
- {"version":3,"file":"providerAvailability.d.cts","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,2BAA0B;AAElD;;;;;;;;;;;;;;GAcG;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
+ {"version":3,"file":"providerAvailability.d.cts","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,14 +1,39 @@
1
1
  import type { Provider } from "./RampsService.mjs";
2
+ /**
3
+ * Canonicalizes a CAIP-19 asset id for comparison against Ramps API values.
4
+ *
5
+ * CAIP-19 does not constrain the case of the asset reference, and the Ramps API
6
+ * is not consistent about it. Every `eip155` key in `regions/{region}/providers`
7
+ * `supportedCryptoCurrencies` is lowercase, while `regions/{region}/topTokens`
8
+ * returns four mainnet `assetId` values EIP-55 checksummed (USDT, USDC, WBTC,
9
+ * LINK) in both its `topTokens` and `allTokens` lists, with no lowercase
10
+ * duplicate. Callers also supply checksummed ids of their own from other
11
+ * controllers, so the two sides of a comparison can disagree on case for the
12
+ * same asset.
13
+ *
14
+ * Non-EVM references are case-sensitive (Solana base58, Tron base58, bitcoin
15
+ * bech32), so lowercasing is restricted to `eip155` rather than applied to the
16
+ * whole string. This is a tightening: for EVM ids a plain `toLowerCase()` on
17
+ * both sides already matched. Current API data carries non-EVM ids in identical
18
+ * case on both endpoints, so the passthrough guards against future drift rather
19
+ * than fixing an observed mismatch.
20
+ *
21
+ * The namespace itself is matched case-insensitively, so an `EIP155:` prefix
22
+ * is treated as EVM even though CAIP-19 defines namespaces as lowercase.
23
+ *
24
+ * @param assetId - CAIP-19 asset id, in either case form.
25
+ * @returns The asset id in the form the Ramps API uses.
26
+ */
27
+ export declare function normalizeRampsAssetId(assetId: string): string;
2
28
  /**
3
29
  * Whether a provider serves the given deposit asset.
4
30
  *
5
31
  * Mirrors the region-provider matching the controller performs internally: a
6
32
  * provider serves the asset when its `supportedCryptoCurrencies` map (keyed by
7
- * CAIP-19 asset id) contains the asset id, compared case-insensitively on both
8
- * sides. EVM CAIP-19 asset ids may arrive checksummed or lowercased and the
9
- * providers API returns both forms, so only the lowercased forms are compared.
10
- * A provider without a `supportedCryptoCurrencies` map is treated as not
11
- * serving the asset.
33
+ * CAIP-19 asset id) contains the asset id. Both sides are canonicalized with
34
+ * {@link normalizeRampsAssetId}, so EVM ids match regardless of checksum
35
+ * casing while non-EVM references stay case-sensitive. A provider without a
36
+ * `supportedCryptoCurrencies` map is treated as not serving the asset.
12
37
  *
13
38
  * @param provider - The provider to test.
14
39
  * @param assetId - CAIP-19 asset id of the deposit asset.
@@ -1 +1 @@
1
- {"version":3,"file":"providerAvailability.d.mts","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,2BAA0B;AAElD;;;;;;;;;;;;;;GAcG;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
+ {"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, compared case-insensitively on both
7
- * sides. EVM CAIP-19 asset ids may arrive checksummed or lowercased and the
8
- * providers API returns both forms, so only the lowercased forms are compared.
9
- * A provider without a `supportedCryptoCurrencies` map is treated as not
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.toLowerCase();
22
- return Object.keys(map).some((key) => key.toLowerCase() === target && map[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;;;;;;;;;;;;;;GAcG;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,OAAO,CAAC,WAAW,EAAE,CAAC;IACrC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAC1B,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAClD,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 * 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, compared case-insensitively on both\n * sides. EVM CAIP-19 asset ids may arrive checksummed or lowercased and the\n * providers API returns both forms, so only the lowercased forms are compared.\n * A provider without a `supportedCryptoCurrencies` map is treated as not\n * 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 = assetId.toLowerCase();\n return Object.keys(map).some(\n (key) => key.toLowerCase() === 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"]}
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": "19.0.0",
3
+ "version": "20.1.0",
4
4
  "description": "A controller for managing cryptocurrency on/off ramps functionality",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -59,8 +59,8 @@
59
59
  "@metamask/base-controller": "^9.1.0",
60
60
  "@metamask/controller-utils": "^12.3.0",
61
61
  "@metamask/messenger": "^2.0.0",
62
- "@metamask/profile-sync-controller": "^28.3.0",
63
- "@metamask/remote-feature-flag-controller": "^5.0.0"
62
+ "@metamask/profile-sync-controller": "^29.0.0",
63
+ "@metamask/remote-feature-flag-controller": "^6.1.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@metamask/auto-changelog": "^6.1.0",