diff --git a/package-lock.json b/package-lock.json index 5f43c34..be8cf12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bolt11", - "version": "1.4.0", + "version": "1.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 297dd4a..8bf69ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bolt11", - "version": "1.4.0", + "version": "1.4.1", "description": "A library for encoding and decoding lightning network payment requests as defined in [BOLT #11](https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md).", "main": "payreq.js", "types": "payreq.d.ts", diff --git a/payreq.js b/payreq.js index ab1ff9c..f22147f 100644 --- a/payreq.js +++ b/payreq.js @@ -772,6 +772,9 @@ function encode (inputData, addDefaults) { // timestamp converted to 5 bit number array (left padded with 0 bits, NOT right padded) const timestampWords = intBEToWords(data.timestamp) + while (timestampWords.length < 7) { + timestampWords.unshift(0) + } const tags = data.tags let tagWords = [] diff --git a/test/index.js b/test/index.js index 9cecf4e..54819ad 100644 --- a/test/index.js +++ b/test/index.js @@ -295,3 +295,31 @@ tape('can decode unknown network payment request', (t) => { t.ok(decoded.complete === true) t.end() }) + +tape('can encode and decode small timestamp', (t) => { + const encoded = lnpayreq.encode({ + satoshis: 12, + timestamp: 1, + network: { + bech32: 'tb', + pubKeyHash: 111, + scriptHash: 196, + validWitnessVersions: [0, 1] + }, + tags: [ + { + tagName: 'payment_hash', + data: '0001020304050607080900010203040506070809000102030405060708090102' + } + ] + }) + + const signedData = lnpayreq.sign(encoded, fixtures.privateKey) + + const decoded = lnpayreq.decode(signedData.paymentRequest) + delete decoded.paymentRequest + // This would fail because of corruption before fixing timestamp encoding + const reEncoded = lnpayreq.encode(decoded) + t.same(reEncoded.paymentRequest, signedData.paymentRequest) + t.end() +})