@shakesco/silent 1.0.7 → 1.0.9

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/README.md CHANGED
@@ -108,13 +108,10 @@ function main() {
108
108
  },
109
109
  ];
110
110
 
111
- const pubkeys = [
112
- "025c471f0e7d30d6f9095058bbaedaf13e1de67dbfcbe8328e6378d2a3bfb5cfd0",
113
- ];
114
- const UTXOPrivatekey = "";
111
+ const UTXOPrivatekey = ""; // sender private key
112
+
115
113
  const builder = new SilentPaymentBuilder({
116
114
  vinOutpoints: vinOutpoints,
117
- pubkeys: pubkeys,
118
115
  }).createOutputs(
119
116
  [
120
117
  new ECPrivateInfo(
@@ -158,6 +155,7 @@ function main() {
158
155
  const pubkeys = [
159
156
  "025c471f0e7d30d6f9095058bbaedaf13e1de67dbfcbe8328e6378d2a3bfb5cfd0",
160
157
  ];
158
+
161
159
  const search = new SilentPaymentBuilder({
162
160
  vinOutpoints: vinOutpoints,
163
161
  pubkeys: pubkeys,
@@ -169,9 +167,7 @@ function main() {
169
167
  ),
170
168
  ]);
171
169
 
172
- console.log(
173
- search[builder[keys.toAddress()][0].address.pubkey.toString("hex")].output
174
- );
170
+ console.log(search);
175
171
  }
176
172
  ```
177
173
 
@@ -199,6 +195,7 @@ function main() {
199
195
  const pubkeys = [
200
196
  "025c471f0e7d30d6f9095058bbaedaf13e1de67dbfcbe8328e6378d2a3bfb5cfd0",
201
197
  ];
198
+
202
199
  const private_key = new SilentPaymentBuilder({
203
200
  vinOutpoints: vinOutpoints,
204
201
  pubkeys: pubkeys,
@@ -300,27 +300,37 @@ class SilentPaymentBuilder {
300
300
  */
301
301
 
302
302
  spendOutputs(b_scan, b_spend) {
303
- const tweakDataForRecipient = this.receiverTweak
304
- ? ec.keyFromPublic(this.receiverTweak).getPublic()
305
- : tweakMulPublic(
306
- ec.keyFromPublic(Buffer.from(this.A_sum, "hex")).getPublic(),
307
- this.inputHash
308
- );
309
- const ecdhSharedSecret = tweakMulPublic(tweakDataForRecipient, b_scan);
303
+ let tweakScalar;
304
+
305
+ if (this.receiverTweak) {
306
+ // The tweak is already the t_k scalar value, use it directly as BigInt
307
+ tweakScalar = new BN(Buffer.from(this.receiverTweak, "hex"));
308
+ } else {
309
+ // Calculate the tweak from inputs
310
+ const tweakDataForRecipient = tweakMulPublic(
311
+ ec.keyFromPublic(Buffer.from(this.A_sum, "hex")).getPublic(),
312
+ this.inputHash
313
+ );
310
314
 
311
- var k = 0;
315
+ const ecdhSharedSecret = tweakMulPublic(tweakDataForRecipient, b_scan);
312
316
 
313
- const t_k = taggedHash(
314
- Buffer.concat([
315
- Buffer.from(ecdhSharedSecret.encodeCompressed(), "array"),
316
- Buffer.from(toBytes(BigInt(k), 4), "array"),
317
- ]),
318
- "BIP0352/SharedSecret"
319
- );
317
+ var k = 0;
318
+
319
+ const t_k = taggedHash(
320
+ Buffer.concat([
321
+ Buffer.from(ecdhSharedSecret.encodeCompressed(), "array"),
322
+ Buffer.from(toBytes(BigInt(k), 4), "array"),
323
+ ]),
324
+ "BIP0352/SharedSecret"
325
+ );
326
+
327
+ tweakScalar = new BN(t_k);
328
+ }
320
329
 
330
+ // Apply the tweak to get the private key
321
331
  const p_k = tweakAddPrivate(
322
332
  ec.keyFromPrivate(b_spend.toString("hex")),
323
- new BN(t_k)
333
+ tweakScalar
324
334
  );
325
335
 
326
336
  return p_k.getPrivate().toString("hex");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shakesco/silent",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Bitcoin Silent Payments",
5
5
  "main": "index.js",
6
6
  "author": "Shawn Kimtai",