@silentswap/sdk 0.0.77 → 0.0.79

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.
@@ -5,6 +5,14 @@
5
5
  * This module provides a simple interface for integrators to execute swaps without
6
6
  * needing to understand the underlying protocol details.
7
7
  *
8
+ * **Recovery (refund / prove delivery):** Save `result.viewingAuth` and the order ID
9
+ * for tracking, refund, and recovery. The mnemonic used for the facilitator group can
10
+ * be derived from the same entropy that was used to create the group: use
11
+ * `exportSecretMnemonicFromEntropy(entropy)` from this package. Recovery paths are
12
+ * BIP-44 paths of the form `m/44'/${coinType}'/${accountIndex}'/0/${addressIndex}`,
13
+ * built from the group's exported public keys (skip coin type `'*'`). See the docs
14
+ * "Save auth & order ID (refund & recovery)" for full details.
15
+ *
8
16
  * @example
9
17
  * ```typescript
10
18
  * import { executeSolanaSwap, createSwapAccounts } from '@silentswap/sdk';
@@ -24,6 +32,7 @@
24
32
  * });
25
33
  *
26
34
  * console.log('Order ID:', result.orderId);
35
+ * console.log('Viewing auth (save for tracking/refund/recovery):', result.viewingAuth);
27
36
  * ```
28
37
  */
29
38
  import type { Caip19 } from './types/core.js';
@@ -90,6 +99,27 @@ export interface SwapResult {
90
99
  usdcAmount: string;
91
100
  /** Actual source amount used (may differ due to bridge optimization) */
92
101
  actualSourceAmount: string;
102
+ /**
103
+ * Viewing auth (Base58 EVM address of the facilitator group's viewer) for this order.
104
+ * Save it together with the order ID to track the order, check refund eligibility, or run
105
+ * recovery flows.
106
+ */
107
+ viewingAuth: string;
108
+ /**
109
+ * Recovery data for refund/recovery: mnemonic (24 words) and BIP-44 derivation paths
110
+ * for the facilitator group. Store securely; do not log or commit.
111
+ */
112
+ recoveryData: {
113
+ mnemonic: string;
114
+ recoveryPaths: string[];
115
+ };
116
+ /** Wallets used for this swap: EVM signer (refundee) and Solana depositor */
117
+ usedWallet: {
118
+ /** EVM address used for auth and as refundee */
119
+ evmAddress: `0x${string}`;
120
+ /** Solana public key (base58) used for the deposit transaction */
121
+ solanaPublicKey: string;
122
+ };
93
123
  }
94
124
  /**
95
125
  * EVM account for signing
@@ -5,6 +5,14 @@
5
5
  * This module provides a simple interface for integrators to execute swaps without
6
6
  * needing to understand the underlying protocol details.
7
7
  *
8
+ * **Recovery (refund / prove delivery):** Save `result.viewingAuth` and the order ID
9
+ * for tracking, refund, and recovery. The mnemonic used for the facilitator group can
10
+ * be derived from the same entropy that was used to create the group: use
11
+ * `exportSecretMnemonicFromEntropy(entropy)` from this package. Recovery paths are
12
+ * BIP-44 paths of the form `m/44'/${coinType}'/${accountIndex}'/0/${addressIndex}`,
13
+ * built from the group's exported public keys (skip coin type `'*'`). See the docs
14
+ * "Save auth & order ID (refund & recovery)" for full details.
15
+ *
8
16
  * @example
9
17
  * ```typescript
10
18
  * import { executeSolanaSwap, createSwapAccounts } from '@silentswap/sdk';
@@ -24,14 +32,15 @@
24
32
  * });
25
33
  *
26
34
  * console.log('Order ID:', result.orderId);
35
+ * console.log('Viewing auth (save for tracking/refund/recovery):', result.viewingAuth);
27
36
  * ```
28
37
  */
29
38
  import { encodeFunctionData, erc20Abi } from 'viem';
30
39
  import { createSilentSwapClient } from './client.js';
31
40
  import { createSignInMessage, createEip712DocForWalletGeneration } from './sdk.js';
32
- import { createHdFacilitatorGroupFromEntropy } from './hd-facilitator-group.js';
41
+ import { createHdFacilitatorGroupFromEntropy, exportSecretMnemonicFromEntropy, } from './hd-facilitator-group.js';
33
42
  import { queryDepositCount } from './wallet.js';
34
- import { hexToBytes } from './encoding.js';
43
+ import { hexToBytes, hexToBase58 } from './encoding.js';
35
44
  import { quoteResponseToEip712Document, DeliveryMethod, FacilitatorKeyType, PublicKeyArgGroups } from './order.js';
36
45
  import { solveOptimalUsdcAmount, fetchRelayQuote, getRelayStatus } from './bridge.js';
37
46
  import { ENVIRONMENT, N_RELAY_CHAIN_ID_SOLANA, NI_CHAIN_ID_AVALANCHE, SB58_ADDR_SOL_PROGRAM_SYSTEM, SB58_CHAIN_ID_SOLANA_MAINNET, S0X_ADDR_USDC_AVALANCHE, } from './constants.js';
@@ -491,12 +500,32 @@ export async function executeSolanaSwap(config) {
491
500
  });
492
501
  }
493
502
  }
503
+ // Derive viewing auth (viewer EVM address as Base58) for tracking, refund, and recovery
504
+ const viewer = await facilitatorGroup.viewer();
505
+ const viewerEvmSigner = await viewer.evmSigner();
506
+ const viewingAuth = hexToBase58(viewerEvmSigner.address);
507
+ // Build recovery data (mnemonic + paths) for refund/recovery
508
+ const groupPublicKeysForRecovery = await facilitatorGroup.exportPublicKeys(1, [...PublicKeyArgGroups.GENERIC]);
509
+ const recoveryPaths = [];
510
+ for (const pk of groupPublicKeysForRecovery[0] ?? []) {
511
+ if (pk.coinType === '*')
512
+ continue;
513
+ recoveryPaths.push(`m/44'/${pk.coinType}'/${depositCount}'/0/0`);
514
+ }
515
+ const mnemonic = (await exportSecretMnemonicFromEntropy(hexToBytes(entropy))).toString();
516
+ const recoveryData = { mnemonic, recoveryPaths };
494
517
  return {
495
518
  orderId,
496
519
  quoteId: quoteResponse.quoteId,
497
520
  depositTxHash: txHash,
498
521
  usdcAmount: bridgeResult.usdcAmountOut.toString(),
499
522
  actualSourceAmount: bridgeResult.actualAmountIn.toString(),
523
+ viewingAuth,
524
+ recoveryData,
525
+ usedWallet: {
526
+ evmAddress: accounts.evm.address,
527
+ solanaPublicKey: accounts.solana.publicKey,
528
+ },
500
529
  };
501
530
  }
502
531
  // ============================================================================
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silentswap/sdk",
3
3
  "type": "module",
4
- "version": "0.0.77",
4
+ "version": "0.0.79",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "files": [