@sip-protocol/sdk 0.3.1 → 0.4.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.
- package/dist/browser.d.mts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +1028 -146
- package/dist/browser.mjs +49 -1
- package/dist/chunk-AOZIY3GU.mjs +12995 -0
- package/dist/chunk-BCLIX5T2.mjs +12940 -0
- package/dist/chunk-EU4UEWWG.mjs +12164 -0
- package/dist/chunk-FKXPHKYD.mjs +12955 -0
- package/dist/chunk-OPQ2GQIO.mjs +13013 -0
- package/dist/index-BcWNakUD.d.ts +7990 -0
- package/dist/index-BsKY3Hr0.d.mts +7990 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +999 -117
- package/dist/index.mjs +49 -1
- package/package.json +2 -1
- package/src/adapters/near-intents.ts +8 -0
- package/src/bitcoin/index.ts +51 -0
- package/src/bitcoin/silent-payments.ts +865 -0
- package/src/bitcoin/taproot.ts +590 -0
- package/src/cosmos/ibc-stealth.ts +825 -0
- package/src/cosmos/index.ts +83 -0
- package/src/cosmos/stealth.ts +487 -0
- package/src/index.ts +51 -0
- package/src/move/aptos.ts +369 -0
- package/src/move/index.ts +35 -0
- package/src/move/sui.ts +367 -0
- package/src/oracle/types.ts +8 -0
- package/src/settlement/backends/direct-chain.ts +8 -0
- package/src/settlement/backends/near-intents.ts +11 -0
- package/src/stealth.ts +3 -3
- package/src/validation.ts +42 -1
- package/src/wallet/aptos/adapter.ts +422 -0
- package/src/wallet/aptos/index.ts +10 -0
- package/src/wallet/aptos/mock.ts +410 -0
- package/src/wallet/aptos/types.ts +278 -0
- package/src/wallet/bitcoin/adapter.ts +470 -0
- package/src/wallet/bitcoin/index.ts +38 -0
- package/src/wallet/bitcoin/mock.ts +516 -0
- package/src/wallet/bitcoin/types.ts +274 -0
- package/src/wallet/cosmos/adapter.ts +484 -0
- package/src/wallet/cosmos/index.ts +63 -0
- package/src/wallet/cosmos/mock.ts +596 -0
- package/src/wallet/cosmos/types.ts +462 -0
- package/src/wallet/index.ts +127 -0
- package/src/wallet/sui/adapter.ts +471 -0
- package/src/wallet/sui/index.ts +10 -0
- package/src/wallet/sui/mock.ts +439 -0
- package/src/wallet/sui/types.ts +245 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bitcoin Wallet Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for Bitcoin wallet adapters.
|
|
5
|
+
* Supports Unisat, Xverse, Leather, and OKX wallets.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { HexString } from '@sip-protocol/types'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Bitcoin address types
|
|
12
|
+
*/
|
|
13
|
+
export type BitcoinAddressType = 'p2tr' | 'p2wpkh' | 'p2sh-p2wpkh' | 'p2pkh'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Bitcoin network types
|
|
17
|
+
*/
|
|
18
|
+
export type BitcoinNetwork = 'livenet' | 'testnet'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Bitcoin address with metadata
|
|
22
|
+
*/
|
|
23
|
+
export interface BitcoinAddress {
|
|
24
|
+
/** Address string (bc1p... for Taproot) */
|
|
25
|
+
address: string
|
|
26
|
+
/** Public key (33 bytes compressed or 32 bytes x-only for Taproot) */
|
|
27
|
+
publicKey: string
|
|
28
|
+
/** Address type */
|
|
29
|
+
type: BitcoinAddressType
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Bitcoin balance information
|
|
34
|
+
*/
|
|
35
|
+
export interface BitcoinBalance {
|
|
36
|
+
/** Confirmed balance in satoshis */
|
|
37
|
+
confirmed: bigint
|
|
38
|
+
/** Unconfirmed balance in satoshis */
|
|
39
|
+
unconfirmed: bigint
|
|
40
|
+
/** Total balance in satoshis */
|
|
41
|
+
total: bigint
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Options for PSBT signing
|
|
46
|
+
*/
|
|
47
|
+
export interface SignPsbtOptions {
|
|
48
|
+
/** Whether to automatically finalize after signing */
|
|
49
|
+
autoFinalized?: boolean
|
|
50
|
+
/** Specific inputs to sign */
|
|
51
|
+
toSignInputs?: ToSignInput[]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Input specification for PSBT signing
|
|
56
|
+
*/
|
|
57
|
+
export interface ToSignInput {
|
|
58
|
+
/** Input index to sign */
|
|
59
|
+
index: number
|
|
60
|
+
/** Address associated with this input */
|
|
61
|
+
address?: string
|
|
62
|
+
/** Public key for this input */
|
|
63
|
+
publicKey?: string
|
|
64
|
+
/** Sighash types allowed (default: [0x01]) */
|
|
65
|
+
sighashTypes?: number[]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Supported Bitcoin wallet names
|
|
70
|
+
*/
|
|
71
|
+
export type BitcoinWalletName = 'unisat' | 'xverse' | 'leather' | 'okx'
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Configuration for Bitcoin wallet adapter
|
|
75
|
+
*/
|
|
76
|
+
export interface BitcoinAdapterConfig {
|
|
77
|
+
/** Wallet to connect to */
|
|
78
|
+
wallet?: BitcoinWalletName
|
|
79
|
+
/** Bitcoin network */
|
|
80
|
+
network?: BitcoinNetwork
|
|
81
|
+
/** Injected provider (for testing) */
|
|
82
|
+
provider?: UnisatAPI
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Unisat wallet API interface
|
|
87
|
+
*
|
|
88
|
+
* Official API: https://docs.unisat.io/dev/unisat-developer-service/unisat-wallet
|
|
89
|
+
*/
|
|
90
|
+
export interface UnisatAPI {
|
|
91
|
+
/**
|
|
92
|
+
* Request account access
|
|
93
|
+
* @returns Array of addresses (Taproot addresses)
|
|
94
|
+
*/
|
|
95
|
+
requestAccounts(): Promise<string[]>
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get current accounts (if already connected)
|
|
99
|
+
* @returns Array of addresses
|
|
100
|
+
*/
|
|
101
|
+
getAccounts(): Promise<string[]>
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Get public key for current account
|
|
105
|
+
* @returns 64-char hex string (32 bytes x-only for Taproot)
|
|
106
|
+
*/
|
|
107
|
+
getPublicKey(): Promise<string>
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get balance for current account
|
|
111
|
+
* @returns Balance information in satoshis
|
|
112
|
+
*/
|
|
113
|
+
getBalance(): Promise<{
|
|
114
|
+
confirmed: number
|
|
115
|
+
unconfirmed: number
|
|
116
|
+
total: number
|
|
117
|
+
}>
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Sign a PSBT (Partially Signed Bitcoin Transaction)
|
|
121
|
+
* @param psbtHex - PSBT in hex format
|
|
122
|
+
* @param options - Signing options
|
|
123
|
+
* @returns Signed PSBT in hex format
|
|
124
|
+
*/
|
|
125
|
+
signPsbt(psbtHex: string, options?: SignPsbtOptions): Promise<string>
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Sign a message
|
|
129
|
+
* @param message - Message to sign
|
|
130
|
+
* @param type - Signature type (default: 'ecdsa')
|
|
131
|
+
* @returns Signature as base64 string
|
|
132
|
+
*/
|
|
133
|
+
signMessage(message: string, type?: 'ecdsa' | 'bip322-simple'): Promise<string>
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Push a signed transaction to the network
|
|
137
|
+
* @param rawTx - Raw transaction hex
|
|
138
|
+
* @returns Transaction ID
|
|
139
|
+
*/
|
|
140
|
+
pushTx(rawTx: string): Promise<string>
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Get current network
|
|
144
|
+
* @returns Network identifier
|
|
145
|
+
*/
|
|
146
|
+
getNetwork(): Promise<BitcoinNetwork>
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Switch network
|
|
150
|
+
* @param network - Network to switch to
|
|
151
|
+
*/
|
|
152
|
+
switchNetwork(network: BitcoinNetwork): Promise<void>
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Get chain info
|
|
156
|
+
* @returns Chain identifier ('BITCOIN_MAINNET' or 'BITCOIN_TESTNET')
|
|
157
|
+
*/
|
|
158
|
+
getChain(): Promise<{ enum: string; name: string }>
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Get inscription info for an inscriptionId
|
|
162
|
+
*/
|
|
163
|
+
getInscriptions?(offset?: number, limit?: number): Promise<{
|
|
164
|
+
total: number
|
|
165
|
+
list: Array<{
|
|
166
|
+
inscriptionId: string
|
|
167
|
+
inscriptionNumber: number
|
|
168
|
+
address: string
|
|
169
|
+
outputValue: number
|
|
170
|
+
content: string
|
|
171
|
+
contentType: string
|
|
172
|
+
}>
|
|
173
|
+
}>
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Global window interface for Unisat
|
|
178
|
+
*/
|
|
179
|
+
declare global {
|
|
180
|
+
interface Window {
|
|
181
|
+
unisat?: UnisatAPI
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get Bitcoin wallet provider from window
|
|
187
|
+
*/
|
|
188
|
+
export function getBitcoinProvider(wallet: BitcoinWalletName): UnisatAPI | undefined {
|
|
189
|
+
if (typeof window === 'undefined') {
|
|
190
|
+
return undefined
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
switch (wallet) {
|
|
194
|
+
case 'unisat':
|
|
195
|
+
return window.unisat
|
|
196
|
+
case 'okx':
|
|
197
|
+
// OKX wallet has bitcoin namespace
|
|
198
|
+
return (window as any).okxwallet?.bitcoin
|
|
199
|
+
case 'xverse':
|
|
200
|
+
case 'leather':
|
|
201
|
+
// TODO: Add Xverse and Leather support
|
|
202
|
+
return undefined
|
|
203
|
+
default:
|
|
204
|
+
return undefined
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Detect available Bitcoin wallets
|
|
210
|
+
*/
|
|
211
|
+
export function detectBitcoinWallets(): BitcoinWalletName[] {
|
|
212
|
+
const wallets: BitcoinWalletName[] = []
|
|
213
|
+
|
|
214
|
+
if (typeof window === 'undefined') {
|
|
215
|
+
return wallets
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (window.unisat) {
|
|
219
|
+
wallets.push('unisat')
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if ((window as any).okxwallet?.bitcoin) {
|
|
223
|
+
wallets.push('okx')
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// TODO: Add detection for Xverse and Leather
|
|
227
|
+
// if ((window as any).XverseProviders?.BitcoinProvider) {
|
|
228
|
+
// wallets.push('xverse')
|
|
229
|
+
// }
|
|
230
|
+
//
|
|
231
|
+
// if ((window as any).LeatherProvider) {
|
|
232
|
+
// wallets.push('leather')
|
|
233
|
+
// }
|
|
234
|
+
|
|
235
|
+
return wallets
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Convert Bitcoin address to hex format
|
|
240
|
+
* For Taproot (P2TR), this extracts the 32-byte x-only pubkey from the address
|
|
241
|
+
*/
|
|
242
|
+
export function bitcoinAddressToHex(address: string): HexString {
|
|
243
|
+
// For now, return the address as-is with 0x prefix
|
|
244
|
+
// Full implementation would decode bech32m and extract the witness program
|
|
245
|
+
return `0x${address}` as HexString
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Convert Bitcoin public key to SIP hex format
|
|
250
|
+
* Handles both compressed (33 bytes) and x-only (32 bytes) public keys
|
|
251
|
+
*/
|
|
252
|
+
export function bitcoinPublicKeyToHex(pubkey: string): HexString {
|
|
253
|
+
// Remove 0x prefix if present
|
|
254
|
+
const cleanPubkey = pubkey.startsWith('0x') ? pubkey.slice(2) : pubkey
|
|
255
|
+
|
|
256
|
+
// Validate length
|
|
257
|
+
if (cleanPubkey.length !== 64 && cleanPubkey.length !== 66) {
|
|
258
|
+
throw new Error(`Invalid Bitcoin public key length: ${cleanPubkey.length} (expected 64 or 66 hex chars)`)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return `0x${cleanPubkey}` as HexString
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Validate Taproot address format
|
|
266
|
+
*/
|
|
267
|
+
export function isValidTaprootAddress(address: string, network: BitcoinNetwork = 'livenet'): boolean {
|
|
268
|
+
// Basic validation - full implementation would use bech32m decoder
|
|
269
|
+
if (network === 'livenet') {
|
|
270
|
+
return address.startsWith('bc1p') && address.length >= 62
|
|
271
|
+
} else {
|
|
272
|
+
return address.startsWith('tb1p') && address.length >= 62
|
|
273
|
+
}
|
|
274
|
+
}
|