Skip to content

Commit

Permalink
tapScriptSig: complete leafHash handling
Browse files Browse the repository at this point in the history
  • Loading branch information
reardencode committed Apr 15, 2022
1 parent f67ad39 commit e058890
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/converter/input/tapScriptSig.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { KeyValue, TapScriptSig } from '../../interfaces';
export declare function decode(keyVal: KeyValue): TapScriptSig;
export declare function encode(tSig: TapScriptSig): KeyValue;
export declare const expected = "{ pubkey: Buffer; signature: Buffer; }";
export declare const expected = "{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }";
export declare function check(data: any): data is TapScriptSig;
export declare function canAddToArray(array: TapScriptSig[], item: TapScriptSig, dupeSet: Set<string>): boolean;
11 changes: 8 additions & 3 deletions src/lib/converter/input/tapScriptSig.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function encode(tSig) {
};
}
exports.encode = encode;
exports.expected = '{ pubkey: Buffer; signature: Buffer; }';
exports.expected = '{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }';
function check(data) {
return (
Buffer.isBuffer(data.pubkey) &&
Expand All @@ -50,9 +50,14 @@ function check(data) {
}
exports.check = check;
function canAddToArray(array, item, dupeSet) {
const dupeString = item.pubkey.toString('hex');
const dupeString =
item.pubkey.toString('hex') + item.leafHash.toString('hex');
if (dupeSet.has(dupeString)) return false;
dupeSet.add(dupeString);
return array.filter(v => v.pubkey.equals(item.pubkey)).length === 0;
return (
array.filter(
v => v.pubkey.equals(item.pubkey) && v.leafHash.equals(item.leafHash),
).length === 0
);
}
exports.canAddToArray = canAddToArray;
12 changes: 9 additions & 3 deletions ts_src/lib/converter/input/tapScriptSig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export function encode(tSig: TapScriptSig): KeyValue {
};
}

export const expected = '{ pubkey: Buffer; signature: Buffer; }';
export const expected =
'{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }';
export function check(data: any): data is TapScriptSig {
return (
Buffer.isBuffer(data.pubkey) &&
Expand All @@ -54,8 +55,13 @@ export function canAddToArray(
item: TapScriptSig,
dupeSet: Set<string>,
): boolean {
const dupeString = item.pubkey.toString('hex');
const dupeString =
item.pubkey.toString('hex') + item.leafHash.toString('hex');
if (dupeSet.has(dupeString)) return false;
dupeSet.add(dupeString);
return array.filter(v => v.pubkey.equals(item.pubkey)).length === 0;
return (
array.filter(
v => v.pubkey.equals(item.pubkey) && v.leafHash.equals(item.leafHash),
).length === 0
);
}

0 comments on commit e058890

Please sign in to comment.