Commit ef9a2818017021a22cd85f062af777205c35969a
U256: support instantiation from Uint8Array (for data coming from WASM)
Alex Beregszaszi committed on 8/16/2016, 11:12:39 PMParent: 6c9a7f1801d055fef0ca11b55a4047a6360bccd6
Files changed
u256.js | changed |
u256.js | ||
---|---|---|
@@ -2,9 +2,12 @@ | ||
2 | 2 | const ethUtils = require('ethereumjs-util') |
3 | 3 | |
4 | 4 | module.exports = class U256 { |
5 | 5 | constructor (value) { |
6 | - if ((typeof value === 'string') && ethUtils.isHexPrefixed(value)) { | |
6 | + // This is the case when data is copied from WASM | |
7 | + if (value instanceof Uint8Array) { | |
8 | + this._value = new BN(value, 16, 'le') | |
9 | + } else if ((typeof value === 'string') && ethUtils.isHexPrefixed(value)) { | |
7 | 10 | this._value = new BN(value, 16) |
8 | 11 | } else { |
9 | 12 | this._value = new BN(value, 10) |
10 | 13 | } |
Built with git-ssb-web