@adelos/sdk 0.1.9 → 0.1.11
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 +37 -7
- package/dist/index.d.ts +37 -7
- package/dist/index.js +65 -2
- package/dist/index.mjs +65 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,20 @@ interface RegistryInfo {
|
|
|
22
22
|
account: RegistryAccount;
|
|
23
23
|
exists: boolean;
|
|
24
24
|
}
|
|
25
|
+
/** Stealth transaction detected during scanning */
|
|
26
|
+
interface StealthTransaction {
|
|
27
|
+
signature: string;
|
|
28
|
+
blockTime: number | null;
|
|
29
|
+
stealthAddress: PublicKey;
|
|
30
|
+
amount: bigint;
|
|
31
|
+
/** Ephemeral public key from memo - needed for withdraw */
|
|
32
|
+
ephemeralPk: Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
/** Stealth transaction ready for withdrawal */
|
|
35
|
+
interface WithdrawableTransaction extends StealthTransaction {
|
|
36
|
+
/** Recovered stealth secret key - used to sign withdraw tx */
|
|
37
|
+
stealthSecretKey: Uint8Array;
|
|
38
|
+
}
|
|
25
39
|
|
|
26
40
|
type SolanaCluster = "devnet";
|
|
27
41
|
declare const ADELOS_CONFIG: {
|
|
@@ -106,12 +120,6 @@ declare function generateStealthAddress(recipientMetaPk: Uint8Array): {
|
|
|
106
120
|
* Adelos Indexer - Privacy-Preserving Transaction Scanner
|
|
107
121
|
*/
|
|
108
122
|
|
|
109
|
-
interface StealthTransaction {
|
|
110
|
-
signature: string;
|
|
111
|
-
blockTime: number | null;
|
|
112
|
-
stealthAddress: PublicKey;
|
|
113
|
-
amount: bigint;
|
|
114
|
-
}
|
|
115
123
|
declare class AdelosIndexer {
|
|
116
124
|
private connection;
|
|
117
125
|
constructor(connection: Connection);
|
|
@@ -124,7 +132,12 @@ declare class AdelosIndexer {
|
|
|
124
132
|
attemptDecryption(tx: ParsedTransactionWithMeta, metaSk: Uint8Array, metaPk: Uint8Array): {
|
|
125
133
|
stealthAddress: PublicKey;
|
|
126
134
|
amount: bigint;
|
|
135
|
+
ephemeralPk: Uint8Array;
|
|
127
136
|
} | null;
|
|
137
|
+
/**
|
|
138
|
+
* Prepare a stealth transaction for withdrawal by recovering the secret key.
|
|
139
|
+
*/
|
|
140
|
+
prepareWithdraw(stealthTx: StealthTransaction, metaSk: Uint8Array, metaPk: Uint8Array): WithdrawableTransaction;
|
|
128
141
|
private extractMemo;
|
|
129
142
|
}
|
|
130
143
|
/** Helper for quick initialization */
|
|
@@ -145,9 +158,26 @@ declare class AdelosSDK {
|
|
|
145
158
|
}>;
|
|
146
159
|
/** Membuat transaksi pendaftaran identitas */
|
|
147
160
|
createRegisterTransaction(owner: PublicKey, metaPubkey: Uint8Array, version?: "legacy" | "v0"): Promise<Transaction | VersionedTransaction>;
|
|
161
|
+
/** Membuat transaksi pembaruan identitas (jika sudah terdaftar) */
|
|
162
|
+
createUpdateTransaction(owner: PublicKey, metaPubkey: Uint8Array, version?: "legacy" | "v0"): Promise<Transaction | VersionedTransaction>;
|
|
163
|
+
/**
|
|
164
|
+
* Create a withdraw transaction from stealth address to any destination.
|
|
165
|
+
* This enables both:
|
|
166
|
+
* - Withdraw to self (destination = user's main wallet)
|
|
167
|
+
* - Withdraw to any address (for enhanced privacy - no link to main wallet!)
|
|
168
|
+
*
|
|
169
|
+
* @param stealthSecretKey - The recovered stealth private key (from prepareWithdraw)
|
|
170
|
+
* @param stealthAddress - The stealth address holding the funds
|
|
171
|
+
* @param destination - Where to send the funds (can be ANY address)
|
|
172
|
+
* @param amountLamports - Amount to withdraw in lamports (use BigInt)
|
|
173
|
+
*/
|
|
174
|
+
createWithdrawTransaction(stealthSecretKey: Uint8Array, stealthAddress: PublicKey, destination: PublicKey, amountLamports: bigint): Promise<{
|
|
175
|
+
transaction: VersionedTransaction;
|
|
176
|
+
signature: string;
|
|
177
|
+
}>;
|
|
148
178
|
buildTransaction(payer: PublicKey, instructions: TransactionInstruction[], version?: "legacy" | "v0"): Promise<Transaction | VersionedTransaction>;
|
|
149
179
|
/** Satu fungsi kirim untuk semua jenis transaksi (Legacy/V0) */
|
|
150
180
|
sendAndConfirm(signedTx: Transaction | VersionedTransaction): Promise<string>;
|
|
151
181
|
}
|
|
152
182
|
|
|
153
|
-
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 };
|
|
183
|
+
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, type WithdrawableTransaction, bytesToHex, computeSharedSecret, computeSharedSecretAsRecipient, createIndexer, derivePublicKey, deriveRegistryPda, deriveStealthPubkey, generateEphemeralKeypair, generateStealthAddress, generateStealthMemo, getDiscriminator, hexToBytes, isValidMetaPubkey, parseStealthMemo, recoverStealthSecretKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,20 @@ interface RegistryInfo {
|
|
|
22
22
|
account: RegistryAccount;
|
|
23
23
|
exists: boolean;
|
|
24
24
|
}
|
|
25
|
+
/** Stealth transaction detected during scanning */
|
|
26
|
+
interface StealthTransaction {
|
|
27
|
+
signature: string;
|
|
28
|
+
blockTime: number | null;
|
|
29
|
+
stealthAddress: PublicKey;
|
|
30
|
+
amount: bigint;
|
|
31
|
+
/** Ephemeral public key from memo - needed for withdraw */
|
|
32
|
+
ephemeralPk: Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
/** Stealth transaction ready for withdrawal */
|
|
35
|
+
interface WithdrawableTransaction extends StealthTransaction {
|
|
36
|
+
/** Recovered stealth secret key - used to sign withdraw tx */
|
|
37
|
+
stealthSecretKey: Uint8Array;
|
|
38
|
+
}
|
|
25
39
|
|
|
26
40
|
type SolanaCluster = "devnet";
|
|
27
41
|
declare const ADELOS_CONFIG: {
|
|
@@ -106,12 +120,6 @@ declare function generateStealthAddress(recipientMetaPk: Uint8Array): {
|
|
|
106
120
|
* Adelos Indexer - Privacy-Preserving Transaction Scanner
|
|
107
121
|
*/
|
|
108
122
|
|
|
109
|
-
interface StealthTransaction {
|
|
110
|
-
signature: string;
|
|
111
|
-
blockTime: number | null;
|
|
112
|
-
stealthAddress: PublicKey;
|
|
113
|
-
amount: bigint;
|
|
114
|
-
}
|
|
115
123
|
declare class AdelosIndexer {
|
|
116
124
|
private connection;
|
|
117
125
|
constructor(connection: Connection);
|
|
@@ -124,7 +132,12 @@ declare class AdelosIndexer {
|
|
|
124
132
|
attemptDecryption(tx: ParsedTransactionWithMeta, metaSk: Uint8Array, metaPk: Uint8Array): {
|
|
125
133
|
stealthAddress: PublicKey;
|
|
126
134
|
amount: bigint;
|
|
135
|
+
ephemeralPk: Uint8Array;
|
|
127
136
|
} | null;
|
|
137
|
+
/**
|
|
138
|
+
* Prepare a stealth transaction for withdrawal by recovering the secret key.
|
|
139
|
+
*/
|
|
140
|
+
prepareWithdraw(stealthTx: StealthTransaction, metaSk: Uint8Array, metaPk: Uint8Array): WithdrawableTransaction;
|
|
128
141
|
private extractMemo;
|
|
129
142
|
}
|
|
130
143
|
/** Helper for quick initialization */
|
|
@@ -145,9 +158,26 @@ declare class AdelosSDK {
|
|
|
145
158
|
}>;
|
|
146
159
|
/** Membuat transaksi pendaftaran identitas */
|
|
147
160
|
createRegisterTransaction(owner: PublicKey, metaPubkey: Uint8Array, version?: "legacy" | "v0"): Promise<Transaction | VersionedTransaction>;
|
|
161
|
+
/** Membuat transaksi pembaruan identitas (jika sudah terdaftar) */
|
|
162
|
+
createUpdateTransaction(owner: PublicKey, metaPubkey: Uint8Array, version?: "legacy" | "v0"): Promise<Transaction | VersionedTransaction>;
|
|
163
|
+
/**
|
|
164
|
+
* Create a withdraw transaction from stealth address to any destination.
|
|
165
|
+
* This enables both:
|
|
166
|
+
* - Withdraw to self (destination = user's main wallet)
|
|
167
|
+
* - Withdraw to any address (for enhanced privacy - no link to main wallet!)
|
|
168
|
+
*
|
|
169
|
+
* @param stealthSecretKey - The recovered stealth private key (from prepareWithdraw)
|
|
170
|
+
* @param stealthAddress - The stealth address holding the funds
|
|
171
|
+
* @param destination - Where to send the funds (can be ANY address)
|
|
172
|
+
* @param amountLamports - Amount to withdraw in lamports (use BigInt)
|
|
173
|
+
*/
|
|
174
|
+
createWithdrawTransaction(stealthSecretKey: Uint8Array, stealthAddress: PublicKey, destination: PublicKey, amountLamports: bigint): Promise<{
|
|
175
|
+
transaction: VersionedTransaction;
|
|
176
|
+
signature: string;
|
|
177
|
+
}>;
|
|
148
178
|
buildTransaction(payer: PublicKey, instructions: TransactionInstruction[], version?: "legacy" | "v0"): Promise<Transaction | VersionedTransaction>;
|
|
149
179
|
/** Satu fungsi kirim untuk semua jenis transaksi (Legacy/V0) */
|
|
150
180
|
sendAndConfirm(signedTx: Transaction | VersionedTransaction): Promise<string>;
|
|
151
181
|
}
|
|
152
182
|
|
|
153
|
-
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 };
|
|
183
|
+
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, type WithdrawableTransaction, bytesToHex, computeSharedSecret, computeSharedSecretAsRecipient, createIndexer, derivePublicKey, deriveRegistryPda, deriveStealthPubkey, generateEphemeralKeypair, generateStealthAddress, generateStealthMemo, getDiscriminator, hexToBytes, isValidMetaPubkey, parseStealthMemo, recoverStealthSecretKey };
|
package/dist/index.js
CHANGED
|
@@ -240,7 +240,8 @@ var AdelosIndexer = class {
|
|
|
240
240
|
signature: s.signature,
|
|
241
241
|
blockTime: tx.blockTime ?? null,
|
|
242
242
|
stealthAddress: detected.stealthAddress,
|
|
243
|
-
amount: detected.amount
|
|
243
|
+
amount: detected.amount,
|
|
244
|
+
ephemeralPk: detected.ephemeralPk
|
|
244
245
|
});
|
|
245
246
|
} else {
|
|
246
247
|
log(` \u21B3 Not for this recipient`);
|
|
@@ -271,7 +272,19 @@ var AdelosIndexer = class {
|
|
|
271
272
|
const change = BigInt(postBalances[idx] || 0) - BigInt(preBalances[idx] || 0);
|
|
272
273
|
return {
|
|
273
274
|
stealthAddress: accounts[idx].pubkey,
|
|
274
|
-
amount: change > 0n ? change : 0n
|
|
275
|
+
amount: change > 0n ? change : 0n,
|
|
276
|
+
ephemeralPk
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Prepare a stealth transaction for withdrawal by recovering the secret key.
|
|
281
|
+
*/
|
|
282
|
+
prepareWithdraw(stealthTx, metaSk, metaPk) {
|
|
283
|
+
const sharedSecret = computeSharedSecretAsRecipient(metaSk, stealthTx.ephemeralPk);
|
|
284
|
+
const stealthSecretKey = recoverStealthSecretKey(metaSk, sharedSecret);
|
|
285
|
+
return {
|
|
286
|
+
...stealthTx,
|
|
287
|
+
stealthSecretKey
|
|
275
288
|
};
|
|
276
289
|
}
|
|
277
290
|
extractMemo(tx) {
|
|
@@ -356,6 +369,56 @@ var AdelosSDK = class {
|
|
|
356
369
|
});
|
|
357
370
|
return this.buildTransaction(owner, [ix], version);
|
|
358
371
|
}
|
|
372
|
+
/** Membuat transaksi pembaruan identitas (jika sudah terdaftar) */
|
|
373
|
+
async createUpdateTransaction(owner, metaPubkey, version = "v0") {
|
|
374
|
+
const [registryPda] = deriveRegistryPda(owner, this.programId);
|
|
375
|
+
const data = Buffer.concat([Buffer.from(getDiscriminator("update_identity")), Buffer.from(metaPubkey)]);
|
|
376
|
+
const ix = new import_web33.TransactionInstruction({
|
|
377
|
+
keys: [
|
|
378
|
+
{ pubkey: owner, isSigner: true, isWritable: true },
|
|
379
|
+
{ pubkey: registryPda, isSigner: false, isWritable: true },
|
|
380
|
+
{ pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false }
|
|
381
|
+
],
|
|
382
|
+
programId: this.programId,
|
|
383
|
+
data
|
|
384
|
+
});
|
|
385
|
+
return this.buildTransaction(owner, [ix], version);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Create a withdraw transaction from stealth address to any destination.
|
|
389
|
+
* This enables both:
|
|
390
|
+
* - Withdraw to self (destination = user's main wallet)
|
|
391
|
+
* - Withdraw to any address (for enhanced privacy - no link to main wallet!)
|
|
392
|
+
*
|
|
393
|
+
* @param stealthSecretKey - The recovered stealth private key (from prepareWithdraw)
|
|
394
|
+
* @param stealthAddress - The stealth address holding the funds
|
|
395
|
+
* @param destination - Where to send the funds (can be ANY address)
|
|
396
|
+
* @param amountLamports - Amount to withdraw in lamports (use BigInt)
|
|
397
|
+
*/
|
|
398
|
+
async createWithdrawTransaction(stealthSecretKey, stealthAddress, destination, amountLamports) {
|
|
399
|
+
const { Keypair } = await import("@solana/web3.js");
|
|
400
|
+
const stealthKeypair = Keypair.fromSeed(stealthSecretKey);
|
|
401
|
+
if (!stealthKeypair.publicKey.equals(stealthAddress)) {
|
|
402
|
+
throw new Error("Stealth secret key does not match stealth address");
|
|
403
|
+
}
|
|
404
|
+
const ix = import_web33.SystemProgram.transfer({
|
|
405
|
+
fromPubkey: stealthAddress,
|
|
406
|
+
toPubkey: destination,
|
|
407
|
+
lamports: amountLamports
|
|
408
|
+
});
|
|
409
|
+
const { blockhash } = await this.connection.getLatestBlockhash();
|
|
410
|
+
const message = new import_web33.TransactionMessage({
|
|
411
|
+
payerKey: stealthAddress,
|
|
412
|
+
// Stealth pays the fee
|
|
413
|
+
recentBlockhash: blockhash,
|
|
414
|
+
instructions: [ix]
|
|
415
|
+
}).compileToV0Message();
|
|
416
|
+
const tx = new import_web33.VersionedTransaction(message);
|
|
417
|
+
tx.sign([stealthKeypair]);
|
|
418
|
+
const sig = await this.connection.sendRawTransaction(tx.serialize());
|
|
419
|
+
await this.connection.confirmTransaction(sig, "confirmed");
|
|
420
|
+
return { transaction: tx, signature: sig };
|
|
421
|
+
}
|
|
359
422
|
// --- 3. Core Engine (Internal Helpers) ---
|
|
360
423
|
async buildTransaction(payer, instructions, version = "v0") {
|
|
361
424
|
const { blockhash } = await this.connection.getLatestBlockhash();
|
package/dist/index.mjs
CHANGED
|
@@ -191,7 +191,8 @@ var AdelosIndexer = class {
|
|
|
191
191
|
signature: s.signature,
|
|
192
192
|
blockTime: tx.blockTime ?? null,
|
|
193
193
|
stealthAddress: detected.stealthAddress,
|
|
194
|
-
amount: detected.amount
|
|
194
|
+
amount: detected.amount,
|
|
195
|
+
ephemeralPk: detected.ephemeralPk
|
|
195
196
|
});
|
|
196
197
|
} else {
|
|
197
198
|
log(` \u21B3 Not for this recipient`);
|
|
@@ -222,7 +223,19 @@ var AdelosIndexer = class {
|
|
|
222
223
|
const change = BigInt(postBalances[idx] || 0) - BigInt(preBalances[idx] || 0);
|
|
223
224
|
return {
|
|
224
225
|
stealthAddress: accounts[idx].pubkey,
|
|
225
|
-
amount: change > 0n ? change : 0n
|
|
226
|
+
amount: change > 0n ? change : 0n,
|
|
227
|
+
ephemeralPk
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Prepare a stealth transaction for withdrawal by recovering the secret key.
|
|
232
|
+
*/
|
|
233
|
+
prepareWithdraw(stealthTx, metaSk, metaPk) {
|
|
234
|
+
const sharedSecret = computeSharedSecretAsRecipient(metaSk, stealthTx.ephemeralPk);
|
|
235
|
+
const stealthSecretKey = recoverStealthSecretKey(metaSk, sharedSecret);
|
|
236
|
+
return {
|
|
237
|
+
...stealthTx,
|
|
238
|
+
stealthSecretKey
|
|
226
239
|
};
|
|
227
240
|
}
|
|
228
241
|
extractMemo(tx) {
|
|
@@ -307,6 +320,56 @@ var AdelosSDK = class {
|
|
|
307
320
|
});
|
|
308
321
|
return this.buildTransaction(owner, [ix], version);
|
|
309
322
|
}
|
|
323
|
+
/** Membuat transaksi pembaruan identitas (jika sudah terdaftar) */
|
|
324
|
+
async createUpdateTransaction(owner, metaPubkey, version = "v0") {
|
|
325
|
+
const [registryPda] = deriveRegistryPda(owner, this.programId);
|
|
326
|
+
const data = Buffer.concat([Buffer.from(getDiscriminator("update_identity")), Buffer.from(metaPubkey)]);
|
|
327
|
+
const ix = new TransactionInstruction({
|
|
328
|
+
keys: [
|
|
329
|
+
{ pubkey: owner, isSigner: true, isWritable: true },
|
|
330
|
+
{ pubkey: registryPda, isSigner: false, isWritable: true },
|
|
331
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
|
|
332
|
+
],
|
|
333
|
+
programId: this.programId,
|
|
334
|
+
data
|
|
335
|
+
});
|
|
336
|
+
return this.buildTransaction(owner, [ix], version);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Create a withdraw transaction from stealth address to any destination.
|
|
340
|
+
* This enables both:
|
|
341
|
+
* - Withdraw to self (destination = user's main wallet)
|
|
342
|
+
* - Withdraw to any address (for enhanced privacy - no link to main wallet!)
|
|
343
|
+
*
|
|
344
|
+
* @param stealthSecretKey - The recovered stealth private key (from prepareWithdraw)
|
|
345
|
+
* @param stealthAddress - The stealth address holding the funds
|
|
346
|
+
* @param destination - Where to send the funds (can be ANY address)
|
|
347
|
+
* @param amountLamports - Amount to withdraw in lamports (use BigInt)
|
|
348
|
+
*/
|
|
349
|
+
async createWithdrawTransaction(stealthSecretKey, stealthAddress, destination, amountLamports) {
|
|
350
|
+
const { Keypair } = await import("@solana/web3.js");
|
|
351
|
+
const stealthKeypair = Keypair.fromSeed(stealthSecretKey);
|
|
352
|
+
if (!stealthKeypair.publicKey.equals(stealthAddress)) {
|
|
353
|
+
throw new Error("Stealth secret key does not match stealth address");
|
|
354
|
+
}
|
|
355
|
+
const ix = SystemProgram.transfer({
|
|
356
|
+
fromPubkey: stealthAddress,
|
|
357
|
+
toPubkey: destination,
|
|
358
|
+
lamports: amountLamports
|
|
359
|
+
});
|
|
360
|
+
const { blockhash } = await this.connection.getLatestBlockhash();
|
|
361
|
+
const message = new TransactionMessage({
|
|
362
|
+
payerKey: stealthAddress,
|
|
363
|
+
// Stealth pays the fee
|
|
364
|
+
recentBlockhash: blockhash,
|
|
365
|
+
instructions: [ix]
|
|
366
|
+
}).compileToV0Message();
|
|
367
|
+
const tx = new VersionedTransaction(message);
|
|
368
|
+
tx.sign([stealthKeypair]);
|
|
369
|
+
const sig = await this.connection.sendRawTransaction(tx.serialize());
|
|
370
|
+
await this.connection.confirmTransaction(sig, "confirmed");
|
|
371
|
+
return { transaction: tx, signature: sig };
|
|
372
|
+
}
|
|
310
373
|
// --- 3. Core Engine (Internal Helpers) ---
|
|
311
374
|
async buildTransaction(payer, instructions, version = "v0") {
|
|
312
375
|
const { blockhash } = await this.connection.getLatestBlockhash();
|