@adelos/sdk 0.1.11 → 0.1.12

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 CHANGED
@@ -115,6 +115,12 @@ declare function generateStealthAddress(recipientMetaPk: Uint8Array): {
115
115
  sharedSecret: Uint8Array<ArrayBufferLike>;
116
116
  memo: string;
117
117
  };
118
+ /**
119
+ * Sign a message using a raw private SCALAR (not seed).
120
+ * Required because derived stealth keys are scalars, not seeds.
121
+ * Uses a random nonce for R, valid for Ed25519.
122
+ */
123
+ declare function signWithScalar(message: Uint8Array, scalarBytes: Uint8Array): Promise<Uint8Array>;
118
124
 
119
125
  /**
120
126
  * Adelos Indexer - Privacy-Preserving Transaction Scanner
@@ -180,4 +186,4 @@ declare class AdelosSDK {
180
186
  sendAndConfirm(signedTx: Transaction | VersionedTransaction): Promise<string>;
181
187
  }
182
188
 
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 };
189
+ 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, signWithScalar };
package/dist/index.d.ts CHANGED
@@ -115,6 +115,12 @@ declare function generateStealthAddress(recipientMetaPk: Uint8Array): {
115
115
  sharedSecret: Uint8Array<ArrayBufferLike>;
116
116
  memo: string;
117
117
  };
118
+ /**
119
+ * Sign a message using a raw private SCALAR (not seed).
120
+ * Required because derived stealth keys are scalars, not seeds.
121
+ * Uses a random nonce for R, valid for Ed25519.
122
+ */
123
+ declare function signWithScalar(message: Uint8Array, scalarBytes: Uint8Array): Promise<Uint8Array>;
118
124
 
119
125
  /**
120
126
  * Adelos Indexer - Privacy-Preserving Transaction Scanner
@@ -180,4 +186,4 @@ declare class AdelosSDK {
180
186
  sendAndConfirm(signedTx: Transaction | VersionedTransaction): Promise<string>;
181
187
  }
182
188
 
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 };
189
+ 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, signWithScalar };
package/dist/index.js CHANGED
@@ -53,7 +53,8 @@ __export(index_exports, {
53
53
  hexToBytes: () => hexToBytes,
54
54
  isValidMetaPubkey: () => isValidMetaPubkey,
55
55
  parseStealthMemo: () => parseStealthMemo,
56
- recoverStealthSecretKey: () => recoverStealthSecretKey
56
+ recoverStealthSecretKey: () => recoverStealthSecretKey,
57
+ signWithScalar: () => signWithScalar
57
58
  });
58
59
  module.exports = __toCommonJS(index_exports);
59
60
  var import_web33 = require("@solana/web3.js");
@@ -186,6 +187,27 @@ function generateStealthAddress(recipientMetaPk) {
186
187
  const memo = generateStealthMemo(ephemeralKeypair.publicKey);
187
188
  return { stealthPubkey, ephemeralKeypair, sharedSecret, memo };
188
189
  }
190
+ async function signWithScalar(message, scalarBytes) {
191
+ const scalar = toScalar(scalarBytes);
192
+ const pubPoint = ed.ExtendedPoint.BASE.multiply(scalar);
193
+ const pubBytes = pubPoint.toRawBytes();
194
+ const rBytes = ed.utils.randomPrivateKey();
195
+ const rScalar = toScalar(rBytes);
196
+ const R = ed.ExtendedPoint.BASE.multiply(rScalar);
197
+ const RBytes = R.toRawBytes();
198
+ const content = new Uint8Array(RBytes.length + pubBytes.length + message.length);
199
+ content.set(RBytes);
200
+ content.set(pubBytes, RBytes.length);
201
+ content.set(message, RBytes.length + pubBytes.length);
202
+ const hram = (0, import_sha512.sha512)(content);
203
+ const k = ed.etc.mod(BigInt("0x" + bytesToHex(hram)), ed.CURVE.n);
204
+ const S = ed.etc.mod(rScalar + k * scalar, ed.CURVE.n);
205
+ const SBytes = hexToBytes(S.toString(16).padStart(64, "0"));
206
+ const signature = new Uint8Array(64);
207
+ signature.set(RBytes);
208
+ signature.set(SBytes, 32);
209
+ return signature;
210
+ }
189
211
 
190
212
  // src/logger.ts
191
213
  var debugMode = false;
@@ -396,11 +418,6 @@ var AdelosSDK = class {
396
418
  * @param amountLamports - Amount to withdraw in lamports (use BigInt)
397
419
  */
398
420
  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
421
  const ix = import_web33.SystemProgram.transfer({
405
422
  fromPubkey: stealthAddress,
406
423
  toPubkey: destination,
@@ -414,7 +431,9 @@ var AdelosSDK = class {
414
431
  instructions: [ix]
415
432
  }).compileToV0Message();
416
433
  const tx = new import_web33.VersionedTransaction(message);
417
- tx.sign([stealthKeypair]);
434
+ const serializedMessage = message.serialize();
435
+ const signature = await signWithScalar(serializedMessage, stealthSecretKey);
436
+ tx.addSignature(stealthAddress, Buffer.from(signature));
418
437
  const sig = await this.connection.sendRawTransaction(tx.serialize());
419
438
  await this.connection.confirmTransaction(sig, "confirmed");
420
439
  return { transaction: tx, signature: sig };
@@ -468,5 +487,6 @@ var AdelosSDK = class {
468
487
  hexToBytes,
469
488
  isValidMetaPubkey,
470
489
  parseStealthMemo,
471
- recoverStealthSecretKey
490
+ recoverStealthSecretKey,
491
+ signWithScalar
472
492
  });
package/dist/index.mjs CHANGED
@@ -137,6 +137,27 @@ function generateStealthAddress(recipientMetaPk) {
137
137
  const memo = generateStealthMemo(ephemeralKeypair.publicKey);
138
138
  return { stealthPubkey, ephemeralKeypair, sharedSecret, memo };
139
139
  }
140
+ async function signWithScalar(message, scalarBytes) {
141
+ const scalar = toScalar(scalarBytes);
142
+ const pubPoint = ed.ExtendedPoint.BASE.multiply(scalar);
143
+ const pubBytes = pubPoint.toRawBytes();
144
+ const rBytes = ed.utils.randomPrivateKey();
145
+ const rScalar = toScalar(rBytes);
146
+ const R = ed.ExtendedPoint.BASE.multiply(rScalar);
147
+ const RBytes = R.toRawBytes();
148
+ const content = new Uint8Array(RBytes.length + pubBytes.length + message.length);
149
+ content.set(RBytes);
150
+ content.set(pubBytes, RBytes.length);
151
+ content.set(message, RBytes.length + pubBytes.length);
152
+ const hram = sha512(content);
153
+ const k = ed.etc.mod(BigInt("0x" + bytesToHex(hram)), ed.CURVE.n);
154
+ const S = ed.etc.mod(rScalar + k * scalar, ed.CURVE.n);
155
+ const SBytes = hexToBytes(S.toString(16).padStart(64, "0"));
156
+ const signature = new Uint8Array(64);
157
+ signature.set(RBytes);
158
+ signature.set(SBytes, 32);
159
+ return signature;
160
+ }
140
161
 
141
162
  // src/logger.ts
142
163
  var debugMode = false;
@@ -347,11 +368,6 @@ var AdelosSDK = class {
347
368
  * @param amountLamports - Amount to withdraw in lamports (use BigInt)
348
369
  */
349
370
  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
371
  const ix = SystemProgram.transfer({
356
372
  fromPubkey: stealthAddress,
357
373
  toPubkey: destination,
@@ -365,7 +381,9 @@ var AdelosSDK = class {
365
381
  instructions: [ix]
366
382
  }).compileToV0Message();
367
383
  const tx = new VersionedTransaction(message);
368
- tx.sign([stealthKeypair]);
384
+ const serializedMessage = message.serialize();
385
+ const signature = await signWithScalar(serializedMessage, stealthSecretKey);
386
+ tx.addSignature(stealthAddress, Buffer.from(signature));
369
387
  const sig = await this.connection.sendRawTransaction(tx.serialize());
370
388
  await this.connection.confirmTransaction(sig, "confirmed");
371
389
  return { transaction: tx, signature: sig };
@@ -418,5 +436,6 @@ export {
418
436
  hexToBytes,
419
437
  isValidMetaPubkey,
420
438
  parseStealthMemo,
421
- recoverStealthSecretKey
439
+ recoverStealthSecretKey,
440
+ signWithScalar
422
441
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adelos/sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Adelos Protocol SDK - Privacy Stealth Transfers on Solana",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",