@sip-protocol/sdk 0.3.2 → 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 +1019 -146
- package/dist/browser.mjs +49 -1
- package/dist/chunk-AOZIY3GU.mjs +12995 -0
- package/dist/chunk-BCLIX5T2.mjs +12940 -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 +990 -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/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,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aptos stealth address implementation
|
|
3
|
+
*
|
|
4
|
+
* Aptos uses ed25519 for signatures, similar to Solana and NEAR.
|
|
5
|
+
* This module provides stealth address generation and address format conversion for Aptos.
|
|
6
|
+
*
|
|
7
|
+
* Key differences from Solana/NEAR:
|
|
8
|
+
* - Aptos addresses are derived via SHA3-256(pubkey || 0x00)
|
|
9
|
+
* - 32-byte addresses encoded as hex with 0x prefix
|
|
10
|
+
* - Single-signature scheme indicator: 0x00 suffix
|
|
11
|
+
*
|
|
12
|
+
* @see https://aptos.dev/concepts/accounts/
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { ed25519 } from '@noble/curves/ed25519'
|
|
16
|
+
import { sha3_256 } from '@noble/hashes/sha3'
|
|
17
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils'
|
|
18
|
+
import type { HexString, StealthMetaAddress, StealthAddress } from '@sip-protocol/types'
|
|
19
|
+
import { ValidationError } from '../errors'
|
|
20
|
+
import { isValidHex, isValidEd25519PublicKey } from '../validation'
|
|
21
|
+
import {
|
|
22
|
+
generateEd25519StealthAddress,
|
|
23
|
+
deriveEd25519StealthPrivateKey,
|
|
24
|
+
checkEd25519StealthAddress,
|
|
25
|
+
} from '../stealth'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Result of Aptos stealth address generation
|
|
29
|
+
*/
|
|
30
|
+
export interface AptosStealthResult {
|
|
31
|
+
/** Aptos address in 0x-prefixed 64-character hex format */
|
|
32
|
+
stealthAddress: string
|
|
33
|
+
/** Raw 32-byte ed25519 stealth public key (hex) */
|
|
34
|
+
stealthPublicKey: HexString
|
|
35
|
+
/** Ephemeral public key for recipient scanning (hex) */
|
|
36
|
+
ephemeralPublicKey: HexString
|
|
37
|
+
/** View tag for efficient scanning (0-255) */
|
|
38
|
+
viewTag: number
|
|
39
|
+
/** Shared secret hash (for verification) */
|
|
40
|
+
sharedSecret: HexString
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Aptos address authentication key scheme
|
|
45
|
+
* 0x00 = Single Ed25519 signature
|
|
46
|
+
* 0x01 = MultiEd25519 signature
|
|
47
|
+
*/
|
|
48
|
+
const APTOS_SINGLE_ED25519_SCHEME = 0x00
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Convert an ed25519 public key to an Aptos address
|
|
52
|
+
*
|
|
53
|
+
* Aptos address derivation:
|
|
54
|
+
* 1. Take the 32-byte ed25519 public key
|
|
55
|
+
* 2. Append the scheme byte (0x00 for single signature)
|
|
56
|
+
* 3. Hash with SHA3-256: address = sha3_256(pubkey || 0x00)
|
|
57
|
+
* 4. Encode as 0x-prefixed hex string (64 characters)
|
|
58
|
+
*
|
|
59
|
+
* @param publicKey - 32-byte ed25519 public key as hex string (with 0x prefix)
|
|
60
|
+
* @returns Aptos address (0x-prefixed, 64 hex characters)
|
|
61
|
+
* @throws {ValidationError} If public key is invalid
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const aptosAddress = ed25519PublicKeyToAptosAddress('0xabc123...')
|
|
66
|
+
* // Returns: "0x1234...abcd" (64 hex chars)
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function ed25519PublicKeyToAptosAddress(publicKey: HexString): string {
|
|
70
|
+
// Validate input
|
|
71
|
+
if (!isValidHex(publicKey)) {
|
|
72
|
+
throw new ValidationError(
|
|
73
|
+
'publicKey must be a valid hex string with 0x prefix',
|
|
74
|
+
'publicKey'
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!isValidEd25519PublicKey(publicKey)) {
|
|
79
|
+
throw new ValidationError(
|
|
80
|
+
'publicKey must be 32 bytes (64 hex characters)',
|
|
81
|
+
'publicKey'
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Convert hex to bytes (remove 0x prefix)
|
|
86
|
+
const publicKeyBytes = hexToBytes(publicKey.slice(2))
|
|
87
|
+
|
|
88
|
+
// Append single-signature scheme byte
|
|
89
|
+
const authKeyInput = new Uint8Array(publicKeyBytes.length + 1)
|
|
90
|
+
authKeyInput.set(publicKeyBytes, 0)
|
|
91
|
+
authKeyInput[publicKeyBytes.length] = APTOS_SINGLE_ED25519_SCHEME
|
|
92
|
+
|
|
93
|
+
// Hash with SHA3-256 to get the address
|
|
94
|
+
const addressHash = sha3_256(authKeyInput)
|
|
95
|
+
|
|
96
|
+
// Return as 0x-prefixed hex string
|
|
97
|
+
return `0x${bytesToHex(addressHash)}`
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Validate an Aptos address format
|
|
102
|
+
*
|
|
103
|
+
* Checks that the address:
|
|
104
|
+
* - Is a valid hex string with 0x prefix
|
|
105
|
+
* - Is exactly 32 bytes (64 hex characters)
|
|
106
|
+
* - Contains only valid hex characters
|
|
107
|
+
*
|
|
108
|
+
* Note: This does NOT verify if the address exists on-chain or is derived correctly.
|
|
109
|
+
* It only validates the format.
|
|
110
|
+
*
|
|
111
|
+
* @param address - Aptos address to validate
|
|
112
|
+
* @returns true if format is valid, false otherwise
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* isValidAptosAddress('0x1234...abcd') // true (64 hex chars)
|
|
117
|
+
* isValidAptosAddress('0x123') // false (too short)
|
|
118
|
+
* isValidAptosAddress('1234abcd...') // false (no 0x prefix)
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export function isValidAptosAddress(address: string): boolean {
|
|
122
|
+
if (typeof address !== 'string' || address.length === 0) {
|
|
123
|
+
return false
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Must start with 0x
|
|
127
|
+
if (!address.startsWith('0x')) {
|
|
128
|
+
return false
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Must be exactly 64 hex characters after 0x (32 bytes)
|
|
132
|
+
const hexPart = address.slice(2)
|
|
133
|
+
if (hexPart.length !== 64) {
|
|
134
|
+
return false
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Must be valid hex
|
|
138
|
+
return /^[0-9a-fA-F]{64}$/.test(hexPart)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Convert an Aptos address back to its authentication key
|
|
143
|
+
*
|
|
144
|
+
* Note: This returns the SHA3-256 hash, not the original public key.
|
|
145
|
+
* The original public key cannot be recovered from the address alone.
|
|
146
|
+
*
|
|
147
|
+
* @param address - Aptos address (0x-prefixed hex string)
|
|
148
|
+
* @returns Authentication key as HexString
|
|
149
|
+
* @throws {ValidationError} If address format is invalid
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const authKey = aptosAddressToAuthKey('0x1234...abcd')
|
|
154
|
+
* // Returns: "0x1234...abcd" (same as input, normalized)
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function aptosAddressToAuthKey(address: string): HexString {
|
|
158
|
+
if (!isValidAptosAddress(address)) {
|
|
159
|
+
throw new ValidationError(
|
|
160
|
+
'Invalid Aptos address format (must be 0x-prefixed 64 hex characters)',
|
|
161
|
+
'address'
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Normalize to lowercase
|
|
166
|
+
return address.toLowerCase() as HexString
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Generate a stealth address for Aptos
|
|
171
|
+
*
|
|
172
|
+
* Uses the existing ed25519 stealth address generation logic and converts
|
|
173
|
+
* the resulting ed25519 public key to Aptos address format.
|
|
174
|
+
*
|
|
175
|
+
* @param recipientMetaAddress - Recipient's stealth meta-address (must be chain: 'aptos')
|
|
176
|
+
* @returns Aptos stealth address result with all necessary data
|
|
177
|
+
* @throws {ValidationError} If meta-address is invalid or not for Aptos
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const metaAddress = {
|
|
182
|
+
* spendingKey: '0x...',
|
|
183
|
+
* viewingKey: '0x...',
|
|
184
|
+
* chain: 'aptos'
|
|
185
|
+
* }
|
|
186
|
+
* const result = generateAptosStealthAddress(metaAddress)
|
|
187
|
+
* console.log(result.stealthAddress) // "0x1234...abcd"
|
|
188
|
+
* console.log(result.viewTag) // 42
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export function generateAptosStealthAddress(
|
|
192
|
+
recipientMetaAddress: StealthMetaAddress,
|
|
193
|
+
): AptosStealthResult {
|
|
194
|
+
// Validate chain
|
|
195
|
+
if (recipientMetaAddress.chain !== 'aptos') {
|
|
196
|
+
throw new ValidationError(
|
|
197
|
+
`Expected chain 'aptos', got '${recipientMetaAddress.chain}'`,
|
|
198
|
+
'recipientMetaAddress.chain'
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Generate ed25519 stealth address using existing logic
|
|
203
|
+
const { stealthAddress, sharedSecret } = generateEd25519StealthAddress(recipientMetaAddress)
|
|
204
|
+
|
|
205
|
+
// Convert the ed25519 public key to Aptos address format
|
|
206
|
+
const aptosAddress = ed25519PublicKeyToAptosAddress(stealthAddress.address)
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
stealthAddress: aptosAddress,
|
|
210
|
+
stealthPublicKey: stealthAddress.address,
|
|
211
|
+
ephemeralPublicKey: stealthAddress.ephemeralPublicKey,
|
|
212
|
+
viewTag: stealthAddress.viewTag,
|
|
213
|
+
sharedSecret,
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Derive the private key for an Aptos stealth address
|
|
219
|
+
*
|
|
220
|
+
* This allows the recipient to claim funds sent to a stealth address.
|
|
221
|
+
* Uses the standard ed25519 stealth key derivation.
|
|
222
|
+
*
|
|
223
|
+
* @param stealthAddress - The stealth address data (from announcement)
|
|
224
|
+
* @param spendingPrivateKey - Recipient's spending private key
|
|
225
|
+
* @param viewingPrivateKey - Recipient's viewing private key
|
|
226
|
+
* @returns Derived private key (raw scalar, little-endian format)
|
|
227
|
+
* @throws {ValidationError} If any input is invalid
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const recovery = deriveAptosStealthPrivateKey(
|
|
232
|
+
* stealthAddress,
|
|
233
|
+
* spendingPrivKey,
|
|
234
|
+
* viewingPrivKey
|
|
235
|
+
* )
|
|
236
|
+
* // Use recovery.privateKey to sign transactions
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export function deriveAptosStealthPrivateKey(
|
|
240
|
+
stealthAddress: StealthAddress,
|
|
241
|
+
spendingPrivateKey: HexString,
|
|
242
|
+
viewingPrivateKey: HexString,
|
|
243
|
+
): {
|
|
244
|
+
stealthAddress: HexString
|
|
245
|
+
ephemeralPublicKey: HexString
|
|
246
|
+
privateKey: HexString
|
|
247
|
+
aptosAddress: string
|
|
248
|
+
} {
|
|
249
|
+
// Use standard ed25519 derivation
|
|
250
|
+
const recovery = deriveEd25519StealthPrivateKey(
|
|
251
|
+
stealthAddress,
|
|
252
|
+
spendingPrivateKey,
|
|
253
|
+
viewingPrivateKey
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
// Convert the stealth public key to Aptos address
|
|
257
|
+
const aptosAddress = ed25519PublicKeyToAptosAddress(recovery.stealthAddress)
|
|
258
|
+
|
|
259
|
+
return {
|
|
260
|
+
...recovery,
|
|
261
|
+
aptosAddress,
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Check if a stealth address belongs to this recipient
|
|
267
|
+
*
|
|
268
|
+
* Uses view tag for efficient filtering before full computation.
|
|
269
|
+
* This is the same as the standard ed25519 check since Aptos stealth
|
|
270
|
+
* addresses use ed25519 stealth public keys.
|
|
271
|
+
*
|
|
272
|
+
* @param stealthAddress - Stealth address to check
|
|
273
|
+
* @param spendingPrivateKey - Recipient's spending private key
|
|
274
|
+
* @param viewingPrivateKey - Recipient's viewing private key
|
|
275
|
+
* @returns true if this address belongs to the recipient
|
|
276
|
+
* @throws {ValidationError} If any input is invalid
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const isMine = checkAptosStealthAddress(
|
|
281
|
+
* stealthAddress,
|
|
282
|
+
* mySpendingPrivKey,
|
|
283
|
+
* myViewingPrivKey
|
|
284
|
+
* )
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
export function checkAptosStealthAddress(
|
|
288
|
+
stealthAddress: StealthAddress,
|
|
289
|
+
spendingPrivateKey: HexString,
|
|
290
|
+
viewingPrivateKey: HexString,
|
|
291
|
+
): boolean {
|
|
292
|
+
// Use standard ed25519 check
|
|
293
|
+
return checkEd25519StealthAddress(
|
|
294
|
+
stealthAddress,
|
|
295
|
+
spendingPrivateKey,
|
|
296
|
+
viewingPrivateKey
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Aptos Stealth Service
|
|
302
|
+
*
|
|
303
|
+
* Provides a convenient class-based interface for Aptos stealth address operations.
|
|
304
|
+
* This is useful when you need to perform multiple operations or want to encapsulate
|
|
305
|
+
* the logic in a service object.
|
|
306
|
+
*/
|
|
307
|
+
export class AptosStealthService {
|
|
308
|
+
/**
|
|
309
|
+
* Generate a stealth address for an Aptos recipient
|
|
310
|
+
*
|
|
311
|
+
* @param recipientMetaAddress - Recipient's stealth meta-address
|
|
312
|
+
* @returns Complete stealth address result
|
|
313
|
+
*/
|
|
314
|
+
generateStealthAddress(recipientMetaAddress: StealthMetaAddress): AptosStealthResult {
|
|
315
|
+
return generateAptosStealthAddress(recipientMetaAddress)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Convert an ed25519 public key to Aptos address format
|
|
320
|
+
*
|
|
321
|
+
* @param publicKey - 32-byte ed25519 public key
|
|
322
|
+
* @returns Aptos address string
|
|
323
|
+
*/
|
|
324
|
+
stealthKeyToAptosAddress(publicKey: HexString): string {
|
|
325
|
+
return ed25519PublicKeyToAptosAddress(publicKey)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Derive the private key for a stealth address
|
|
330
|
+
*
|
|
331
|
+
* @param stealthAddress - Stealth address data
|
|
332
|
+
* @param spendingPrivateKey - Recipient's spending private key
|
|
333
|
+
* @param viewingPrivateKey - Recipient's viewing private key
|
|
334
|
+
* @returns Recovery data with derived private key
|
|
335
|
+
*/
|
|
336
|
+
deriveStealthPrivateKey(
|
|
337
|
+
stealthAddress: StealthAddress,
|
|
338
|
+
spendingPrivateKey: HexString,
|
|
339
|
+
viewingPrivateKey: HexString,
|
|
340
|
+
) {
|
|
341
|
+
return deriveAptosStealthPrivateKey(stealthAddress, spendingPrivateKey, viewingPrivateKey)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Check if a stealth address belongs to this recipient
|
|
346
|
+
*
|
|
347
|
+
* @param stealthAddress - Stealth address to check
|
|
348
|
+
* @param spendingPrivateKey - Recipient's spending private key
|
|
349
|
+
* @param viewingPrivateKey - Recipient's viewing private key
|
|
350
|
+
* @returns true if the address belongs to this recipient
|
|
351
|
+
*/
|
|
352
|
+
checkStealthAddress(
|
|
353
|
+
stealthAddress: StealthAddress,
|
|
354
|
+
spendingPrivateKey: HexString,
|
|
355
|
+
viewingPrivateKey: HexString,
|
|
356
|
+
): boolean {
|
|
357
|
+
return checkAptosStealthAddress(stealthAddress, spendingPrivateKey, viewingPrivateKey)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Validate an Aptos address format
|
|
362
|
+
*
|
|
363
|
+
* @param address - Address to validate
|
|
364
|
+
* @returns true if valid format
|
|
365
|
+
*/
|
|
366
|
+
isValidAddress(address: string): boolean {
|
|
367
|
+
return isValidAptosAddress(address)
|
|
368
|
+
}
|
|
369
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Move blockchain stealth address support
|
|
3
|
+
*
|
|
4
|
+
* This module provides stealth address implementations for Move-based chains:
|
|
5
|
+
* - Aptos: ed25519 with SHA3-256 address derivation
|
|
6
|
+
* - Sui: ed25519 with BLAKE2b-256 address derivation
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
// Aptos stealth addresses
|
|
11
|
+
AptosStealthService,
|
|
12
|
+
generateAptosStealthAddress,
|
|
13
|
+
deriveAptosStealthPrivateKey,
|
|
14
|
+
checkAptosStealthAddress,
|
|
15
|
+
// Aptos address utilities
|
|
16
|
+
ed25519PublicKeyToAptosAddress,
|
|
17
|
+
aptosAddressToAuthKey,
|
|
18
|
+
isValidAptosAddress,
|
|
19
|
+
} from './aptos'
|
|
20
|
+
|
|
21
|
+
export type { AptosStealthResult } from './aptos'
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
// Sui stealth addresses
|
|
25
|
+
SuiStealthService,
|
|
26
|
+
generateSuiStealthAddress,
|
|
27
|
+
deriveSuiStealthPrivateKey,
|
|
28
|
+
checkSuiStealthAddress,
|
|
29
|
+
// Sui address utilities
|
|
30
|
+
ed25519PublicKeyToSuiAddress,
|
|
31
|
+
normalizeSuiAddress,
|
|
32
|
+
isValidSuiAddress,
|
|
33
|
+
} from './sui'
|
|
34
|
+
|
|
35
|
+
export type { SuiStealthResult } from './sui'
|