@rhinestone/1auth 0.1.1 → 0.1.2

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.
@@ -10,8 +10,8 @@ interface ThemeConfig {
10
10
  interface PasskeyProviderConfig {
11
11
  /** Base URL of the auth API. Defaults to https://passkey.1auth.box */
12
12
  providerUrl?: string;
13
- /** Client identifier for this application */
14
- clientId: string;
13
+ /** Client identifier for this application (optional for development) */
14
+ clientId?: string;
15
15
  /** Optional redirect URL for redirect flow */
16
16
  redirectUrl?: string;
17
17
  /** Optional URL of the dialog UI. Defaults to providerUrl */
@@ -45,6 +45,22 @@ interface RegisterResult {
45
45
  message: string;
46
46
  };
47
47
  }
48
+ /**
49
+ * Result of the connect modal (lightweight connection without passkey auth)
50
+ */
51
+ interface ConnectResult {
52
+ success: boolean;
53
+ /** Username of the connected account */
54
+ username?: string;
55
+ /** Whether this was auto-connected (user had auto-connect enabled) */
56
+ autoConnected?: boolean;
57
+ /** Action to take when connection was not successful */
58
+ action?: "switch" | "cancel";
59
+ error?: {
60
+ code: string;
61
+ message: string;
62
+ };
63
+ }
48
64
  /**
49
65
  * Options for the authenticate() method
50
66
  */
@@ -77,7 +93,7 @@ interface AuthenticateResult {
77
93
  signature?: WebAuthnSignature;
78
94
  /**
79
95
  * The hash that was actually signed (so apps can verify server-side).
80
- * Computed as: keccak256("\x19Passkey Signed Message:\n" + len + challenge)
96
+ * Computed as: keccak256("\x19Ethereum Signed Message:\n" + len + challenge) (EIP-191)
81
97
  */
82
98
  signedHash?: `0x${string}`;
83
99
  error?: {
@@ -112,8 +128,8 @@ interface SignMessageResult {
112
128
  /** The message that was signed */
113
129
  signedMessage?: string;
114
130
  /**
115
- * The hash that was actually signed (with domain separator).
116
- * Computed as: keccak256("\x19Passkey Signed Message:\n" + len + message)
131
+ * The hash that was actually signed (EIP-191 format).
132
+ * Computed as: keccak256("\x19Ethereum Signed Message:\n" + len + message)
117
133
  * Use hashMessage() from the SDK to verify this matches your original message.
118
134
  */
119
135
  signedHash?: `0x${string}`;
@@ -186,8 +202,14 @@ interface PasskeyCredentials {
186
202
  interface SigningSuccess {
187
203
  success: true;
188
204
  requestId?: string;
189
- signature: WebAuthnSignature;
205
+ /** WebAuthn signature - present for message/typedData signing */
206
+ signature?: WebAuthnSignature;
207
+ /** Array of signatures for multi-origin cross-chain intents (one per source chain) */
208
+ originSignatures?: WebAuthnSignature[];
209
+ /** Credentials of the passkey used for signing - present for message/typedData signing */
190
210
  passkey?: PasskeyCredentials;
211
+ /** Intent ID - present for intent signing (after execute in dialog) */
212
+ intentId?: string;
191
213
  }
192
214
  type SigningErrorCode = "USER_REJECTED" | "EXPIRED" | "INVALID_REQUEST" | "NETWORK_ERROR" | "POPUP_BLOCKED" | "SIGNING_FAILED" | "UNKNOWN";
193
215
  interface EmbedOptions {
@@ -242,21 +264,21 @@ interface IntentCall {
242
264
  interface IntentTokenRequest {
243
265
  /** Token contract address */
244
266
  token: string;
245
- /** Amount (as string for serialization) */
246
- amount: string;
267
+ /** Amount in base units (use parseUnits for decimals) */
268
+ amount: bigint;
247
269
  }
248
270
  /**
249
271
  * A signed intent request from a backend.
250
272
  * This provides XSS protection by ensuring calls were constructed server-side.
251
273
  */
252
- interface MerchantSignedIntent {
274
+ interface DeveloperSignedIntent {
253
275
  /** Developer ID (clientId). Mapped to merchantId for the API. */
254
276
  developerId?: string;
255
277
  /** Wire field used by the API (same value as developerId) */
256
278
  merchantId?: string;
257
279
  /** Target chain ID */
258
280
  targetChain: number;
259
- /** Calls to execute (signed by merchant) */
281
+ /** Calls to execute (signed by developer) */
260
282
  calls: IntentCall[];
261
283
  /** Username of the signer */
262
284
  username?: string;
@@ -273,6 +295,8 @@ interface MerchantSignedIntent {
273
295
  /** Optional token requests */
274
296
  tokenRequests?: IntentTokenRequest[];
275
297
  }
298
+ /** @deprecated Use DeveloperSignedIntent instead */
299
+ type MerchantSignedIntent = DeveloperSignedIntent;
276
300
  type IntentSigner = (params: {
277
301
  username: string;
278
302
  accountAddress?: string;
@@ -280,7 +304,7 @@ type IntentSigner = (params: {
280
304
  calls: IntentCall[];
281
305
  tokenRequests?: IntentTokenRequest[];
282
306
  sourceAssets?: string[];
283
- }) => Promise<MerchantSignedIntent>;
307
+ }) => Promise<DeveloperSignedIntent>;
284
308
  /**
285
309
  * Options for sendIntent
286
310
  */
@@ -299,13 +323,19 @@ interface SendIntentOptions {
299
323
  * Example: ['USDC'] or ['0x...'] to only use USDC as input.
300
324
  */
301
325
  sourceAssets?: string[];
326
+ /**
327
+ * Source chain ID for the assets.
328
+ * When specified with sourceAssets containing addresses, tells orchestrator
329
+ * which chain to look for those tokens on.
330
+ */
331
+ sourceChainId?: number;
302
332
  /** When to close the dialog and return success. Defaults to "preconfirmed" */
303
333
  closeOn?: CloseOnStatus;
304
334
  /**
305
- * Pre-signed intent from merchant backend (XSS protected)
335
+ * Pre-signed intent from developer backend (XSS protected)
306
336
  * If provided, username/targetChain/calls/tokenRequests are ignored
307
337
  */
308
- signedIntent?: MerchantSignedIntent;
338
+ signedIntent?: DeveloperSignedIntent;
309
339
  /**
310
340
  * Wait for a transaction hash before resolving.
311
341
  * Defaults to false to preserve existing behavior.
@@ -339,7 +369,7 @@ interface IntentQuote {
339
369
  /**
340
370
  * Status of an intent (local states)
341
371
  */
342
- type IntentStatus = "pending" | "quoted" | "signed" | "submitted" | "completed" | "failed" | "expired";
372
+ type IntentStatus = "pending" | "quoted" | "signed" | "submitted" | "claimed" | "preconfirmed" | "filled" | "completed" | "failed" | "expired" | "unknown";
343
373
  /**
344
374
  * Orchestrator status (from Rhinestone)
345
375
  * These are the statuses we can receive when polling
@@ -377,13 +407,25 @@ interface SendIntentResult {
377
407
  * Prepare intent response from auth service
378
408
  */
379
409
  interface PrepareIntentResponse {
380
- intentId: string;
381
410
  quote: IntentQuote;
382
411
  transaction: TransactionDetails;
383
412
  challenge: string;
384
413
  expiresAt: string;
385
414
  /** Account address for the sign dialog to detect self-transfer vs external send */
386
415
  accountAddress?: string;
416
+ /** Serialized PreparedTransactionData from orchestrator - needed for execute */
417
+ intentOp: string;
418
+ /** User ID for creating intent record on execute */
419
+ userId: string;
420
+ /** Target chain ID */
421
+ targetChain: number;
422
+ /** JSON stringified calls */
423
+ calls: string;
424
+ /** Origin message hashes for multi-source cross-chain intents */
425
+ originMessages?: Array<{
426
+ chainId: number;
427
+ messageHash: string;
428
+ }>;
387
429
  }
388
430
  /**
389
431
  * Execute intent response from auth service
@@ -394,6 +436,8 @@ interface ExecuteIntentResponse {
394
436
  operationId?: string;
395
437
  status: IntentStatus;
396
438
  transactionHash?: string;
439
+ /** Transaction result data needed for waiting via POST /api/intent/wait */
440
+ transactionResult?: unknown;
397
441
  error?: {
398
442
  code: string;
399
443
  message: string;
@@ -407,8 +451,8 @@ interface SendSwapOptions {
407
451
  username: string;
408
452
  /** Target chain ID where swap executes */
409
453
  targetChain: number;
410
- /** Token to swap from (address or supported symbol like 'ETH', 'USDC') */
411
- fromToken: string;
454
+ /** Token to swap from (address or supported symbol like 'ETH', 'USDC'). Omit to let the orchestrator pick. */
455
+ fromToken?: string;
412
456
  /** Token to swap to (address or supported symbol) */
413
457
  toToken: string;
414
458
  /** Amount to swap in human-readable format (e.g., "0.1") */
@@ -420,6 +464,11 @@ interface SendSwapOptions {
420
464
  * This constrains which tokens the orchestrator can use as input.
421
465
  */
422
466
  sourceAssets?: string[];
467
+ /**
468
+ * Source chain ID for the assets. When specified, the orchestrator will only
469
+ * look for source assets on this specific chain.
470
+ */
471
+ sourceChainId?: number;
423
472
  /** When to close the dialog. Defaults to "preconfirmed" */
424
473
  closeOn?: CloseOnStatus;
425
474
  /** Wait for a transaction hash before resolving. */
@@ -433,8 +482,8 @@ interface SendSwapOptions {
433
482
  * Quote information from DEX aggregator
434
483
  */
435
484
  interface SwapQuote {
436
- /** Token being sold */
437
- fromToken: string;
485
+ /** Token being sold (undefined when orchestrator picks) */
486
+ fromToken?: string;
438
487
  /** Token being bought */
439
488
  toToken: string;
440
489
  /** Amount of fromToken being sold */
@@ -519,6 +568,147 @@ interface SignTypedDataResult {
519
568
  message: string;
520
569
  };
521
570
  }
571
+ /**
572
+ * Options for querying intent history
573
+ */
574
+ interface IntentHistoryOptions {
575
+ /** Maximum number of intents to return (default: 50, max: 100) */
576
+ limit?: number;
577
+ /** Number of intents to skip for pagination */
578
+ offset?: number;
579
+ /** Filter by intent status */
580
+ status?: IntentStatus;
581
+ /** Filter by creation date (ISO string) - intents created on or after this date */
582
+ from?: string;
583
+ /** Filter by creation date (ISO string) - intents created on or before this date */
584
+ to?: string;
585
+ }
586
+ /**
587
+ * Single intent item in history response
588
+ */
589
+ interface IntentHistoryItem {
590
+ /** Intent identifier (orchestrator's ID, used as primary key) */
591
+ intentId: string;
592
+ /** Current status of the intent */
593
+ status: IntentStatus;
594
+ /** Transaction hash (if completed) */
595
+ transactionHash?: string;
596
+ /** Target chain ID */
597
+ targetChain: number;
598
+ /** Calls that were executed */
599
+ calls: IntentCall[];
600
+ /** When the intent was created (ISO string) */
601
+ createdAt: string;
602
+ /** When the intent was last updated (ISO string) */
603
+ updatedAt: string;
604
+ }
605
+ /**
606
+ * Result of getIntentHistory
607
+ */
608
+ interface IntentHistoryResult {
609
+ /** List of intents */
610
+ intents: IntentHistoryItem[];
611
+ /** Total count of matching intents */
612
+ total: number;
613
+ /** Whether there are more intents beyond this page */
614
+ hasMore: boolean;
615
+ }
616
+ /**
617
+ * A single intent within a batch
618
+ */
619
+ interface BatchIntentItem {
620
+ /** Target chain ID */
621
+ targetChain: number;
622
+ /** Calls to execute on the target chain */
623
+ calls: IntentCall[];
624
+ /** Optional token requests */
625
+ tokenRequests?: IntentTokenRequest[];
626
+ /** Constrain which tokens can be used as input */
627
+ sourceAssets?: string[];
628
+ /** Source chain ID for the assets */
629
+ sourceChainId?: number;
630
+ }
631
+ /**
632
+ * Options for sendBatchIntent
633
+ */
634
+ interface SendBatchIntentOptions {
635
+ /** Username of the signer */
636
+ username: string;
637
+ /** Array of intents to execute as a batch */
638
+ intents: BatchIntentItem[];
639
+ /** When to close the dialog for each intent. Defaults to "preconfirmed" */
640
+ closeOn?: CloseOnStatus;
641
+ }
642
+ /**
643
+ * Result for a single intent within a batch
644
+ */
645
+ interface BatchIntentItemResult {
646
+ /** Index in the original batch */
647
+ index: number;
648
+ /** Whether this intent succeeded */
649
+ success: boolean;
650
+ /** Intent ID from orchestrator */
651
+ intentId: string;
652
+ /** Current status */
653
+ status: IntentStatus;
654
+ /** Error details if failed */
655
+ error?: {
656
+ code: string;
657
+ message: string;
658
+ };
659
+ }
660
+ /**
661
+ * Result of sendBatchIntent
662
+ */
663
+ interface SendBatchIntentResult {
664
+ /** Whether ALL intents succeeded */
665
+ success: boolean;
666
+ /** Per-intent results */
667
+ results: BatchIntentItemResult[];
668
+ /** Count of successful intents */
669
+ successCount: number;
670
+ /** Count of failed intents */
671
+ failureCount: number;
672
+ }
673
+ /**
674
+ * Prepared intent data within a batch response
675
+ */
676
+ interface PreparedBatchIntent {
677
+ /** Index in the original batch */
678
+ index: number;
679
+ /** Quote from orchestrator */
680
+ quote: IntentQuote;
681
+ /** Decoded transaction details for UI */
682
+ transaction: TransactionDetails;
683
+ /** Serialized PreparedTransactionData from orchestrator */
684
+ intentOp: string;
685
+ /** Expiry for this specific intent */
686
+ expiresAt: string;
687
+ /** Target chain ID */
688
+ targetChain: number;
689
+ /** JSON stringified calls */
690
+ calls: string;
691
+ /** Origin message hashes for this intent */
692
+ originMessages: Array<{
693
+ chainId: number;
694
+ messageHash: string;
695
+ }>;
696
+ }
697
+ /**
698
+ * Prepare batch intent response from auth service
699
+ */
700
+ interface PrepareBatchIntentResponse {
701
+ /** Per-intent prepared data */
702
+ intents: PreparedBatchIntent[];
703
+ /** Shared challenge (merkle root of ALL origin hashes across ALL intents) */
704
+ challenge: string;
705
+ /** User ID */
706
+ userId: string;
707
+ /** Account address */
708
+ accountAddress?: string;
709
+ /** Global expiry (earliest of all intent expiries) */
710
+ expiresAt: string;
711
+ }
522
712
 
523
713
  declare class OneAuthClient {
524
714
  private config;
@@ -549,7 +739,7 @@ declare class OneAuthClient {
549
739
  /**
550
740
  * Get the configured client ID
551
741
  */
552
- getClientId(): string;
742
+ getClientId(): string | undefined;
553
743
  private waitForTransactionHash;
554
744
  /**
555
745
  * Open the auth dialog (sign in + sign up).
@@ -559,6 +749,31 @@ declare class OneAuthClient {
559
749
  theme?: ThemeConfig;
560
750
  oauthEnabled?: boolean;
561
751
  }): Promise<LoginResult | RegisterResult>;
752
+ /**
753
+ * Open the connect dialog (lightweight connection without passkey auth).
754
+ *
755
+ * This method shows a simple connection confirmation dialog that doesn't
756
+ * require a passkey signature. Users can optionally enable "auto-connect"
757
+ * to skip this dialog in the future.
758
+ *
759
+ * If the user has never connected before, this will return action: "switch"
760
+ * to indicate that the full auth modal should be opened instead.
761
+ *
762
+ * @example
763
+ * ```typescript
764
+ * const result = await client.connectWithModal();
765
+ *
766
+ * if (result.success) {
767
+ * console.log('Connected as:', result.username);
768
+ * } else if (result.action === 'switch') {
769
+ * // User needs to sign in first
770
+ * const authResult = await client.authWithModal();
771
+ * }
772
+ * ```
773
+ */
774
+ connectWithModal(options?: {
775
+ theme?: ThemeConfig;
776
+ }): Promise<ConnectResult>;
562
777
  /**
563
778
  * Authenticate a user with an optional challenge to sign.
564
779
  *
@@ -595,7 +810,7 @@ declare class OneAuthClient {
595
810
  theme?: ThemeConfig;
596
811
  }): Promise<AuthenticateResult>;
597
812
  /**
598
- * Show signing in a modal overlay (Porto-style iframe dialog)
813
+ * Show signing in a modal overlay (iframe dialog)
599
814
  */
600
815
  signWithModal(options: SigningRequestOptions & {
601
816
  theme?: ThemeConfig;
@@ -630,6 +845,34 @@ declare class OneAuthClient {
630
845
  * ```
631
846
  */
632
847
  sendIntent(options: SendIntentOptions): Promise<SendIntentResult>;
848
+ /**
849
+ * Send a batch of intents for multi-chain execution with a single passkey tap.
850
+ *
851
+ * This method prepares multiple intents, shows a paginated review,
852
+ * and signs all intents with a single passkey tap via a shared merkle tree.
853
+ *
854
+ * @example
855
+ * ```typescript
856
+ * const result = await client.sendBatchIntent({
857
+ * username: 'alice',
858
+ * intents: [
859
+ * {
860
+ * targetChain: 8453, // Base
861
+ * calls: [{ to: '0x...', data: '0x...', label: 'Swap on Base' }],
862
+ * },
863
+ * {
864
+ * targetChain: 42161, // Arbitrum
865
+ * calls: [{ to: '0x...', data: '0x...', label: 'Mint on Arbitrum' }],
866
+ * },
867
+ * ],
868
+ * });
869
+ *
870
+ * if (result.success) {
871
+ * console.log(`${result.successCount} intents submitted`);
872
+ * }
873
+ * ```
874
+ */
875
+ sendBatchIntent(options: SendBatchIntentOptions): Promise<SendBatchIntentResult>;
633
876
  /**
634
877
  * Send transaction status to the dialog iframe
635
878
  */
@@ -642,6 +885,11 @@ declare class OneAuthClient {
642
885
  * Wait for signing result (simplified - no requestId matching)
643
886
  */
644
887
  private waitForSigningResponse;
888
+ /**
889
+ * Wait for signing result with auto-refresh support
890
+ * This method handles both signing results and quote refresh requests from the dialog
891
+ */
892
+ private waitForSigningWithRefresh;
645
893
  /**
646
894
  * Wait for the dialog to be closed
647
895
  */
@@ -653,6 +901,26 @@ declare class OneAuthClient {
653
901
  * that hasn't completed yet.
654
902
  */
655
903
  getIntentStatus(intentId: string): Promise<SendIntentResult>;
904
+ /**
905
+ * Get the history of intents for the authenticated user.
906
+ *
907
+ * Requires an active session (user must be logged in).
908
+ *
909
+ * @example
910
+ * ```typescript
911
+ * // Get recent intents
912
+ * const history = await client.getIntentHistory({ limit: 10 });
913
+ *
914
+ * // Filter by status
915
+ * const pending = await client.getIntentHistory({ status: 'pending' });
916
+ *
917
+ * // Filter by date range
918
+ * const lastWeek = await client.getIntentHistory({
919
+ * from: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
920
+ * });
921
+ * ```
922
+ */
923
+ getIntentHistory(options?: IntentHistoryOptions): Promise<IntentHistoryResult>;
656
924
  /**
657
925
  * Send a swap intent through the Rhinestone orchestrator
658
926
  *
@@ -771,15 +1039,27 @@ declare class OneAuthClient {
771
1039
  getPasskeys(username: string): Promise<PasskeyCredential[]>;
772
1040
  private createSigningRequest;
773
1041
  private openPopup;
1042
+ /**
1043
+ * Wait for the dialog iframe to signal ready, then send init data.
1044
+ * Also handles early close (X button, escape, backdrop) during the ready phase.
1045
+ * Returns true if dialog is ready, false if it was closed before becoming ready.
1046
+ */
1047
+ private waitForDialogReady;
774
1048
  /**
775
1049
  * Create a modal dialog with an iframe inside.
776
1050
  */
777
1051
  private createModalDialog;
778
1052
  private waitForModalAuthResponse;
1053
+ /**
1054
+ * Open a popup for auth and wait for the result.
1055
+ * Used when iframe mode fails (e.g., due to password manager interference).
1056
+ */
1057
+ private waitForPopupAuthResponse;
779
1058
  private waitForAuthenticateResponse;
1059
+ private waitForConnectResponse;
780
1060
  private waitForModalSigningResponse;
781
1061
  private waitForPopupResponse;
782
1062
  private fetchSigningResult;
783
1063
  }
784
1064
 
785
- export { type AuthenticateOptions as A, type BalanceRequirement as B, type CreateSigningRequestResponse as C, type PrepareIntentResponse as D, type EmbedOptions as E, type ExecuteIntentResponse as F, type SendSwapOptions as G, type SendSwapResult as H, type IntentSigner as I, type SwapQuote as J, type ThemeConfig as K, type LoginOptions as L, type MerchantSignedIntent as M, OneAuthClient as O, type PasskeyProviderConfig as P, type RegisterOptions as R, type SendIntentResult as S, type TransactionAction as T, type UserPasskeysResponse as U, type WebAuthnSignature as W, type IntentCall as a, type SigningRequestOptions as b, type SigningResult as c, type SigningSuccess as d, type SigningError as e, type SigningErrorCode as f, type SigningRequestStatus as g, type PasskeyCredential as h, type RegisterResult as i, type LoginResult as j, type AuthenticateResult as k, type SignMessageOptions as l, type SignMessageResult as m, type SignTypedDataOptions as n, type SignTypedDataResult as o, type EIP712Domain as p, type EIP712Types as q, type EIP712TypeField as r, type TransactionFees as s, type TransactionDetails as t, type IntentTokenRequest as u, type SendIntentOptions as v, type IntentQuote as w, type IntentStatus as x, type OrchestratorStatus as y, type CloseOnStatus as z };
1065
+ export { type TransactionAction as $, type AuthenticateOptions as A, type BalanceRequirement as B, type CloseOnStatus as C, type DeveloperSignedIntent as D, type EIP712Domain as E, type SendSwapOptions as F, type SendSwapResult as G, type SignMessageOptions as H, type IntentSigner as I, type SignMessageResult as J, type SignTypedDataOptions as K, type LoginOptions as L, type MerchantSignedIntent as M, type SignTypedDataResult as N, OneAuthClient as O, type PasskeyCredential as P, type SigningError as Q, type RegisterOptions as R, type SendIntentResult as S, type SigningErrorCode as T, type SigningRequestOptions as U, type SigningRequestStatus as V, type WebAuthnSignature as W, type SigningResult as X, type SigningSuccess as Y, type SwapQuote as Z, type ThemeConfig as _, type IntentCall as a, type TransactionDetails as a0, type TransactionFees as a1, type UserPasskeysResponse as a2, type AuthenticateResult as b, type BatchIntentItem as c, type BatchIntentItemResult as d, type ConnectResult as e, type CreateSigningRequestResponse as f, type EIP712TypeField as g, type EIP712Types as h, type EmbedOptions as i, type ExecuteIntentResponse as j, type IntentHistoryItem as k, type IntentHistoryOptions as l, type IntentHistoryResult as m, type IntentQuote as n, type IntentStatus as o, type IntentTokenRequest as p, type LoginResult as q, type OrchestratorStatus as r, type PasskeyProviderConfig as s, type PrepareBatchIntentResponse as t, type PrepareIntentResponse as u, type PreparedBatchIntent as v, type RegisterResult as w, type SendBatchIntentOptions as x, type SendBatchIntentResult as y, type SendIntentOptions as z };