@adelos/sdk 0.1.6 → 0.1.8
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/index.d.mts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +47 -5
- package/dist/index.mjs +46 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -13,6 +13,8 @@ interface AdelosOptions {
|
|
|
13
13
|
rpcUrl?: string;
|
|
14
14
|
/** Helius API key for indexer webhooks (optional) */
|
|
15
15
|
heliusApiKey?: string;
|
|
16
|
+
/** Enable debug logging (optional - defaults to false) */
|
|
17
|
+
debug?: boolean;
|
|
16
18
|
}
|
|
17
19
|
/** Result of a registry lookup */
|
|
18
20
|
interface RegistryInfo {
|
|
@@ -77,6 +79,8 @@ declare function generateEphemeralKeypair(): {
|
|
|
77
79
|
secretKey: ed.Bytes;
|
|
78
80
|
publicKey: ed.Bytes;
|
|
79
81
|
};
|
|
82
|
+
/** Derive Public Key from Secret Key */
|
|
83
|
+
declare function derivePublicKey(secretKey: Uint8Array): Uint8Array;
|
|
80
84
|
/** Compute Shared Secret (Sender) */
|
|
81
85
|
declare function computeSharedSecret(ephemeralSk: Uint8Array, recipientMetaPk: Uint8Array): Uint8Array;
|
|
82
86
|
/** Compute Shared Secret (Recipient) */
|
|
@@ -113,8 +117,9 @@ declare class AdelosIndexer {
|
|
|
113
117
|
constructor(connection: Connection);
|
|
114
118
|
/** Scan for stealth transfers to this recipient */
|
|
115
119
|
scanForStealthTransfers(metaSk: Uint8Array, metaPk: Uint8Array, limit?: number): Promise<StealthTransaction[]>;
|
|
116
|
-
/**
|
|
117
|
-
*
|
|
120
|
+
/**
|
|
121
|
+
* Trial Decryption: Check if this transaction belongs to the user.
|
|
122
|
+
* Made 'public' for testing purposes.
|
|
118
123
|
*/
|
|
119
124
|
attemptDecryption(tx: ParsedTransactionWithMeta, metaSk: Uint8Array, metaPk: Uint8Array): {
|
|
120
125
|
stealthAddress: PublicKey;
|
|
@@ -122,7 +127,7 @@ declare class AdelosIndexer {
|
|
|
122
127
|
} | null;
|
|
123
128
|
private extractMemo;
|
|
124
129
|
}
|
|
125
|
-
/** Helper
|
|
130
|
+
/** Helper for quick initialization */
|
|
126
131
|
declare function createIndexer(connection: Connection): AdelosIndexer;
|
|
127
132
|
|
|
128
133
|
declare class AdelosSDK {
|
|
@@ -141,4 +146,4 @@ declare class AdelosSDK {
|
|
|
141
146
|
sendAndConfirm(signedTx: Transaction | VersionedTransaction): Promise<string>;
|
|
142
147
|
}
|
|
143
148
|
|
|
144
|
-
export { ADELOS_CONFIG, AdelosIndexer, type AdelosOptions, AdelosSDK, MEMO_PREFIX, MEMO_PROGRAM_ID, PROGRAM_ID, REGISTRY_SEED, RPC_URL, type RegistryAccount, type RegistryInfo, STEALTH_DOMAIN, type SolanaCluster, type StealthTransaction, bytesToHex, computeSharedSecret, computeSharedSecretAsRecipient, createIndexer, deriveRegistryPda, deriveStealthPubkey, generateEphemeralKeypair, generateStealthAddress, generateStealthMemo, getDiscriminator, hexToBytes, isValidMetaPubkey, parseStealthMemo, recoverStealthSecretKey };
|
|
149
|
+
export { ADELOS_CONFIG, AdelosIndexer, type AdelosOptions, AdelosSDK, MEMO_PREFIX, MEMO_PROGRAM_ID, PROGRAM_ID, REGISTRY_SEED, RPC_URL, type RegistryAccount, type RegistryInfo, STEALTH_DOMAIN, type SolanaCluster, type StealthTransaction, bytesToHex, computeSharedSecret, computeSharedSecretAsRecipient, createIndexer, derivePublicKey, deriveRegistryPda, deriveStealthPubkey, generateEphemeralKeypair, generateStealthAddress, generateStealthMemo, getDiscriminator, hexToBytes, isValidMetaPubkey, parseStealthMemo, recoverStealthSecretKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ interface AdelosOptions {
|
|
|
13
13
|
rpcUrl?: string;
|
|
14
14
|
/** Helius API key for indexer webhooks (optional) */
|
|
15
15
|
heliusApiKey?: string;
|
|
16
|
+
/** Enable debug logging (optional - defaults to false) */
|
|
17
|
+
debug?: boolean;
|
|
16
18
|
}
|
|
17
19
|
/** Result of a registry lookup */
|
|
18
20
|
interface RegistryInfo {
|
|
@@ -77,6 +79,8 @@ declare function generateEphemeralKeypair(): {
|
|
|
77
79
|
secretKey: ed.Bytes;
|
|
78
80
|
publicKey: ed.Bytes;
|
|
79
81
|
};
|
|
82
|
+
/** Derive Public Key from Secret Key */
|
|
83
|
+
declare function derivePublicKey(secretKey: Uint8Array): Uint8Array;
|
|
80
84
|
/** Compute Shared Secret (Sender) */
|
|
81
85
|
declare function computeSharedSecret(ephemeralSk: Uint8Array, recipientMetaPk: Uint8Array): Uint8Array;
|
|
82
86
|
/** Compute Shared Secret (Recipient) */
|
|
@@ -113,8 +117,9 @@ declare class AdelosIndexer {
|
|
|
113
117
|
constructor(connection: Connection);
|
|
114
118
|
/** Scan for stealth transfers to this recipient */
|
|
115
119
|
scanForStealthTransfers(metaSk: Uint8Array, metaPk: Uint8Array, limit?: number): Promise<StealthTransaction[]>;
|
|
116
|
-
/**
|
|
117
|
-
*
|
|
120
|
+
/**
|
|
121
|
+
* Trial Decryption: Check if this transaction belongs to the user.
|
|
122
|
+
* Made 'public' for testing purposes.
|
|
118
123
|
*/
|
|
119
124
|
attemptDecryption(tx: ParsedTransactionWithMeta, metaSk: Uint8Array, metaPk: Uint8Array): {
|
|
120
125
|
stealthAddress: PublicKey;
|
|
@@ -122,7 +127,7 @@ declare class AdelosIndexer {
|
|
|
122
127
|
} | null;
|
|
123
128
|
private extractMemo;
|
|
124
129
|
}
|
|
125
|
-
/** Helper
|
|
130
|
+
/** Helper for quick initialization */
|
|
126
131
|
declare function createIndexer(connection: Connection): AdelosIndexer;
|
|
127
132
|
|
|
128
133
|
declare class AdelosSDK {
|
|
@@ -141,4 +146,4 @@ declare class AdelosSDK {
|
|
|
141
146
|
sendAndConfirm(signedTx: Transaction | VersionedTransaction): Promise<string>;
|
|
142
147
|
}
|
|
143
148
|
|
|
144
|
-
export { ADELOS_CONFIG, AdelosIndexer, type AdelosOptions, AdelosSDK, MEMO_PREFIX, MEMO_PROGRAM_ID, PROGRAM_ID, REGISTRY_SEED, RPC_URL, type RegistryAccount, type RegistryInfo, STEALTH_DOMAIN, type SolanaCluster, type StealthTransaction, bytesToHex, computeSharedSecret, computeSharedSecretAsRecipient, createIndexer, deriveRegistryPda, deriveStealthPubkey, generateEphemeralKeypair, generateStealthAddress, generateStealthMemo, getDiscriminator, hexToBytes, isValidMetaPubkey, parseStealthMemo, recoverStealthSecretKey };
|
|
149
|
+
export { ADELOS_CONFIG, AdelosIndexer, type AdelosOptions, AdelosSDK, MEMO_PREFIX, MEMO_PROGRAM_ID, PROGRAM_ID, REGISTRY_SEED, RPC_URL, type RegistryAccount, type RegistryInfo, STEALTH_DOMAIN, type SolanaCluster, type StealthTransaction, bytesToHex, computeSharedSecret, computeSharedSecretAsRecipient, createIndexer, derivePublicKey, deriveRegistryPda, deriveStealthPubkey, generateEphemeralKeypair, generateStealthAddress, generateStealthMemo, getDiscriminator, hexToBytes, isValidMetaPubkey, parseStealthMemo, recoverStealthSecretKey };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
computeSharedSecret: () => computeSharedSecret,
|
|
44
44
|
computeSharedSecretAsRecipient: () => computeSharedSecretAsRecipient,
|
|
45
45
|
createIndexer: () => createIndexer,
|
|
46
|
+
derivePublicKey: () => derivePublicKey,
|
|
46
47
|
deriveRegistryPda: () => deriveRegistryPda,
|
|
47
48
|
deriveStealthPubkey: () => deriveStealthPubkey,
|
|
48
49
|
generateEphemeralKeypair: () => generateEphemeralKeypair,
|
|
@@ -134,6 +135,10 @@ function generateEphemeralKeypair() {
|
|
|
134
135
|
const publicKey = ed.ExtendedPoint.BASE.multiply(scalar).toRawBytes();
|
|
135
136
|
return { secretKey, publicKey };
|
|
136
137
|
}
|
|
138
|
+
function derivePublicKey(secretKey) {
|
|
139
|
+
const scalar = toScalar(secretKey);
|
|
140
|
+
return ed.ExtendedPoint.BASE.multiply(scalar).toRawBytes();
|
|
141
|
+
}
|
|
137
142
|
function computeSharedSecret(ephemeralSk, recipientMetaPk) {
|
|
138
143
|
const point = ed.ExtendedPoint.fromHex(bytesToHex(recipientMetaPk));
|
|
139
144
|
const scalar = toScalar(ephemeralSk);
|
|
@@ -182,40 +187,73 @@ function generateStealthAddress(recipientMetaPk) {
|
|
|
182
187
|
return { stealthPubkey, ephemeralKeypair, sharedSecret, memo };
|
|
183
188
|
}
|
|
184
189
|
|
|
190
|
+
// src/logger.ts
|
|
191
|
+
var debugMode = false;
|
|
192
|
+
function setDebugMode(enabled) {
|
|
193
|
+
debugMode = enabled;
|
|
194
|
+
}
|
|
195
|
+
function log(...args) {
|
|
196
|
+
if (debugMode) {
|
|
197
|
+
console.log(...args);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
185
201
|
// src/indexer.ts
|
|
186
202
|
var AdelosIndexer = class {
|
|
187
|
-
//
|
|
203
|
+
// Directly accepts Connection object
|
|
188
204
|
constructor(connection) {
|
|
189
205
|
this.connection = connection;
|
|
190
206
|
}
|
|
191
207
|
/** Scan for stealth transfers to this recipient */
|
|
192
208
|
async scanForStealthTransfers(metaSk, metaPk, limit = 100) {
|
|
209
|
+
log(`[Indexer] Starting scan for stealth transfers (limit: ${limit})`);
|
|
210
|
+
const startTime = Date.now();
|
|
193
211
|
const sigs = await this.connection.getSignaturesForAddress(
|
|
194
212
|
ADELOS_CONFIG.MEMO_PROGRAM_ID,
|
|
195
213
|
{ limit }
|
|
196
214
|
);
|
|
215
|
+
log(`[Indexer] Found ${sigs.length} memo program transactions to check`);
|
|
197
216
|
const results = [];
|
|
217
|
+
let processed = 0;
|
|
218
|
+
let adelosMemos = 0;
|
|
198
219
|
for (const s of sigs) {
|
|
220
|
+
processed++;
|
|
221
|
+
log(`[Indexer] Processing tx ${processed}/${sigs.length}: ${s.signature.substring(0, 10)}...`);
|
|
199
222
|
const tx = await this.connection.getParsedTransaction(s.signature, {
|
|
200
223
|
maxSupportedTransactionVersion: 0
|
|
201
224
|
});
|
|
202
|
-
if (!tx)
|
|
225
|
+
if (!tx) {
|
|
226
|
+
log(` \u21B3 Skipped (tx not found)`);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
203
229
|
const memo = this.extractMemo(tx);
|
|
204
|
-
if (!memo?.startsWith(ADELOS_CONFIG.MEMO_PREFIX))
|
|
230
|
+
if (!memo?.startsWith(ADELOS_CONFIG.MEMO_PREFIX)) {
|
|
231
|
+
log(` \u21B3 Skipped (not Adelos memo)`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
adelosMemos++;
|
|
235
|
+
log(` \u21B3 Found Adelos memo! Attempting trial decryption...`);
|
|
205
236
|
const detected = this.attemptDecryption(tx, metaSk, metaPk);
|
|
206
237
|
if (detected) {
|
|
238
|
+
log(` \u21B3 \u2705 MATCH! Stealth transfer detected: ${Number(detected.amount) / 1e9} SOL`);
|
|
207
239
|
results.push({
|
|
208
240
|
signature: s.signature,
|
|
209
241
|
blockTime: tx.blockTime ?? null,
|
|
210
242
|
stealthAddress: detected.stealthAddress,
|
|
211
243
|
amount: detected.amount
|
|
212
244
|
});
|
|
245
|
+
} else {
|
|
246
|
+
log(` \u21B3 Not for this recipient`);
|
|
213
247
|
}
|
|
214
248
|
}
|
|
249
|
+
const elapsed = ((Date.now() - startTime) / 1e3).toFixed(2);
|
|
250
|
+
log(`[Indexer] Scan complete in ${elapsed}s`);
|
|
251
|
+
log(`[Indexer] Summary: ${processed} total, ${adelosMemos} Adelos memos, ${results.length} matches`);
|
|
215
252
|
return results;
|
|
216
253
|
}
|
|
217
|
-
/**
|
|
218
|
-
*
|
|
254
|
+
/**
|
|
255
|
+
* Trial Decryption: Check if this transaction belongs to the user.
|
|
256
|
+
* Made 'public' for testing purposes.
|
|
219
257
|
*/
|
|
220
258
|
attemptDecryption(tx, metaSk, metaPk) {
|
|
221
259
|
const memo = this.extractMemo(tx);
|
|
@@ -252,6 +290,9 @@ var AdelosSDK = class {
|
|
|
252
290
|
constructor(options = {}) {
|
|
253
291
|
this.connection = new import_web33.Connection(options.rpcUrl ?? ADELOS_CONFIG.RPC_URL, "confirmed");
|
|
254
292
|
this.programId = ADELOS_CONFIG.PROGRAM_ID;
|
|
293
|
+
if (options.debug !== void 0) {
|
|
294
|
+
setDebugMode(options.debug);
|
|
295
|
+
}
|
|
255
296
|
}
|
|
256
297
|
// --- 1. Identity & Registry ---
|
|
257
298
|
async getRegistry(owner) {
|
|
@@ -349,6 +390,7 @@ var AdelosSDK = class {
|
|
|
349
390
|
computeSharedSecret,
|
|
350
391
|
computeSharedSecretAsRecipient,
|
|
351
392
|
createIndexer,
|
|
393
|
+
derivePublicKey,
|
|
352
394
|
deriveRegistryPda,
|
|
353
395
|
deriveStealthPubkey,
|
|
354
396
|
generateEphemeralKeypair,
|
package/dist/index.mjs
CHANGED
|
@@ -86,6 +86,10 @@ function generateEphemeralKeypair() {
|
|
|
86
86
|
const publicKey = ed.ExtendedPoint.BASE.multiply(scalar).toRawBytes();
|
|
87
87
|
return { secretKey, publicKey };
|
|
88
88
|
}
|
|
89
|
+
function derivePublicKey(secretKey) {
|
|
90
|
+
const scalar = toScalar(secretKey);
|
|
91
|
+
return ed.ExtendedPoint.BASE.multiply(scalar).toRawBytes();
|
|
92
|
+
}
|
|
89
93
|
function computeSharedSecret(ephemeralSk, recipientMetaPk) {
|
|
90
94
|
const point = ed.ExtendedPoint.fromHex(bytesToHex(recipientMetaPk));
|
|
91
95
|
const scalar = toScalar(ephemeralSk);
|
|
@@ -134,40 +138,73 @@ function generateStealthAddress(recipientMetaPk) {
|
|
|
134
138
|
return { stealthPubkey, ephemeralKeypair, sharedSecret, memo };
|
|
135
139
|
}
|
|
136
140
|
|
|
141
|
+
// src/logger.ts
|
|
142
|
+
var debugMode = false;
|
|
143
|
+
function setDebugMode(enabled) {
|
|
144
|
+
debugMode = enabled;
|
|
145
|
+
}
|
|
146
|
+
function log(...args) {
|
|
147
|
+
if (debugMode) {
|
|
148
|
+
console.log(...args);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
137
152
|
// src/indexer.ts
|
|
138
153
|
var AdelosIndexer = class {
|
|
139
|
-
//
|
|
154
|
+
// Directly accepts Connection object
|
|
140
155
|
constructor(connection) {
|
|
141
156
|
this.connection = connection;
|
|
142
157
|
}
|
|
143
158
|
/** Scan for stealth transfers to this recipient */
|
|
144
159
|
async scanForStealthTransfers(metaSk, metaPk, limit = 100) {
|
|
160
|
+
log(`[Indexer] Starting scan for stealth transfers (limit: ${limit})`);
|
|
161
|
+
const startTime = Date.now();
|
|
145
162
|
const sigs = await this.connection.getSignaturesForAddress(
|
|
146
163
|
ADELOS_CONFIG.MEMO_PROGRAM_ID,
|
|
147
164
|
{ limit }
|
|
148
165
|
);
|
|
166
|
+
log(`[Indexer] Found ${sigs.length} memo program transactions to check`);
|
|
149
167
|
const results = [];
|
|
168
|
+
let processed = 0;
|
|
169
|
+
let adelosMemos = 0;
|
|
150
170
|
for (const s of sigs) {
|
|
171
|
+
processed++;
|
|
172
|
+
log(`[Indexer] Processing tx ${processed}/${sigs.length}: ${s.signature.substring(0, 10)}...`);
|
|
151
173
|
const tx = await this.connection.getParsedTransaction(s.signature, {
|
|
152
174
|
maxSupportedTransactionVersion: 0
|
|
153
175
|
});
|
|
154
|
-
if (!tx)
|
|
176
|
+
if (!tx) {
|
|
177
|
+
log(` \u21B3 Skipped (tx not found)`);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
155
180
|
const memo = this.extractMemo(tx);
|
|
156
|
-
if (!memo?.startsWith(ADELOS_CONFIG.MEMO_PREFIX))
|
|
181
|
+
if (!memo?.startsWith(ADELOS_CONFIG.MEMO_PREFIX)) {
|
|
182
|
+
log(` \u21B3 Skipped (not Adelos memo)`);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
adelosMemos++;
|
|
186
|
+
log(` \u21B3 Found Adelos memo! Attempting trial decryption...`);
|
|
157
187
|
const detected = this.attemptDecryption(tx, metaSk, metaPk);
|
|
158
188
|
if (detected) {
|
|
189
|
+
log(` \u21B3 \u2705 MATCH! Stealth transfer detected: ${Number(detected.amount) / 1e9} SOL`);
|
|
159
190
|
results.push({
|
|
160
191
|
signature: s.signature,
|
|
161
192
|
blockTime: tx.blockTime ?? null,
|
|
162
193
|
stealthAddress: detected.stealthAddress,
|
|
163
194
|
amount: detected.amount
|
|
164
195
|
});
|
|
196
|
+
} else {
|
|
197
|
+
log(` \u21B3 Not for this recipient`);
|
|
165
198
|
}
|
|
166
199
|
}
|
|
200
|
+
const elapsed = ((Date.now() - startTime) / 1e3).toFixed(2);
|
|
201
|
+
log(`[Indexer] Scan complete in ${elapsed}s`);
|
|
202
|
+
log(`[Indexer] Summary: ${processed} total, ${adelosMemos} Adelos memos, ${results.length} matches`);
|
|
167
203
|
return results;
|
|
168
204
|
}
|
|
169
|
-
/**
|
|
170
|
-
*
|
|
205
|
+
/**
|
|
206
|
+
* Trial Decryption: Check if this transaction belongs to the user.
|
|
207
|
+
* Made 'public' for testing purposes.
|
|
171
208
|
*/
|
|
172
209
|
attemptDecryption(tx, metaSk, metaPk) {
|
|
173
210
|
const memo = this.extractMemo(tx);
|
|
@@ -204,6 +241,9 @@ var AdelosSDK = class {
|
|
|
204
241
|
constructor(options = {}) {
|
|
205
242
|
this.connection = new Connection(options.rpcUrl ?? ADELOS_CONFIG.RPC_URL, "confirmed");
|
|
206
243
|
this.programId = ADELOS_CONFIG.PROGRAM_ID;
|
|
244
|
+
if (options.debug !== void 0) {
|
|
245
|
+
setDebugMode(options.debug);
|
|
246
|
+
}
|
|
207
247
|
}
|
|
208
248
|
// --- 1. Identity & Registry ---
|
|
209
249
|
async getRegistry(owner) {
|
|
@@ -300,6 +340,7 @@ export {
|
|
|
300
340
|
computeSharedSecret,
|
|
301
341
|
computeSharedSecretAsRecipient,
|
|
302
342
|
createIndexer,
|
|
343
|
+
derivePublicKey,
|
|
303
344
|
deriveRegistryPda,
|
|
304
345
|
deriveStealthPubkey,
|
|
305
346
|
generateEphemeralKeypair,
|