Commit dc345a6b3c23a49b736a6ae85494f4e5be6fb17d
U256: support padding output to other than 32 bytes
Alex Beregszaszi committed on 8/16/2016, 10:33:25 PMParent: ed7fedaaf934add17793bd10403532159cd34f21
Files changed
u256.js | changed |
u256.js | ||
---|---|---|
@@ -16,10 +16,13 @@ | ||
16 | 16 | } |
17 | 17 | return this._value.toString(radix) |
18 | 18 | } |
19 | 19 | |
20 | - toBuffer () { | |
21 | - return this._value.toBuffer('le', 32) | |
20 | + toBuffer (width) { | |
21 | + if (width <= 0 || width > 32) { | |
22 | + throw new Error('Invalid U256 width') | |
23 | + } | |
24 | + return this._value.toBuffer('le', width || 32) | |
22 | 25 | } |
23 | 26 | |
24 | 27 | sub (u256) { |
25 | 28 | return new U256(this._value.sub(u256._value)) |
Built with git-ssb-web