@moonpay/platform-sdk-core 1.16.0 → 1.18.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/dist/index.d.cts CHANGED
@@ -215,6 +215,21 @@ interface CoreClientOptions extends ClientContextOptions, UrlBuilderOptions {
215
215
  */
216
216
  createTransport: () => FrameTransport;
217
217
  }
218
+ /**
219
+ * Customer-scoped credentials the client holds after a successful connection.
220
+ * Surfaced to partners via `getCredentials()` — see that method for caveats.
221
+ */
222
+ interface Credentials {
223
+ /** Short-lived bearer token scoped to the connected customer. */
224
+ accessToken: string;
225
+ /** Token identifying the SDK client; used when launching frames. */
226
+ clientToken: string;
227
+ }
228
+ /** Returned by `getCredentials()` when no customer session is active yet. */
229
+ interface GetCredentialsError {
230
+ code: 'noActiveSession';
231
+ message: string;
232
+ }
218
233
  interface CoreClient {
219
234
  /** Access the internal context (for platform SDKs). */
220
235
  readonly context: ClientContext;
@@ -222,6 +237,18 @@ interface CoreClient {
222
237
  readonly frameBaseUrl: string | undefined;
223
238
  /** Factory to create transports (for platform SDKs). */
224
239
  createTransport(): FrameTransport;
240
+ /**
241
+ * Returns the connected customer's credentials so the `accessToken` can be
242
+ * forwarded to your backend for customer-scoped Platform API calls (e.g.
243
+ * server-side quote fetching).
244
+ *
245
+ * Advanced escape hatch — the SDK otherwise keeps these internal. The
246
+ * `accessToken` is short-lived and scoped to the connected customer. Errs
247
+ * with `noActiveSession` until a customer session exists (populated by
248
+ * `getConnection()` / `connect()` / `setupAuth()`). Synchronous: returns a
249
+ * `Result` directly, not a Promise.
250
+ */
251
+ getCredentials(): Result<Credentials, GetCredentialsError>;
225
252
  getQuote(params: GetQuoteParams): Promise<Result<{
226
253
  data: Quote;
227
254
  }, GetQuoteError>>;
@@ -300,6 +327,13 @@ interface KeyPair {
300
327
  }
301
328
  /** Generate an ephemeral X25519 key pair for the encrypted credential exchange. */
302
329
  declare function generateKeyPair(): KeyPair;
330
+ /**
331
+ * Whether a cryptographically-secure RNG (Web Crypto `getRandomValues`) is
332
+ * available in this runtime. React Native (Hermes) has none by default, so
333
+ * `generateKeyPair()` will throw unless a polyfill is installed. Always true in
334
+ * browsers and Node.
335
+ */
336
+ declare function isSecureRandomAvailable(): boolean;
303
337
 
304
338
  interface FrameOrchestratorOptions {
305
339
  transport: FrameTransport;
@@ -355,4 +389,4 @@ declare function isTrustedFrameOrigin(origin: string): boolean;
355
389
  */
356
390
  declare function isTrustedFrameUrl(value: string): boolean;
357
391
 
358
- export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type KeyPair, type ListAssetsParams, type ListTransactionsParams, type PresentationMode, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyClientTokenParam, applyPresentationParam, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
392
+ export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, type Credentials, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type GetCredentialsError, type KeyPair, type ListAssetsParams, type ListTransactionsParams, type PresentationMode, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyClientTokenParam, applyPresentationParam, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isSecureRandomAvailable, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
package/dist/index.d.ts CHANGED
@@ -215,6 +215,21 @@ interface CoreClientOptions extends ClientContextOptions, UrlBuilderOptions {
215
215
  */
216
216
  createTransport: () => FrameTransport;
217
217
  }
218
+ /**
219
+ * Customer-scoped credentials the client holds after a successful connection.
220
+ * Surfaced to partners via `getCredentials()` — see that method for caveats.
221
+ */
222
+ interface Credentials {
223
+ /** Short-lived bearer token scoped to the connected customer. */
224
+ accessToken: string;
225
+ /** Token identifying the SDK client; used when launching frames. */
226
+ clientToken: string;
227
+ }
228
+ /** Returned by `getCredentials()` when no customer session is active yet. */
229
+ interface GetCredentialsError {
230
+ code: 'noActiveSession';
231
+ message: string;
232
+ }
218
233
  interface CoreClient {
219
234
  /** Access the internal context (for platform SDKs). */
220
235
  readonly context: ClientContext;
@@ -222,6 +237,18 @@ interface CoreClient {
222
237
  readonly frameBaseUrl: string | undefined;
223
238
  /** Factory to create transports (for platform SDKs). */
224
239
  createTransport(): FrameTransport;
240
+ /**
241
+ * Returns the connected customer's credentials so the `accessToken` can be
242
+ * forwarded to your backend for customer-scoped Platform API calls (e.g.
243
+ * server-side quote fetching).
244
+ *
245
+ * Advanced escape hatch — the SDK otherwise keeps these internal. The
246
+ * `accessToken` is short-lived and scoped to the connected customer. Errs
247
+ * with `noActiveSession` until a customer session exists (populated by
248
+ * `getConnection()` / `connect()` / `setupAuth()`). Synchronous: returns a
249
+ * `Result` directly, not a Promise.
250
+ */
251
+ getCredentials(): Result<Credentials, GetCredentialsError>;
225
252
  getQuote(params: GetQuoteParams): Promise<Result<{
226
253
  data: Quote;
227
254
  }, GetQuoteError>>;
@@ -300,6 +327,13 @@ interface KeyPair {
300
327
  }
301
328
  /** Generate an ephemeral X25519 key pair for the encrypted credential exchange. */
302
329
  declare function generateKeyPair(): KeyPair;
330
+ /**
331
+ * Whether a cryptographically-secure RNG (Web Crypto `getRandomValues`) is
332
+ * available in this runtime. React Native (Hermes) has none by default, so
333
+ * `generateKeyPair()` will throw unless a polyfill is installed. Always true in
334
+ * browsers and Node.
335
+ */
336
+ declare function isSecureRandomAvailable(): boolean;
303
337
 
304
338
  interface FrameOrchestratorOptions {
305
339
  transport: FrameTransport;
@@ -355,4 +389,4 @@ declare function isTrustedFrameOrigin(origin: string): boolean;
355
389
  */
356
390
  declare function isTrustedFrameUrl(value: string): boolean;
357
391
 
358
- export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type KeyPair, type ListAssetsParams, type ListTransactionsParams, type PresentationMode, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyClientTokenParam, applyPresentationParam, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
392
+ export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, type Credentials, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type GetCredentialsError, type KeyPair, type ListAssetsParams, type ListTransactionsParams, type PresentationMode, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyClientTokenParam, applyPresentationParam, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isSecureRandomAvailable, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
package/dist/index.js CHANGED
@@ -206,6 +206,7 @@ async function simulateBankTransfer(ctx, id, params) {
206
206
  }
207
207
 
208
208
  // src/client.ts
209
+ import { err as err4, ok as ok4 } from "@moonpay/platform-protocol/result";
209
210
  function createClientCore(options) {
210
211
  const ctx = createClientContext({
211
212
  apiBaseUrl: options.apiBaseUrl
@@ -218,6 +219,10 @@ function createClientCore(options) {
218
219
  return options.frameBaseUrl;
219
220
  },
220
221
  createTransport: options.createTransport,
222
+ getCredentials: () => ctx.accessToken ? ok4({ accessToken: ctx.accessToken, clientToken: ctx.clientToken }) : err4({
223
+ code: "noActiveSession",
224
+ message: "No active session. Connect a customer (getConnection / connect / setupAuth) before requesting credentials."
225
+ }),
221
226
  getQuote: (params) => getQuote(ctx, params),
222
227
  getAssets: (params) => getAssets(ctx, params),
223
228
  getPaymentMethods: () => getPaymentMethods(ctx),
@@ -1551,6 +1556,9 @@ function generateKeyPair() {
1551
1556
  publicKey: bytesToHex(publicKey)
1552
1557
  };
1553
1558
  }
1559
+ function isSecureRandomAvailable() {
1560
+ return typeof globalThis.crypto?.getRandomValues === "function";
1561
+ }
1554
1562
 
1555
1563
  // src/frames/frame-orchestrator.ts
1556
1564
  import {
@@ -1719,6 +1727,7 @@ export {
1719
1727
  getPaymentMethods,
1720
1728
  getQuote,
1721
1729
  getTransaction,
1730
+ isSecureRandomAvailable,
1722
1731
  isTrustedFrameOrigin,
1723
1732
  isTrustedFrameUrl,
1724
1733
  listTransactions,