@bsv/sdk 2.0.6 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -737,8 +737,14 @@ export default class Spend {
737
737
  }
738
738
  bn1 = new BigNumber(buf1)
739
739
  let shiftedBn: BigNumber
740
- if (currentOpcode === OP.OP_LSHIFT) shiftedBn = bn1.ushln(shiftBits)
741
- else shiftedBn = bn1.ushrn(shiftBits)
740
+ if (currentOpcode === OP.OP_LSHIFT) {
741
+ shiftedBn = bn1.ushln(shiftBits)
742
+ // Truncate to original byte length by masking off the overflow MSBs
743
+ const mask = new BigNumber(1).ushln(buf1.length * 8).isubn(1)
744
+ shiftedBn = shiftedBn.iand(mask)
745
+ } else {
746
+ shiftedBn = bn1.ushrn(shiftBits)
747
+ }
742
748
 
743
749
  const shiftedArr = shiftedBn.toArray('be', buf1.length)
744
750
  this.pushStack(shiftedArr)
@@ -266,6 +266,16 @@ describe('Spend', () => {
266
266
  expect(spend.validate()).toBe(true)
267
267
  })
268
268
 
269
+ it('truncates overflow MSBs on OP_LSHIFT (0x6A09E667 << 30 === 0xC0000000)', () => {
270
+ // 0x6A09E667 left-shifted by 30 bits produces 0x1A827999C0000000 (8 bytes),
271
+ // but must be truncated to the original 4 bytes → 0xC0000000
272
+ const spend = createSpendWithPushes(
273
+ '1e OP_LSHIFT c0000000 OP_EQUAL',
274
+ [[0x6a, 0x09, 0xe6, 0x67]]
275
+ )
276
+ expect(spend.validate()).toBe(true)
277
+ })
278
+
269
279
  it('Successfully validates an R-puzzle spend (HASH256)', async () => {
270
280
  const k = new PrivateKey(2)
271
281
  const c = new Curve()