@@ -103,30 +103,29 @@ export const expw = (a: internal.primitives.StubUint64Compat, b: internal.primit
103103 return toUint128 ( base ** exponent )
104104}
105105
106- export const extract = (
106+ type ExtractType = ( ( a : internal . primitives . StubBytesCompat , b : internal . primitives . StubUint64Compat ) => bytes ) &
107+ ( ( a : internal . primitives . StubBytesCompat , b : internal . primitives . StubUint64Compat , c : internal . primitives . StubUint64Compat ) => bytes )
108+ export const extract = ( (
107109 a : internal . primitives . StubBytesCompat ,
108110 b : internal . primitives . StubUint64Compat ,
109- c : internal . primitives . StubUint64Compat ,
111+ c ? : internal . primitives . StubUint64Compat ,
110112) : bytes => {
111113 const bytesValue = internal . primitives . BytesCls . fromCompat ( a )
112114 const bytesLength = bytesValue . length . asBigInt ( )
113115
114116 const start = internal . primitives . Uint64Cls . fromCompat ( b ) . asBigInt ( )
115- const length = internal . primitives . Uint64Cls . fromCompat ( c ) . asBigInt ( )
116- let end = start + length
117- if ( ( typeof b === 'number' || typeof b === 'bigint' ) && ( typeof c === 'number' || typeof c === 'bigint' ) && length === 0n ) {
118- end = bytesLength
119- }
117+ const length = c !== undefined ? internal . primitives . Uint64Cls . fromCompat ( c ) . asBigInt ( ) : undefined
118+ const end = length !== undefined ? start + length : undefined
120119
121120 if ( start > bytesLength ) {
122121 internal . errors . codeError ( `extraction start ${ start } is beyond length` )
123122 }
124- if ( end > bytesLength ) {
123+ if ( end !== undefined && end > bytesLength ) {
125124 internal . errors . codeError ( `extraction end ${ end } is beyond length` )
126125 }
127126
128127 return bytesValue . slice ( start , end ) . asAlgoTs ( )
129- }
128+ } ) as ExtractType
130129
131130export const extractUint16 = ( a : internal . primitives . StubBytesCompat , b : internal . primitives . StubUint64Compat ) : uint64 => {
132131 const result = extract ( a , b , 2 )
0 commit comments