@metamask/ramps-controller 20.2.0 → 20.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 +14 -1
- package/dist/NeoBankService-method-action-types.cjs +7 -0
- package/dist/NeoBankService-method-action-types.cjs.map +1 -0
- package/dist/NeoBankService-method-action-types.d.cts +126 -0
- package/dist/NeoBankService-method-action-types.d.cts.map +1 -0
- package/dist/NeoBankService-method-action-types.d.mts +126 -0
- package/dist/NeoBankService-method-action-types.d.mts.map +1 -0
- package/dist/NeoBankService-method-action-types.mjs +6 -0
- package/dist/NeoBankService-method-action-types.mjs.map +1 -0
- package/dist/NeoBankService.cjs +387 -0
- package/dist/NeoBankService.cjs.map +1 -0
- package/dist/NeoBankService.d.cts +191 -0
- package/dist/NeoBankService.d.cts.map +1 -0
- package/dist/NeoBankService.d.mts +191 -0
- package/dist/NeoBankService.d.mts.map +1 -0
- package/dist/NeoBankService.mjs +379 -0
- package/dist/NeoBankService.mjs.map +1 -0
- package/dist/RampsController-method-action-types.cjs.map +1 -1
- package/dist/RampsController-method-action-types.d.cts +91 -1
- package/dist/RampsController-method-action-types.d.cts.map +1 -1
- package/dist/RampsController-method-action-types.d.mts +91 -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 +372 -2
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +152 -5
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +152 -5
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +371 -1
- package/dist/RampsController.mjs.map +1 -1
- package/dist/autoramp-types.cjs +3 -0
- package/dist/autoramp-types.cjs.map +1 -0
- package/dist/autoramp-types.d.cts +22 -0
- package/dist/autoramp-types.d.cts.map +1 -0
- package/dist/autoramp-types.d.mts +22 -0
- package/dist/autoramp-types.d.mts.map +1 -0
- package/dist/autoramp-types.mjs +2 -0
- package/dist/autoramp-types.mjs.map +1 -0
- package/dist/autorampAccount.cjs +155 -0
- package/dist/autorampAccount.cjs.map +1 -0
- package/dist/autorampAccount.d.cts +126 -0
- package/dist/autorampAccount.d.cts.map +1 -0
- package/dist/autorampAccount.d.mts +126 -0
- package/dist/autorampAccount.d.mts.map +1 -0
- package/dist/autorampAccount.mjs +147 -0
- package/dist/autorampAccount.mjs.map +1 -0
- package/dist/index.cjs +20 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +12 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/dist/ownership-message.cjs +26 -0
- package/dist/ownership-message.cjs.map +1 -0
- package/dist/ownership-message.d.cts +22 -0
- package/dist/ownership-message.d.cts.map +1 -0
- package/dist/ownership-message.d.mts +22 -0
- package/dist/ownership-message.d.mts.map +1 -0
- package/dist/ownership-message.mjs +22 -0
- package/dist/ownership-message.mjs.map +1 -0
- package/dist/wallet-registration-machine.cjs +144 -0
- package/dist/wallet-registration-machine.cjs.map +1 -0
- package/dist/wallet-registration-machine.d.cts +81 -0
- package/dist/wallet-registration-machine.d.cts.map +1 -0
- package/dist/wallet-registration-machine.d.mts +81 -0
- package/dist/wallet-registration-machine.d.mts.map +1 -0
- package/dist/wallet-registration-machine.mjs +139 -0
- package/dist/wallet-registration-machine.mjs.map +1 -0
- package/dist/wallet-registration-service.cjs +351 -0
- package/dist/wallet-registration-service.cjs.map +1 -0
- package/dist/wallet-registration-service.d.cts +144 -0
- package/dist/wallet-registration-service.d.cts.map +1 -0
- package/dist/wallet-registration-service.d.mts +144 -0
- package/dist/wallet-registration-service.d.mts.map +1 -0
- package/dist/wallet-registration-service.mjs +344 -0
- package/dist/wallet-registration-service.mjs.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
3
|
+
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
|
4
|
+
import type { AutorampRemoteSnapshot } from "./autoramp-types.mjs";
|
|
5
|
+
import type { NeoBankServiceMethodActions } from "./NeoBankService-method-action-types.mjs";
|
|
6
|
+
import { RampsEnvironment } from "./RampsService.mjs";
|
|
7
|
+
import type { RegistrationOutcome, RegistrationStatus } from "./wallet-registration-service.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* Name of the NeoBankService messenger namespace.
|
|
10
|
+
*/
|
|
11
|
+
export declare const serviceName = "NeoBankService";
|
|
12
|
+
/**
|
|
13
|
+
* Raw autoramp payload from the MetaMask Ramp API neo-bank proxy.
|
|
14
|
+
* Shape mirrors MoonPay Enterprise `GET /api/autoramps/{autoramp_id}`.
|
|
15
|
+
* The Ramp API handles partner auth / headers; the client only sends the
|
|
16
|
+
* MetaMask bearer token.
|
|
17
|
+
*/
|
|
18
|
+
export type NeoBankAutorampResponse = {
|
|
19
|
+
id: string;
|
|
20
|
+
customer_id?: string;
|
|
21
|
+
status: string;
|
|
22
|
+
/**
|
|
23
|
+
* Destination wallet when present on the proxy response.
|
|
24
|
+
* Field name may evolve with the Ramp API contract.
|
|
25
|
+
*/
|
|
26
|
+
wallet_address?: string;
|
|
27
|
+
recipient_account?: {
|
|
28
|
+
address?: string;
|
|
29
|
+
};
|
|
30
|
+
deposit_rails?: unknown[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Optional headers for neo-bank mutating requests.
|
|
34
|
+
*/
|
|
35
|
+
export type NeoBankRequestOptions = {
|
|
36
|
+
/**
|
|
37
|
+
* Forwarded as `Idempotency-Key` when set (MoonPay requires it on some POSTs;
|
|
38
|
+
* neobank-proxy generates one when omitted).
|
|
39
|
+
*/
|
|
40
|
+
idempotencyKey?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Query string values accepted by neo-bank GET helpers.
|
|
44
|
+
*/
|
|
45
|
+
export type NeoBankQueryParams = Record<string, string | number | boolean | undefined | null>;
|
|
46
|
+
export type GetWalletRegistrationStatusParams = {
|
|
47
|
+
customerId: string;
|
|
48
|
+
address: string;
|
|
49
|
+
};
|
|
50
|
+
export type RegisterSelfHostedWalletParams = {
|
|
51
|
+
customerId: string;
|
|
52
|
+
address: string;
|
|
53
|
+
message: string;
|
|
54
|
+
signature: string;
|
|
55
|
+
/**
|
|
56
|
+
* Forwarded as `Idempotency-Key` on the neobank-proxy POST. Prefer a stable
|
|
57
|
+
* key across retries of the same ownership body.
|
|
58
|
+
*/
|
|
59
|
+
idempotencyKey?: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Actions that {@link NeoBankService} exposes to other consumers.
|
|
63
|
+
*/
|
|
64
|
+
export type NeoBankServiceActions = NeoBankServiceMethodActions;
|
|
65
|
+
type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerTokenAction | AuthenticationController.AuthenticationControllerGetSessionProfileAction;
|
|
66
|
+
export type NeoBankServiceEvents = never;
|
|
67
|
+
type AllowedEvents = never;
|
|
68
|
+
/**
|
|
69
|
+
* The messenger restricted to actions and events accessed by
|
|
70
|
+
* {@link NeoBankService}.
|
|
71
|
+
*/
|
|
72
|
+
export type NeoBankServiceMessenger = Messenger<typeof serviceName, NeoBankServiceActions | AllowedActions, NeoBankServiceEvents | AllowedEvents>;
|
|
73
|
+
/**
|
|
74
|
+
* Maps a Ramp API / MoonPay-shaped autoramp response into the local remote snapshot.
|
|
75
|
+
*
|
|
76
|
+
* @param response - Proxy response body.
|
|
77
|
+
* @returns Snapshot for the controller last-seen cursor.
|
|
78
|
+
*/
|
|
79
|
+
export declare function mapNeoBankAutorampToRemoteSnapshot(response: NeoBankAutorampResponse): AutorampRemoteSnapshot;
|
|
80
|
+
/**
|
|
81
|
+
* Client for MetaMask Ramp API neo-bank endpoints (MoonPay Enterprise proxy).
|
|
82
|
+
*
|
|
83
|
+
* Lives alongside {@link RampsService} and {@link TransakService}. Authentication
|
|
84
|
+
* and MoonPay partner headers are handled by the Ramp API; this service only
|
|
85
|
+
* attaches the MetaMask user bearer token.
|
|
86
|
+
*
|
|
87
|
+
* Paths use the neobank-proxy `/neobank` prefix on the on-ramp.api host.
|
|
88
|
+
*/
|
|
89
|
+
export declare class NeoBankService {
|
|
90
|
+
#private;
|
|
91
|
+
readonly name: typeof serviceName;
|
|
92
|
+
constructor({ messenger, environment, context, fetch: fetchFunction, policyOptions, baseUrlOverride, }: {
|
|
93
|
+
messenger: NeoBankServiceMessenger;
|
|
94
|
+
environment?: RampsEnvironment;
|
|
95
|
+
context: string;
|
|
96
|
+
fetch: typeof fetch;
|
|
97
|
+
policyOptions?: CreateServicePolicyOptions;
|
|
98
|
+
baseUrlOverride?: string;
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Fetches an autoramp account via neobank-proxy
|
|
102
|
+
* `GET /neobank/autoramps/{autoramp_id}` (MoonPay
|
|
103
|
+
* `GET /api/autoramps/{autoramp_id}`).
|
|
104
|
+
*
|
|
105
|
+
* @param autorampId - MoonPay / Ramp API autoramp id.
|
|
106
|
+
* @returns Remote snapshot for controller apply/refresh.
|
|
107
|
+
*/
|
|
108
|
+
getAutoramp(autorampId: string): Promise<AutorampRemoteSnapshot>;
|
|
109
|
+
/**
|
|
110
|
+
* Registers a Pix address via neobank-proxy `POST /neobank/addresses/pix`.
|
|
111
|
+
* Body is forwarded as opaque JSON (MoonPay address schema).
|
|
112
|
+
*
|
|
113
|
+
* @param body - Pix address registration payload.
|
|
114
|
+
* @param options - Optional idempotency key.
|
|
115
|
+
* @returns Parsed proxy JSON response.
|
|
116
|
+
*/
|
|
117
|
+
registerPixAddress(body: Record<string, unknown>, options?: NeoBankRequestOptions): Promise<unknown>;
|
|
118
|
+
/**
|
|
119
|
+
* Fetches an autoramp quote via neobank-proxy `GET /neobank/autoramps/quote`.
|
|
120
|
+
*
|
|
121
|
+
* @param query - Quote query params (forwarded as-is).
|
|
122
|
+
* @returns Parsed proxy JSON response.
|
|
123
|
+
*/
|
|
124
|
+
getAutorampQuote(query?: NeoBankQueryParams): Promise<unknown>;
|
|
125
|
+
/**
|
|
126
|
+
* Creates an autoramp from a signed quote via neobank-proxy
|
|
127
|
+
* `POST /neobank/autoramps` (MoonPay `POST /api/autoramps`).
|
|
128
|
+
*
|
|
129
|
+
* @param body - CreateAutoramp / signed-quote payload (forwarded as-is).
|
|
130
|
+
* @param options - Optional idempotency key.
|
|
131
|
+
* @returns Remote snapshot for controller apply/refresh.
|
|
132
|
+
*/
|
|
133
|
+
createAutoramp(body: Record<string, unknown>, options?: NeoBankRequestOptions): Promise<AutorampRemoteSnapshot>;
|
|
134
|
+
/**
|
|
135
|
+
* Fetches a quote for an existing autoramp via neobank-proxy
|
|
136
|
+
* `GET /neobank/autoramps/{autoramp_id}/quote`.
|
|
137
|
+
*
|
|
138
|
+
* @param autorampId - Autoramp id.
|
|
139
|
+
* @param query - Quote query params (forwarded as-is).
|
|
140
|
+
* @returns Parsed proxy JSON response.
|
|
141
|
+
*/
|
|
142
|
+
getAutorampQuoteForAutoramp(autorampId: string, query?: NeoBankQueryParams): Promise<unknown>;
|
|
143
|
+
/**
|
|
144
|
+
* Attaches a signed quote to an autoramp via neobank-proxy
|
|
145
|
+
* `POST /neobank/autoramps/{autoramp_id}/quotes`.
|
|
146
|
+
*
|
|
147
|
+
* @param autorampId - Autoramp id.
|
|
148
|
+
* @param body - Quote attachment payload (forwarded as-is).
|
|
149
|
+
* @param options - Optional idempotency key.
|
|
150
|
+
* @returns Parsed proxy JSON response.
|
|
151
|
+
*/
|
|
152
|
+
attachAutorampQuote(autorampId: string, body: Record<string, unknown>, options?: NeoBankRequestOptions): Promise<unknown>;
|
|
153
|
+
/**
|
|
154
|
+
* Fetches a customer by partner external id via neobank-proxy
|
|
155
|
+
* `GET /neobank/customers/{external_id}/external`.
|
|
156
|
+
*
|
|
157
|
+
* @param externalId - Partner-assigned external customer id.
|
|
158
|
+
* @returns Parsed proxy JSON response.
|
|
159
|
+
*/
|
|
160
|
+
getCustomerByExternalId(externalId: string): Promise<unknown>;
|
|
161
|
+
/**
|
|
162
|
+
* Resolves Iron's internal customer id via neobank-proxy customer lookup,
|
|
163
|
+
* using the MetaMask canonical profile id as the partner `external_id`.
|
|
164
|
+
*
|
|
165
|
+
* @returns Iron's internal customer id.
|
|
166
|
+
*/
|
|
167
|
+
getMoonpayCustomerId(): Promise<string>;
|
|
168
|
+
/**
|
|
169
|
+
* Checks whether a Monad Money Account address is already registered for the
|
|
170
|
+
* given Iron customer.
|
|
171
|
+
*
|
|
172
|
+
* @param params - Customer id and address to check.
|
|
173
|
+
* @param params.customerId - Iron / MoonPay customer UUID.
|
|
174
|
+
* @param params.address - Money Account address.
|
|
175
|
+
* @returns Active, disabled, or absent registration status.
|
|
176
|
+
*/
|
|
177
|
+
getWalletRegistrationStatus({ customerId, address, }: GetWalletRegistrationStatusParams): Promise<RegistrationStatus>;
|
|
178
|
+
/**
|
|
179
|
+
* Submits a signed Monad Money Account ownership proof via neobank-proxy
|
|
180
|
+
* `POST /neobank/addresses/crypto/selfhosted`.
|
|
181
|
+
*
|
|
182
|
+
* @param params - Signed ownership proof.
|
|
183
|
+
* @returns Registered wallet record.
|
|
184
|
+
*/
|
|
185
|
+
registerSelfHostedWallet(params: RegisterSelfHostedWalletParams): Promise<RegistrationOutcome>;
|
|
186
|
+
onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): ReturnType<ServicePolicy['onRetry']>;
|
|
187
|
+
onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): ReturnType<ServicePolicy['onBreak']>;
|
|
188
|
+
onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]): ReturnType<ServicePolicy['onDegraded']>;
|
|
189
|
+
}
|
|
190
|
+
export {};
|
|
191
|
+
//# sourceMappingURL=NeoBankService.d.mts.map
|
|
@@ -0,0 +1 @@
|
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AC,CAAC,CAAC,CAAC,GACnD,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;CAG3C"}
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _NeoBankService_instances, _NeoBankService_messenger, _NeoBankService_fetch, _NeoBankService_policy, _NeoBankService_noRetryPolicy, _NeoBankService_environment, _NeoBankService_context, _NeoBankService_baseUrlOverride, _NeoBankService_walletRegistrationService, _NeoBankService_getBaseUrl, _NeoBankService_getWalletRegistrationService, _NeoBankService_getRequestHeaders, _NeoBankService_buildUrl, _NeoBankService_throwHttpError, _NeoBankService_getJson, _NeoBankService_postJson, _NeoBankService_mapAutorampResponse, _NeoBankService_getCanonicalExternalId;
|
|
13
|
+
import { createServicePolicy, handleWhen, HttpError } from "@metamask/controller-utils";
|
|
14
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
15
|
+
import { RAMPS_SDK_VERSION, RampsEnvironment } from "./RampsService.mjs";
|
|
16
|
+
import { WalletRegistrationService } from "./wallet-registration-service.mjs";
|
|
17
|
+
/**
|
|
18
|
+
* Name of the NeoBankService messenger namespace.
|
|
19
|
+
*/
|
|
20
|
+
export const serviceName = 'NeoBankService';
|
|
21
|
+
/**
|
|
22
|
+
* Determines whether a failed neo-bank request is worth re-issuing.
|
|
23
|
+
*
|
|
24
|
+
* 4xx responses describe the request or the account's state (e.g. 403
|
|
25
|
+
* "Customer is not active", 422 validation), so repeating them only multiplies
|
|
26
|
+
* the same rejection. 429 stays retryable alongside 5xx and non-HTTP
|
|
27
|
+
* network/timeout errors.
|
|
28
|
+
*
|
|
29
|
+
* @param error - Error thrown while performing the request.
|
|
30
|
+
* @returns `true` when the error is worth retrying.
|
|
31
|
+
*/
|
|
32
|
+
function isRetryableError(error) {
|
|
33
|
+
if (error instanceof HttpError) {
|
|
34
|
+
if (error.httpStatus === 429) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return error.httpStatus < 400 || error.httpStatus >= 500;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
42
|
+
'getAutoramp',
|
|
43
|
+
'registerPixAddress',
|
|
44
|
+
'getAutorampQuote',
|
|
45
|
+
'createAutoramp',
|
|
46
|
+
'getAutorampQuoteForAutoramp',
|
|
47
|
+
'attachAutorampQuote',
|
|
48
|
+
'getCustomerByExternalId',
|
|
49
|
+
'getMoonpayCustomerId',
|
|
50
|
+
'getWalletRegistrationStatus',
|
|
51
|
+
'registerSelfHostedWallet',
|
|
52
|
+
];
|
|
53
|
+
/**
|
|
54
|
+
* Builds a path under the neobank-proxy global prefix.
|
|
55
|
+
*
|
|
56
|
+
* Live neobank-proxy (#1124) mounts routes at `/neobank` on the on-ramp.api
|
|
57
|
+
* host (ALB path routing, no rewrite). Prefer this over `/api/v2/...` so Core
|
|
58
|
+
* matches the proxy that ships.
|
|
59
|
+
*
|
|
60
|
+
* @param path - Path under `/neobank` (no leading slash).
|
|
61
|
+
* @returns Absolute path segment for URL join against the Ramp API host.
|
|
62
|
+
*/
|
|
63
|
+
function getNeoBankPath(path) {
|
|
64
|
+
return `neobank/${path.replace(/^\//u, '')}`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Resolves the Ramp API host for neo-bank calls (same hosts as {@link RampsService}).
|
|
68
|
+
*
|
|
69
|
+
* @param environment - Ramp environment.
|
|
70
|
+
* @returns Base URL.
|
|
71
|
+
*/
|
|
72
|
+
function getBaseUrl(environment) {
|
|
73
|
+
switch (environment) {
|
|
74
|
+
case RampsEnvironment.Production:
|
|
75
|
+
return 'https://on-ramp.api.cx.metamask.io';
|
|
76
|
+
case RampsEnvironment.Staging:
|
|
77
|
+
return 'https://on-ramp.uat-api.cx.metamask.io';
|
|
78
|
+
case RampsEnvironment.Development:
|
|
79
|
+
return 'https://on-ramp.dev-api.cx.metamask.io';
|
|
80
|
+
case RampsEnvironment.Local:
|
|
81
|
+
return 'http://localhost:3000';
|
|
82
|
+
default:
|
|
83
|
+
throw new Error(`Invalid environment: ${String(environment)}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Maps a Ramp API / MoonPay-shaped autoramp response into the local remote snapshot.
|
|
88
|
+
*
|
|
89
|
+
* @param response - Proxy response body.
|
|
90
|
+
* @returns Snapshot for the controller last-seen cursor.
|
|
91
|
+
*/
|
|
92
|
+
export function mapNeoBankAutorampToRemoteSnapshot(response) {
|
|
93
|
+
const depositRails = response.deposit_rails;
|
|
94
|
+
const hasDepositRails = Array.isArray(depositRails) && depositRails.length > 0;
|
|
95
|
+
const depositRailsSummary = hasDepositRails || response.status === 'Approved'
|
|
96
|
+
? {
|
|
97
|
+
ready: response.status === 'Approved' && hasDepositRails,
|
|
98
|
+
}
|
|
99
|
+
: undefined;
|
|
100
|
+
return {
|
|
101
|
+
id: response.id,
|
|
102
|
+
customerId: response.customer_id,
|
|
103
|
+
walletAddress: response.wallet_address !== undefined &&
|
|
104
|
+
response.wallet_address.length > 0
|
|
105
|
+
? response.wallet_address
|
|
106
|
+
: response.recipient_account?.address,
|
|
107
|
+
status: response.status,
|
|
108
|
+
depositRailsSummary,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Client for MetaMask Ramp API neo-bank endpoints (MoonPay Enterprise proxy).
|
|
113
|
+
*
|
|
114
|
+
* Lives alongside {@link RampsService} and {@link TransakService}. Authentication
|
|
115
|
+
* and MoonPay partner headers are handled by the Ramp API; this service only
|
|
116
|
+
* attaches the MetaMask user bearer token.
|
|
117
|
+
*
|
|
118
|
+
* Paths use the neobank-proxy `/neobank` prefix on the on-ramp.api host.
|
|
119
|
+
*/
|
|
120
|
+
export class NeoBankService {
|
|
121
|
+
constructor({ messenger, environment = RampsEnvironment.Staging, context, fetch: fetchFunction, policyOptions = {}, baseUrlOverride, }) {
|
|
122
|
+
_NeoBankService_instances.add(this);
|
|
123
|
+
_NeoBankService_messenger.set(this, void 0);
|
|
124
|
+
_NeoBankService_fetch.set(this, void 0);
|
|
125
|
+
_NeoBankService_policy.set(this, void 0);
|
|
126
|
+
_NeoBankService_noRetryPolicy.set(this, void 0);
|
|
127
|
+
_NeoBankService_environment.set(this, void 0);
|
|
128
|
+
_NeoBankService_context.set(this, void 0);
|
|
129
|
+
_NeoBankService_baseUrlOverride.set(this, void 0);
|
|
130
|
+
_NeoBankService_walletRegistrationService.set(this, void 0);
|
|
131
|
+
this.name = serviceName;
|
|
132
|
+
__classPrivateFieldSet(this, _NeoBankService_messenger, messenger, "f");
|
|
133
|
+
__classPrivateFieldSet(this, _NeoBankService_fetch, fetchFunction, "f");
|
|
134
|
+
__classPrivateFieldSet(this, _NeoBankService_policy, createServicePolicy({
|
|
135
|
+
retryFilterPolicy: handleWhen(isRetryableError),
|
|
136
|
+
...policyOptions,
|
|
137
|
+
}), "f");
|
|
138
|
+
__classPrivateFieldSet(this, _NeoBankService_noRetryPolicy, createServicePolicy({
|
|
139
|
+
retryFilterPolicy: handleWhen(isRetryableError),
|
|
140
|
+
...policyOptions,
|
|
141
|
+
maxRetries: 0,
|
|
142
|
+
}), "f");
|
|
143
|
+
__classPrivateFieldSet(this, _NeoBankService_environment, environment, "f");
|
|
144
|
+
__classPrivateFieldSet(this, _NeoBankService_context, context, "f");
|
|
145
|
+
__classPrivateFieldSet(this, _NeoBankService_baseUrlOverride, baseUrlOverride, "f");
|
|
146
|
+
__classPrivateFieldGet(this, _NeoBankService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Fetches an autoramp account via neobank-proxy
|
|
150
|
+
* `GET /neobank/autoramps/{autoramp_id}` (MoonPay
|
|
151
|
+
* `GET /api/autoramps/{autoramp_id}`).
|
|
152
|
+
*
|
|
153
|
+
* @param autorampId - MoonPay / Ramp API autoramp id.
|
|
154
|
+
* @returns Remote snapshot for controller apply/refresh.
|
|
155
|
+
*/
|
|
156
|
+
async getAutoramp(autorampId) {
|
|
157
|
+
const response = await __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getJson).call(this, `autoramps/${encodeURIComponent(autorampId)}`);
|
|
158
|
+
return __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_mapAutorampResponse).call(this, response);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Registers a Pix address via neobank-proxy `POST /neobank/addresses/pix`.
|
|
162
|
+
* Body is forwarded as opaque JSON (MoonPay address schema).
|
|
163
|
+
*
|
|
164
|
+
* @param body - Pix address registration payload.
|
|
165
|
+
* @param options - Optional idempotency key.
|
|
166
|
+
* @returns Parsed proxy JSON response.
|
|
167
|
+
*/
|
|
168
|
+
async registerPixAddress(body, options = {}) {
|
|
169
|
+
return __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_postJson).call(this, 'addresses/pix', body, options);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Fetches an autoramp quote via neobank-proxy `GET /neobank/autoramps/quote`.
|
|
173
|
+
*
|
|
174
|
+
* @param query - Quote query params (forwarded as-is).
|
|
175
|
+
* @returns Parsed proxy JSON response.
|
|
176
|
+
*/
|
|
177
|
+
async getAutorampQuote(query = {}) {
|
|
178
|
+
return __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getJson).call(this, 'autoramps/quote', query);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Creates an autoramp from a signed quote via neobank-proxy
|
|
182
|
+
* `POST /neobank/autoramps` (MoonPay `POST /api/autoramps`).
|
|
183
|
+
*
|
|
184
|
+
* @param body - CreateAutoramp / signed-quote payload (forwarded as-is).
|
|
185
|
+
* @param options - Optional idempotency key.
|
|
186
|
+
* @returns Remote snapshot for controller apply/refresh.
|
|
187
|
+
*/
|
|
188
|
+
async createAutoramp(body, options = {}) {
|
|
189
|
+
const response = await __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_postJson).call(this, 'autoramps', body, options);
|
|
190
|
+
return __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_mapAutorampResponse).call(this, response);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Fetches a quote for an existing autoramp via neobank-proxy
|
|
194
|
+
* `GET /neobank/autoramps/{autoramp_id}/quote`.
|
|
195
|
+
*
|
|
196
|
+
* @param autorampId - Autoramp id.
|
|
197
|
+
* @param query - Quote query params (forwarded as-is).
|
|
198
|
+
* @returns Parsed proxy JSON response.
|
|
199
|
+
*/
|
|
200
|
+
async getAutorampQuoteForAutoramp(autorampId, query = {}) {
|
|
201
|
+
return __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getJson).call(this, `autoramps/${encodeURIComponent(autorampId)}/quote`, query);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Attaches a signed quote to an autoramp via neobank-proxy
|
|
205
|
+
* `POST /neobank/autoramps/{autoramp_id}/quotes`.
|
|
206
|
+
*
|
|
207
|
+
* @param autorampId - Autoramp id.
|
|
208
|
+
* @param body - Quote attachment payload (forwarded as-is).
|
|
209
|
+
* @param options - Optional idempotency key.
|
|
210
|
+
* @returns Parsed proxy JSON response.
|
|
211
|
+
*/
|
|
212
|
+
async attachAutorampQuote(autorampId, body, options = {}) {
|
|
213
|
+
return __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_postJson).call(this, `autoramps/${encodeURIComponent(autorampId)}/quotes`, body, options);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Fetches a customer by partner external id via neobank-proxy
|
|
217
|
+
* `GET /neobank/customers/{external_id}/external`.
|
|
218
|
+
*
|
|
219
|
+
* @param externalId - Partner-assigned external customer id.
|
|
220
|
+
* @returns Parsed proxy JSON response.
|
|
221
|
+
*/
|
|
222
|
+
async getCustomerByExternalId(externalId) {
|
|
223
|
+
return __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getJson).call(this, `customers/${encodeURIComponent(externalId)}/external`);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Resolves Iron's internal customer id via neobank-proxy customer lookup,
|
|
227
|
+
* using the MetaMask canonical profile id as the partner `external_id`.
|
|
228
|
+
*
|
|
229
|
+
* @returns Iron's internal customer id.
|
|
230
|
+
*/
|
|
231
|
+
async getMoonpayCustomerId() {
|
|
232
|
+
return await __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getWalletRegistrationService).call(this).getMoonpayCustomerId();
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Checks whether a Monad Money Account address is already registered for the
|
|
236
|
+
* given Iron customer.
|
|
237
|
+
*
|
|
238
|
+
* @param params - Customer id and address to check.
|
|
239
|
+
* @param params.customerId - Iron / MoonPay customer UUID.
|
|
240
|
+
* @param params.address - Money Account address.
|
|
241
|
+
* @returns Active, disabled, or absent registration status.
|
|
242
|
+
*/
|
|
243
|
+
async getWalletRegistrationStatus({ customerId, address, }) {
|
|
244
|
+
return await __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getWalletRegistrationService).call(this).getRegistrationStatus({
|
|
245
|
+
customerId,
|
|
246
|
+
address,
|
|
247
|
+
blockchain: 'Monad',
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Submits a signed Monad Money Account ownership proof via neobank-proxy
|
|
252
|
+
* `POST /neobank/addresses/crypto/selfhosted`.
|
|
253
|
+
*
|
|
254
|
+
* @param params - Signed ownership proof.
|
|
255
|
+
* @returns Registered wallet record.
|
|
256
|
+
*/
|
|
257
|
+
async registerSelfHostedWallet(params) {
|
|
258
|
+
return await __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getWalletRegistrationService).call(this).registerSelfHostedWallet({
|
|
259
|
+
...params,
|
|
260
|
+
blockchain: 'Monad',
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
onRetry(listener) {
|
|
264
|
+
return __classPrivateFieldGet(this, _NeoBankService_policy, "f").onRetry(listener);
|
|
265
|
+
}
|
|
266
|
+
onBreak(listener) {
|
|
267
|
+
return __classPrivateFieldGet(this, _NeoBankService_policy, "f").onBreak(listener);
|
|
268
|
+
}
|
|
269
|
+
onDegraded(listener) {
|
|
270
|
+
return __classPrivateFieldGet(this, _NeoBankService_policy, "f").onDegraded(listener);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
_NeoBankService_messenger = new WeakMap(), _NeoBankService_fetch = new WeakMap(), _NeoBankService_policy = new WeakMap(), _NeoBankService_noRetryPolicy = new WeakMap(), _NeoBankService_environment = new WeakMap(), _NeoBankService_context = new WeakMap(), _NeoBankService_baseUrlOverride = new WeakMap(), _NeoBankService_walletRegistrationService = new WeakMap(), _NeoBankService_instances = new WeakSet(), _NeoBankService_getBaseUrl = function _NeoBankService_getBaseUrl() {
|
|
274
|
+
if (__classPrivateFieldGet(this, _NeoBankService_baseUrlOverride, "f")) {
|
|
275
|
+
return __classPrivateFieldGet(this, _NeoBankService_baseUrlOverride, "f");
|
|
276
|
+
}
|
|
277
|
+
return getBaseUrl(__classPrivateFieldGet(this, _NeoBankService_environment, "f"));
|
|
278
|
+
}, _NeoBankService_getWalletRegistrationService = function _NeoBankService_getWalletRegistrationService() {
|
|
279
|
+
__classPrivateFieldSet(this, _NeoBankService_walletRegistrationService, __classPrivateFieldGet(this, _NeoBankService_walletRegistrationService, "f") ?? new WalletRegistrationService({
|
|
280
|
+
fetch: __classPrivateFieldGet(this, _NeoBankService_fetch, "f"),
|
|
281
|
+
baseUrl: __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getBaseUrl).call(this),
|
|
282
|
+
getAuthToken: async () => __classPrivateFieldGet(this, _NeoBankService_messenger, "f").call('AuthenticationController:getBearerToken'),
|
|
283
|
+
getExternalId: async () => __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getCanonicalExternalId).call(this),
|
|
284
|
+
}), "f");
|
|
285
|
+
return __classPrivateFieldGet(this, _NeoBankService_walletRegistrationService, "f");
|
|
286
|
+
}, _NeoBankService_getRequestHeaders = async function _NeoBankService_getRequestHeaders(options = {}) {
|
|
287
|
+
const bearerToken = await __classPrivateFieldGet(this, _NeoBankService_messenger, "f").call('AuthenticationController:getBearerToken');
|
|
288
|
+
const headers = {
|
|
289
|
+
Authorization: `Bearer ${bearerToken}`,
|
|
290
|
+
};
|
|
291
|
+
if (options.idempotencyKey) {
|
|
292
|
+
headers['Idempotency-Key'] = options.idempotencyKey;
|
|
293
|
+
}
|
|
294
|
+
return headers;
|
|
295
|
+
}, _NeoBankService_buildUrl = function _NeoBankService_buildUrl(path, query) {
|
|
296
|
+
const url = new URL(getNeoBankPath(path), __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getBaseUrl).call(this));
|
|
297
|
+
url.searchParams.set('sdk', RAMPS_SDK_VERSION);
|
|
298
|
+
url.searchParams.set('controller', packageJson.version);
|
|
299
|
+
url.searchParams.set('context', __classPrivateFieldGet(this, _NeoBankService_context, "f"));
|
|
300
|
+
if (query) {
|
|
301
|
+
for (const [key, value] of Object.entries(query)) {
|
|
302
|
+
if (value !== undefined && value !== null) {
|
|
303
|
+
url.searchParams.set(key, String(value));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return url;
|
|
308
|
+
}, _NeoBankService_throwHttpError =
|
|
309
|
+
/**
|
|
310
|
+
* Throws an {@link HttpError} that carries the upstream response body.
|
|
311
|
+
*
|
|
312
|
+
* The neobank-proxy mirrors MoonPay's status *and* body verbatim, so the
|
|
313
|
+
* body is usually the only place that explains a 4xx (e.g. which field or
|
|
314
|
+
* permission was rejected). Dropping it makes failures undiagnosable.
|
|
315
|
+
*
|
|
316
|
+
* @param url - Request URL, for context in the message.
|
|
317
|
+
* @param response - Non-OK fetch response.
|
|
318
|
+
*/
|
|
319
|
+
async function _NeoBankService_throwHttpError(url, response) {
|
|
320
|
+
let detail = '';
|
|
321
|
+
try {
|
|
322
|
+
const body = (await response.text()).trim();
|
|
323
|
+
if (body) {
|
|
324
|
+
detail = ` - ${body.slice(0, 500)}`;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
// Body already consumed or unreadable; the status alone still helps.
|
|
329
|
+
}
|
|
330
|
+
throw new HttpError(response.status, `Fetching '${url.toString()}' failed with status '${response.status}'${detail}`);
|
|
331
|
+
}, _NeoBankService_getJson = async function _NeoBankService_getJson(path, query) {
|
|
332
|
+
const url = __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_buildUrl).call(this, path, query);
|
|
333
|
+
return __classPrivateFieldGet(this, _NeoBankService_policy, "f").execute(async () => {
|
|
334
|
+
const headers = await __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getRequestHeaders).call(this);
|
|
335
|
+
const fetchResponse = await __classPrivateFieldGet(this, _NeoBankService_fetch, "f").call(this, url, { headers });
|
|
336
|
+
if (!fetchResponse.ok) {
|
|
337
|
+
await __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_throwHttpError).call(this, url, fetchResponse);
|
|
338
|
+
}
|
|
339
|
+
return fetchResponse.json();
|
|
340
|
+
});
|
|
341
|
+
}, _NeoBankService_postJson = async function _NeoBankService_postJson(path, body, options) {
|
|
342
|
+
const url = __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_buildUrl).call(this, path);
|
|
343
|
+
return __classPrivateFieldGet(this, _NeoBankService_noRetryPolicy, "f").execute(async () => {
|
|
344
|
+
const headers = await __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_getRequestHeaders).call(this, options);
|
|
345
|
+
headers['Content-Type'] = 'application/json';
|
|
346
|
+
const fetchResponse = await __classPrivateFieldGet(this, _NeoBankService_fetch, "f").call(this, url, {
|
|
347
|
+
method: 'POST',
|
|
348
|
+
headers,
|
|
349
|
+
body: JSON.stringify(body),
|
|
350
|
+
});
|
|
351
|
+
if (!fetchResponse.ok) {
|
|
352
|
+
await __classPrivateFieldGet(this, _NeoBankService_instances, "m", _NeoBankService_throwHttpError).call(this, url, fetchResponse);
|
|
353
|
+
}
|
|
354
|
+
return fetchResponse.json();
|
|
355
|
+
});
|
|
356
|
+
}, _NeoBankService_mapAutorampResponse = function _NeoBankService_mapAutorampResponse(response) {
|
|
357
|
+
if (!response || typeof response !== 'object' || !response.id) {
|
|
358
|
+
throw new Error('Malformed response received from neo-bank autoramp API');
|
|
359
|
+
}
|
|
360
|
+
return mapNeoBankAutorampToRemoteSnapshot(response);
|
|
361
|
+
}, _NeoBankService_getCanonicalExternalId =
|
|
362
|
+
/**
|
|
363
|
+
* Resolves the MetaMask canonical profile id used as MoonPay's partner
|
|
364
|
+
* `external_id` for neobank customer lookup.
|
|
365
|
+
*
|
|
366
|
+
* @returns Canonical profile id.
|
|
367
|
+
*/
|
|
368
|
+
async function _NeoBankService_getCanonicalExternalId() {
|
|
369
|
+
const profile = await __classPrivateFieldGet(this, _NeoBankService_messenger, "f").call('AuthenticationController:getSessionProfile');
|
|
370
|
+
const canonical = profile?.canonicalProfileId;
|
|
371
|
+
const externalId = typeof canonical === 'string' && canonical.length > 0
|
|
372
|
+
? canonical
|
|
373
|
+
: profile?.profileId;
|
|
374
|
+
if (typeof externalId !== 'string' || externalId.length === 0) {
|
|
375
|
+
throw new Error('Unable to resolve MetaMask canonical profile id for MoonPay customer lookup');
|
|
376
|
+
}
|
|
377
|
+
return externalId;
|
|
378
|
+
};
|
|
379
|
+
//# sourceMappingURL=NeoBankService.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NeoBankService.mjs","sourceRoot":"","sources":["../src/NeoBankService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,SAAS,EACV,mCAAmC;AAIpC,OAAO,WAAW,8CAAwB;AAM1C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,2BAA0B;AACxE,OAAO,EAAE,yBAAyB,EAAE,0CAAyC;AAM7E;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC,UAAU,GAAG,GAAG,IAAI,KAAK,CAAC,UAAU,IAAI,GAAG,CAAC;IAC3D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AA+DD,MAAM,yBAAyB,GAAG;IAChC,aAAa;IACb,oBAAoB;IACpB,kBAAkB;IAClB,gBAAgB;IAChB,6BAA6B;IAC7B,qBAAqB;IACrB,yBAAyB;IACzB,sBAAsB;IACtB,6BAA6B;IAC7B,0BAA0B;CAClB,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AAC;IAC9C,MAAM,UAAU,GACd,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC;QACnD,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC;IACzB,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport {\n createServicePolicy,\n handleWhen,\n HttpError,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\n\nimport packageJson from '../package.json';\nimport type {\n AutorampDepositRailsSummary,\n AutorampRemoteSnapshot,\n} from './autoramp-types.js';\nimport type { NeoBankServiceMethodActions } from './NeoBankService-method-action-types.js';\nimport { RAMPS_SDK_VERSION, RampsEnvironment } from './RampsService.js';\nimport { WalletRegistrationService } from './wallet-registration-service.js';\nimport type {\n RegistrationOutcome,\n RegistrationStatus,\n} from './wallet-registration-service.js';\n\n/**\n * Name of the NeoBankService messenger namespace.\n */\nexport const serviceName = 'NeoBankService';\n\n/**\n * Determines whether a failed neo-bank request is worth re-issuing.\n *\n * 4xx responses describe the request or the account's state (e.g. 403\n * \"Customer is not active\", 422 validation), so repeating them only multiplies\n * the same rejection. 429 stays retryable alongside 5xx and non-HTTP\n * network/timeout errors.\n *\n * @param error - Error thrown while performing the request.\n * @returns `true` when the error is worth retrying.\n */\nfunction isRetryableError(error: unknown): boolean {\n if (error instanceof HttpError) {\n if (error.httpStatus === 429) {\n return true;\n }\n return error.httpStatus < 400 || error.httpStatus >= 500;\n }\n return true;\n}\n\n/**\n * Raw autoramp payload from the MetaMask Ramp API neo-bank proxy.\n * Shape mirrors MoonPay Enterprise `GET /api/autoramps/{autoramp_id}`.\n * The Ramp API handles partner auth / headers; the client only sends the\n * MetaMask bearer token.\n */\nexport type NeoBankAutorampResponse = {\n id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- MoonPay API field\n customer_id?: string;\n status: string;\n /**\n * Destination wallet when present on the proxy response.\n * Field name may evolve with the Ramp API contract.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention -- MoonPay API field\n wallet_address?: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- MoonPay API field\n recipient_account?: {\n address?: string;\n };\n // eslint-disable-next-line @typescript-eslint/naming-convention -- MoonPay API field\n deposit_rails?: unknown[];\n};\n\n/**\n * Optional headers for neo-bank mutating requests.\n */\nexport type NeoBankRequestOptions = {\n /**\n * Forwarded as `Idempotency-Key` when set (MoonPay requires it on some POSTs;\n * neobank-proxy generates one when omitted).\n */\n idempotencyKey?: string;\n};\n\n/**\n * Query string values accepted by neo-bank GET helpers.\n */\nexport type NeoBankQueryParams = Record<\n string,\n string | number | boolean | undefined | null\n>;\n\nexport type GetWalletRegistrationStatusParams = {\n customerId: string;\n address: string;\n};\n\nexport type RegisterSelfHostedWalletParams = {\n customerId: string;\n address: string;\n message: string;\n signature: string;\n /**\n * Forwarded as `Idempotency-Key` on the neobank-proxy POST. Prefer a stable\n * key across retries of the same ownership body.\n */\n idempotencyKey?: string;\n};\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getAutoramp',\n 'registerPixAddress',\n 'getAutorampQuote',\n 'createAutoramp',\n 'getAutorampQuoteForAutoramp',\n 'attachAutorampQuote',\n 'getCustomerByExternalId',\n 'getMoonpayCustomerId',\n 'getWalletRegistrationStatus',\n 'registerSelfHostedWallet',\n] as const;\n\n/**\n * Actions that {@link NeoBankService} exposes to other consumers.\n */\nexport type NeoBankServiceActions = NeoBankServiceMethodActions;\n\ntype AllowedActions =\n | AuthenticationController.AuthenticationControllerGetBearerTokenAction\n | AuthenticationController.AuthenticationControllerGetSessionProfileAction;\n\nexport type NeoBankServiceEvents = never;\n\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link NeoBankService}.\n */\nexport type NeoBankServiceMessenger = Messenger<\n typeof serviceName,\n NeoBankServiceActions | AllowedActions,\n NeoBankServiceEvents | AllowedEvents\n>;\n\n/**\n * Builds a path under the neobank-proxy global prefix.\n *\n * Live neobank-proxy (#1124) mounts routes at `/neobank` on the on-ramp.api\n * host (ALB path routing, no rewrite). Prefer this over `/api/v2/...` so Core\n * matches the proxy that ships.\n *\n * @param path - Path under `/neobank` (no leading slash).\n * @returns Absolute path segment for URL join against the Ramp API host.\n */\nfunction getNeoBankPath(path: string): string {\n return `neobank/${path.replace(/^\\//u, '')}`;\n}\n\n/**\n * Resolves the Ramp API host for neo-bank calls (same hosts as {@link RampsService}).\n *\n * @param environment - Ramp environment.\n * @returns Base URL.\n */\nfunction getBaseUrl(environment: RampsEnvironment): string {\n switch (environment) {\n case RampsEnvironment.Production:\n return 'https://on-ramp.api.cx.metamask.io';\n case RampsEnvironment.Staging:\n return 'https://on-ramp.uat-api.cx.metamask.io';\n case RampsEnvironment.Development:\n return 'https://on-ramp.dev-api.cx.metamask.io';\n case RampsEnvironment.Local:\n return 'http://localhost:3000';\n default:\n throw new Error(`Invalid environment: ${String(environment)}`);\n }\n}\n\n/**\n * Maps a Ramp API / MoonPay-shaped autoramp response into the local remote snapshot.\n *\n * @param response - Proxy response body.\n * @returns Snapshot for the controller last-seen cursor.\n */\nexport function mapNeoBankAutorampToRemoteSnapshot(\n response: NeoBankAutorampResponse,\n): AutorampRemoteSnapshot {\n const depositRails = response.deposit_rails;\n const hasDepositRails =\n Array.isArray(depositRails) && depositRails.length > 0;\n const depositRailsSummary: AutorampDepositRailsSummary | undefined =\n hasDepositRails || response.status === 'Approved'\n ? {\n ready: response.status === 'Approved' && hasDepositRails,\n }\n : undefined;\n\n return {\n id: response.id,\n customerId: response.customer_id,\n walletAddress:\n response.wallet_address !== undefined &&\n response.wallet_address.length > 0\n ? response.wallet_address\n : response.recipient_account?.address,\n status: response.status,\n depositRailsSummary,\n };\n}\n\n/**\n * Client for MetaMask Ramp API neo-bank endpoints (MoonPay Enterprise proxy).\n *\n * Lives alongside {@link RampsService} and {@link TransakService}. Authentication\n * and MoonPay partner headers are handled by the Ramp API; this service only\n * attaches the MetaMask user bearer token.\n *\n * Paths use the neobank-proxy `/neobank` prefix on the on-ramp.api host.\n */\nexport class NeoBankService {\n readonly name: typeof serviceName;\n\n readonly #messenger: NeoBankServiceMessenger;\n\n readonly #fetch: typeof fetch;\n\n readonly #policy: ServicePolicy;\n\n readonly #noRetryPolicy: ServicePolicy;\n\n readonly #environment: RampsEnvironment;\n\n readonly #context: string;\n\n readonly #baseUrlOverride?: string;\n\n #walletRegistrationService: WalletRegistrationService | undefined;\n\n constructor({\n messenger,\n environment = RampsEnvironment.Staging,\n context,\n fetch: fetchFunction,\n policyOptions = {},\n baseUrlOverride,\n }: {\n messenger: NeoBankServiceMessenger;\n environment?: RampsEnvironment;\n context: string;\n fetch: typeof fetch;\n policyOptions?: CreateServicePolicyOptions;\n baseUrlOverride?: string;\n }) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n this.#policy = createServicePolicy({\n retryFilterPolicy: handleWhen(isRetryableError),\n ...policyOptions,\n });\n this.#noRetryPolicy = createServicePolicy({\n retryFilterPolicy: handleWhen(isRetryableError),\n ...policyOptions,\n maxRetries: 0,\n });\n this.#environment = environment;\n this.#context = context;\n this.#baseUrlOverride = baseUrlOverride;\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n #getBaseUrl(): string {\n if (this.#baseUrlOverride) {\n return this.#baseUrlOverride;\n }\n return getBaseUrl(this.#environment);\n }\n\n /**\n * Lazily builds the wallet registration client. Deferred so constructing the\n * service never resolves the base URL eagerly (an invalid environment only\n * throws when a request is made, matching the other neo-bank methods).\n *\n * @returns The wallet registration client.\n */\n #getWalletRegistrationService(): WalletRegistrationService {\n this.#walletRegistrationService ??= new WalletRegistrationService({\n fetch: this.#fetch,\n baseUrl: this.#getBaseUrl(),\n getAuthToken: async (): Promise<string> =>\n this.#messenger.call('AuthenticationController:getBearerToken'),\n getExternalId: async (): Promise<string> =>\n this.#getCanonicalExternalId(),\n });\n return this.#walletRegistrationService;\n }\n\n async #getRequestHeaders(\n options: NeoBankRequestOptions = {},\n ): Promise<Record<string, string>> {\n const bearerToken = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n const headers: Record<string, string> = {\n Authorization: `Bearer ${bearerToken}`,\n };\n if (options.idempotencyKey) {\n headers['Idempotency-Key'] = options.idempotencyKey;\n }\n return headers;\n }\n\n #buildUrl(path: string, query?: NeoBankQueryParams): URL {\n const url = new URL(getNeoBankPath(path), this.#getBaseUrl());\n url.searchParams.set('sdk', RAMPS_SDK_VERSION);\n url.searchParams.set('controller', packageJson.version);\n url.searchParams.set('context', this.#context);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n return url;\n }\n\n /**\n * Throws an {@link HttpError} that carries the upstream response body.\n *\n * The neobank-proxy mirrors MoonPay's status *and* body verbatim, so the\n * body is usually the only place that explains a 4xx (e.g. which field or\n * permission was rejected). Dropping it makes failures undiagnosable.\n *\n * @param url - Request URL, for context in the message.\n * @param response - Non-OK fetch response.\n */\n async #throwHttpError(url: URL, response: Response): Promise<never> {\n let detail = '';\n try {\n const body = (await response.text()).trim();\n if (body) {\n detail = ` - ${body.slice(0, 500)}`;\n }\n } catch {\n // Body already consumed or unreadable; the status alone still helps.\n }\n throw new HttpError(\n response.status,\n `Fetching '${url.toString()}' failed with status '${response.status}'${detail}`,\n );\n }\n\n async #getJson<ResponseBody>(\n path: string,\n query?: NeoBankQueryParams,\n ): Promise<ResponseBody> {\n const url = this.#buildUrl(path, query);\n return this.#policy.execute(async () => {\n const headers = await this.#getRequestHeaders();\n const fetchResponse = await this.#fetch(url, { headers });\n if (!fetchResponse.ok) {\n await this.#throwHttpError(url, fetchResponse);\n }\n return fetchResponse.json() as Promise<ResponseBody>;\n });\n }\n\n async #postJson<ResponseBody>(\n path: string,\n body: Record<string, unknown>,\n options: NeoBankRequestOptions,\n ): Promise<ResponseBody> {\n const url = this.#buildUrl(path);\n return this.#noRetryPolicy.execute(async () => {\n const headers = await this.#getRequestHeaders(options);\n headers['Content-Type'] = 'application/json';\n const fetchResponse = await this.#fetch(url, {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n });\n if (!fetchResponse.ok) {\n await this.#throwHttpError(url, fetchResponse);\n }\n return fetchResponse.json() as Promise<ResponseBody>;\n });\n }\n\n #mapAutorampResponse(\n response: NeoBankAutorampResponse,\n ): AutorampRemoteSnapshot {\n if (!response || typeof response !== 'object' || !response.id) {\n throw new Error('Malformed response received from neo-bank autoramp API');\n }\n return mapNeoBankAutorampToRemoteSnapshot(response);\n }\n\n /**\n * Fetches an autoramp account via neobank-proxy\n * `GET /neobank/autoramps/{autoramp_id}` (MoonPay\n * `GET /api/autoramps/{autoramp_id}`).\n *\n * @param autorampId - MoonPay / Ramp API autoramp id.\n * @returns Remote snapshot for controller apply/refresh.\n */\n async getAutoramp(autorampId: string): Promise<AutorampRemoteSnapshot> {\n const response = await this.#getJson<NeoBankAutorampResponse>(\n `autoramps/${encodeURIComponent(autorampId)}`,\n );\n return this.#mapAutorampResponse(response);\n }\n\n /**\n * Registers a Pix address via neobank-proxy `POST /neobank/addresses/pix`.\n * Body is forwarded as opaque JSON (MoonPay address schema).\n *\n * @param body - Pix address registration payload.\n * @param options - Optional idempotency key.\n * @returns Parsed proxy JSON response.\n */\n async registerPixAddress(\n body: Record<string, unknown>,\n options: NeoBankRequestOptions = {},\n ): Promise<unknown> {\n return this.#postJson('addresses/pix', body, options);\n }\n\n /**\n * Fetches an autoramp quote via neobank-proxy `GET /neobank/autoramps/quote`.\n *\n * @param query - Quote query params (forwarded as-is).\n * @returns Parsed proxy JSON response.\n */\n async getAutorampQuote(query: NeoBankQueryParams = {}): Promise<unknown> {\n return this.#getJson('autoramps/quote', query);\n }\n\n /**\n * Creates an autoramp from a signed quote via neobank-proxy\n * `POST /neobank/autoramps` (MoonPay `POST /api/autoramps`).\n *\n * @param body - CreateAutoramp / signed-quote payload (forwarded as-is).\n * @param options - Optional idempotency key.\n * @returns Remote snapshot for controller apply/refresh.\n */\n async createAutoramp(\n body: Record<string, unknown>,\n options: NeoBankRequestOptions = {},\n ): Promise<AutorampRemoteSnapshot> {\n const response = await this.#postJson<NeoBankAutorampResponse>(\n 'autoramps',\n body,\n options,\n );\n return this.#mapAutorampResponse(response);\n }\n\n /**\n * Fetches a quote for an existing autoramp via neobank-proxy\n * `GET /neobank/autoramps/{autoramp_id}/quote`.\n *\n * @param autorampId - Autoramp id.\n * @param query - Quote query params (forwarded as-is).\n * @returns Parsed proxy JSON response.\n */\n async getAutorampQuoteForAutoramp(\n autorampId: string,\n query: NeoBankQueryParams = {},\n ): Promise<unknown> {\n return this.#getJson(\n `autoramps/${encodeURIComponent(autorampId)}/quote`,\n query,\n );\n }\n\n /**\n * Attaches a signed quote to an autoramp via neobank-proxy\n * `POST /neobank/autoramps/{autoramp_id}/quotes`.\n *\n * @param autorampId - Autoramp id.\n * @param body - Quote attachment payload (forwarded as-is).\n * @param options - Optional idempotency key.\n * @returns Parsed proxy JSON response.\n */\n async attachAutorampQuote(\n autorampId: string,\n body: Record<string, unknown>,\n options: NeoBankRequestOptions = {},\n ): Promise<unknown> {\n return this.#postJson(\n `autoramps/${encodeURIComponent(autorampId)}/quotes`,\n body,\n options,\n );\n }\n\n /**\n * Fetches a customer by partner external id via neobank-proxy\n * `GET /neobank/customers/{external_id}/external`.\n *\n * @param externalId - Partner-assigned external customer id.\n * @returns Parsed proxy JSON response.\n */\n async getCustomerByExternalId(externalId: string): Promise<unknown> {\n return this.#getJson(\n `customers/${encodeURIComponent(externalId)}/external`,\n );\n }\n\n /**\n * Resolves Iron's internal customer id via neobank-proxy customer lookup,\n * using the MetaMask canonical profile id as the partner `external_id`.\n *\n * @returns Iron's internal customer id.\n */\n async getMoonpayCustomerId(): Promise<string> {\n return await this.#getWalletRegistrationService().getMoonpayCustomerId();\n }\n\n /**\n * Checks whether a Monad Money Account address is already registered for the\n * given Iron customer.\n *\n * @param params - Customer id and address to check.\n * @param params.customerId - Iron / MoonPay customer UUID.\n * @param params.address - Money Account address.\n * @returns Active, disabled, or absent registration status.\n */\n async getWalletRegistrationStatus({\n customerId,\n address,\n }: GetWalletRegistrationStatusParams): Promise<RegistrationStatus> {\n return await this.#getWalletRegistrationService().getRegistrationStatus({\n customerId,\n address,\n blockchain: 'Monad',\n });\n }\n\n /**\n * Submits a signed Monad Money Account ownership proof via neobank-proxy\n * `POST /neobank/addresses/crypto/selfhosted`.\n *\n * @param params - Signed ownership proof.\n * @returns Registered wallet record.\n */\n async registerSelfHostedWallet(\n params: RegisterSelfHostedWalletParams,\n ): Promise<RegistrationOutcome> {\n return await this.#getWalletRegistrationService().registerSelfHostedWallet({\n ...params,\n blockchain: 'Monad',\n });\n }\n\n /**\n * Resolves the MetaMask canonical profile id used as MoonPay's partner\n * `external_id` for neobank customer lookup.\n *\n * @returns Canonical profile id.\n */\n async #getCanonicalExternalId(): Promise<string> {\n const profile = await this.#messenger.call(\n 'AuthenticationController:getSessionProfile',\n );\n const canonical = profile?.canonicalProfileId;\n const externalId =\n typeof canonical === 'string' && canonical.length > 0\n ? canonical\n : profile?.profileId;\n if (typeof externalId !== 'string' || externalId.length === 0) {\n throw new Error(\n 'Unable to resolve MetaMask canonical profile id for MoonPay customer lookup',\n );\n }\n return externalId;\n }\n\n onRetry(\n listener: Parameters<ServicePolicy['onRetry']>[0],\n ): ReturnType<ServicePolicy['onRetry']> {\n return this.#policy.onRetry(listener);\n }\n\n onBreak(\n listener: Parameters<ServicePolicy['onBreak']>[0],\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(listener);\n }\n\n onDegraded(\n listener: Parameters<ServicePolicy['onDegraded']>[0],\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded(listener);\n }\n}\n"]}
|