@sodax/wallet-sdk-core 2.0.0-rc.18 → 2.0.0-rc.19
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.cjs +92 -1
- package/dist/index.d.cts +33 -2
- package/dist/index.d.ts +33 -2
- package/dist/index.mjs +95 -4
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2426,7 +2426,7 @@ var RelayChainIdMap = {
|
|
|
2426
2426
|
[ChainKeys.KAIA_MAINNET]: 27489n,
|
|
2427
2427
|
[ChainKeys.STACKS_MAINNET]: 60n
|
|
2428
2428
|
};
|
|
2429
|
-
|
|
2429
|
+
new Map(Object.entries(RelayChainIdMap).map(([chainKey, chainId]) => [chainId, chainKey]));
|
|
2430
2430
|
var CHAIN_LOGO_BASE_URL = "https://raw.githubusercontent.com/icon-project/sodax-sdks/main/packages/assets/chain";
|
|
2431
2431
|
var chainLogo = (key) => `${CHAIN_LOGO_BASE_URL}/${key}.png`;
|
|
2432
2432
|
var baseChainInfo = {
|
|
@@ -3840,6 +3840,12 @@ var SolanaWalletProvider = class extends BaseWalletProvider {
|
|
|
3840
3840
|
const sendOptions = shallowMerge(this.defaults.sendOptions, options);
|
|
3841
3841
|
return this.connection.sendRawTransaction(rawTransaction, sendOptions);
|
|
3842
3842
|
}
|
|
3843
|
+
async signAndSendTransaction(params) {
|
|
3844
|
+
const serializedTxBytes = Buffer.from(params.data, "base64");
|
|
3845
|
+
const versionedTx = web3_js.VersionedTransaction.deserialize(serializedTxBytes);
|
|
3846
|
+
const signedTx = await this.signAndSerializeTransaction(versionedTx);
|
|
3847
|
+
return this.sendTransaction(signedTx);
|
|
3848
|
+
}
|
|
3843
3849
|
async sendTransactionWithConfirmation(rawTransaction, optionsOrCommitment) {
|
|
3844
3850
|
const isCommitmentArg = typeof optionsOrCommitment === "string";
|
|
3845
3851
|
const sendOpts = isCommitmentArg ? void 0 : optionsOrCommitment?.send;
|
|
@@ -3873,6 +3879,31 @@ var SolanaWalletProvider = class extends BaseWalletProvider {
|
|
|
3873
3879
|
const tx = await adapterWallet.signTransaction(new web3_js.VersionedTransaction(messageV0));
|
|
3874
3880
|
return tx.serialize();
|
|
3875
3881
|
}
|
|
3882
|
+
async signTransaction(transaction) {
|
|
3883
|
+
if (this.isAdapterMode) {
|
|
3884
|
+
return this.signTransactionWithAdapter(transaction);
|
|
3885
|
+
}
|
|
3886
|
+
return this.signTransactionWithKeypair(transaction);
|
|
3887
|
+
}
|
|
3888
|
+
async signAndSerializeTransaction(transaction) {
|
|
3889
|
+
const tx = await this.signTransaction(transaction);
|
|
3890
|
+
return tx.serialize();
|
|
3891
|
+
}
|
|
3892
|
+
async signTransactionWithAdapter(transaction) {
|
|
3893
|
+
const adapterWallet = this.wallet;
|
|
3894
|
+
if (!adapterWallet.signTransaction) {
|
|
3895
|
+
throw new Error("Wallet signTransaction is not initialized");
|
|
3896
|
+
}
|
|
3897
|
+
return adapterWallet.signTransaction(transaction);
|
|
3898
|
+
}
|
|
3899
|
+
async signTransactionWithKeypair(transaction) {
|
|
3900
|
+
if (this.isAdapterMode) {
|
|
3901
|
+
throw new Error("Cannot sign transaction with keypair in adapter mode");
|
|
3902
|
+
}
|
|
3903
|
+
const keypairWallet = this.wallet;
|
|
3904
|
+
transaction.sign([keypairWallet]);
|
|
3905
|
+
return transaction;
|
|
3906
|
+
}
|
|
3876
3907
|
async buildV0TxnWithKeypair(rawInstructions) {
|
|
3877
3908
|
const keypairWallet = this.wallet;
|
|
3878
3909
|
const instructions = this.buildTransactionInstruction(rawInstructions);
|
|
@@ -3924,6 +3955,10 @@ var STELLAR_HORIZON_URLS = {
|
|
|
3924
3955
|
TESTNET: "https://horizon-testnet.stellar.org",
|
|
3925
3956
|
PUBLIC: "https://horizon.stellar.org"
|
|
3926
3957
|
};
|
|
3958
|
+
var STELLAR_SOROBAN_URLS = {
|
|
3959
|
+
TESTNET: "https://soroban-testnet.stellar.org",
|
|
3960
|
+
PUBLIC: "https://rpc.ankr.com/stellar_soroban"
|
|
3961
|
+
};
|
|
3927
3962
|
var STELLAR_NETWORK_PASSPHRASES = {
|
|
3928
3963
|
TESTNET: stellarSdk.Networks.TESTNET,
|
|
3929
3964
|
PUBLIC: stellarSdk.Networks.PUBLIC
|
|
@@ -3965,6 +4000,7 @@ var StellarWalletProvider = class extends BaseWalletProvider {
|
|
|
3965
4000
|
chainType = "STELLAR";
|
|
3966
4001
|
wallet;
|
|
3967
4002
|
server;
|
|
4003
|
+
sorobanServer;
|
|
3968
4004
|
networkPassphrase;
|
|
3969
4005
|
constructor(config) {
|
|
3970
4006
|
super(config.defaults);
|
|
@@ -3973,6 +4009,9 @@ var StellarWalletProvider = class extends BaseWalletProvider {
|
|
|
3973
4009
|
}
|
|
3974
4010
|
this.networkPassphrase = this.defaults.networkPassphrase ?? STELLAR_NETWORK_PASSPHRASES[config.network];
|
|
3975
4011
|
this.server = new stellarSdk.Horizon.Server(config.rpcUrl ?? STELLAR_HORIZON_URLS[config.network]);
|
|
4012
|
+
this.sorobanServer = new stellarSdk.rpc.Server(config.sorobanRpcUrl ?? STELLAR_SOROBAN_URLS[config.network], {
|
|
4013
|
+
allowHttp: true
|
|
4014
|
+
});
|
|
3976
4015
|
if (isPrivateKeyStellarWalletConfig(config)) {
|
|
3977
4016
|
if (!isValidStellarPrivateKey(config.privateKey)) {
|
|
3978
4017
|
throw new StellarWalletError("Invalid private key format", "INVALID_PRIVATE_KEY");
|
|
@@ -4023,6 +4062,38 @@ var StellarWalletProvider = class extends BaseWalletProvider {
|
|
|
4023
4062
|
);
|
|
4024
4063
|
}
|
|
4025
4064
|
}
|
|
4065
|
+
/**
|
|
4066
|
+
* Broadcasts an already-signed XDR transaction via the Soroban RPC server.
|
|
4067
|
+
* @returns The transaction hash.
|
|
4068
|
+
* @throws {StellarWalletError} with code `SEND_TX_ERROR` if submission fails or the RPC returns an error status.
|
|
4069
|
+
*/
|
|
4070
|
+
async sendTransaction(signedTx) {
|
|
4071
|
+
try {
|
|
4072
|
+
const tx = stellarSdk.TransactionBuilder.fromXDR(signedTx, this.networkPassphrase);
|
|
4073
|
+
const response = await this.sorobanServer.sendTransaction(tx);
|
|
4074
|
+
if (response.status === "ERROR") {
|
|
4075
|
+
throw new StellarWalletError(`Failed to submit transaction: ${JSON.stringify(response)}`, "SEND_TX_ERROR");
|
|
4076
|
+
}
|
|
4077
|
+
return response.hash;
|
|
4078
|
+
} catch (error) {
|
|
4079
|
+
if (error instanceof StellarWalletError) {
|
|
4080
|
+
throw error;
|
|
4081
|
+
}
|
|
4082
|
+
throw new StellarWalletError(
|
|
4083
|
+
error instanceof Error ? error.message : "Failed to send transaction",
|
|
4084
|
+
"SEND_TX_ERROR"
|
|
4085
|
+
);
|
|
4086
|
+
}
|
|
4087
|
+
}
|
|
4088
|
+
/**
|
|
4089
|
+
* Signs and broadcasts an unsigned `StellarRawTransaction` (e.g. from the Swaps API).
|
|
4090
|
+
* @returns The transaction hash.
|
|
4091
|
+
* @throws {StellarWalletError} with code `SIGN_TX_ERROR` if signing fails, or `SEND_TX_ERROR` if broadcasting fails.
|
|
4092
|
+
*/
|
|
4093
|
+
async signAndSendTransaction(params) {
|
|
4094
|
+
const signedXdr = await this.signTransaction(params.data);
|
|
4095
|
+
return this.sendTransaction(signedXdr);
|
|
4096
|
+
}
|
|
4026
4097
|
/**
|
|
4027
4098
|
* Polls the Horizon server until the transaction is confirmed or the timeout is reached.
|
|
4028
4099
|
* @throws {StellarWalletError} with code `TX_RECEIPT_TIMEOUT` if the transaction is not found within `pollTimeout` ms.
|
|
@@ -4091,6 +4162,26 @@ var StacksWalletProvider = class extends BaseWalletProvider {
|
|
|
4091
4162
|
}
|
|
4092
4163
|
return this.sendTransactionWithAdapter(finalParams, this.wallet);
|
|
4093
4164
|
}
|
|
4165
|
+
/**
|
|
4166
|
+
* Signs and broadcasts an unsigned `StacksRawTransaction` (e.g. from the Swaps API). The raw tx's
|
|
4167
|
+
* `payload` is the hex-serialized contract-call payload; this deserializes it back into the
|
|
4168
|
+
* contract-call params and routes through `sendTransaction` (which signs + broadcasts in both
|
|
4169
|
+
* private-key and browser-extension modes). Returns the transaction id.
|
|
4170
|
+
*/
|
|
4171
|
+
async signAndSendTransaction(params) {
|
|
4172
|
+
const payload = core.deserializePayload(params.payload);
|
|
4173
|
+
if (payload.payloadType !== core.PayloadType.ContractCall) {
|
|
4174
|
+
throw new Error("signAndSendTransaction: expected a contract-call payload.");
|
|
4175
|
+
}
|
|
4176
|
+
return this.sendTransaction({
|
|
4177
|
+
contractAddress: core.addressToString(payload.contractAddress),
|
|
4178
|
+
contractName: payload.contractName.content,
|
|
4179
|
+
functionName: payload.functionName.content,
|
|
4180
|
+
functionArgs: payload.functionArgs,
|
|
4181
|
+
postConditionMode: core.PostConditionMode.Allow
|
|
4182
|
+
// matches how the spoke service builds the tx
|
|
4183
|
+
});
|
|
4184
|
+
}
|
|
4094
4185
|
async sendTransactionWithPrivateKey(txParams, wallet) {
|
|
4095
4186
|
const transaction = await core.makeContractCall({
|
|
4096
4187
|
contractAddress: txParams.contractAddress,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EvmRawTransaction, EvmChainKey, IEvmWalletProvider, EvmRawTransactionReceipt, ISuiWalletProvider, SuiTransaction, SuiExecutionResult, SuiPaginatedCoins, IIconWalletProvider, IcxCallTransaction, IconTransactionResult, InjectiveCoin, IInjectiveWalletProvider, JsonObject, InjectiveRawTransaction, InjectiveEoaAddress, InjectiveExecuteResponse, ISolanaWalletProvider, SolanaRpcResponseAndContext, SolanaSignatureResult, TransactionSignature, SolanaRawTransactionInstruction, SolanaSerializedTransaction, SolanaBase58PublicKey, XDR, Hex as Hex$1, IStellarWalletProvider, StellarRawTransactionReceipt, IStacksWalletProvider, StacksTransactionParams, INearWalletProvider, CallContractParams, NearRawTransaction, BtcAddressType, IBitcoinWalletProvider } from '@sodax/types';
|
|
1
|
+
import { EvmRawTransaction, EvmChainKey, IEvmWalletProvider, EvmRawTransactionReceipt, ISuiWalletProvider, SuiTransaction, SuiExecutionResult, SuiPaginatedCoins, IIconWalletProvider, IcxCallTransaction, IconTransactionResult, InjectiveCoin, IInjectiveWalletProvider, JsonObject, InjectiveRawTransaction, InjectiveEoaAddress, InjectiveExecuteResponse, ISolanaWalletProvider, SolanaRpcResponseAndContext, SolanaSignatureResult, TransactionSignature, SolanaRawTransaction, SolanaRawTransactionInstruction, SolanaSerializedTransaction, SolanaBase58PublicKey, XDR, Hex as Hex$1, IStellarWalletProvider, StellarRawTransaction, StellarRawTransactionReceipt, IStacksWalletProvider, StacksTransactionParams, StacksRawTransaction, INearWalletProvider, CallContractParams, NearRawTransaction, BtcAddressType, IBitcoinWalletProvider } from '@sodax/types';
|
|
2
2
|
import * as viem from 'viem';
|
|
3
3
|
import { WalletClient, Transport, Chain, Account, PublicClient, PublicClientConfig, WalletClientConfig, HttpTransportConfig, SendTransactionParameters, WaitForTransactionReceiptParameters, Address, Hash as Hash$1 } from 'viem';
|
|
4
4
|
export { Account, Address, Chain, HttpTransportConfig, PublicClient, PublicClientConfig, SendTransactionParameters, TransactionReceipt, Transport, WaitForTransactionReceiptParameters, WalletClient, WalletClientConfig } from 'viem';
|
|
@@ -17,7 +17,7 @@ import { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
|
17
17
|
export { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
18
18
|
import { MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
19
19
|
export { MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
20
|
-
import { PublicKey, Commitment, ConnectionConfig, SendOptions, Connection, RpcResponseAndContext, TokenAmount } from '@solana/web3.js';
|
|
20
|
+
import { PublicKey, Commitment, ConnectionConfig, SendOptions, Connection, VersionedTransaction, RpcResponseAndContext, TokenAmount } from '@solana/web3.js';
|
|
21
21
|
export { Commitment, ConnectionConfig, SendOptions } from '@solana/web3.js';
|
|
22
22
|
import { SignerWalletAdapterProps } from '@solana/wallet-adapter-base';
|
|
23
23
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
@@ -490,12 +490,17 @@ declare class SolanaWalletProvider extends BaseWalletProvider<SolanaWalletDefaul
|
|
|
490
490
|
constructor(walletConfig: SolanaWalletConfig);
|
|
491
491
|
waitForConfirmation(signature: string, commitment?: Commitment): Promise<SolanaRpcResponseAndContext<SolanaSignatureResult>>;
|
|
492
492
|
sendTransaction(rawTransaction: Uint8Array | Array<number>, options?: SendOptions): Promise<TransactionSignature>;
|
|
493
|
+
signAndSendTransaction(params: SolanaRawTransaction): Promise<TransactionSignature>;
|
|
493
494
|
sendTransactionWithConfirmation(rawTransaction: Uint8Array | Array<number>, optionsOrCommitment?: Commitment | {
|
|
494
495
|
send?: SendOptions;
|
|
495
496
|
commitment?: Commitment;
|
|
496
497
|
}): Promise<TransactionSignature>;
|
|
497
498
|
buildV0Txn(rawInstructions: SolanaRawTransactionInstruction[]): Promise<SolanaSerializedTransaction>;
|
|
498
499
|
private buildV0TxnWithAdapter;
|
|
500
|
+
signTransaction(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
501
|
+
signAndSerializeTransaction(transaction: VersionedTransaction): Promise<SolanaSerializedTransaction>;
|
|
502
|
+
signTransactionWithAdapter(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
503
|
+
signTransactionWithKeypair(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
499
504
|
private buildV0TxnWithKeypair;
|
|
500
505
|
getWalletBase58PublicKey(): SolanaBase58PublicKey;
|
|
501
506
|
getWalletAddress(): Promise<string>;
|
|
@@ -531,7 +536,10 @@ type PrivateKeyStellarWalletConfig = {
|
|
|
531
536
|
type: 'PRIVATE_KEY';
|
|
532
537
|
privateKey: Hex$1;
|
|
533
538
|
network: StellarNetwork;
|
|
539
|
+
/** Horizon server URL. Defaults per network. */
|
|
534
540
|
rpcUrl?: string;
|
|
541
|
+
/** Soroban RPC server URL used to broadcast transactions. Defaults per network. */
|
|
542
|
+
sorobanRpcUrl?: string;
|
|
535
543
|
defaults?: StellarWalletDefaults;
|
|
536
544
|
};
|
|
537
545
|
/** Configuration for constructing a `StellarWalletProvider` backed by a browser-extension wallet. */
|
|
@@ -539,7 +547,10 @@ type BrowserExtensionStellarWalletConfig = {
|
|
|
539
547
|
type: 'BROWSER_EXTENSION';
|
|
540
548
|
walletsKit: StellarWalletsKit;
|
|
541
549
|
network: StellarNetwork;
|
|
550
|
+
/** Horizon server URL. Defaults per network. */
|
|
542
551
|
rpcUrl?: string;
|
|
552
|
+
/** Soroban RPC server URL used to broadcast transactions. Defaults per network. */
|
|
553
|
+
sorobanRpcUrl?: string;
|
|
543
554
|
defaults?: StellarWalletDefaults;
|
|
544
555
|
};
|
|
545
556
|
type StellarWalletConfig = PrivateKeyStellarWalletConfig | BrowserExtensionStellarWalletConfig;
|
|
@@ -575,6 +586,7 @@ declare class StellarWalletProvider extends BaseWalletProvider<StellarWalletDefa
|
|
|
575
586
|
readonly chainType: "STELLAR";
|
|
576
587
|
private readonly wallet;
|
|
577
588
|
private readonly server;
|
|
589
|
+
private readonly sorobanServer;
|
|
578
590
|
private readonly networkPassphrase;
|
|
579
591
|
constructor(config: StellarWalletConfig);
|
|
580
592
|
getWalletAddress(): Promise<string>;
|
|
@@ -583,6 +595,18 @@ declare class StellarWalletProvider extends BaseWalletProvider<StellarWalletDefa
|
|
|
583
595
|
* @throws {StellarWalletError} with code `SIGN_TX_ERROR` if signing fails.
|
|
584
596
|
*/
|
|
585
597
|
signTransaction(tx: XDR): Promise<XDR>;
|
|
598
|
+
/**
|
|
599
|
+
* Broadcasts an already-signed XDR transaction via the Soroban RPC server.
|
|
600
|
+
* @returns The transaction hash.
|
|
601
|
+
* @throws {StellarWalletError} with code `SEND_TX_ERROR` if submission fails or the RPC returns an error status.
|
|
602
|
+
*/
|
|
603
|
+
sendTransaction(signedTx: XDR): Promise<string>;
|
|
604
|
+
/**
|
|
605
|
+
* Signs and broadcasts an unsigned `StellarRawTransaction` (e.g. from the Swaps API).
|
|
606
|
+
* @returns The transaction hash.
|
|
607
|
+
* @throws {StellarWalletError} with code `SIGN_TX_ERROR` if signing fails, or `SEND_TX_ERROR` if broadcasting fails.
|
|
608
|
+
*/
|
|
609
|
+
signAndSendTransaction(params: StellarRawTransaction): Promise<string>;
|
|
586
610
|
/**
|
|
587
611
|
* Polls the Horizon server until the transaction is confirmed or the timeout is reached.
|
|
588
612
|
* @throws {StellarWalletError} with code `TX_RECEIPT_TIMEOUT` if the transaction is not found within `pollTimeout` ms.
|
|
@@ -630,6 +654,13 @@ declare class StacksWalletProvider extends BaseWalletProvider<StacksWalletDefaul
|
|
|
630
654
|
private readonly wallet;
|
|
631
655
|
constructor(config: StacksWalletConfig);
|
|
632
656
|
sendTransaction(txParams: StacksTransactionParams, options?: Pick<StacksWalletDefaults, 'postConditionMode'>): Promise<string>;
|
|
657
|
+
/**
|
|
658
|
+
* Signs and broadcasts an unsigned `StacksRawTransaction` (e.g. from the Swaps API). The raw tx's
|
|
659
|
+
* `payload` is the hex-serialized contract-call payload; this deserializes it back into the
|
|
660
|
+
* contract-call params and routes through `sendTransaction` (which signs + broadcasts in both
|
|
661
|
+
* private-key and browser-extension modes). Returns the transaction id.
|
|
662
|
+
*/
|
|
663
|
+
signAndSendTransaction(params: StacksRawTransaction): Promise<string>;
|
|
633
664
|
private sendTransactionWithPrivateKey;
|
|
634
665
|
private sendTransactionWithAdapter;
|
|
635
666
|
readContract(txParams: StacksTransactionParams): Promise<ClarityValue>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EvmRawTransaction, EvmChainKey, IEvmWalletProvider, EvmRawTransactionReceipt, ISuiWalletProvider, SuiTransaction, SuiExecutionResult, SuiPaginatedCoins, IIconWalletProvider, IcxCallTransaction, IconTransactionResult, InjectiveCoin, IInjectiveWalletProvider, JsonObject, InjectiveRawTransaction, InjectiveEoaAddress, InjectiveExecuteResponse, ISolanaWalletProvider, SolanaRpcResponseAndContext, SolanaSignatureResult, TransactionSignature, SolanaRawTransactionInstruction, SolanaSerializedTransaction, SolanaBase58PublicKey, XDR, Hex as Hex$1, IStellarWalletProvider, StellarRawTransactionReceipt, IStacksWalletProvider, StacksTransactionParams, INearWalletProvider, CallContractParams, NearRawTransaction, BtcAddressType, IBitcoinWalletProvider } from '@sodax/types';
|
|
1
|
+
import { EvmRawTransaction, EvmChainKey, IEvmWalletProvider, EvmRawTransactionReceipt, ISuiWalletProvider, SuiTransaction, SuiExecutionResult, SuiPaginatedCoins, IIconWalletProvider, IcxCallTransaction, IconTransactionResult, InjectiveCoin, IInjectiveWalletProvider, JsonObject, InjectiveRawTransaction, InjectiveEoaAddress, InjectiveExecuteResponse, ISolanaWalletProvider, SolanaRpcResponseAndContext, SolanaSignatureResult, TransactionSignature, SolanaRawTransaction, SolanaRawTransactionInstruction, SolanaSerializedTransaction, SolanaBase58PublicKey, XDR, Hex as Hex$1, IStellarWalletProvider, StellarRawTransaction, StellarRawTransactionReceipt, IStacksWalletProvider, StacksTransactionParams, StacksRawTransaction, INearWalletProvider, CallContractParams, NearRawTransaction, BtcAddressType, IBitcoinWalletProvider } from '@sodax/types';
|
|
2
2
|
import * as viem from 'viem';
|
|
3
3
|
import { WalletClient, Transport, Chain, Account, PublicClient, PublicClientConfig, WalletClientConfig, HttpTransportConfig, SendTransactionParameters, WaitForTransactionReceiptParameters, Address, Hash as Hash$1 } from 'viem';
|
|
4
4
|
export { Account, Address, Chain, HttpTransportConfig, PublicClient, PublicClientConfig, SendTransactionParameters, TransactionReceipt, Transport, WaitForTransactionReceiptParameters, WalletClient, WalletClientConfig } from 'viem';
|
|
@@ -17,7 +17,7 @@ import { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
|
17
17
|
export { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
18
18
|
import { MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
19
19
|
export { MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
20
|
-
import { PublicKey, Commitment, ConnectionConfig, SendOptions, Connection, RpcResponseAndContext, TokenAmount } from '@solana/web3.js';
|
|
20
|
+
import { PublicKey, Commitment, ConnectionConfig, SendOptions, Connection, VersionedTransaction, RpcResponseAndContext, TokenAmount } from '@solana/web3.js';
|
|
21
21
|
export { Commitment, ConnectionConfig, SendOptions } from '@solana/web3.js';
|
|
22
22
|
import { SignerWalletAdapterProps } from '@solana/wallet-adapter-base';
|
|
23
23
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
@@ -490,12 +490,17 @@ declare class SolanaWalletProvider extends BaseWalletProvider<SolanaWalletDefaul
|
|
|
490
490
|
constructor(walletConfig: SolanaWalletConfig);
|
|
491
491
|
waitForConfirmation(signature: string, commitment?: Commitment): Promise<SolanaRpcResponseAndContext<SolanaSignatureResult>>;
|
|
492
492
|
sendTransaction(rawTransaction: Uint8Array | Array<number>, options?: SendOptions): Promise<TransactionSignature>;
|
|
493
|
+
signAndSendTransaction(params: SolanaRawTransaction): Promise<TransactionSignature>;
|
|
493
494
|
sendTransactionWithConfirmation(rawTransaction: Uint8Array | Array<number>, optionsOrCommitment?: Commitment | {
|
|
494
495
|
send?: SendOptions;
|
|
495
496
|
commitment?: Commitment;
|
|
496
497
|
}): Promise<TransactionSignature>;
|
|
497
498
|
buildV0Txn(rawInstructions: SolanaRawTransactionInstruction[]): Promise<SolanaSerializedTransaction>;
|
|
498
499
|
private buildV0TxnWithAdapter;
|
|
500
|
+
signTransaction(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
501
|
+
signAndSerializeTransaction(transaction: VersionedTransaction): Promise<SolanaSerializedTransaction>;
|
|
502
|
+
signTransactionWithAdapter(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
503
|
+
signTransactionWithKeypair(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
499
504
|
private buildV0TxnWithKeypair;
|
|
500
505
|
getWalletBase58PublicKey(): SolanaBase58PublicKey;
|
|
501
506
|
getWalletAddress(): Promise<string>;
|
|
@@ -531,7 +536,10 @@ type PrivateKeyStellarWalletConfig = {
|
|
|
531
536
|
type: 'PRIVATE_KEY';
|
|
532
537
|
privateKey: Hex$1;
|
|
533
538
|
network: StellarNetwork;
|
|
539
|
+
/** Horizon server URL. Defaults per network. */
|
|
534
540
|
rpcUrl?: string;
|
|
541
|
+
/** Soroban RPC server URL used to broadcast transactions. Defaults per network. */
|
|
542
|
+
sorobanRpcUrl?: string;
|
|
535
543
|
defaults?: StellarWalletDefaults;
|
|
536
544
|
};
|
|
537
545
|
/** Configuration for constructing a `StellarWalletProvider` backed by a browser-extension wallet. */
|
|
@@ -539,7 +547,10 @@ type BrowserExtensionStellarWalletConfig = {
|
|
|
539
547
|
type: 'BROWSER_EXTENSION';
|
|
540
548
|
walletsKit: StellarWalletsKit;
|
|
541
549
|
network: StellarNetwork;
|
|
550
|
+
/** Horizon server URL. Defaults per network. */
|
|
542
551
|
rpcUrl?: string;
|
|
552
|
+
/** Soroban RPC server URL used to broadcast transactions. Defaults per network. */
|
|
553
|
+
sorobanRpcUrl?: string;
|
|
543
554
|
defaults?: StellarWalletDefaults;
|
|
544
555
|
};
|
|
545
556
|
type StellarWalletConfig = PrivateKeyStellarWalletConfig | BrowserExtensionStellarWalletConfig;
|
|
@@ -575,6 +586,7 @@ declare class StellarWalletProvider extends BaseWalletProvider<StellarWalletDefa
|
|
|
575
586
|
readonly chainType: "STELLAR";
|
|
576
587
|
private readonly wallet;
|
|
577
588
|
private readonly server;
|
|
589
|
+
private readonly sorobanServer;
|
|
578
590
|
private readonly networkPassphrase;
|
|
579
591
|
constructor(config: StellarWalletConfig);
|
|
580
592
|
getWalletAddress(): Promise<string>;
|
|
@@ -583,6 +595,18 @@ declare class StellarWalletProvider extends BaseWalletProvider<StellarWalletDefa
|
|
|
583
595
|
* @throws {StellarWalletError} with code `SIGN_TX_ERROR` if signing fails.
|
|
584
596
|
*/
|
|
585
597
|
signTransaction(tx: XDR): Promise<XDR>;
|
|
598
|
+
/**
|
|
599
|
+
* Broadcasts an already-signed XDR transaction via the Soroban RPC server.
|
|
600
|
+
* @returns The transaction hash.
|
|
601
|
+
* @throws {StellarWalletError} with code `SEND_TX_ERROR` if submission fails or the RPC returns an error status.
|
|
602
|
+
*/
|
|
603
|
+
sendTransaction(signedTx: XDR): Promise<string>;
|
|
604
|
+
/**
|
|
605
|
+
* Signs and broadcasts an unsigned `StellarRawTransaction` (e.g. from the Swaps API).
|
|
606
|
+
* @returns The transaction hash.
|
|
607
|
+
* @throws {StellarWalletError} with code `SIGN_TX_ERROR` if signing fails, or `SEND_TX_ERROR` if broadcasting fails.
|
|
608
|
+
*/
|
|
609
|
+
signAndSendTransaction(params: StellarRawTransaction): Promise<string>;
|
|
586
610
|
/**
|
|
587
611
|
* Polls the Horizon server until the transaction is confirmed or the timeout is reached.
|
|
588
612
|
* @throws {StellarWalletError} with code `TX_RECEIPT_TIMEOUT` if the transaction is not found within `pollTimeout` ms.
|
|
@@ -630,6 +654,13 @@ declare class StacksWalletProvider extends BaseWalletProvider<StacksWalletDefaul
|
|
|
630
654
|
private readonly wallet;
|
|
631
655
|
constructor(config: StacksWalletConfig);
|
|
632
656
|
sendTransaction(txParams: StacksTransactionParams, options?: Pick<StacksWalletDefaults, 'postConditionMode'>): Promise<string>;
|
|
657
|
+
/**
|
|
658
|
+
* Signs and broadcasts an unsigned `StacksRawTransaction` (e.g. from the Swaps API). The raw tx's
|
|
659
|
+
* `payload` is the hex-serialized contract-call payload; this deserializes it back into the
|
|
660
|
+
* contract-call params and routes through `sendTransaction` (which signs + broadcasts in both
|
|
661
|
+
* private-key and browser-extension modes). Returns the transaction id.
|
|
662
|
+
*/
|
|
663
|
+
signAndSendTransaction(params: StacksRawTransaction): Promise<string>;
|
|
633
664
|
private sendTransactionWithPrivateKey;
|
|
634
665
|
private sendTransactionWithAdapter;
|
|
635
666
|
readContract(txParams: StacksTransactionParams): Promise<ClarityValue>;
|
package/dist/index.mjs
CHANGED
|
@@ -11,10 +11,10 @@ import { TxRaw, SignDoc, TxBody } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
|
|
|
11
11
|
import { MsgExecuteContract as MsgExecuteContract$1 } from 'cosmjs-types/cosmwasm/wasm/v1/tx.js';
|
|
12
12
|
import { getNetworkEndpoints } from '@injectivelabs/networks';
|
|
13
13
|
import { getAssociatedTokenAddress } from '@solana/spl-token';
|
|
14
|
-
import { Keypair, Connection,
|
|
15
|
-
import { Networks, Keypair as Keypair$1, Horizon, Transaction } from '@stellar/stellar-sdk';
|
|
14
|
+
import { Keypair, Connection, VersionedTransaction, TransactionMessage, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
15
|
+
import { Networks, Keypair as Keypair$1, Horizon, rpc, Transaction, TransactionBuilder } from '@stellar/stellar-sdk';
|
|
16
16
|
export { Networks } from '@stellar/stellar-sdk';
|
|
17
|
-
import { makeContractCall, broadcastTransaction, fetchCallReadOnlyFunction, getAddressFromPrivateKey, publicKeyToHex, privateKeyToPublic, networkFrom
|
|
17
|
+
import { deserializePayload, PayloadType, PostConditionMode, addressToString, makeContractCall, broadcastTransaction, fetchCallReadOnlyFunction, getAddressFromPrivateKey, publicKeyToHex, privateKeyToPublic, networkFrom } from '@sodax/libs/stacks/core';
|
|
18
18
|
export { PostConditionMode } from '@sodax/libs/stacks/core';
|
|
19
19
|
import { request } from '@sodax/libs/stacks/connect';
|
|
20
20
|
import * as bitcoin from 'bitcoinjs-lib';
|
|
@@ -2400,7 +2400,7 @@ var RelayChainIdMap = {
|
|
|
2400
2400
|
[ChainKeys.KAIA_MAINNET]: 27489n,
|
|
2401
2401
|
[ChainKeys.STACKS_MAINNET]: 60n
|
|
2402
2402
|
};
|
|
2403
|
-
|
|
2403
|
+
new Map(Object.entries(RelayChainIdMap).map(([chainKey, chainId]) => [chainId, chainKey]));
|
|
2404
2404
|
var CHAIN_LOGO_BASE_URL = "https://raw.githubusercontent.com/icon-project/sodax-sdks/main/packages/assets/chain";
|
|
2405
2405
|
var chainLogo = (key) => `${CHAIN_LOGO_BASE_URL}/${key}.png`;
|
|
2406
2406
|
var baseChainInfo = {
|
|
@@ -3814,6 +3814,12 @@ var SolanaWalletProvider = class extends BaseWalletProvider {
|
|
|
3814
3814
|
const sendOptions = shallowMerge(this.defaults.sendOptions, options);
|
|
3815
3815
|
return this.connection.sendRawTransaction(rawTransaction, sendOptions);
|
|
3816
3816
|
}
|
|
3817
|
+
async signAndSendTransaction(params) {
|
|
3818
|
+
const serializedTxBytes = Buffer.from(params.data, "base64");
|
|
3819
|
+
const versionedTx = VersionedTransaction.deserialize(serializedTxBytes);
|
|
3820
|
+
const signedTx = await this.signAndSerializeTransaction(versionedTx);
|
|
3821
|
+
return this.sendTransaction(signedTx);
|
|
3822
|
+
}
|
|
3817
3823
|
async sendTransactionWithConfirmation(rawTransaction, optionsOrCommitment) {
|
|
3818
3824
|
const isCommitmentArg = typeof optionsOrCommitment === "string";
|
|
3819
3825
|
const sendOpts = isCommitmentArg ? void 0 : optionsOrCommitment?.send;
|
|
@@ -3847,6 +3853,31 @@ var SolanaWalletProvider = class extends BaseWalletProvider {
|
|
|
3847
3853
|
const tx = await adapterWallet.signTransaction(new VersionedTransaction(messageV0));
|
|
3848
3854
|
return tx.serialize();
|
|
3849
3855
|
}
|
|
3856
|
+
async signTransaction(transaction) {
|
|
3857
|
+
if (this.isAdapterMode) {
|
|
3858
|
+
return this.signTransactionWithAdapter(transaction);
|
|
3859
|
+
}
|
|
3860
|
+
return this.signTransactionWithKeypair(transaction);
|
|
3861
|
+
}
|
|
3862
|
+
async signAndSerializeTransaction(transaction) {
|
|
3863
|
+
const tx = await this.signTransaction(transaction);
|
|
3864
|
+
return tx.serialize();
|
|
3865
|
+
}
|
|
3866
|
+
async signTransactionWithAdapter(transaction) {
|
|
3867
|
+
const adapterWallet = this.wallet;
|
|
3868
|
+
if (!adapterWallet.signTransaction) {
|
|
3869
|
+
throw new Error("Wallet signTransaction is not initialized");
|
|
3870
|
+
}
|
|
3871
|
+
return adapterWallet.signTransaction(transaction);
|
|
3872
|
+
}
|
|
3873
|
+
async signTransactionWithKeypair(transaction) {
|
|
3874
|
+
if (this.isAdapterMode) {
|
|
3875
|
+
throw new Error("Cannot sign transaction with keypair in adapter mode");
|
|
3876
|
+
}
|
|
3877
|
+
const keypairWallet = this.wallet;
|
|
3878
|
+
transaction.sign([keypairWallet]);
|
|
3879
|
+
return transaction;
|
|
3880
|
+
}
|
|
3850
3881
|
async buildV0TxnWithKeypair(rawInstructions) {
|
|
3851
3882
|
const keypairWallet = this.wallet;
|
|
3852
3883
|
const instructions = this.buildTransactionInstruction(rawInstructions);
|
|
@@ -3898,6 +3929,10 @@ var STELLAR_HORIZON_URLS = {
|
|
|
3898
3929
|
TESTNET: "https://horizon-testnet.stellar.org",
|
|
3899
3930
|
PUBLIC: "https://horizon.stellar.org"
|
|
3900
3931
|
};
|
|
3932
|
+
var STELLAR_SOROBAN_URLS = {
|
|
3933
|
+
TESTNET: "https://soroban-testnet.stellar.org",
|
|
3934
|
+
PUBLIC: "https://rpc.ankr.com/stellar_soroban"
|
|
3935
|
+
};
|
|
3901
3936
|
var STELLAR_NETWORK_PASSPHRASES = {
|
|
3902
3937
|
TESTNET: Networks.TESTNET,
|
|
3903
3938
|
PUBLIC: Networks.PUBLIC
|
|
@@ -3939,6 +3974,7 @@ var StellarWalletProvider = class extends BaseWalletProvider {
|
|
|
3939
3974
|
chainType = "STELLAR";
|
|
3940
3975
|
wallet;
|
|
3941
3976
|
server;
|
|
3977
|
+
sorobanServer;
|
|
3942
3978
|
networkPassphrase;
|
|
3943
3979
|
constructor(config) {
|
|
3944
3980
|
super(config.defaults);
|
|
@@ -3947,6 +3983,9 @@ var StellarWalletProvider = class extends BaseWalletProvider {
|
|
|
3947
3983
|
}
|
|
3948
3984
|
this.networkPassphrase = this.defaults.networkPassphrase ?? STELLAR_NETWORK_PASSPHRASES[config.network];
|
|
3949
3985
|
this.server = new Horizon.Server(config.rpcUrl ?? STELLAR_HORIZON_URLS[config.network]);
|
|
3986
|
+
this.sorobanServer = new rpc.Server(config.sorobanRpcUrl ?? STELLAR_SOROBAN_URLS[config.network], {
|
|
3987
|
+
allowHttp: true
|
|
3988
|
+
});
|
|
3950
3989
|
if (isPrivateKeyStellarWalletConfig(config)) {
|
|
3951
3990
|
if (!isValidStellarPrivateKey(config.privateKey)) {
|
|
3952
3991
|
throw new StellarWalletError("Invalid private key format", "INVALID_PRIVATE_KEY");
|
|
@@ -3997,6 +4036,38 @@ var StellarWalletProvider = class extends BaseWalletProvider {
|
|
|
3997
4036
|
);
|
|
3998
4037
|
}
|
|
3999
4038
|
}
|
|
4039
|
+
/**
|
|
4040
|
+
* Broadcasts an already-signed XDR transaction via the Soroban RPC server.
|
|
4041
|
+
* @returns The transaction hash.
|
|
4042
|
+
* @throws {StellarWalletError} with code `SEND_TX_ERROR` if submission fails or the RPC returns an error status.
|
|
4043
|
+
*/
|
|
4044
|
+
async sendTransaction(signedTx) {
|
|
4045
|
+
try {
|
|
4046
|
+
const tx = TransactionBuilder.fromXDR(signedTx, this.networkPassphrase);
|
|
4047
|
+
const response = await this.sorobanServer.sendTransaction(tx);
|
|
4048
|
+
if (response.status === "ERROR") {
|
|
4049
|
+
throw new StellarWalletError(`Failed to submit transaction: ${JSON.stringify(response)}`, "SEND_TX_ERROR");
|
|
4050
|
+
}
|
|
4051
|
+
return response.hash;
|
|
4052
|
+
} catch (error) {
|
|
4053
|
+
if (error instanceof StellarWalletError) {
|
|
4054
|
+
throw error;
|
|
4055
|
+
}
|
|
4056
|
+
throw new StellarWalletError(
|
|
4057
|
+
error instanceof Error ? error.message : "Failed to send transaction",
|
|
4058
|
+
"SEND_TX_ERROR"
|
|
4059
|
+
);
|
|
4060
|
+
}
|
|
4061
|
+
}
|
|
4062
|
+
/**
|
|
4063
|
+
* Signs and broadcasts an unsigned `StellarRawTransaction` (e.g. from the Swaps API).
|
|
4064
|
+
* @returns The transaction hash.
|
|
4065
|
+
* @throws {StellarWalletError} with code `SIGN_TX_ERROR` if signing fails, or `SEND_TX_ERROR` if broadcasting fails.
|
|
4066
|
+
*/
|
|
4067
|
+
async signAndSendTransaction(params) {
|
|
4068
|
+
const signedXdr = await this.signTransaction(params.data);
|
|
4069
|
+
return this.sendTransaction(signedXdr);
|
|
4070
|
+
}
|
|
4000
4071
|
/**
|
|
4001
4072
|
* Polls the Horizon server until the transaction is confirmed or the timeout is reached.
|
|
4002
4073
|
* @throws {StellarWalletError} with code `TX_RECEIPT_TIMEOUT` if the transaction is not found within `pollTimeout` ms.
|
|
@@ -4065,6 +4136,26 @@ var StacksWalletProvider = class extends BaseWalletProvider {
|
|
|
4065
4136
|
}
|
|
4066
4137
|
return this.sendTransactionWithAdapter(finalParams, this.wallet);
|
|
4067
4138
|
}
|
|
4139
|
+
/**
|
|
4140
|
+
* Signs and broadcasts an unsigned `StacksRawTransaction` (e.g. from the Swaps API). The raw tx's
|
|
4141
|
+
* `payload` is the hex-serialized contract-call payload; this deserializes it back into the
|
|
4142
|
+
* contract-call params and routes through `sendTransaction` (which signs + broadcasts in both
|
|
4143
|
+
* private-key and browser-extension modes). Returns the transaction id.
|
|
4144
|
+
*/
|
|
4145
|
+
async signAndSendTransaction(params) {
|
|
4146
|
+
const payload = deserializePayload(params.payload);
|
|
4147
|
+
if (payload.payloadType !== PayloadType.ContractCall) {
|
|
4148
|
+
throw new Error("signAndSendTransaction: expected a contract-call payload.");
|
|
4149
|
+
}
|
|
4150
|
+
return this.sendTransaction({
|
|
4151
|
+
contractAddress: addressToString(payload.contractAddress),
|
|
4152
|
+
contractName: payload.contractName.content,
|
|
4153
|
+
functionName: payload.functionName.content,
|
|
4154
|
+
functionArgs: payload.functionArgs,
|
|
4155
|
+
postConditionMode: PostConditionMode.Allow
|
|
4156
|
+
// matches how the spoke service builds the tx
|
|
4157
|
+
});
|
|
4158
|
+
}
|
|
4068
4159
|
async sendTransactionWithPrivateKey(txParams, wallet) {
|
|
4069
4160
|
const transaction = await makeContractCall({
|
|
4070
4161
|
contractAddress: txParams.contractAddress,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "2.0.0-rc.
|
|
7
|
+
"version": "2.0.0-rc.19",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"description": "Sodax Wallet SDK Core",
|
|
10
10
|
"keywords": [
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"near-api-js": "7.2.0",
|
|
68
68
|
"secp256k1": "^5.0.1",
|
|
69
69
|
"viem": "2.29.2",
|
|
70
|
-
"@sodax/libs": "2.0.0-rc.
|
|
71
|
-
"@sodax/types": "2.0.0-rc.
|
|
70
|
+
"@sodax/libs": "2.0.0-rc.19",
|
|
71
|
+
"@sodax/types": "2.0.0-rc.19"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@arethetypeswrong/cli": "0.17.4",
|