@silentswap/sdk 0.1.78 → 0.1.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.
@@ -1,10 +1,16 @@
1
1
  import { Account, Hex } from 'viem';
2
+ import { type Secp256k1 } from '@solar-republic/wasm-secp256k1';
2
3
  import { OfflineAminoSigner } from '@cosmjs/amino';
3
4
  import { FacilitatorKeyType, type FacilitatorPublicKey } from './order.js';
4
5
  import type { EncryptSecretKeyArgs, ExportedFacilitator } from './types/sdk.js';
5
6
  import type { CoinTypeStr } from './types/core.js';
6
7
  import type { ProxyAuthInstruction } from './types/authorization.js';
7
- export declare const SECP256K1: import("@solar-republic/wasm-secp256k1").Secp256k1;
8
+ /**
9
+ * Ensures the wasm-secp256k1 module is initialized. Idempotent and safe to call concurrently.
10
+ * Must be awaited before constructing or using a {@link FacilitatorAccount}.
11
+ * @returns the initialized wasm-secp256k1 instance
12
+ */
13
+ export declare function initSecp256k1(): Promise<Secp256k1>;
8
14
  export declare class FacilitatorAccount {
9
15
  #private;
10
16
  /**
@@ -5,8 +5,32 @@ import { privateKeyToAccount } from 'viem/accounts';
5
5
  import { Secp256k1Wallet } from '@cosmjs/amino';
6
6
  import { normalizeBytesish, normalizeJson } from './util.js';
7
7
  import { FacilitatorKeyType } from './order.js';
8
- // wasm-secp256k1 instance
9
- export const SECP256K1 = await initWasmSecp256k1();
8
+ // wasm-secp256k1 instance, lazily initialized to avoid a top-level await
9
+ // (top-level await isn't supported when bundlers target older browsers, e.g. esbuild/Angular).
10
+ let secp256k1;
11
+ let secp256k1Init;
12
+ /**
13
+ * Ensures the wasm-secp256k1 module is initialized. Idempotent and safe to call concurrently.
14
+ * Must be awaited before constructing or using a {@link FacilitatorAccount}.
15
+ * @returns the initialized wasm-secp256k1 instance
16
+ */
17
+ export async function initSecp256k1() {
18
+ if (secp256k1)
19
+ return secp256k1;
20
+ secp256k1Init ??= initWasmSecp256k1();
21
+ secp256k1 = await secp256k1Init;
22
+ return secp256k1;
23
+ }
24
+ /**
25
+ * Returns the initialized wasm-secp256k1 instance synchronously.
26
+ * @throws Error if {@link initSecp256k1} has not been awaited yet
27
+ */
28
+ function getSecp256k1() {
29
+ if (!secp256k1) {
30
+ throw new Error('wasm-secp256k1 is not initialized. Call and await initSecp256k1() before using a FacilitatorAccount.');
31
+ }
32
+ return secp256k1;
33
+ }
10
34
  /**
11
35
  * Get the Web Crypto API's subtle property, handling both browser and Node.js environments
12
36
  * @returns The SubtleCrypto interface
@@ -37,7 +61,7 @@ export class FacilitatorAccount {
37
61
  */
38
62
  constructor(secretKeyBytes) {
39
63
  // if secret was given, copy its bytes into a new section of memory so parent can zeroize original
40
- this.#secretKey = secretKeyBytes ? secretKeyBytes.slice() : SECP256K1.gen_sk();
64
+ this.#secretKey = secretKeyBytes ? secretKeyBytes.slice() : getSecp256k1().gen_sk();
41
65
  }
42
66
  /**
43
67
  * Exports the secret key
@@ -56,7 +80,7 @@ export class FacilitatorAccount {
56
80
  let publicKeyBytes;
57
81
  switch (keyType) {
58
82
  case FacilitatorKeyType.SECP256K1:
59
- publicKeyBytes = SECP256K1.sk_to_pk(this.#secretKey, true);
83
+ publicKeyBytes = getSecp256k1().sk_to_pk(this.#secretKey, true);
60
84
  break;
61
85
  // case FacilitatorKeyType.ED25519:
62
86
  // publicKeyBytes =
@@ -111,10 +135,11 @@ export class FacilitatorAccount {
111
135
  // normalize public key
112
136
  const proxyPubKey = normalizeBytesish(args.proxyPublicKey);
113
137
  // generate key pair for encryption
114
- const encPrivKey = SECP256K1.gen_sk();
115
- const encPubKey = SECP256K1.sk_to_pk(encPrivKey);
138
+ const secp256k1 = getSecp256k1();
139
+ const encPrivKey = secp256k1.gen_sk();
140
+ const encPubKey = secp256k1.sk_to_pk(encPrivKey);
116
141
  // derive shared secret
117
- const sharedSecret = SECP256K1.ecdh(encPrivKey, proxyPubKey);
142
+ const sharedSecret = secp256k1.ecdh(encPrivKey, proxyPubKey);
118
143
  // zeroize secret key bytes
119
144
  encPrivKey.fill(0);
120
145
  // import secret as wrapping key
@@ -1,6 +1,6 @@
1
1
  import { keccak256 } from 'viem';
2
2
  import { Bip39, Slip10, Slip10Curve, stringToPath } from '@cosmjs/crypto';
3
- import { FacilitatorAccount } from './facilitator-account.js';
3
+ import { FacilitatorAccount, initSecp256k1 } from './facilitator-account.js';
4
4
  export class HdFacilitatorGroup {
5
5
  accountIndex;
6
6
  #seed;
@@ -16,6 +16,8 @@ export class HdFacilitatorGroup {
16
16
  * @returns
17
17
  */
18
18
  async account(coinType, addressIndex) {
19
+ // ensure wasm-secp256k1 is initialized (replaces former top-level await)
20
+ await initSecp256k1();
19
21
  // if global fallback type, use BTC (`0`)
20
22
  if ('*' === coinType)
21
23
  coinType = '0';
@@ -37,6 +39,8 @@ export class HdFacilitatorGroup {
37
39
  * @returns
38
40
  */
39
41
  async viewer() {
42
+ // ensure wasm-secp256k1 is initialized (replaces former top-level await)
43
+ await initSecp256k1();
40
44
  // derive private account BIP-32 node using BIP-44m for BTC at group's account index and "internal" change
41
45
  const path = stringToPath(`m/44'/0'/${this.accountIndex}'/1/0`);
42
46
  // export private key
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export type { CalculationDirection, } from './constants.js';
11
11
  export { EVM_PHONY_ADDRESS, EVM_NATIVE_ADDRESS, DEAD_ADDRESS, S0X_ADDR_EVM_ZERO, UINT256_MAX, MAINNET_GATEWAY_ADDRESS, MAINNET_GATEWAY_PUBLIC_KEY, ENVIRONMENT, ENVIRONMENT_CONFIGS, S0X_ADDR_USDC_AVALANCHE, S_CAIP19_USDC_AVALANCHE, NI_CHAIN_ID_AVALANCHE, XT_TTL_SESSION_CACHE, X_MINIMUM_INPUT_USD, X_MAX_IMPACT_PERCENT, COIN_TYPES, SB58_CHAIN_ID_SOLANA_MAINNET, SB58_ADDR_SOL_PROGRAM_SYSTEM, SB58_ADDR_SOL_RELAY_LINK_RECIPIENT, SB58_ADDR_SOL_DEAD, SBTC_ADDR_BITCOIN_NATIVE, SBTC_ADDR_BTC_RELAY_LINK_RECIPIENT, S0X_ADDR_TRON_NATIVE, SB58_ADDR_TRON_DEAD, N_RELAY_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_BITCOIN, N_RELAY_CHAIN_ID_TRON, N_RELAY_CHAIN_ID_SUI, N_DEBRIDGE_CHAIN_ID_SOLANA, N_DEBRIDGE_CHAIN_ID_TRON, S0X_ADDR_EVM_RELAY_LINK_DEAD, P_URL_API_RPC_SOLANA, CALCULATION_DIRECTION_INPUT_TO_OUTPUT, CALCULATION_DIRECTION_OUTPUT_TO_INPUT, } from './constants.js';
12
12
  export { GATEWAY_ABI, } from './gateway-abi.js';
13
13
  export { createHdFacilitatorGroupFromEntropy, exportSecretMnemonicFromEntropy, type HdFacilitatorGroup, } from './hd-facilitator-group.js';
14
+ export { initSecp256k1, } from './facilitator-account.js';
14
15
  export { createSignInMessage, createEip712DocForOrder, createEip712DocForWalletGeneration, } from './sdk.js';
15
16
  export { createViemSigner, parseTransactionRequestForViem, } from './signer-adapters/viem.js';
16
17
  export type { BridgeProvider, BridgeQuote, SolanaInstruction, BridgeTransaction, BridgeStatus, BridgeQuoteParams, RelayQuoteParams, RelayQuoteResponse, DeBridgeOrderParams, DeBridgeOrderResponse, SolveUsdcResult, } from './bridge.js';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { EVM_PHONY_ADDRESS, EVM_NATIVE_ADDRESS, DEAD_ADDRESS, S0X_ADDR_EVM_ZERO,
5
5
  // gateway-abi
6
6
  export { GATEWAY_ABI, } from './gateway-abi.js';
7
7
  export { createHdFacilitatorGroupFromEntropy, exportSecretMnemonicFromEntropy, } from './hd-facilitator-group.js';
8
+ export { initSecp256k1, } from './facilitator-account.js';
8
9
  export { createSignInMessage, createEip712DocForOrder, createEip712DocForWalletGeneration, } from './sdk.js';
9
10
  export { createViemSigner, parseTransactionRequestForViem, } from './signer-adapters/viem.js';
10
11
  export { getRelayOriginAsset, executeRelayBridge, executeDebridgeBridge, getRelayStatus, getDebridgeStatus, fetchRelayQuote, fetchDebridgeOrder, solveOptimalUsdcAmount, } from './bridge.js';
@@ -14,6 +14,16 @@ export interface SimpleSwapExchangeRequest {
14
14
  user_refund_extra_id?: string;
15
15
  fixed: boolean;
16
16
  }
17
+ export interface SimpleSwapCurrencyInfo {
18
+ network: string;
19
+ name: string;
20
+ symbol: string;
21
+ contract_address: string | null;
22
+ warnings_from: string[];
23
+ warnings_to: string[];
24
+ tx_explorer: string | null;
25
+ image: string | null;
26
+ }
17
27
  export interface SimpleSwapExchangeResponse {
18
28
  id: string;
19
29
  type: string;
@@ -36,6 +46,8 @@ export interface SimpleSwapExchangeResponse {
36
46
  tx_to: string | null;
37
47
  status: SimpleSwapExchangeStatus;
38
48
  redirect_url: string | null;
49
+ /** Per-currency metadata keyed by SimpleSwap symbol (includes deposit-network warnings). */
50
+ currencies?: Record<string, SimpleSwapCurrencyInfo>;
39
51
  }
40
52
  export type SimpleSwapExchangeStatus = 'waiting' | 'confirming' | 'exchanging' | 'sending' | 'finished' | 'failed' | 'refunded' | 'expired';
41
53
  export interface SimpleSwapEstimateResult {
@@ -82,6 +82,13 @@ export async function getSimpleSwapExchangeStatus(baseUrl, exchangeId, signal) {
82
82
  }
83
83
  return response.json();
84
84
  }
85
+ // IMPORTANT: SimpleSwap's API keys on the `currency_from`/`currency_to` SYMBOL
86
+ // and effectively ignores the network field. Each network has its OWN symbol
87
+ // (e.g. ETH-on-Base is `ethbase`, USDT-on-BSC is `usdtbep20`) — sending a bare
88
+ // `eth`/`usdt` silently resolves to the Ethereum-mainnet currency and returns a
89
+ // MAINNET deposit address, which would lose funds for L2/alt-network deposits.
90
+ // `ticker` below MUST be SimpleSwap's exact symbol (verified via get_all_currencies
91
+ // by contract address); `network` mirrors SimpleSwap's network string.
85
92
  const CAIP19_TO_SIMPLESWAP = {
86
93
  // Monero
87
94
  'monero:mainnet/slip44:128': { ticker: 'xmr', network: 'xmr' },
@@ -90,47 +97,47 @@ const CAIP19_TO_SIMPLESWAP = {
90
97
  // Ethereum native
91
98
  'eip155:1/slip44:60': { ticker: 'eth', network: 'eth' },
92
99
  // USDT on Ethereum
93
- 'eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7': { ticker: 'usdt', network: 'eth' },
100
+ 'eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7': { ticker: 'usdterc20', network: 'eth' },
94
101
  // USDC on Ethereum
95
102
  'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': { ticker: 'usdc', network: 'eth' },
96
103
  // BNB native (BSC)
97
- 'eip155:56/slip44:60': { ticker: 'bnb', network: 'bsc' },
104
+ 'eip155:56/slip44:60': { ticker: 'bnb-bsc', network: 'bsc' },
98
105
  // USDT on BSC
99
- 'eip155:56/erc20:0x55d398326f99059ff775485246999027b3197955': { ticker: 'usdt', network: 'bsc' },
106
+ 'eip155:56/erc20:0x55d398326f99059ff775485246999027b3197955': { ticker: 'usdtbep20', network: 'bsc' },
100
107
  // USDC on BSC
101
- 'eip155:56/erc20:0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d': { ticker: 'usdc', network: 'bsc' },
108
+ 'eip155:56/erc20:0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d': { ticker: 'usdcbep20', network: 'bsc' },
102
109
  // Solana native
103
- 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501': { ticker: 'sol', network: 'sol' },
110
+ 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501': { ticker: 'sol', network: 'solana' },
104
111
  // USDT on Solana
105
- 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB': { ticker: 'usdt', network: 'sol' },
112
+ 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB': { ticker: 'usdtspl', network: 'solana' },
106
113
  // USDC on Solana
107
- 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v': { ticker: 'usdc', network: 'sol' },
114
+ 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v': { ticker: 'usdcspl', network: 'solana' },
108
115
  // AVAX native (Avalanche C-Chain)
109
- 'eip155:43114/slip44:60': { ticker: 'avax', network: 'avax' },
116
+ 'eip155:43114/slip44:60': { ticker: 'avaxc', network: 'avax-c' },
110
117
  // USDT on Avalanche
111
- 'eip155:43114/erc20:0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7': { ticker: 'usdt', network: 'avax' },
118
+ 'eip155:43114/erc20:0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7': { ticker: 'usdtavaxc', network: 'avax-c' },
112
119
  // USDC on Avalanche
113
- 'eip155:43114/erc20:0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e': { ticker: 'usdc', network: 'avax' },
120
+ 'eip155:43114/erc20:0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e': { ticker: 'usdcavaxc', network: 'avax-c' },
114
121
  // Polygon native (MATIC/POL)
115
- 'eip155:137/slip44:60': { ticker: 'matic', network: 'matic' },
122
+ 'eip155:137/slip44:60': { ticker: 'pol', network: 'matic' },
116
123
  // USDT on Polygon
117
- 'eip155:137/erc20:0xc2132d05d31c914a87c6611c10748aeb04b58e8f': { ticker: 'usdt', network: 'matic' },
124
+ 'eip155:137/erc20:0xc2132d05d31c914a87c6611c10748aeb04b58e8f': { ticker: 'usdtpoly', network: 'matic' },
118
125
  // USDC on Polygon
119
- 'eip155:137/erc20:0x3c499c542cef5e3811e1192ce70d8cc03d5c3359': { ticker: 'usdc', network: 'matic' },
126
+ 'eip155:137/erc20:0x3c499c542cef5e3811e1192ce70d8cc03d5c3359': { ticker: 'usdcpoly', network: 'matic' },
120
127
  // Arbitrum native
121
- 'eip155:42161/slip44:60': { ticker: 'eth', network: 'arbitrum' },
128
+ 'eip155:42161/slip44:60': { ticker: 'etharb', network: 'arbitrum' },
122
129
  // USDT on Arbitrum
123
- 'eip155:42161/erc20:0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9': { ticker: 'usdt', network: 'arbitrum' },
130
+ 'eip155:42161/erc20:0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9': { ticker: 'usdtarb', network: 'arbitrum' },
124
131
  // USDC on Arbitrum
125
- 'eip155:42161/erc20:0xaf88d065e77c8cc2239327c5edb3a432268e5831': { ticker: 'usdc', network: 'arbitrum' },
132
+ 'eip155:42161/erc20:0xaf88d065e77c8cc2239327c5edb3a432268e5831': { ticker: 'usdcarb', network: 'arbitrum' },
126
133
  // Optimism native
127
- 'eip155:10/slip44:60': { ticker: 'eth', network: 'op' },
134
+ 'eip155:10/slip44:60': { ticker: 'ethop', network: 'optimism' },
128
135
  // Base native
129
- 'eip155:8453/slip44:60': { ticker: 'eth', network: 'base' },
136
+ 'eip155:8453/slip44:60': { ticker: 'ethbase', network: 'base' },
130
137
  // TRX native (Tron)
131
138
  'tron:0x2b6653dc/slip44:195': { ticker: 'trx', network: 'trx' },
132
139
  // USDT on Tron
133
- 'tron:0x2b6653dc/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t': { ticker: 'usdt', network: 'trx' },
140
+ 'tron:0x2b6653dc/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t': { ticker: 'usdttrc20', network: 'trx' },
134
141
  };
135
142
  const SIMPLESWAP_TO_CAIP19 = {};
136
143
  for (const [caip19, ticker] of Object.entries(CAIP19_TO_SIMPLESWAP)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silentswap/sdk",
3
3
  "type": "module",
4
- "version": "0.1.78",
4
+ "version": "0.1.79",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "main": "dist/index.js",