@sodax/wallet-sdk-core 0.0.1-rc.1

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.
@@ -0,0 +1,291 @@
1
+ import { ChainId, IEvmWalletProvider, EvmRawTransaction, EvmRawTransactionReceipt, ISuiWalletProvider, SuiTransaction, SuiExecutionResult, SuiPaginatedCoins, IIconWalletProvider, IcxCallTransaction, IconTransactionResult, InjectiveEoaAddress, IInjectiveWalletProvider, JsonObject, InjectiveRawTransaction, InjectiveCoin, InjectiveExecuteResponse, ISolanaWalletProvider, SolanaRpcResponseAndContext, SolanaSignatureResult, TransactionSignature, SolanaRawTransactionInstruction, SolanaSerializedTransaction, SolanaBase58PublicKey, Hex as Hex$1, XDR, IStellarWalletProvider, StellarRawTransactionReceipt } from '@sodax/types';
2
+ import { Chain, PublicClient, WalletClient, Transport, Account, Hash as Hash$1, Address } from 'viem';
3
+ import { SuiClient } from '@mysten/sui/client';
4
+ import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
5
+ import { Transaction } from '@mysten/sui/transactions';
6
+ import { WalletWithFeatures, SuiWalletFeatures, WalletAccount } from '@mysten/wallet-standard';
7
+ import { IconService, Wallet } from 'icon-sdk-js';
8
+ import { MsgBroadcaster } from '@injectivelabs/wallet-core';
9
+ import { PublicKey, Connection, Commitment, RpcResponseAndContext, TokenAmount } from '@solana/web3.js';
10
+ import { SignerWalletAdapterProps } from '@solana/wallet-adapter-base';
11
+ import { Keypair } from '@stellar/stellar-sdk';
12
+
13
+ declare function getEvmViemChain(id: ChainId): Chain;
14
+ declare class EvmWalletProvider implements IEvmWalletProvider {
15
+ private readonly walletClient;
16
+ readonly publicClient: PublicClient;
17
+ constructor(config: EvmWalletConfig);
18
+ sendTransaction(evmRawTx: EvmRawTransaction): Promise<Hash$1>;
19
+ waitForTransactionReceipt(txHash: Hash$1): Promise<EvmRawTransactionReceipt>;
20
+ getWalletAddress(): Promise<Address>;
21
+ }
22
+ /**
23
+ * EVM Wallet Configuration Types
24
+ */
25
+ type PrivateKeyEvmWalletConfig = {
26
+ privateKey: `0x${string}`;
27
+ chainId: ChainId;
28
+ rpcUrl?: `http${string}`;
29
+ };
30
+ type BrowserExtensionEvmWalletConfig = {
31
+ walletClient: WalletClient<Transport, Chain, Account>;
32
+ publicClient: PublicClient;
33
+ };
34
+ type EvmWalletConfig = PrivateKeyEvmWalletConfig | BrowserExtensionEvmWalletConfig;
35
+ /**
36
+ * EVM Type Guards
37
+ */
38
+ declare function isPrivateKeyEvmWalletConfig(config: EvmWalletConfig): config is PrivateKeyEvmWalletConfig;
39
+ declare function isBrowserExtensionEvmWalletConfig(config: EvmWalletConfig): config is BrowserExtensionEvmWalletConfig;
40
+
41
+ type PrivateKeySuiWalletConfig = {
42
+ rpcUrl: string;
43
+ mnemonics: string;
44
+ };
45
+ type BrowserExtensionSuiWalletConfig = {
46
+ client: SuiClient;
47
+ wallet: WalletWithFeatures<Partial<SuiWalletFeatures>>;
48
+ account: WalletAccount;
49
+ };
50
+ type SuiWalletConfig = PrivateKeySuiWalletConfig | BrowserExtensionSuiWalletConfig;
51
+ type PkSuiWallet = {
52
+ keyPair: Ed25519Keypair;
53
+ };
54
+ type BrowserExtensionSuiWallet = {
55
+ wallet: WalletWithFeatures<Partial<SuiWalletFeatures>>;
56
+ account: WalletAccount;
57
+ };
58
+ type SuiWallet = PkSuiWallet | BrowserExtensionSuiWallet;
59
+ declare function isPkSuiWallet(wallet: SuiWallet): wallet is PkSuiWallet;
60
+ declare function isBrowserExtensionSuiWallet(wallet: SuiWallet): wallet is BrowserExtensionSuiWallet;
61
+ declare function isSuiWallet(wallet: SuiWallet): wallet is SuiWallet;
62
+ declare class SuiWalletProvider implements ISuiWalletProvider {
63
+ private readonly client;
64
+ private readonly wallet;
65
+ constructor(walletConfig: SuiWalletConfig);
66
+ signAndExecuteTxn(txn: SuiTransaction): Promise<string>;
67
+ viewContract(tx: Transaction, packageId: string, module: string, functionName: string, args: unknown[], typeArgs?: string[]): Promise<SuiExecutionResult>;
68
+ getCoins(address: string, token: string): Promise<SuiPaginatedCoins>;
69
+ private getSuiAddress;
70
+ getWalletAddress(): Promise<string>;
71
+ }
72
+
73
+ declare class IconWalletProvider implements IIconWalletProvider {
74
+ private readonly wallet;
75
+ readonly iconService: IconService;
76
+ constructor(wallet: IconWalletConfig);
77
+ sendTransaction(tx: IcxCallTransaction): Promise<Hash>;
78
+ waitForTransactionReceipt(txHash: Hash): Promise<IconTransactionResult>;
79
+ getWalletAddress(): Promise<IconEoaAddress>;
80
+ }
81
+ /**
82
+ * Icon Types
83
+ */
84
+ type IconJsonRpcVersion = '2.0';
85
+ type Hex = `0x${string}`;
86
+ type Hash = `0x${string}`;
87
+ type IconAddress = `hx${string}` | `cx${string}`;
88
+ type IconEoaAddress = `hx${string}`;
89
+ type PrivateKeyIconWalletConfig = {
90
+ privateKey: `0x${string}`;
91
+ rpcUrl: `http${string}`;
92
+ };
93
+ type BrowserExtensionIconWalletConfig = {
94
+ walletAddress?: IconEoaAddress;
95
+ rpcUrl: `http${string}`;
96
+ };
97
+ type IconWalletConfig = PrivateKeyIconWalletConfig | BrowserExtensionIconWalletConfig;
98
+ type IconPkWallet = {
99
+ type: 'PRIVATE_KEY';
100
+ wallet: Wallet;
101
+ };
102
+ type IconBrowserExtensionWallet = {
103
+ type: 'BROWSER_EXTENSION';
104
+ wallet?: IconEoaAddress;
105
+ };
106
+ type IconWallet = IconPkWallet | IconBrowserExtensionWallet;
107
+ type HanaWalletRequestEvent = 'REQUEST_HAS_ACCOUNT' | 'REQUEST_HAS_ADDRESS' | 'REQUEST_ADDRESS' | 'REQUEST_JSON' | 'REQUEST_SIGNING' | 'REQUEST_JSON-RPC';
108
+ type HanaWalletResponseEvent = 'RESPONSE_HAS_ACCOUNT' | 'RESPONSE_HAS_ADDRESS' | 'RESPONSE_ADDRESS' | 'RESPONSE_JSON-RPC' | 'RESPONSE_SIGNING' | 'CANCEL_SIGNING' | 'CANCEL_JSON-RPC';
109
+ type ResponseAddressType = {
110
+ type: 'RESPONSE_ADDRESS';
111
+ payload: IconAddress;
112
+ };
113
+ type ResponseSigningType = {
114
+ type: 'RESPONSE_SIGNING';
115
+ payload: string;
116
+ };
117
+ type RelayRequestDetail = {
118
+ type: HanaWalletRequestEvent;
119
+ payload?: {
120
+ jsonrpc: IconJsonRpcVersion;
121
+ method: string;
122
+ params: unknown;
123
+ id: number | undefined;
124
+ };
125
+ };
126
+ type RelayRequestSigning = {
127
+ type: 'REQUEST_SIGNING';
128
+ payload: {
129
+ from: IconAddress;
130
+ hash: string;
131
+ };
132
+ };
133
+ type JsonRpcPayloadResponse = {
134
+ id: number;
135
+ result: string;
136
+ };
137
+ /**
138
+ * Icon Type Guards
139
+ */
140
+ declare function isIconPkWallet(wallet: IconWallet): wallet is IconPkWallet;
141
+ declare function isIconBrowserExtensionWallet(wallet: IconWallet): wallet is IconBrowserExtensionWallet;
142
+ declare function isPrivateKeyIconWalletConfig(config: IconWalletConfig): config is PrivateKeyIconWalletConfig;
143
+ declare function isBrowserExtensionIconWalletConfig(config: IconWalletConfig): config is BrowserExtensionIconWalletConfig;
144
+ declare function isIconAddress(value: unknown): value is IconAddress;
145
+ declare function isIconEoaAddress(value: unknown): value is IconEoaAddress;
146
+ declare function isResponseAddressType(value: unknown): value is ResponseAddressType;
147
+ declare function isResponseSigningType(value: unknown): value is ResponseSigningType;
148
+ declare function isJsonRpcPayloadResponse(value: unknown): value is JsonRpcPayloadResponse;
149
+ /**
150
+ * Methods to interact with Icon Browser Extension Wallet (e.g. Hana Wallet)
151
+ */
152
+ declare function requestAddress(): Promise<IconAddress>;
153
+ declare function requestSigning(from: IconAddress, hash: string): Promise<string>;
154
+ declare function requestJsonRpc(rawTransaction: unknown, id?: number): Promise<JsonRpcPayloadResponse>;
155
+ /**
156
+ * Icon Utils
157
+ */
158
+ declare function BigNumberToBigInt(bigNumber: BigNumber): bigint;
159
+
160
+ /**
161
+ * Injective Wallet Configuration Types
162
+ */
163
+ type BrowserExtensionInjectiveWalletConfig = {
164
+ msgBroadcaster: MsgBroadcaster;
165
+ walletAddress: InjectiveEoaAddress | undefined;
166
+ };
167
+ type InjectiveWalletConfig = BrowserExtensionInjectiveWalletConfig;
168
+ /**
169
+ * Injective Type Guards
170
+ */
171
+ declare function isBrowserExtensionInjectiveWalletConfig(config: InjectiveWalletConfig): config is BrowserExtensionInjectiveWalletConfig;
172
+ declare class InjectiveWalletProvider implements IInjectiveWalletProvider {
173
+ private msgBroadcaster;
174
+ walletAddress: InjectiveEoaAddress | undefined;
175
+ constructor(config: InjectiveWalletConfig);
176
+ getRawTransaction(chainId: string, _: string, senderAddress: string, contractAddress: string, msg: JsonObject, memo?: string): Promise<InjectiveRawTransaction>;
177
+ getWalletAddress(): Promise<InjectiveEoaAddress>;
178
+ execute(senderAddress: string, contractAddress: string, msg: JsonObject, funds?: InjectiveCoin[]): Promise<InjectiveExecuteResponse>;
179
+ }
180
+
181
+ interface WalletContextState {
182
+ publicKey: PublicKey | null;
183
+ signTransaction: SignerWalletAdapterProps['signTransaction'] | undefined;
184
+ }
185
+ type PrivateKeySolanaWalletConfig = {
186
+ privateKey: Uint8Array;
187
+ endpoint: string;
188
+ };
189
+ type BrowserExtensionSolanaWalletConfig = {
190
+ wallet: WalletContextState;
191
+ connection: Connection;
192
+ };
193
+ type SolanaWalletConfig = PrivateKeySolanaWalletConfig | BrowserExtensionSolanaWalletConfig;
194
+ declare class SolanaWalletProvider implements ISolanaWalletProvider {
195
+ private readonly wallet;
196
+ readonly connection: Connection;
197
+ private readonly isAdapterMode;
198
+ constructor(walletConfig: SolanaWalletConfig);
199
+ waitForConfirmation(signature: string, commitment?: Commitment): Promise<SolanaRpcResponseAndContext<SolanaSignatureResult>>;
200
+ /**
201
+ * Send a raw transaction to the Solana network.
202
+ * @param rawTransaction - The raw transaction to send.
203
+ * @returns The transaction signature.
204
+ */
205
+ sendTransaction(rawTransaction: Uint8Array | Array<number>): Promise<TransactionSignature>;
206
+ /**
207
+ * Send a raw transaction to the Solana network and wait for confirmation.
208
+ * @param rawTransaction - The raw transaction to send.
209
+ * @param commitment - The commitment level to use. Defaults to 'finalized'.
210
+ * @returns The transaction signature.
211
+ */
212
+ sendTransactionWithConfirmation(rawTransaction: Uint8Array | Array<number>, commitment?: Commitment): Promise<TransactionSignature>;
213
+ /**
214
+ * Build a v0 versioned transaction.
215
+ * @param instructions - The instructions to include in the transaction.
216
+ * @returns The v0 transaction.
217
+ */
218
+ buildV0Txn(rawInstructions: SolanaRawTransactionInstruction[]): Promise<SolanaSerializedTransaction>;
219
+ private buildV0TxnWithAdapter;
220
+ private buildV0TxnWithKeypair;
221
+ getWalletBase58PublicKey(): SolanaBase58PublicKey;
222
+ getWalletAddress(): Promise<string>;
223
+ getAssociatedTokenAddress(mint: SolanaBase58PublicKey): Promise<SolanaBase58PublicKey>;
224
+ getBalance(publicKey: SolanaBase58PublicKey): Promise<number>;
225
+ getTokenAccountBalance(publicKey: SolanaBase58PublicKey): Promise<RpcResponseAndContext<TokenAmount>>;
226
+ private buildTransactionInstruction;
227
+ }
228
+
229
+ interface StellarWalletsKit {
230
+ getAddress(): Promise<{
231
+ address: string;
232
+ }>;
233
+ signTransaction(tx: XDR, options: {
234
+ networkPassphrase: string;
235
+ }): Promise<{
236
+ signedTxXdr: XDR;
237
+ }>;
238
+ }
239
+ type StellarNetwork = 'TESTNET' | 'PUBLIC';
240
+ declare const STELLAR_ERROR_CODES: {
241
+ readonly INVALID_CONFIG: "INVALID_CONFIG";
242
+ readonly SIGN_TX_ERROR: "SIGN_TX_ERROR";
243
+ readonly TX_RECEIPT_TIMEOUT: "TX_RECEIPT_TIMEOUT";
244
+ readonly SEND_TX_ERROR: "SEND_TX_ERROR";
245
+ readonly INVALID_NETWORK: "INVALID_NETWORK";
246
+ readonly INVALID_PRIVATE_KEY: "INVALID_PRIVATE_KEY";
247
+ };
248
+ type StellarAddress = string;
249
+ type PrivateKeyStellarWalletConfig = {
250
+ type: 'PRIVATE_KEY';
251
+ privateKey: Hex$1;
252
+ network: StellarNetwork;
253
+ rpcUrl?: string;
254
+ };
255
+ type BrowserExtensionStellarWalletConfig = {
256
+ type: 'BROWSER_EXTENSION';
257
+ walletsKit: StellarWalletsKit;
258
+ network: StellarNetwork;
259
+ rpcUrl?: string;
260
+ };
261
+ type StellarWalletConfig = PrivateKeyStellarWalletConfig | BrowserExtensionStellarWalletConfig;
262
+ type StellarPkWallet = {
263
+ type: 'PRIVATE_KEY';
264
+ keypair: Keypair;
265
+ };
266
+ type StellarBrowserExtensionWallet = {
267
+ type: 'BROWSER_EXTENSION';
268
+ walletsKit: StellarWalletsKit;
269
+ };
270
+ type StellarWallet = StellarPkWallet | StellarBrowserExtensionWallet;
271
+ declare class StellarWalletError extends Error {
272
+ readonly code: keyof typeof STELLAR_ERROR_CODES;
273
+ constructor(message: string, code: keyof typeof STELLAR_ERROR_CODES);
274
+ }
275
+ declare function isPrivateKeyStellarWalletConfig(config: StellarWalletConfig): config is PrivateKeyStellarWalletConfig;
276
+ declare function isBrowserExtensionStellarWalletConfig(config: StellarWalletConfig): config is BrowserExtensionStellarWalletConfig;
277
+ declare function isStellarPkWallet(wallet: StellarWallet): wallet is StellarPkWallet;
278
+ declare function isStellarBrowserExtensionWallet(wallet: StellarWallet): wallet is StellarBrowserExtensionWallet;
279
+ declare function isValidStellarNetwork(network: string): network is StellarNetwork;
280
+ declare function isValidStellarPrivateKey(privateKey: string): boolean;
281
+ declare class StellarWalletProvider implements IStellarWalletProvider {
282
+ private readonly wallet;
283
+ private readonly server;
284
+ private readonly networkPassphrase;
285
+ constructor(config: StellarWalletConfig);
286
+ getWalletAddress(): Promise<string>;
287
+ signTransaction(tx: XDR): Promise<XDR>;
288
+ waitForTransactionReceipt(txHash: string): Promise<StellarRawTransactionReceipt>;
289
+ }
290
+
291
+ export { BigNumberToBigInt, type BrowserExtensionEvmWalletConfig, type BrowserExtensionIconWalletConfig, type BrowserExtensionInjectiveWalletConfig, type BrowserExtensionSolanaWalletConfig, type BrowserExtensionStellarWalletConfig, type BrowserExtensionSuiWallet, type BrowserExtensionSuiWalletConfig, type EvmWalletConfig, EvmWalletProvider, type HanaWalletRequestEvent, type HanaWalletResponseEvent, type Hash, type Hex, type IconAddress, type IconBrowserExtensionWallet, type IconEoaAddress, type IconJsonRpcVersion, type IconPkWallet, type IconWallet, type IconWalletConfig, IconWalletProvider, type InjectiveWalletConfig, InjectiveWalletProvider, type JsonRpcPayloadResponse, type PkSuiWallet, type PrivateKeyEvmWalletConfig, type PrivateKeyIconWalletConfig, type PrivateKeySolanaWalletConfig, type PrivateKeyStellarWalletConfig, type PrivateKeySuiWalletConfig, type RelayRequestDetail, type RelayRequestSigning, type ResponseAddressType, type ResponseSigningType, type SolanaWalletConfig, SolanaWalletProvider, type StellarAddress, type StellarBrowserExtensionWallet, type StellarNetwork, type StellarPkWallet, type StellarWallet, type StellarWalletConfig, StellarWalletError, StellarWalletProvider, type SuiWallet, type SuiWalletConfig, SuiWalletProvider, getEvmViemChain, isBrowserExtensionEvmWalletConfig, isBrowserExtensionIconWalletConfig, isBrowserExtensionInjectiveWalletConfig, isBrowserExtensionStellarWalletConfig, isBrowserExtensionSuiWallet, isIconAddress, isIconBrowserExtensionWallet, isIconEoaAddress, isIconPkWallet, isJsonRpcPayloadResponse, isPkSuiWallet, isPrivateKeyEvmWalletConfig, isPrivateKeyIconWalletConfig, isPrivateKeyStellarWalletConfig, isResponseAddressType, isResponseSigningType, isStellarBrowserExtensionWallet, isStellarPkWallet, isSuiWallet, isValidStellarNetwork, isValidStellarPrivateKey, requestAddress, requestJsonRpc, requestSigning };