Skip to content

Commit

Permalink
check v before ecrecover (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannbarbie authored May 9, 2019
1 parent d0c22a4 commit 95f5263
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ export default class Input {
const r = buf.slice(33 + off, 65 + off);
const s = buf.slice(65 + off, 97 + off);
const v = buf.readUInt8(97 + off);
const signer = Input.recoverSignerAddress(sigHashBuf, v, r, s);

input.setSig(r, s, v, signer);
if (v > 0) {
const signer = Input.recoverSignerAddress(sigHashBuf, v, r, s);
input.setSig(r, s, v, signer);
}

return input;
}
Expand Down
17 changes: 17 additions & 0 deletions lib/transaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ describe('transactions', () => {
assert.equal(condition.inputs[1].signer, ADDR);
});

it('should allow to create and parse spending condition tx without signed input.', () => {
const prevTx = '0x7777777777777777777777777777777777777777777777777777777777777777';
const value = BigInt('99000000');
const color = 1337;
const condition = Tx.spendCond(
[new Input({
prevout: new Outpoint(prevTx, 0),
script: '0x123456',
}), new Input({
prevout: new Outpoint(prevTx, 1),
})
], [new Output(value, ADDR, color)],
);
condition.inputs[0].setMsgData('0xabcdef');
assert.deepEqual(Tx.fromRaw(condition.toRaw()), condition);
});

it('should allow to create and parse spending condition with different tokens', () => {
const prevTx = '0x7777777777777777777777777777777777777777777777777777777777777777';
const NFT_COLOR_BASE = 32769; // 2^15 + 1
Expand Down

0 comments on commit 95f5263

Please sign in to comment.