@moon-x/core 0.7.0 → 0.8.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/{chunk-JU5MWLXH.mjs → chunk-KRZVIDBQ.mjs} +67 -22
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +67 -22
- package/dist/index.mjs +1 -1
- package/dist/{interfaces-BZ5GMWS9.d.ts → interfaces-B5zxo2Jx.d.ts} +1 -1
- package/dist/{interfaces-BWxOajnD.d.mts → interfaces-CF5UrEBb.d.mts} +1 -1
- package/dist/{post-message-Z6cLf0mS.d.ts → post-message-2NAnU0Lf.d.mts} +4 -0
- package/dist/{post-message-Z6cLf0mS.d.mts → post-message-2NAnU0Lf.d.ts} +4 -0
- package/dist/sdk/index.d.mts +3 -3
- package/dist/sdk/index.d.ts +3 -3
- package/dist/sdk/index.mjs +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +67 -22
- package/dist/utils/index.mjs +1 -1
- package/dist/web/index.d.mts +2 -2
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.js +67 -22
- package/dist/web/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -177,8 +177,11 @@ var sendReactNativeReply = (response) => {
|
|
|
177
177
|
} catch {
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
|
+
var QUEUE_TTL_MS = 2e4;
|
|
181
|
+
var MAX_PENDING_PER_KEY = 16;
|
|
180
182
|
var PostMessageServer = class {
|
|
181
183
|
constructor(originValidator) {
|
|
184
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
182
185
|
this.trustedSources = /* @__PURE__ */ new Set();
|
|
183
186
|
this.handlers = /* @__PURE__ */ new Map();
|
|
184
187
|
this.originValidator = originValidator;
|
|
@@ -193,6 +196,20 @@ var PostMessageServer = class {
|
|
|
193
196
|
register(type, method, handler) {
|
|
194
197
|
const key = `${type}:${method}`;
|
|
195
198
|
this.handlers.set(key, handler);
|
|
199
|
+
const queued = this.pending.get(key);
|
|
200
|
+
if (queued?.length) {
|
|
201
|
+
this.pending.delete(key);
|
|
202
|
+
const now = Date.now();
|
|
203
|
+
for (const { request, reply, at } of queued) {
|
|
204
|
+
if (now - at < QUEUE_TTL_MS) {
|
|
205
|
+
void this.invokeHandler(
|
|
206
|
+
handler,
|
|
207
|
+
request,
|
|
208
|
+
reply
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
196
213
|
}
|
|
197
214
|
cleanup() {
|
|
198
215
|
window.removeEventListener("message", this.handleMessage.bind(this));
|
|
@@ -257,29 +274,57 @@ var PostMessageServer = class {
|
|
|
257
274
|
const key = `${request.type}:${request.method}`;
|
|
258
275
|
const handler = this.handlers.get(key);
|
|
259
276
|
if (handler) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
277
|
+
await this.invokeHandler(handler, request, reply);
|
|
278
|
+
} else {
|
|
279
|
+
this.bufferRequest(key, request, reply);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async invokeHandler(handler, request, reply) {
|
|
283
|
+
try {
|
|
284
|
+
const data = await handler(request.payload);
|
|
285
|
+
reply({
|
|
286
|
+
id: request.id,
|
|
287
|
+
type: request.type,
|
|
288
|
+
success: true,
|
|
289
|
+
data
|
|
290
|
+
});
|
|
291
|
+
} catch (error) {
|
|
292
|
+
const extras = {};
|
|
293
|
+
if (error && typeof error === "object") {
|
|
294
|
+
for (const key of FORWARDED_ERROR_FIELDS) {
|
|
295
|
+
const value = error[key];
|
|
296
|
+
if (value !== void 0) extras[key] = value;
|
|
275
297
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
298
|
+
}
|
|
299
|
+
reply({
|
|
300
|
+
...extras,
|
|
301
|
+
id: request.id,
|
|
302
|
+
type: request.type,
|
|
303
|
+
success: false,
|
|
304
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
bufferRequest(key, request, reply) {
|
|
309
|
+
this.evictExpiredPending();
|
|
310
|
+
let queue = this.pending.get(key);
|
|
311
|
+
if (!queue) {
|
|
312
|
+
queue = [];
|
|
313
|
+
this.pending.set(key, queue);
|
|
314
|
+
}
|
|
315
|
+
queue.push({ request, reply, at: Date.now() });
|
|
316
|
+
if (queue.length > MAX_PENDING_PER_KEY) {
|
|
317
|
+
queue.splice(0, queue.length - MAX_PENDING_PER_KEY);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
evictExpiredPending() {
|
|
321
|
+
const now = Date.now();
|
|
322
|
+
for (const [key, queue] of this.pending) {
|
|
323
|
+
const fresh = queue.filter((e) => now - e.at < QUEUE_TTL_MS);
|
|
324
|
+
if (fresh.length) {
|
|
325
|
+
this.pending.set(key, fresh);
|
|
326
|
+
} else {
|
|
327
|
+
this.pending.delete(key);
|
|
283
328
|
}
|
|
284
329
|
}
|
|
285
330
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { AccessTokenClaims, AppConfigRequest, AppConfigResponse, AttachOAuthTokenRequest, AttachOAuthTokenResponse, AuthAppearance, AuthFlow, AuthFlowComponent, AuthLoginMethod, AuthProviderConfig, BaseGetBalanceParams, BaseGetBalanceResult, BaseGetTokenAccountsParams, BaseSendTransactionParams, BaseSendTransactionResult, BaseSignMessageParams, BaseSignMessageResult, BaseSignTransactionParams, BaseSignTransactionResult, BaseTokenClaims, BaseUIOptions, BaseWalletHooks, BlockExplorer, Chain, ChainLikeWithId, ContractUIOptions, CreateWalletResponse, DefaultFundingMethod, DeleteSessionRequest, DeleteSessionResponse, DetachOAuthTokenRequest, DeviceFingerprint, DisplayMode, EmailOtpConfig, EmailOtpFlowState, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet, EthereumChainConfig, EthereumFundingConfig, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumGetTokenAccountsByOwnerParams, EthereumGetTokenAccountsByOwnerResult, EthereumSendTransactionParams, EthereumSendTransactionRequest, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSwitchChainParams, ExportKeyConfig, Factor, FlexibleTheme, FundWalletConfig, FundingEvents, FundingMethod, FundingUIConfig, GetCurrentSessionRequest, GetCurrentSessionResponse, Hex, IdentityTokenClaims, IdpProvider, IsAuthenticatedRequest, IsAuthenticatedResponse, ListEphemeralSignersResult, LoginTokenBundle, LogoutRequest, LogoutResponse, MessageTypeProperty, MessageTypes, MoonKeyThemeConfig, MoonPaySignRequest, MoonPaySignResponse, MpcKeyShares, NativeCurrency, Network, OAuthRequest, OAuthResponse, OnrampFundingSettings, PasskeyEnrollConfig, PasskeySettings, PreferredCardProvider, PrefillConfig, PresenceTokenClaims, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicEthereumWallet, PublicSessionData, PublicWallet, RefreshSessionRequest, RefreshSessionResponse, RetrieveWalletKeyRequest, RetrieveWalletKeyResponse, RevokeEphemeralSignerParams, RpcConfig, RpcUrls, SdkSettings, SendEmailOtpRequest, SendEmailOtpResponse, SendTransactionConfig, SendTransactionRequest, SessionData, SharesDeviceRequest, SharesDeviceResponse, Sign7702AuthorizationError, Sign7702AuthorizationParams, Sign7702AuthorizationResponse, Sign7702AuthorizationResult, SignMessageConfig, SignTransactionConfig, SignTypedDataError, SignTypedDataParams, SignTypedDataResponse, SignTypedDataResult, SmsSettings, SolanaChain, SolanaFundingConfig, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, TransactionCommitment, TransactionEncoding, TransactionUIOptions, TypedMessage, UseFundWalletInterface, UsersMePublicResponse, UsersMeRequest, UsersMeResponse, VerifiedSession, VerifyEmailOtpRequest, VerifyEmailOtpResponse, VerifyEmailOtpUser, VerifyOAuthTokenRequest, VerifyOAuthTokenResponse, VerifySiweWalletRegistrationRequest, WALLET_ERROR_CODES, Wallet, WalletChain, WalletChainType, WalletConnectConfig, WalletCreationError, WalletError, WalletErrorCode, WalletKeyRequest, WalletListEntry, WalletRegistrationNonceRequest, WalletRegistrationNonceResponse, WalletType, WalletVerifyRequest } from './types/index.mjs';
|
|
2
2
|
export { getIframeOrigin, getIframeUrl, getMoonKeyApiUrl } from './utils/index.mjs';
|
|
3
|
-
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from './post-message-
|
|
3
|
+
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from './post-message-2NAnU0Lf.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { AccessTokenClaims, AppConfigRequest, AppConfigResponse, AttachOAuthTokenRequest, AttachOAuthTokenResponse, AuthAppearance, AuthFlow, AuthFlowComponent, AuthLoginMethod, AuthProviderConfig, BaseGetBalanceParams, BaseGetBalanceResult, BaseGetTokenAccountsParams, BaseSendTransactionParams, BaseSendTransactionResult, BaseSignMessageParams, BaseSignMessageResult, BaseSignTransactionParams, BaseSignTransactionResult, BaseTokenClaims, BaseUIOptions, BaseWalletHooks, BlockExplorer, Chain, ChainLikeWithId, ContractUIOptions, CreateWalletResponse, DefaultFundingMethod, DeleteSessionRequest, DeleteSessionResponse, DetachOAuthTokenRequest, DeviceFingerprint, DisplayMode, EmailOtpConfig, EmailOtpFlowState, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet, EthereumChainConfig, EthereumFundingConfig, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumGetTokenAccountsByOwnerParams, EthereumGetTokenAccountsByOwnerResult, EthereumSendTransactionParams, EthereumSendTransactionRequest, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSwitchChainParams, ExportKeyConfig, Factor, FlexibleTheme, FundWalletConfig, FundingEvents, FundingMethod, FundingUIConfig, GetCurrentSessionRequest, GetCurrentSessionResponse, Hex, IdentityTokenClaims, IdpProvider, IsAuthenticatedRequest, IsAuthenticatedResponse, ListEphemeralSignersResult, LoginTokenBundle, LogoutRequest, LogoutResponse, MessageTypeProperty, MessageTypes, MoonKeyThemeConfig, MoonPaySignRequest, MoonPaySignResponse, MpcKeyShares, NativeCurrency, Network, OAuthRequest, OAuthResponse, OnrampFundingSettings, PasskeyEnrollConfig, PasskeySettings, PreferredCardProvider, PrefillConfig, PresenceTokenClaims, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicEthereumWallet, PublicSessionData, PublicWallet, RefreshSessionRequest, RefreshSessionResponse, RetrieveWalletKeyRequest, RetrieveWalletKeyResponse, RevokeEphemeralSignerParams, RpcConfig, RpcUrls, SdkSettings, SendEmailOtpRequest, SendEmailOtpResponse, SendTransactionConfig, SendTransactionRequest, SessionData, SharesDeviceRequest, SharesDeviceResponse, Sign7702AuthorizationError, Sign7702AuthorizationParams, Sign7702AuthorizationResponse, Sign7702AuthorizationResult, SignMessageConfig, SignTransactionConfig, SignTypedDataError, SignTypedDataParams, SignTypedDataResponse, SignTypedDataResult, SmsSettings, SolanaChain, SolanaFundingConfig, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, TransactionCommitment, TransactionEncoding, TransactionUIOptions, TypedMessage, UseFundWalletInterface, UsersMePublicResponse, UsersMeRequest, UsersMeResponse, VerifiedSession, VerifyEmailOtpRequest, VerifyEmailOtpResponse, VerifyEmailOtpUser, VerifyOAuthTokenRequest, VerifyOAuthTokenResponse, VerifySiweWalletRegistrationRequest, WALLET_ERROR_CODES, Wallet, WalletChain, WalletChainType, WalletConnectConfig, WalletCreationError, WalletError, WalletErrorCode, WalletKeyRequest, WalletListEntry, WalletRegistrationNonceRequest, WalletRegistrationNonceResponse, WalletType, WalletVerifyRequest } from './types/index.js';
|
|
2
2
|
export { getIframeOrigin, getIframeUrl, getMoonKeyApiUrl } from './utils/index.js';
|
|
3
|
-
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from './post-message-
|
|
3
|
+
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from './post-message-2NAnU0Lf.js';
|
package/dist/index.js
CHANGED
|
@@ -303,8 +303,11 @@ var sendReactNativeReply = (response) => {
|
|
|
303
303
|
} catch {
|
|
304
304
|
}
|
|
305
305
|
};
|
|
306
|
+
var QUEUE_TTL_MS = 2e4;
|
|
307
|
+
var MAX_PENDING_PER_KEY = 16;
|
|
306
308
|
var PostMessageServer = class {
|
|
307
309
|
constructor(originValidator) {
|
|
310
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
308
311
|
this.trustedSources = /* @__PURE__ */ new Set();
|
|
309
312
|
this.handlers = /* @__PURE__ */ new Map();
|
|
310
313
|
this.originValidator = originValidator;
|
|
@@ -319,6 +322,20 @@ var PostMessageServer = class {
|
|
|
319
322
|
register(type, method, handler) {
|
|
320
323
|
const key = `${type}:${method}`;
|
|
321
324
|
this.handlers.set(key, handler);
|
|
325
|
+
const queued = this.pending.get(key);
|
|
326
|
+
if (queued?.length) {
|
|
327
|
+
this.pending.delete(key);
|
|
328
|
+
const now = Date.now();
|
|
329
|
+
for (const { request, reply, at } of queued) {
|
|
330
|
+
if (now - at < QUEUE_TTL_MS) {
|
|
331
|
+
void this.invokeHandler(
|
|
332
|
+
handler,
|
|
333
|
+
request,
|
|
334
|
+
reply
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
322
339
|
}
|
|
323
340
|
cleanup() {
|
|
324
341
|
window.removeEventListener("message", this.handleMessage.bind(this));
|
|
@@ -383,29 +400,57 @@ var PostMessageServer = class {
|
|
|
383
400
|
const key = `${request.type}:${request.method}`;
|
|
384
401
|
const handler = this.handlers.get(key);
|
|
385
402
|
if (handler) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
403
|
+
await this.invokeHandler(handler, request, reply);
|
|
404
|
+
} else {
|
|
405
|
+
this.bufferRequest(key, request, reply);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
async invokeHandler(handler, request, reply) {
|
|
409
|
+
try {
|
|
410
|
+
const data = await handler(request.payload);
|
|
411
|
+
reply({
|
|
412
|
+
id: request.id,
|
|
413
|
+
type: request.type,
|
|
414
|
+
success: true,
|
|
415
|
+
data
|
|
416
|
+
});
|
|
417
|
+
} catch (error) {
|
|
418
|
+
const extras = {};
|
|
419
|
+
if (error && typeof error === "object") {
|
|
420
|
+
for (const key of FORWARDED_ERROR_FIELDS) {
|
|
421
|
+
const value = error[key];
|
|
422
|
+
if (value !== void 0) extras[key] = value;
|
|
401
423
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
424
|
+
}
|
|
425
|
+
reply({
|
|
426
|
+
...extras,
|
|
427
|
+
id: request.id,
|
|
428
|
+
type: request.type,
|
|
429
|
+
success: false,
|
|
430
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
bufferRequest(key, request, reply) {
|
|
435
|
+
this.evictExpiredPending();
|
|
436
|
+
let queue = this.pending.get(key);
|
|
437
|
+
if (!queue) {
|
|
438
|
+
queue = [];
|
|
439
|
+
this.pending.set(key, queue);
|
|
440
|
+
}
|
|
441
|
+
queue.push({ request, reply, at: Date.now() });
|
|
442
|
+
if (queue.length > MAX_PENDING_PER_KEY) {
|
|
443
|
+
queue.splice(0, queue.length - MAX_PENDING_PER_KEY);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
evictExpiredPending() {
|
|
447
|
+
const now = Date.now();
|
|
448
|
+
for (const [key, queue] of this.pending) {
|
|
449
|
+
const fresh = queue.filter((e) => now - e.at < QUEUE_TTL_MS);
|
|
450
|
+
if (fresh.length) {
|
|
451
|
+
this.pending.set(key, fresh);
|
|
452
|
+
} else {
|
|
453
|
+
this.pending.delete(key);
|
|
409
454
|
}
|
|
410
455
|
}
|
|
411
456
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -60,6 +60,7 @@ declare class PostMessageClient {
|
|
|
60
60
|
}
|
|
61
61
|
declare class PostMessageServer {
|
|
62
62
|
private handlers;
|
|
63
|
+
private pending;
|
|
63
64
|
private originValidator?;
|
|
64
65
|
private trustedSources;
|
|
65
66
|
constructor(originValidator?: (origin: string, publishableKey?: string) => Promise<boolean>);
|
|
@@ -70,6 +71,9 @@ declare class PostMessageServer {
|
|
|
70
71
|
private static isLocalhostOrigin;
|
|
71
72
|
private isValidPostMessageRequest;
|
|
72
73
|
private handleMessage;
|
|
74
|
+
private invokeHandler;
|
|
75
|
+
private bufferRequest;
|
|
76
|
+
private evictExpiredPending;
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
export { FORWARDED_ERROR_FIELDS as F, PostMessageClient as P, PostMessageMethod as a, PostMessageServer as b, PostMessageType as c };
|
|
@@ -60,6 +60,7 @@ declare class PostMessageClient {
|
|
|
60
60
|
}
|
|
61
61
|
declare class PostMessageServer {
|
|
62
62
|
private handlers;
|
|
63
|
+
private pending;
|
|
63
64
|
private originValidator?;
|
|
64
65
|
private trustedSources;
|
|
65
66
|
constructor(originValidator?: (origin: string, publishableKey?: string) => Promise<boolean>);
|
|
@@ -70,6 +71,9 @@ declare class PostMessageServer {
|
|
|
70
71
|
private static isLocalhostOrigin;
|
|
71
72
|
private isValidPostMessageRequest;
|
|
72
73
|
private handleMessage;
|
|
74
|
+
private invokeHandler;
|
|
75
|
+
private bufferRequest;
|
|
76
|
+
private evictExpiredPending;
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
export { FORWARDED_ERROR_FIELDS as F, PostMessageClient as P, PostMessageMethod as a, PostMessageServer as b, PostMessageType as c };
|
package/dist/sdk/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { T as Transport, P as PasskeyAssertor, R as RelyingPartyOriginInput, K as KvStorage } from '../interfaces-
|
|
2
|
-
export { O as OAuthOpener, a as PlatformImpls, W as WebAuthnAssertionResponse, b as WebAuthnRequestOptions, r as resolveRelyingPartyOrigin } from '../interfaces-
|
|
1
|
+
import { T as Transport, P as PasskeyAssertor, R as RelyingPartyOriginInput, K as KvStorage } from '../interfaces-CF5UrEBb.mjs';
|
|
2
|
+
export { O as OAuthOpener, a as PlatformImpls, W as WebAuthnAssertionResponse, b as WebAuthnRequestOptions, r as resolveRelyingPartyOrigin } from '../interfaces-CF5UrEBb.mjs';
|
|
3
3
|
import { C as CachedAssertion } from '../passkey-cache-WnDFQ-v4.mjs';
|
|
4
4
|
import { EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumGetTokenAccountsByOwnerParams, EthereumGetTokenAccountsByOwnerResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, SendEmailOtpResponse, PublicWallet, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, ListEphemeralSignersResult, RevokeEphemeralSignerParams } from '../types/index.mjs';
|
|
5
|
-
import '../post-message-
|
|
5
|
+
import '../post-message-2NAnU0Lf.mjs';
|
|
6
6
|
|
|
7
7
|
type AssertPasskeyInParentResult = CachedAssertion;
|
|
8
8
|
declare const assertPasskeyInParent: ({ transport, passkey, publishableKey, validateCredentialInAllowList, }: {
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { T as Transport, P as PasskeyAssertor, R as RelyingPartyOriginInput, K as KvStorage } from '../interfaces-
|
|
2
|
-
export { O as OAuthOpener, a as PlatformImpls, W as WebAuthnAssertionResponse, b as WebAuthnRequestOptions, r as resolveRelyingPartyOrigin } from '../interfaces-
|
|
1
|
+
import { T as Transport, P as PasskeyAssertor, R as RelyingPartyOriginInput, K as KvStorage } from '../interfaces-B5zxo2Jx.js';
|
|
2
|
+
export { O as OAuthOpener, a as PlatformImpls, W as WebAuthnAssertionResponse, b as WebAuthnRequestOptions, r as resolveRelyingPartyOrigin } from '../interfaces-B5zxo2Jx.js';
|
|
3
3
|
import { C as CachedAssertion } from '../passkey-cache-WnDFQ-v4.js';
|
|
4
4
|
import { EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumGetTokenAccountsByOwnerParams, EthereumGetTokenAccountsByOwnerResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, SendEmailOtpResponse, PublicWallet, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, ListEphemeralSignersResult, RevokeEphemeralSignerParams } from '../types/index.js';
|
|
5
|
-
import '../post-message-
|
|
5
|
+
import '../post-message-2NAnU0Lf.js';
|
|
6
6
|
|
|
7
7
|
type AssertPasskeyInParentResult = CachedAssertion;
|
|
8
8
|
declare const assertPasskeyInParent: ({ transport, passkey, publishableKey, validateCredentialInAllowList, }: {
|
package/dist/sdk/index.mjs
CHANGED
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from '../post-message-
|
|
1
|
+
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from '../post-message-2NAnU0Lf.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get the appropriate MoonKey API URL based on environment configuration
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from '../post-message-
|
|
1
|
+
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from '../post-message-2NAnU0Lf.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get the appropriate MoonKey API URL based on environment configuration
|
package/dist/utils/index.js
CHANGED
|
@@ -269,8 +269,11 @@ var sendReactNativeReply = (response) => {
|
|
|
269
269
|
} catch {
|
|
270
270
|
}
|
|
271
271
|
};
|
|
272
|
+
var QUEUE_TTL_MS = 2e4;
|
|
273
|
+
var MAX_PENDING_PER_KEY = 16;
|
|
272
274
|
var PostMessageServer = class {
|
|
273
275
|
constructor(originValidator) {
|
|
276
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
274
277
|
this.trustedSources = /* @__PURE__ */ new Set();
|
|
275
278
|
this.handlers = /* @__PURE__ */ new Map();
|
|
276
279
|
this.originValidator = originValidator;
|
|
@@ -285,6 +288,20 @@ var PostMessageServer = class {
|
|
|
285
288
|
register(type, method, handler) {
|
|
286
289
|
const key = `${type}:${method}`;
|
|
287
290
|
this.handlers.set(key, handler);
|
|
291
|
+
const queued = this.pending.get(key);
|
|
292
|
+
if (queued?.length) {
|
|
293
|
+
this.pending.delete(key);
|
|
294
|
+
const now = Date.now();
|
|
295
|
+
for (const { request, reply, at } of queued) {
|
|
296
|
+
if (now - at < QUEUE_TTL_MS) {
|
|
297
|
+
void this.invokeHandler(
|
|
298
|
+
handler,
|
|
299
|
+
request,
|
|
300
|
+
reply
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
288
305
|
}
|
|
289
306
|
cleanup() {
|
|
290
307
|
window.removeEventListener("message", this.handleMessage.bind(this));
|
|
@@ -349,29 +366,57 @@ var PostMessageServer = class {
|
|
|
349
366
|
const key = `${request.type}:${request.method}`;
|
|
350
367
|
const handler = this.handlers.get(key);
|
|
351
368
|
if (handler) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
369
|
+
await this.invokeHandler(handler, request, reply);
|
|
370
|
+
} else {
|
|
371
|
+
this.bufferRequest(key, request, reply);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
async invokeHandler(handler, request, reply) {
|
|
375
|
+
try {
|
|
376
|
+
const data = await handler(request.payload);
|
|
377
|
+
reply({
|
|
378
|
+
id: request.id,
|
|
379
|
+
type: request.type,
|
|
380
|
+
success: true,
|
|
381
|
+
data
|
|
382
|
+
});
|
|
383
|
+
} catch (error) {
|
|
384
|
+
const extras = {};
|
|
385
|
+
if (error && typeof error === "object") {
|
|
386
|
+
for (const key of FORWARDED_ERROR_FIELDS) {
|
|
387
|
+
const value = error[key];
|
|
388
|
+
if (value !== void 0) extras[key] = value;
|
|
367
389
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
390
|
+
}
|
|
391
|
+
reply({
|
|
392
|
+
...extras,
|
|
393
|
+
id: request.id,
|
|
394
|
+
type: request.type,
|
|
395
|
+
success: false,
|
|
396
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
bufferRequest(key, request, reply) {
|
|
401
|
+
this.evictExpiredPending();
|
|
402
|
+
let queue = this.pending.get(key);
|
|
403
|
+
if (!queue) {
|
|
404
|
+
queue = [];
|
|
405
|
+
this.pending.set(key, queue);
|
|
406
|
+
}
|
|
407
|
+
queue.push({ request, reply, at: Date.now() });
|
|
408
|
+
if (queue.length > MAX_PENDING_PER_KEY) {
|
|
409
|
+
queue.splice(0, queue.length - MAX_PENDING_PER_KEY);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
evictExpiredPending() {
|
|
413
|
+
const now = Date.now();
|
|
414
|
+
for (const [key, queue] of this.pending) {
|
|
415
|
+
const fresh = queue.filter((e) => now - e.at < QUEUE_TTL_MS);
|
|
416
|
+
if (fresh.length) {
|
|
417
|
+
this.pending.set(key, fresh);
|
|
418
|
+
} else {
|
|
419
|
+
this.pending.delete(key);
|
|
375
420
|
}
|
|
376
421
|
}
|
|
377
422
|
}
|
package/dist/utils/index.mjs
CHANGED
package/dist/web/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PostMessageClient } from '../post-message-
|
|
2
|
-
import { T as Transport, P as PasskeyAssertor, K as KvStorage } from '../interfaces-
|
|
1
|
+
import { P as PostMessageClient } from '../post-message-2NAnU0Lf.mjs';
|
|
2
|
+
import { T as Transport, P as PasskeyAssertor, K as KvStorage } from '../interfaces-CF5UrEBb.mjs';
|
|
3
3
|
|
|
4
4
|
declare const getCachedPostMessageClient: (contentWindow: Window) => PostMessageClient;
|
|
5
5
|
/**
|
package/dist/web/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PostMessageClient } from '../post-message-
|
|
2
|
-
import { T as Transport, P as PasskeyAssertor, K as KvStorage } from '../interfaces-
|
|
1
|
+
import { P as PostMessageClient } from '../post-message-2NAnU0Lf.js';
|
|
2
|
+
import { T as Transport, P as PasskeyAssertor, K as KvStorage } from '../interfaces-B5zxo2Jx.js';
|
|
3
3
|
|
|
4
4
|
declare const getCachedPostMessageClient: (contentWindow: Window) => PostMessageClient;
|
|
5
5
|
/**
|
package/dist/web/index.js
CHANGED
|
@@ -114,8 +114,11 @@ var sendReactNativeReply = (response) => {
|
|
|
114
114
|
} catch {
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
|
+
var QUEUE_TTL_MS = 2e4;
|
|
118
|
+
var MAX_PENDING_PER_KEY = 16;
|
|
117
119
|
var PostMessageServer = class {
|
|
118
120
|
constructor(originValidator) {
|
|
121
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
119
122
|
this.trustedSources = /* @__PURE__ */ new Set();
|
|
120
123
|
this.handlers = /* @__PURE__ */ new Map();
|
|
121
124
|
this.originValidator = originValidator;
|
|
@@ -130,6 +133,20 @@ var PostMessageServer = class {
|
|
|
130
133
|
register(type, method, handler) {
|
|
131
134
|
const key = `${type}:${method}`;
|
|
132
135
|
this.handlers.set(key, handler);
|
|
136
|
+
const queued = this.pending.get(key);
|
|
137
|
+
if (queued?.length) {
|
|
138
|
+
this.pending.delete(key);
|
|
139
|
+
const now = Date.now();
|
|
140
|
+
for (const { request, reply, at } of queued) {
|
|
141
|
+
if (now - at < QUEUE_TTL_MS) {
|
|
142
|
+
void this.invokeHandler(
|
|
143
|
+
handler,
|
|
144
|
+
request,
|
|
145
|
+
reply
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
133
150
|
}
|
|
134
151
|
cleanup() {
|
|
135
152
|
window.removeEventListener("message", this.handleMessage.bind(this));
|
|
@@ -194,29 +211,57 @@ var PostMessageServer = class {
|
|
|
194
211
|
const key = `${request.type}:${request.method}`;
|
|
195
212
|
const handler = this.handlers.get(key);
|
|
196
213
|
if (handler) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
214
|
+
await this.invokeHandler(handler, request, reply);
|
|
215
|
+
} else {
|
|
216
|
+
this.bufferRequest(key, request, reply);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async invokeHandler(handler, request, reply) {
|
|
220
|
+
try {
|
|
221
|
+
const data = await handler(request.payload);
|
|
222
|
+
reply({
|
|
223
|
+
id: request.id,
|
|
224
|
+
type: request.type,
|
|
225
|
+
success: true,
|
|
226
|
+
data
|
|
227
|
+
});
|
|
228
|
+
} catch (error) {
|
|
229
|
+
const extras = {};
|
|
230
|
+
if (error && typeof error === "object") {
|
|
231
|
+
for (const key of FORWARDED_ERROR_FIELDS) {
|
|
232
|
+
const value = error[key];
|
|
233
|
+
if (value !== void 0) extras[key] = value;
|
|
212
234
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
235
|
+
}
|
|
236
|
+
reply({
|
|
237
|
+
...extras,
|
|
238
|
+
id: request.id,
|
|
239
|
+
type: request.type,
|
|
240
|
+
success: false,
|
|
241
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
bufferRequest(key, request, reply) {
|
|
246
|
+
this.evictExpiredPending();
|
|
247
|
+
let queue = this.pending.get(key);
|
|
248
|
+
if (!queue) {
|
|
249
|
+
queue = [];
|
|
250
|
+
this.pending.set(key, queue);
|
|
251
|
+
}
|
|
252
|
+
queue.push({ request, reply, at: Date.now() });
|
|
253
|
+
if (queue.length > MAX_PENDING_PER_KEY) {
|
|
254
|
+
queue.splice(0, queue.length - MAX_PENDING_PER_KEY);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
evictExpiredPending() {
|
|
258
|
+
const now = Date.now();
|
|
259
|
+
for (const [key, queue] of this.pending) {
|
|
260
|
+
const fresh = queue.filter((e) => now - e.at < QUEUE_TTL_MS);
|
|
261
|
+
if (fresh.length) {
|
|
262
|
+
this.pending.set(key, fresh);
|
|
263
|
+
} else {
|
|
264
|
+
this.pending.delete(key);
|
|
220
265
|
}
|
|
221
266
|
}
|
|
222
267
|
}
|
package/dist/web/index.mjs
CHANGED