@@ -239,8 +239,8 @@ public struct Utilities {
239
239
/// Takes a hash of some message. What message is hashed should be checked by user separately.
240
240
public static func hashECRecover( hash: Data , signature: Data ) -> EthereumAddress ? {
241
241
if signature. count != 65 { return nil }
242
- let rData = signature [ 0 ..< 32 ] . bytes
243
- let sData = signature [ 32 ..< 64 ] . bytes
242
+ let rData : [ UInt8 ] = Array ( signature. prefix ( 32 ) )
243
+ let sData : [ UInt8 ] = Array ( signature. dropFirst ( 32 ) . prefix ( 32 ) )
244
244
var vData = signature [ 64 ]
245
245
if vData >= 27 && vData <= 30 {
246
246
vData -= 27
@@ -274,11 +274,11 @@ public struct Utilities {
274
274
275
275
/// Unmarshals a 65 byte recoverable EC signature into internal structure.
276
276
static func unmarshalSignature( signatureData: Data ) -> SECP256K1 . UnmarshaledSignature ? {
277
- if signatureData. count != 65 { return nil }
278
- let bytes = signatureData. bytes
279
- let r = Array ( bytes [ 0 ..< 32 ] )
280
- let s = Array ( bytes [ 32 ..< 64 ] )
281
- return SECP256K1 . UnmarshaledSignature ( v: bytes [ 64 ] , r: Data ( r ) , s: Data ( s ) )
277
+ guard signatureData. count == 65 else { return nil }
278
+ let rSlice = signatureData. prefix ( 32 )
279
+ let sSlice = signatureData . dropFirst ( 32 ) . prefix ( 32 )
280
+ let v = signatureData [ 64 ]
281
+ return SECP256K1 . UnmarshaledSignature ( v: v , r: Data ( rSlice ) , s: Data ( sSlice ) )
282
282
}
283
283
284
284
/// Marshals the V, R and S signature parameters into a 65 byte recoverable EC signature.
0 commit comments