@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/dist/cjs/package.json +1 -1
- package/dist/cjs/src/script/Spend.js +7 -2
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/script/Spend.js +7 -2
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/dist/umd/bundle.js.map +1 -1
- package/package.json +1 -1
- package/src/script/Spend.ts +8 -2
- package/src/script/__tests/Spend.test.ts +10 -0
package/package.json
CHANGED
package/src/script/Spend.ts
CHANGED
|
@@ -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)
|
|
741
|
-
|
|
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()
|