Skip to content

Commit

Permalink
feat: update scanning to match specification in BIP352
Browse files Browse the repository at this point in the history
Signed-off-by: Anmol Sharma <anmolsharma0234@gmail.com>
  • Loading branch information
theanmolsharma committed Mar 3, 2024
1 parent 77172c6 commit 3316c64
Show file tree
Hide file tree
Showing 3 changed files with 329 additions and 201 deletions.
14 changes: 7 additions & 7 deletions packages/core/src/scanning.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { serialiseUint32 } from './utility.ts';
import { createTaggedHash, serialiseUint32 } from './utility.ts';
import { LabelMap } from './interface.ts';
import secp256k1 from 'secp256k1';
import createHash from 'create-hash';
import { Buffer } from 'buffer';

// Handle additional label-related logic
Expand Down Expand Up @@ -78,13 +77,13 @@ export const scanOutputs = (
scanPrivateKey: Buffer,
spendPublicKey: Buffer,
sumOfInputPublicKeys: Buffer,
outpointHash: Buffer,
inputHash: Buffer,
outputs: Buffer[],
labels?: LabelMap,
): Map<string, Buffer> => {
const ecdhSecret = secp256k1.publicKeyTweakMul(
sumOfInputPublicKeys,
secp256k1.privateKeyTweakMul(scanPrivateKey, outpointHash),
secp256k1.privateKeyTweakMul(scanPrivateKey, inputHash),
true,
);

Expand All @@ -94,9 +93,10 @@ export const scanOutputs = (
let counterIncrement = 0;

do {
const tweak = createHash('sha256')
.update(Buffer.concat([ecdhSecret, serialiseUint32(n)]))
.digest();
const tweak = createTaggedHash(
'BIP0352/SharedSecret',
Buffer.concat([ecdhSecret, serialiseUint32(n)]),
);
counterIncrement = processTweak(
spendPublicKey,
tweak,
Expand Down
Loading

0 comments on commit 3316c64

Please sign in to comment.