@accesly/react 1.5.0 → 1.6.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
@@ -467,6 +467,45 @@ interface SendXlmResult {
467
467
  readonly status: string;
468
468
  readonly explorerUrl: string;
469
469
  }
470
+ /**
471
+ * Input para `tx.swap(...)` — cambia XLM por USDC (o viceversa) usando Soroswap
472
+ * Aggregator. El SDK firma la auth entry del Smart Account contra la regla
473
+ * biometric-tx del asset de entrada.
474
+ */
475
+ interface SwapInput {
476
+ /** Asset de entrada. */
477
+ readonly fromAsset: TransferAsset;
478
+ /** Asset de salida (debe diferir de `fromAsset`). */
479
+ readonly toAsset: TransferAsset;
480
+ /** Stroops del input (1e-7). Ejemplo: `"125000000"` = 12.5 XLM. */
481
+ readonly amountIn: string;
482
+ /** Tolerancia de slippage en basis points. Default 50 (0.5%). */
483
+ readonly slippageBps?: number;
484
+ /** F1 (Shamir share) en plano — zeroizado tras firmar. */
485
+ readonly fragmentF1Plain: Uint8Array;
486
+ /** Llave AES-256 para descifrar el F2 envelope. */
487
+ readonly fragmentF2Key: Uint8Array;
488
+ /** Pubkey ed25519 del owner del Smart Account. */
489
+ readonly ownerPubkey: Uint8Array;
490
+ }
491
+ interface SwapResult {
492
+ readonly txHash: string;
493
+ readonly status: string;
494
+ readonly explorerUrl: string;
495
+ /**
496
+ * Quote summary que cotizó Soroswap. La UI puede mostrar
497
+ * `recibiste ${amountOut} ${toAsset}` después del success.
498
+ */
499
+ readonly quote: {
500
+ readonly fromAsset: TransferAsset;
501
+ readonly toAsset: TransferAsset;
502
+ readonly amountIn: string;
503
+ readonly amountOut: string;
504
+ readonly minAmountOut: string;
505
+ readonly priceImpactPct: string;
506
+ readonly platform: string;
507
+ };
508
+ }
470
509
  interface TxNamespace {
471
510
  /**
472
511
  * End-to-end XLM transfer desde el Smart Account del user.
@@ -491,6 +530,21 @@ interface TxNamespace {
491
530
  * - La pubkey derivada de la seed no matchea `ownerPubkey`.
492
531
  */
493
532
  send(input: SendXlmInput): Promise<SendXlmResult>;
533
+ /**
534
+ * **Fase D (1.6+):** swap XLM↔USDC vía Soroswap Aggregator. El backend hace
535
+ * el round-trip a la API de Soroswap (`/quote` + `/quote/build`), procesa el
536
+ * XDR resultante, y devuelve el material para que el SDK firme con el
537
+ * mismo passkey que `tx.send`.
538
+ *
539
+ * Auth: la auth entry del Smart Account se firma contra la regla
540
+ * biometric-tx del `fromAsset` (rule 0 para XLM, rule 1 para USDC). Si la
541
+ * wallet no tiene la regla del `fromAsset` (pre-1.4 sin USDC), el backend
542
+ * devuelve 409 — el caller debe disparar `wallet.activateAsset` primero.
543
+ *
544
+ * Returns `txHash` + `quote` summary con `amountOut` y `priceImpactPct` para
545
+ * que la UI muestre "Recibiste X USDC".
546
+ */
547
+ swap(input: SwapInput): Promise<SwapResult>;
494
548
  /**
495
549
  * Bajo nivel: firma un envelope Stellar ya construido con una seed ed25519
496
550
  * dada. Útil para flows custom que arman la tx fuera del SDK.
package/dist/index.d.ts CHANGED
@@ -467,6 +467,45 @@ interface SendXlmResult {
467
467
  readonly status: string;
468
468
  readonly explorerUrl: string;
469
469
  }
470
+ /**
471
+ * Input para `tx.swap(...)` — cambia XLM por USDC (o viceversa) usando Soroswap
472
+ * Aggregator. El SDK firma la auth entry del Smart Account contra la regla
473
+ * biometric-tx del asset de entrada.
474
+ */
475
+ interface SwapInput {
476
+ /** Asset de entrada. */
477
+ readonly fromAsset: TransferAsset;
478
+ /** Asset de salida (debe diferir de `fromAsset`). */
479
+ readonly toAsset: TransferAsset;
480
+ /** Stroops del input (1e-7). Ejemplo: `"125000000"` = 12.5 XLM. */
481
+ readonly amountIn: string;
482
+ /** Tolerancia de slippage en basis points. Default 50 (0.5%). */
483
+ readonly slippageBps?: number;
484
+ /** F1 (Shamir share) en plano — zeroizado tras firmar. */
485
+ readonly fragmentF1Plain: Uint8Array;
486
+ /** Llave AES-256 para descifrar el F2 envelope. */
487
+ readonly fragmentF2Key: Uint8Array;
488
+ /** Pubkey ed25519 del owner del Smart Account. */
489
+ readonly ownerPubkey: Uint8Array;
490
+ }
491
+ interface SwapResult {
492
+ readonly txHash: string;
493
+ readonly status: string;
494
+ readonly explorerUrl: string;
495
+ /**
496
+ * Quote summary que cotizó Soroswap. La UI puede mostrar
497
+ * `recibiste ${amountOut} ${toAsset}` después del success.
498
+ */
499
+ readonly quote: {
500
+ readonly fromAsset: TransferAsset;
501
+ readonly toAsset: TransferAsset;
502
+ readonly amountIn: string;
503
+ readonly amountOut: string;
504
+ readonly minAmountOut: string;
505
+ readonly priceImpactPct: string;
506
+ readonly platform: string;
507
+ };
508
+ }
470
509
  interface TxNamespace {
471
510
  /**
472
511
  * End-to-end XLM transfer desde el Smart Account del user.
@@ -491,6 +530,21 @@ interface TxNamespace {
491
530
  * - La pubkey derivada de la seed no matchea `ownerPubkey`.
492
531
  */
493
532
  send(input: SendXlmInput): Promise<SendXlmResult>;
533
+ /**
534
+ * **Fase D (1.6+):** swap XLM↔USDC vía Soroswap Aggregator. El backend hace
535
+ * el round-trip a la API de Soroswap (`/quote` + `/quote/build`), procesa el
536
+ * XDR resultante, y devuelve el material para que el SDK firme con el
537
+ * mismo passkey que `tx.send`.
538
+ *
539
+ * Auth: la auth entry del Smart Account se firma contra la regla
540
+ * biometric-tx del `fromAsset` (rule 0 para XLM, rule 1 para USDC). Si la
541
+ * wallet no tiene la regla del `fromAsset` (pre-1.4 sin USDC), el backend
542
+ * devuelve 409 — el caller debe disparar `wallet.activateAsset` primero.
543
+ *
544
+ * Returns `txHash` + `quote` summary con `amountOut` y `priceImpactPct` para
545
+ * que la UI muestre "Recibiste X USDC".
546
+ */
547
+ swap(input: SwapInput): Promise<SwapResult>;
494
548
  /**
495
549
  * Bajo nivel: firma un envelope Stellar ya construido con una seed ed25519
496
550
  * dada. Útil para flows custom que arman la tx fuera del SDK.
package/dist/index.js CHANGED
@@ -900,6 +900,49 @@ function useAccesly() {
900
900
  networkPassphrase: stellarConfig.networkPassphrase,
901
901
  ...input.expectedPublicKey ? { expectedPublicKey: input.expectedPublicKey } : {}
902
902
  });
903
+ },
904
+ async swap(input) {
905
+ const networkPassphrase = stellarConfig.networkPassphrase;
906
+ const verifierAddress = stellarConfig.ed25519VerifierAddress;
907
+ const explorerBase = networkPassphrase === "Public Global Stellar Network ; September 2015" ? "https://stellar.expert/explorer/public/tx/" : "https://stellar.expert/explorer/testnet/tx/";
908
+ const sim = await ctx.endpoints.swapSimulate({
909
+ fromAsset: input.fromAsset,
910
+ toAsset: input.toAsset,
911
+ amountIn: input.amountIn,
912
+ ...input.slippageBps !== void 0 ? { slippageBps: input.slippageBps } : {}
913
+ });
914
+ const ephemeral = generateX25519Keypair();
915
+ const wrappedF2 = await ctx.endpoints.getFragment2({
916
+ clientEphemeralPubkey: base64FromBytes(ephemeral.publicKey)
917
+ });
918
+ const sessionPlaintext = unwrapSessionFragment2(wrappedF2, ephemeral.privateKey).plaintext;
919
+ const fragmentF2Wire = JSON.parse(new TextDecoder().decode(sessionPlaintext));
920
+ const fragmentF2Envelope = {
921
+ nonce: base64ToBytes(fragmentF2Wire.nonce),
922
+ ciphertext: base64ToBytes(fragmentF2Wire.ciphertext)
923
+ };
924
+ const reconstructed = reconstructFromPlainAndEncrypted({
925
+ fragmentF1Plain: input.fragmentF1Plain,
926
+ fragmentF2: { envelope: fragmentF2Envelope, key: input.fragmentF2Key }
927
+ });
928
+ const { signedAuthEntryXdr } = await signSorobanAuthEntry({
929
+ signaturePayloadHashBase64: sim.signaturePayloadHashBase64,
930
+ contextRuleIds: [...sim.contextRuleIds],
931
+ placeholderAuthEntryXdr: sim.placeholderAuthEntryXdr,
932
+ ed25519Seed: reconstructed.privateSeed,
933
+ ed25519VerifierAddress: verifierAddress,
934
+ ownerPubkey: input.ownerPubkey
935
+ });
936
+ const submit = await ctx.endpoints.swapSubmit({
937
+ unsignedXdr: sim.unsignedXdr,
938
+ signedAuthEntryXdr
939
+ });
940
+ return {
941
+ txHash: submit.txHash,
942
+ status: submit.status,
943
+ explorerUrl: `${explorerBase}${submit.txHash}`,
944
+ quote: sim.quote
945
+ };
903
946
  }
904
947
  }),
905
948
  [ctx, stellarConfig]