@sip-protocol/sdk 0.3.2 → 0.5.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.
Files changed (64) hide show
  1. package/dist/browser.d.mts +2 -2
  2. package/dist/browser.d.ts +2 -2
  3. package/dist/browser.js +2881 -295
  4. package/dist/browser.mjs +62 -2
  5. package/dist/chunk-AOZIY3GU.mjs +12995 -0
  6. package/dist/chunk-BCLIX5T2.mjs +12940 -0
  7. package/dist/chunk-DMHBKRWV.mjs +14712 -0
  8. package/dist/chunk-FKXPHKYD.mjs +12955 -0
  9. package/dist/chunk-HGU6HZRC.mjs +231 -0
  10. package/dist/chunk-J4Q4NJ2U.mjs +13544 -0
  11. package/dist/chunk-OPQ2GQIO.mjs +13013 -0
  12. package/dist/chunk-W2B7T6WU.mjs +14714 -0
  13. package/dist/index-5jAdWMA-.d.ts +8973 -0
  14. package/dist/index-B9Vkpaao.d.mts +8973 -0
  15. package/dist/index-BcWNakUD.d.ts +7990 -0
  16. package/dist/index-BsKY3Hr0.d.mts +7990 -0
  17. package/dist/index.d.mts +2 -2
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.js +2852 -266
  20. package/dist/index.mjs +62 -2
  21. package/dist/proofs/noir.mjs +1 -1
  22. package/package.json +2 -1
  23. package/src/adapters/near-intents.ts +8 -0
  24. package/src/bitcoin/index.ts +51 -0
  25. package/src/bitcoin/silent-payments.ts +865 -0
  26. package/src/bitcoin/taproot.ts +590 -0
  27. package/src/compliance/compliance-manager.ts +87 -0
  28. package/src/compliance/conditional-threshold.ts +379 -0
  29. package/src/compliance/conditional.ts +382 -0
  30. package/src/compliance/derivation.ts +489 -0
  31. package/src/compliance/index.ts +50 -8
  32. package/src/compliance/pdf.ts +365 -0
  33. package/src/compliance/reports.ts +644 -0
  34. package/src/compliance/threshold.ts +529 -0
  35. package/src/compliance/types.ts +223 -0
  36. package/src/cosmos/ibc-stealth.ts +825 -0
  37. package/src/cosmos/index.ts +83 -0
  38. package/src/cosmos/stealth.ts +487 -0
  39. package/src/errors.ts +8 -0
  40. package/src/index.ts +80 -1
  41. package/src/move/aptos.ts +369 -0
  42. package/src/move/index.ts +35 -0
  43. package/src/move/sui.ts +367 -0
  44. package/src/oracle/types.ts +8 -0
  45. package/src/settlement/backends/direct-chain.ts +8 -0
  46. package/src/stealth.ts +3 -3
  47. package/src/validation.ts +42 -1
  48. package/src/wallet/aptos/adapter.ts +422 -0
  49. package/src/wallet/aptos/index.ts +10 -0
  50. package/src/wallet/aptos/mock.ts +410 -0
  51. package/src/wallet/aptos/types.ts +278 -0
  52. package/src/wallet/bitcoin/adapter.ts +470 -0
  53. package/src/wallet/bitcoin/index.ts +38 -0
  54. package/src/wallet/bitcoin/mock.ts +516 -0
  55. package/src/wallet/bitcoin/types.ts +274 -0
  56. package/src/wallet/cosmos/adapter.ts +484 -0
  57. package/src/wallet/cosmos/index.ts +63 -0
  58. package/src/wallet/cosmos/mock.ts +596 -0
  59. package/src/wallet/cosmos/types.ts +462 -0
  60. package/src/wallet/index.ts +127 -0
  61. package/src/wallet/sui/adapter.ts +471 -0
  62. package/src/wallet/sui/index.ts +10 -0
  63. package/src/wallet/sui/mock.ts +439 -0
  64. package/src/wallet/sui/types.ts +245 -0
@@ -0,0 +1,439 @@
1
+ /**
2
+ * Mock Sui Wallet Adapter
3
+ *
4
+ * Testing implementation of Sui wallet adapter.
5
+ * Provides full mock functionality without requiring browser environment.
6
+ */
7
+
8
+ import type {
9
+ HexString,
10
+ Asset,
11
+ Signature,
12
+ UnsignedTransaction,
13
+ SignedTransaction,
14
+ TransactionReceipt,
15
+ } from '@sip-protocol/types'
16
+ import { WalletErrorCode } from '@sip-protocol/types'
17
+ import { BaseWalletAdapter } from '../base-adapter'
18
+ import { WalletError } from '../errors'
19
+ import type {
20
+ SuiWalletProvider,
21
+ SuiAccountInfo,
22
+ SuiTransactionBlock,
23
+ SuiSignMessageInput,
24
+ SuiSignMessageResponse,
25
+ SignedSuiTransaction,
26
+ } from './types'
27
+ import { suiPublicKeyToHex, getDefaultSuiRpcEndpoint } from './types'
28
+
29
+ /**
30
+ * Configuration for mock Sui adapter
31
+ */
32
+ export interface MockSuiAdapterConfig {
33
+ /** Mock address (0x-prefixed hex) */
34
+ address?: string
35
+ /** Mock public key (0x-prefixed hex) */
36
+ publicKey?: string
37
+ /** Mock balance in MIST */
38
+ balance?: bigint
39
+ /** Token balances by coin type */
40
+ tokenBalances?: Record<string, bigint>
41
+ /** Whether to simulate connection failure */
42
+ shouldFailConnect?: boolean
43
+ /** Whether to simulate signing failure */
44
+ shouldFailSign?: boolean
45
+ /** Whether to simulate transaction failure */
46
+ shouldFailTransaction?: boolean
47
+ /** Simulated network */
48
+ network?: string
49
+ /** Simulated latency in ms */
50
+ latency?: number
51
+ }
52
+
53
+ /**
54
+ * Mock Sui wallet adapter for testing
55
+ *
56
+ * Provides full Sui wallet functionality with mock data.
57
+ * No browser environment or actual wallet required.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const wallet = new MockSuiAdapter({
62
+ * address: '0x1234...abcd',
63
+ * balance: 1_000_000_000n, // 1 SUI
64
+ * })
65
+ *
66
+ * await wallet.connect()
67
+ * const balance = await wallet.getBalance() // 1_000_000_000n
68
+ *
69
+ * // Simulate failures
70
+ * const failingWallet = new MockSuiAdapter({
71
+ * shouldFailSign: true,
72
+ * })
73
+ * ```
74
+ */
75
+ export class MockSuiAdapter extends BaseWalletAdapter {
76
+ readonly chain = 'sui' as const
77
+ readonly name = 'mock-sui'
78
+
79
+ private mockAddress: HexString
80
+ private mockPublicKey: HexString
81
+ private mockBalance: bigint
82
+ private mockTokenBalances: Map<string, bigint>
83
+ private shouldFailConnect: boolean
84
+ private shouldFailSign: boolean
85
+ private shouldFailTransaction: boolean
86
+ private network: string
87
+ private latency: number
88
+ private accounts: SuiAccountInfo[]
89
+
90
+ // Track signed transactions for verification
91
+ private signedTransactions: SuiTransactionBlock[] = []
92
+ private sentTransactions: string[] = []
93
+
94
+ constructor(config: MockSuiAdapterConfig = {}) {
95
+ super()
96
+ this.mockAddress = (config.address ?? '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef') as HexString
97
+ this.mockPublicKey = (config.publicKey ?? '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd') as HexString
98
+ this.mockBalance = config.balance ?? 1_000_000_000n // 1 SUI default
99
+ this.mockTokenBalances = new Map(Object.entries(config.tokenBalances ?? {}))
100
+ this.shouldFailConnect = config.shouldFailConnect ?? false
101
+ this.shouldFailSign = config.shouldFailSign ?? false
102
+ this.shouldFailTransaction = config.shouldFailTransaction ?? false
103
+ this.network = config.network ?? 'mainnet'
104
+ this.latency = config.latency ?? 10
105
+
106
+ this.accounts = [
107
+ {
108
+ address: this.mockAddress,
109
+ publicKey: this.mockPublicKey,
110
+ },
111
+ ]
112
+ }
113
+
114
+ /**
115
+ * Get the current Sui network
116
+ */
117
+ getNetwork(): string {
118
+ return this.network
119
+ }
120
+
121
+ /**
122
+ * Get RPC endpoint
123
+ */
124
+ getRpcEndpoint(): string {
125
+ return getDefaultSuiRpcEndpoint(this.network)
126
+ }
127
+
128
+ /**
129
+ * Get all connected accounts
130
+ */
131
+ getAccounts(): SuiAccountInfo[] {
132
+ return [...this.accounts]
133
+ }
134
+
135
+ /**
136
+ * Connect to the mock wallet
137
+ */
138
+ async connect(): Promise<void> {
139
+ this._connectionState = 'connecting'
140
+
141
+ // Simulate network latency
142
+ await this.simulateLatency()
143
+
144
+ if (this.shouldFailConnect) {
145
+ this.setError(WalletErrorCode.CONNECTION_FAILED, 'Mock connection failure')
146
+ throw new WalletError('Mock connection failure', WalletErrorCode.CONNECTION_FAILED)
147
+ }
148
+
149
+ this.setConnected(this.mockAddress, this.mockPublicKey)
150
+ }
151
+
152
+ /**
153
+ * Disconnect from the mock wallet
154
+ */
155
+ async disconnect(): Promise<void> {
156
+ await this.simulateLatency()
157
+ this.setDisconnected('User disconnected')
158
+ }
159
+
160
+ /**
161
+ * Sign a message
162
+ */
163
+ async signMessage(message: Uint8Array): Promise<Signature> {
164
+ this.requireConnected()
165
+ await this.simulateLatency()
166
+
167
+ if (this.shouldFailSign) {
168
+ throw new WalletError('Mock signing failure', WalletErrorCode.SIGNING_REJECTED)
169
+ }
170
+
171
+ // Create deterministic mock signature (64 bytes)
172
+ const mockSig = new Uint8Array(64)
173
+ for (let i = 0; i < 64; i++) {
174
+ mockSig[i] = (message[i % message.length] ?? 0) ^ (i * 7) ^ this.mockAddress.charCodeAt(i % this.mockAddress.length)
175
+ }
176
+
177
+ return {
178
+ signature: ('0x' + Buffer.from(mockSig).toString('hex')) as HexString,
179
+ publicKey: this._publicKey as HexString,
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Sign a transaction
185
+ */
186
+ async signTransaction(tx: UnsignedTransaction): Promise<SignedTransaction> {
187
+ this.requireConnected()
188
+ await this.simulateLatency()
189
+
190
+ if (this.shouldFailSign) {
191
+ throw new WalletError('Mock signing failure', WalletErrorCode.SIGNING_REJECTED)
192
+ }
193
+
194
+ const suiTx = tx.data as SuiTransactionBlock
195
+ this.signedTransactions.push(suiTx)
196
+
197
+ // Create mock signed bytes
198
+ const txDataStr = JSON.stringify(tx.data)
199
+ const signature = await this.signMessage(new TextEncoder().encode(txDataStr))
200
+
201
+ return {
202
+ unsigned: tx,
203
+ signatures: [signature],
204
+ serialized: signature.signature,
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Sign and send a transaction
210
+ */
211
+ async signAndSendTransaction(tx: UnsignedTransaction): Promise<TransactionReceipt> {
212
+ this.requireConnected()
213
+ await this.simulateLatency()
214
+
215
+ if (this.shouldFailSign) {
216
+ throw new WalletError('Mock signing failure', WalletErrorCode.SIGNING_REJECTED)
217
+ }
218
+
219
+ if (this.shouldFailTransaction) {
220
+ throw new WalletError('Mock transaction failure', WalletErrorCode.TRANSACTION_FAILED)
221
+ }
222
+
223
+ // Generate mock transaction hash (digest)
224
+ const txHash = `0x${Date.now().toString(16)}${Math.random().toString(16).slice(2)}`
225
+ this.sentTransactions.push(txHash)
226
+
227
+ return {
228
+ txHash: txHash as HexString,
229
+ status: 'confirmed',
230
+ blockNumber: BigInt(Math.floor(Math.random() * 1000000)),
231
+ timestamp: Date.now(),
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Get native SUI balance
237
+ */
238
+ async getBalance(): Promise<bigint> {
239
+ this.requireConnected()
240
+ await this.simulateLatency()
241
+ return this.mockBalance
242
+ }
243
+
244
+ /**
245
+ * Get token balance
246
+ */
247
+ async getTokenBalance(asset: Asset): Promise<bigint> {
248
+ this.requireConnected()
249
+ await this.simulateLatency()
250
+
251
+ if (asset.chain !== 'sui') {
252
+ throw new WalletError(
253
+ `Asset chain ${asset.chain} not supported by Sui adapter`,
254
+ WalletErrorCode.UNSUPPORTED_CHAIN
255
+ )
256
+ }
257
+
258
+ // Native SUI
259
+ if (!asset.address || asset.address === '0x2::sui::SUI') {
260
+ return this.mockBalance
261
+ }
262
+
263
+ const coinType = asset.address
264
+ return this.mockTokenBalances.get(coinType) ?? 0n
265
+ }
266
+
267
+ // ── Mock Control Methods ──────────────────────────────────────────────────
268
+
269
+ /**
270
+ * Set mock balance
271
+ */
272
+ setMockBalance(balance: bigint): void {
273
+ this.mockBalance = balance
274
+ }
275
+
276
+ /**
277
+ * Set mock token balance
278
+ */
279
+ setMockTokenBalance(coinType: string, balance: bigint): void {
280
+ this.mockTokenBalances.set(coinType, balance)
281
+ }
282
+
283
+ /**
284
+ * Get all signed transactions (for verification)
285
+ */
286
+ getSignedTransactions(): SuiTransactionBlock[] {
287
+ return [...this.signedTransactions]
288
+ }
289
+
290
+ /**
291
+ * Get all sent transaction hashes (for verification)
292
+ */
293
+ getSentTransactions(): string[] {
294
+ return [...this.sentTransactions]
295
+ }
296
+
297
+ /**
298
+ * Clear transaction history
299
+ */
300
+ clearTransactionHistory(): void {
301
+ this.signedTransactions = []
302
+ this.sentTransactions = []
303
+ }
304
+
305
+ /**
306
+ * Simulate an account change event
307
+ */
308
+ simulateAccountChange(newAddress: HexString, newPublicKey?: HexString): void {
309
+ const previousAddress = this._address
310
+ this.mockAddress = newAddress
311
+ this._address = newAddress as string
312
+
313
+ if (newPublicKey) {
314
+ this.mockPublicKey = newPublicKey
315
+ this._publicKey = newPublicKey
316
+ }
317
+
318
+ this.accounts = [
319
+ {
320
+ address: newAddress,
321
+ publicKey: this.mockPublicKey,
322
+ },
323
+ ]
324
+
325
+ this.emitAccountChanged(previousAddress, newAddress)
326
+ }
327
+
328
+ /**
329
+ * Simulate a disconnect event
330
+ */
331
+ simulateDisconnect(): void {
332
+ this.setDisconnected('Simulated disconnect')
333
+ }
334
+
335
+ private async simulateLatency(): Promise<void> {
336
+ if (this.latency > 0) {
337
+ await new Promise((resolve) => setTimeout(resolve, this.latency))
338
+ }
339
+ }
340
+ }
341
+
342
+ /**
343
+ * Create a mock Sui wallet provider for testing real adapter
344
+ */
345
+ export function createMockSuiProvider(
346
+ config: MockSuiAdapterConfig = {}
347
+ ): SuiWalletProvider {
348
+ const address = config.address ?? '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
349
+ const publicKey = config.publicKey ?? '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd'
350
+
351
+ const account: SuiAccountInfo = {
352
+ address,
353
+ publicKey,
354
+ }
355
+
356
+ return {
357
+ async hasPermissions(): Promise<boolean> {
358
+ return !config.shouldFailConnect
359
+ },
360
+
361
+ async requestPermissions(): Promise<boolean> {
362
+ if (config.shouldFailConnect) {
363
+ throw new Error('User rejected the request')
364
+ }
365
+ return true
366
+ },
367
+
368
+ async getAccounts(): Promise<SuiAccountInfo[]> {
369
+ if (config.shouldFailConnect) {
370
+ throw new Error('User rejected the request')
371
+ }
372
+ return [account]
373
+ },
374
+
375
+ async signTransactionBlock(input: {
376
+ transactionBlock: SuiTransactionBlock | any
377
+ account?: SuiAccountInfo
378
+ chain?: string
379
+ }): Promise<SignedSuiTransaction> {
380
+ if (config.shouldFailSign) {
381
+ throw new Error('User rejected the request')
382
+ }
383
+
384
+ // Return mock signed transaction
385
+ const mockSig = new Uint8Array(64)
386
+ for (let i = 0; i < 64; i++) {
387
+ mockSig[i] = i
388
+ }
389
+
390
+ return {
391
+ signature: Buffer.from(mockSig).toString('base64'),
392
+ transactionBlockBytes: Buffer.from(new Uint8Array(128).fill(1)).toString('base64'),
393
+ }
394
+ },
395
+
396
+ async signAndExecuteTransactionBlock(input: {
397
+ transactionBlock: SuiTransactionBlock | any
398
+ account?: SuiAccountInfo
399
+ chain?: string
400
+ options?: any
401
+ }): Promise<{ digest: string }> {
402
+ if (config.shouldFailSign) {
403
+ throw new Error('User rejected the request')
404
+ }
405
+
406
+ if (config.shouldFailTransaction) {
407
+ throw new Error('Transaction failed')
408
+ }
409
+
410
+ const digest = `${Date.now().toString(16)}${Math.random().toString(16).slice(2)}`
411
+ return { digest }
412
+ },
413
+
414
+ async signMessage(input: SuiSignMessageInput): Promise<SuiSignMessageResponse> {
415
+ if (config.shouldFailSign) {
416
+ throw new Error('User rejected the request')
417
+ }
418
+
419
+ const mockSig = new Uint8Array(64)
420
+ for (let i = 0; i < 64; i++) {
421
+ mockSig[i] = (input.message[i % input.message.length] ?? 0) ^ i
422
+ }
423
+
424
+ return {
425
+ signature: Buffer.from(mockSig).toString('base64'),
426
+ messageBytes: Buffer.from(input.message).toString('base64'),
427
+ }
428
+ },
429
+ }
430
+ }
431
+
432
+ /**
433
+ * Create a mock Sui adapter
434
+ */
435
+ export function createMockSuiAdapter(
436
+ config: MockSuiAdapterConfig = {}
437
+ ): MockSuiAdapter {
438
+ return new MockSuiAdapter(config)
439
+ }
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Sui Wallet Types
3
+ *
4
+ * Type definitions for Sui wallet adapters.
5
+ * Supports Sui Wallet, Ethos, Suiet, and other Sui wallets.
6
+ */
7
+
8
+ import type { HexString } from '@sip-protocol/types'
9
+
10
+ /**
11
+ * Supported Sui wallet names
12
+ */
13
+ export type SuiWalletName = 'sui-wallet' | 'ethos' | 'suiet' | 'generic'
14
+
15
+ /**
16
+ * Sui account information
17
+ */
18
+ export interface SuiAccountInfo {
19
+ /** Account address (0x-prefixed hex, 64 characters) */
20
+ address: string
21
+ /** Public key (0x-prefixed hex) */
22
+ publicKey: string
23
+ }
24
+
25
+ /**
26
+ * Sui transaction block
27
+ */
28
+ export interface SuiTransactionBlock {
29
+ /** Transaction kind */
30
+ kind: 'moveCall' | 'transferObjects' | 'splitCoins' | 'mergeCoins' | 'publish'
31
+ /** Transaction data */
32
+ data: any
33
+ /** Sender address */
34
+ sender?: string
35
+ /** Gas budget */
36
+ gasBudget?: string
37
+ /** Gas price */
38
+ gasPrice?: string
39
+ }
40
+
41
+ /**
42
+ * Signed Sui transaction
43
+ */
44
+ export interface SignedSuiTransaction {
45
+ /** Transaction signature */
46
+ signature: string
47
+ /** Signed transaction bytes */
48
+ transactionBlockBytes: string
49
+ }
50
+
51
+ /**
52
+ * Sui sign message input
53
+ */
54
+ export interface SuiSignMessageInput {
55
+ /** Message bytes to sign */
56
+ message: Uint8Array
57
+ /** Account to sign with */
58
+ account?: SuiAccountInfo
59
+ }
60
+
61
+ /**
62
+ * Sui sign message response
63
+ */
64
+ export interface SuiSignMessageResponse {
65
+ /** Signature (base64 or hex) */
66
+ signature: string
67
+ /** Message bytes (base64) */
68
+ messageBytes: string
69
+ }
70
+
71
+ /**
72
+ * Sui Wallet API interface
73
+ *
74
+ * @see https://docs.sui.io/standards/wallet-standard
75
+ */
76
+ export interface SuiWalletAPI {
77
+ /**
78
+ * Check if wallet has permissions
79
+ */
80
+ hasPermissions(permissions?: string[]): Promise<boolean>
81
+
82
+ /**
83
+ * Request wallet permissions
84
+ */
85
+ requestPermissions(permissions?: string[]): Promise<boolean>
86
+
87
+ /**
88
+ * Get connected accounts
89
+ */
90
+ getAccounts(): Promise<SuiAccountInfo[]>
91
+
92
+ /**
93
+ * Sign a transaction block
94
+ */
95
+ signTransactionBlock(input: {
96
+ transactionBlock: SuiTransactionBlock | any
97
+ account?: SuiAccountInfo
98
+ chain?: string
99
+ }): Promise<SignedSuiTransaction>
100
+
101
+ /**
102
+ * Sign and execute a transaction block
103
+ */
104
+ signAndExecuteTransactionBlock(input: {
105
+ transactionBlock: SuiTransactionBlock | any
106
+ account?: SuiAccountInfo
107
+ chain?: string
108
+ options?: {
109
+ showEffects?: boolean
110
+ showEvents?: boolean
111
+ showObjectChanges?: boolean
112
+ showBalanceChanges?: boolean
113
+ }
114
+ }): Promise<{
115
+ digest: string
116
+ effects?: any
117
+ events?: any[]
118
+ objectChanges?: any[]
119
+ balanceChanges?: any[]
120
+ }>
121
+
122
+ /**
123
+ * Sign a message
124
+ */
125
+ signMessage(input: SuiSignMessageInput): Promise<SuiSignMessageResponse>
126
+
127
+ /**
128
+ * Event listeners
129
+ */
130
+ on?: (event: string, handler: (...args: any[]) => void) => void
131
+ off?: (event: string, handler: (...args: any[]) => void) => void
132
+ }
133
+
134
+ /**
135
+ * Ethos wallet API interface
136
+ */
137
+ export interface EthosAPI extends SuiWalletAPI {
138
+ // Ethos-specific methods can be added here
139
+ }
140
+
141
+ /**
142
+ * Generic Sui wallet provider interface
143
+ */
144
+ export interface SuiWalletProvider {
145
+ hasPermissions(permissions?: string[]): Promise<boolean>
146
+ requestPermissions(permissions?: string[]): Promise<boolean>
147
+ getAccounts(): Promise<SuiAccountInfo[]>
148
+ signTransactionBlock(input: {
149
+ transactionBlock: SuiTransactionBlock | any
150
+ account?: SuiAccountInfo
151
+ chain?: string
152
+ }): Promise<SignedSuiTransaction>
153
+ signAndExecuteTransactionBlock(input: {
154
+ transactionBlock: SuiTransactionBlock | any
155
+ account?: SuiAccountInfo
156
+ chain?: string
157
+ options?: any
158
+ }): Promise<{ digest: string; [key: string]: any }>
159
+ signMessage(input: SuiSignMessageInput): Promise<SuiSignMessageResponse>
160
+
161
+ // Event handling
162
+ on?: (event: string, handler: (...args: any[]) => void) => void
163
+ off?: (event: string, handler: (...args: any[]) => void) => void
164
+ }
165
+
166
+ /**
167
+ * Window interface for Sui wallets
168
+ */
169
+ declare global {
170
+ interface Window {
171
+ suiWallet?: SuiWalletAPI
172
+ ethos?: EthosAPI
173
+ suiet?: SuiWalletProvider
174
+ sui?: SuiWalletProvider
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Sui wallet adapter configuration
180
+ */
181
+ export interface SuiAdapterConfig {
182
+ /** Wallet name (default: 'sui-wallet') */
183
+ wallet?: SuiWalletName
184
+ /** Custom provider (for testing) */
185
+ provider?: SuiWalletProvider
186
+ /** Network name (default: 'mainnet') */
187
+ network?: string
188
+ /** RPC endpoint (optional) */
189
+ rpcEndpoint?: string
190
+ }
191
+
192
+ /**
193
+ * Get Sui wallet provider from window
194
+ */
195
+ export function getSuiProvider(walletName: SuiWalletName): SuiWalletProvider | undefined {
196
+ if (typeof window === 'undefined') return undefined
197
+
198
+ switch (walletName) {
199
+ case 'sui-wallet':
200
+ return window.suiWallet as SuiWalletProvider | undefined
201
+ case 'ethos':
202
+ return window.ethos as SuiWalletProvider | undefined
203
+ case 'suiet':
204
+ return window.suiet
205
+ case 'generic':
206
+ return window.sui
207
+ default:
208
+ return undefined
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Convert Sui public key to hex format
214
+ *
215
+ * Ensures proper 0x prefix and formatting
216
+ */
217
+ export function suiPublicKeyToHex(publicKey: string | Uint8Array): HexString {
218
+ if (typeof publicKey === 'string') {
219
+ // Already a string, ensure 0x prefix
220
+ return (publicKey.startsWith('0x') ? publicKey : `0x${publicKey}`) as HexString
221
+ }
222
+
223
+ // Convert Uint8Array to hex
224
+ const hex = Array.from(publicKey)
225
+ .map(b => b.toString(16).padStart(2, '0'))
226
+ .join('')
227
+ return `0x${hex}` as HexString
228
+ }
229
+
230
+ /**
231
+ * Default RPC endpoints for Sui networks
232
+ */
233
+ export const DEFAULT_SUI_RPC_ENDPOINTS: Record<string, string> = {
234
+ mainnet: 'https://fullnode.mainnet.sui.io:443',
235
+ testnet: 'https://fullnode.testnet.sui.io:443',
236
+ devnet: 'https://fullnode.devnet.sui.io:443',
237
+ localnet: 'http://localhost:9000',
238
+ }
239
+
240
+ /**
241
+ * Get default RPC endpoint for network
242
+ */
243
+ export function getDefaultSuiRpcEndpoint(network: string): string {
244
+ return DEFAULT_SUI_RPC_ENDPOINTS[network.toLowerCase()] ?? DEFAULT_SUI_RPC_ENDPOINTS.mainnet
245
+ }