Commit 049bedec5fd1ee9c75b10b89b9254d6d5ecaa39c
Address: support instantiation from Uint8Array (for data coming from WASM)
Alex Beregszaszi committed on 8/16/2016, 11:12:39 PMParent: ef9a2818017021a22cd85f062af777205c35969a
Files changed
address.js | changed |
address.js | ||
---|---|---|
@@ -7,18 +7,18 @@ | ||
7 | 7 | this._value = new Buffer(value._value) |
8 | 8 | return |
9 | 9 | } |
10 | 10 | |
11 | - if (typeof value !== 'string') { | |
11 | + if (value instanceof Uint8Array) { | |
12 | + this._value = new Buffer(value) | |
13 | + } else if (typeof value !== 'string') { | |
12 | 14 | throw new Error('Invalid input to address') |
13 | - } | |
14 | - | |
15 | - if (!ethUtils.isHexPrefixed(value)) { | |
15 | + } else if (!ethUtils.isHexPrefixed(value)) { | |
16 | 16 | throw new Error('Invalid address format') |
17 | + } else { | |
18 | + this._value = new Buffer(ethUtils.stripHexPrefix(value), 'hex') | |
17 | 19 | } |
18 | 20 | |
19 | - this._value = new Buffer(ethUtils.stripHexPrefix(value), 'hex') | |
20 | - | |
21 | 21 | if (this._value.length !== 20) { |
22 | 22 | throw new Error('Invalid address length') |
23 | 23 | } |
24 | 24 | } |
Built with git-ssb-web