@sip-protocol/sdk 0.1.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.
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Solana Wallet Types
3
+ *
4
+ * Type definitions for Solana wallet integration.
5
+ * These types match the interface of injected Solana wallet providers
6
+ * like Phantom, Solflare, and Backpack.
7
+ */
8
+
9
+ import type { HexString } from '@sip-protocol/types'
10
+
11
+ /**
12
+ * Solana public key interface
13
+ * Matches @solana/web3.js PublicKey
14
+ */
15
+ export interface SolanaPublicKey {
16
+ toBase58(): string
17
+ toBytes(): Uint8Array
18
+ toString(): string
19
+ }
20
+
21
+ /**
22
+ * Solana transaction interface
23
+ * Matches @solana/web3.js Transaction
24
+ */
25
+ export interface SolanaTransaction {
26
+ /** Transaction signature after signing */
27
+ signature?: Uint8Array
28
+ /** Serialized transaction */
29
+ serialize(): Uint8Array
30
+ /** Add signature to transaction */
31
+ addSignature(pubkey: SolanaPublicKey, signature: Uint8Array): void
32
+ }
33
+
34
+ /**
35
+ * Solana versioned transaction (v0)
36
+ * Matches @solana/web3.js VersionedTransaction
37
+ */
38
+ export interface SolanaVersionedTransaction {
39
+ serialize(): Uint8Array
40
+ signatures: Uint8Array[]
41
+ }
42
+
43
+ /**
44
+ * Solana send options
45
+ */
46
+ export interface SolanaSendOptions {
47
+ /** Skip preflight transaction checks */
48
+ skipPreflight?: boolean
49
+ /** Preflight commitment level */
50
+ preflightCommitment?: 'processed' | 'confirmed' | 'finalized'
51
+ /** Maximum retries */
52
+ maxRetries?: number
53
+ }
54
+
55
+ /**
56
+ * Solana connection interface for RPC calls
57
+ */
58
+ export interface SolanaConnection {
59
+ /** Get account balance in lamports */
60
+ getBalance(publicKey: SolanaPublicKey): Promise<number>
61
+ /** Get token account balance */
62
+ getTokenAccountBalance(publicKey: SolanaPublicKey): Promise<{
63
+ value: { amount: string; decimals: number }
64
+ }>
65
+ /** Get latest blockhash */
66
+ getLatestBlockhash(): Promise<{
67
+ blockhash: string
68
+ lastValidBlockHeight: number
69
+ }>
70
+ /** Send raw transaction */
71
+ sendRawTransaction(
72
+ rawTransaction: Uint8Array,
73
+ options?: SolanaSendOptions
74
+ ): Promise<string>
75
+ /** Confirm transaction */
76
+ confirmTransaction(
77
+ signature: string,
78
+ commitment?: 'processed' | 'confirmed' | 'finalized'
79
+ ): Promise<{ value: { err: unknown } }>
80
+ }
81
+
82
+ /**
83
+ * Injected Solana wallet provider interface
84
+ * This is what Phantom/Solflare/etc inject into window
85
+ */
86
+ export interface SolanaWalletProvider {
87
+ /** Provider is Phantom */
88
+ isPhantom?: boolean
89
+ /** Provider is Solflare */
90
+ isSolflare?: boolean
91
+ /** Provider is Backpack */
92
+ isBackpack?: boolean
93
+ /** Public key when connected */
94
+ publicKey: SolanaPublicKey | null
95
+ /** Whether wallet is connected */
96
+ isConnected: boolean
97
+ /** Connect to wallet */
98
+ connect(options?: { onlyIfTrusted?: boolean }): Promise<{ publicKey: SolanaPublicKey }>
99
+ /** Disconnect from wallet */
100
+ disconnect(): Promise<void>
101
+ /** Sign a message */
102
+ signMessage(message: Uint8Array, encoding?: 'utf8'): Promise<{ signature: Uint8Array }>
103
+ /** Sign a transaction */
104
+ signTransaction<T extends SolanaTransaction | SolanaVersionedTransaction>(
105
+ transaction: T
106
+ ): Promise<T>
107
+ /** Sign multiple transactions */
108
+ signAllTransactions<T extends SolanaTransaction | SolanaVersionedTransaction>(
109
+ transactions: T[]
110
+ ): Promise<T[]>
111
+ /** Sign and send transaction */
112
+ signAndSendTransaction<T extends SolanaTransaction | SolanaVersionedTransaction>(
113
+ transaction: T,
114
+ options?: SolanaSendOptions
115
+ ): Promise<{ signature: string }>
116
+ /** Event handling */
117
+ on(event: 'connect' | 'disconnect' | 'accountChanged', handler: (...args: unknown[]) => void): void
118
+ off(event: 'connect' | 'disconnect' | 'accountChanged', handler: (...args: unknown[]) => void): void
119
+ }
120
+
121
+ /**
122
+ * Solana wallet name/type
123
+ */
124
+ export type SolanaWalletName = 'phantom' | 'solflare' | 'backpack' | 'generic'
125
+
126
+ /**
127
+ * Solana network/cluster
128
+ */
129
+ export type SolanaCluster = 'mainnet-beta' | 'testnet' | 'devnet' | 'localnet'
130
+
131
+ /**
132
+ * Solana adapter configuration
133
+ */
134
+ export interface SolanaAdapterConfig {
135
+ /** Wallet to connect to */
136
+ wallet?: SolanaWalletName
137
+ /** Solana cluster/network */
138
+ cluster?: SolanaCluster
139
+ /** RPC endpoint URL */
140
+ rpcEndpoint?: string
141
+ /** Custom wallet provider (for testing) */
142
+ provider?: SolanaWalletProvider
143
+ /** Custom connection (for testing) */
144
+ connection?: SolanaConnection
145
+ }
146
+
147
+ /**
148
+ * Solana-specific unsigned transaction
149
+ */
150
+ export interface SolanaUnsignedTransaction {
151
+ /** The Solana transaction object */
152
+ transaction: SolanaTransaction | SolanaVersionedTransaction
153
+ /** Whether this is a versioned transaction */
154
+ isVersioned?: boolean
155
+ /** Send options */
156
+ sendOptions?: SolanaSendOptions
157
+ }
158
+
159
+ /**
160
+ * Extended signature with Solana-specific data
161
+ */
162
+ export interface SolanaSignature {
163
+ /** Raw signature bytes */
164
+ signature: HexString
165
+ /** Solana public key (base58) */
166
+ publicKey: HexString
167
+ /** Base58 encoded signature (Solana standard) */
168
+ base58Signature?: string
169
+ }
170
+
171
+ /**
172
+ * Get the injected Solana wallet provider
173
+ */
174
+ export function getSolanaProvider(wallet: SolanaWalletName = 'phantom'): SolanaWalletProvider | undefined {
175
+ if (typeof window === 'undefined') return undefined
176
+
177
+ const win = window as unknown as {
178
+ phantom?: { solana?: SolanaWalletProvider }
179
+ solflare?: SolanaWalletProvider
180
+ backpack?: { solana?: SolanaWalletProvider }
181
+ solana?: SolanaWalletProvider
182
+ }
183
+
184
+ switch (wallet) {
185
+ case 'phantom':
186
+ return win.phantom?.solana
187
+ case 'solflare':
188
+ return win.solflare
189
+ case 'backpack':
190
+ return win.backpack?.solana
191
+ case 'generic':
192
+ default:
193
+ // Try to find any available provider
194
+ return win.phantom?.solana ?? win.solflare ?? win.backpack?.solana ?? win.solana
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Detect which Solana wallets are installed
200
+ */
201
+ export function detectSolanaWallets(): SolanaWalletName[] {
202
+ if (typeof window === 'undefined') return []
203
+
204
+ const detected: SolanaWalletName[] = []
205
+ const win = window as unknown as {
206
+ phantom?: { solana?: SolanaWalletProvider }
207
+ solflare?: SolanaWalletProvider
208
+ backpack?: { solana?: SolanaWalletProvider }
209
+ }
210
+
211
+ if (win.phantom?.solana) detected.push('phantom')
212
+ if (win.solflare) detected.push('solflare')
213
+ if (win.backpack?.solana) detected.push('backpack')
214
+
215
+ return detected
216
+ }
217
+
218
+ /**
219
+ * Convert Solana public key to hex string
220
+ */
221
+ export function solanaPublicKeyToHex(pubkey: SolanaPublicKey): HexString {
222
+ const bytes = pubkey.toBytes()
223
+ return ('0x' + Buffer.from(bytes).toString('hex')) as HexString
224
+ }
225
+
226
+ /**
227
+ * Convert base58 string to hex
228
+ */
229
+ export function base58ToHex(base58: string): HexString {
230
+ // Simple base58 alphabet
231
+ const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
232
+ const ALPHABET_MAP: Record<string, number> = {}
233
+ for (let i = 0; i < ALPHABET.length; i++) {
234
+ ALPHABET_MAP[ALPHABET[i]] = i
235
+ }
236
+
237
+ let result = 0n
238
+ for (const char of base58) {
239
+ const value = ALPHABET_MAP[char]
240
+ if (value === undefined) throw new Error(`Invalid base58 character: ${char}`)
241
+ result = result * 58n + BigInt(value)
242
+ }
243
+
244
+ let hex = result.toString(16)
245
+ // Pad to even length
246
+ if (hex.length % 2 !== 0) hex = '0' + hex
247
+ // Handle leading zeros
248
+ for (let i = 0; i < base58.length && base58[i] === '1'; i++) {
249
+ hex = '00' + hex
250
+ }
251
+
252
+ return ('0x' + hex) as HexString
253
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Zcash Module
3
+ *
4
+ * Provides Zcash RPC client and shielded transaction support.
5
+ */
6
+
7
+ // RPC Client
8
+ export { ZcashRPCClient, ZcashRPCError, createZcashClient } from './rpc-client'
9
+
10
+ // Shielded Service
11
+ export {
12
+ ZcashShieldedService,
13
+ createZcashShieldedService,
14
+ } from './shielded-service'
15
+
16
+ export type {
17
+ ZcashShieldedServiceConfig,
18
+ ShieldedSendParams,
19
+ ShieldedSendResult,
20
+ ReceivedNote,
21
+ ShieldedBalance,
22
+ ExportedViewingKey,
23
+ } from './shielded-service'
24
+
25
+ // Re-export types from types package
26
+ export type {
27
+ ZcashConfig,
28
+ ZcashNetwork,
29
+ ZcashAddressType,
30
+ ZcashReceiverType,
31
+ ZcashAddressInfo,
32
+ ZcashNewAccount,
33
+ ZcashAccountAddress,
34
+ ZcashPoolBalance,
35
+ ZcashAccountBalance,
36
+ ZcashPool,
37
+ ZcashUnspentNote,
38
+ ZcashSendRecipient,
39
+ ZcashPrivacyPolicy,
40
+ ZcashShieldedSendParams,
41
+ ZcashOperationStatus,
42
+ ZcashOperationTxResult,
43
+ ZcashOperationError,
44
+ ZcashOperation,
45
+ ZcashBlockHeader,
46
+ ZcashBlock,
47
+ ZcashRPCRequest,
48
+ ZcashRPCResponse,
49
+ ZcashBlockchainInfo,
50
+ ZcashNetworkInfo,
51
+ } from '@sip-protocol/types'
52
+
53
+ export { ZcashErrorCode } from '@sip-protocol/types'