File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
packages/core/src/vcdm/encoding/rlp Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,13 @@ class RLP implements VeChainDataModel<RLP> {
13
13
protected constructor ( data : RLPInput ) ;
14
14
protected constructor ( data : Uint8Array ) ;
15
15
protected constructor ( data : RLPInput | Uint8Array ) {
16
- this . decoded =
17
- data instanceof Uint8Array ? EthereumjsRLP . decode ( data ) : data ;
18
- this . encoded =
19
- data instanceof Uint8Array ? data : EthereumjsRLP . encode ( data ) ;
16
+ // ArrayBuffer.isView so we support https://github.com/vitest-dev/vitest/issues/5183
17
+ this . decoded = ArrayBuffer . isView ( data )
18
+ ? EthereumjsRLP . decode ( data )
19
+ : data ;
20
+ this . encoded = ArrayBuffer . isView ( data )
21
+ ? data
22
+ : EthereumjsRLP . encode ( data ) ;
20
23
}
21
24
22
25
/**
@@ -214,7 +217,8 @@ class RLP implements VeChainDataModel<RLP> {
214
217
215
218
// ScalarKind: Direct decoding using the provided method.
216
219
if ( kind instanceof ScalarKind ) {
217
- if ( ! ( packed instanceof Uint8Array ) ) {
220
+ // ArrayBuffer.isView so we support https://github.com/vitest-dev/vitest/issues/5183
221
+ if ( ! ArrayBuffer . isView ( packed ) ) {
218
222
throw new InvalidRLP (
219
223
'RLP.unpackData()' ,
220
224
`Unpacking error: Expected data type is Uint8Array.` ,
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ class BufferKind extends ScalarKind {
17
17
*/
18
18
public data ( data : RLPInput , context : string ) : DataOutput {
19
19
// Ensure that the data is indeed a Buffer before encoding.
20
- if ( ! ( data instanceof Uint8Array ) )
20
+ // ArrayBuffer.isView so we support https://github.com/vitest-dev/vitest/issues/5183
21
+ if ( ! ArrayBuffer . isView ( data ) ) {
21
22
throw new InvalidRLP (
22
23
'BufferKind.data()' ,
23
24
`Validation error: Expected a Uint8Array type in ${ context } .` ,
@@ -28,6 +29,7 @@ class BufferKind extends ScalarKind {
28
29
}
29
30
}
30
31
) ;
32
+ }
31
33
32
34
return {
33
35
encode : ( ) => data // Data is already a Buffer, so return as-is.
You can’t perform that action at this time.
0 commit comments