diff --git a/lib/input.js b/lib/input.js index 75f90ba..3e1d0f5 100644 --- a/lib/input.js +++ b/lib/input.js @@ -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; } diff --git a/lib/transaction.spec.js b/lib/transaction.spec.js index 55a9abd..3f0d05c 100644 --- a/lib/transaction.spec.js +++ b/lib/transaction.spec.js @@ -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