@@ -89,7 +89,7 @@ export function getSeenAttDataKeyElectra(electraAttestationBytes: Uint8Array): A
89
89
return null ;
90
90
}
91
91
92
- return Buffer . from ( electraAttestationBytes . subarray ( startIndex , startIndex + seenKeyLength ) ) . toString ( "base64" ) ;
92
+ return toBase64 ( electraAttestationBytes . subarray ( startIndex , startIndex + seenKeyLength ) ) ;
93
93
}
94
94
95
95
/**
@@ -102,9 +102,7 @@ export function getSeenAttDataKeyPhase0(data: Uint8Array): AttDataBase64 | null
102
102
}
103
103
104
104
// base64 is a bit efficient than hex
105
- return Buffer . from ( data . subarray ( VARIABLE_FIELD_OFFSET , VARIABLE_FIELD_OFFSET + ATTESTATION_DATA_SIZE ) ) . toString (
106
- "base64"
107
- ) ;
105
+ return toBase64 ( data . subarray ( VARIABLE_FIELD_OFFSET , VARIABLE_FIELD_OFFSET + ATTESTATION_DATA_SIZE ) ) ;
108
106
}
109
107
110
108
/**
@@ -229,7 +227,7 @@ export function getSeenAttDataKeyFromSignedAggregateAndProofElectra(data: Uint8A
229
227
}
230
228
231
229
// base64 is a bit efficient than hex
232
- return Buffer . from ( data . subarray ( startIndex , endIndex ) ) . toString ( "base64" ) ;
230
+ return toBase64 ( data . subarray ( startIndex , endIndex ) ) ;
233
231
}
234
232
235
233
/**
@@ -242,12 +240,12 @@ export function getSeenAttDataKeyFromSignedAggregateAndProofPhase0(data: Uint8Ar
242
240
}
243
241
244
242
// base64 is a bit efficient than hex
245
- return Buffer . from (
243
+ return toBase64 (
246
244
data . subarray (
247
245
SIGNED_AGGREGATE_AND_PROOF_SLOT_OFFSET ,
248
246
SIGNED_AGGREGATE_AND_PROOF_SLOT_OFFSET + ATTESTATION_DATA_SIZE
249
247
)
250
- ) . toString ( "base64" ) ;
248
+ ) ;
251
249
}
252
250
253
251
/**
@@ -301,3 +299,7 @@ function getSlotFromOffset(data: Uint8Array, offset: number): Slot {
301
299
// Read only the first 4 bytes of Slot, max value is 4,294,967,295 will be reached 1634 years after genesis
302
300
return dv . getUint32 ( offset , true ) ;
303
301
}
302
+
303
+ function toBase64 ( data : Uint8Array ) : string {
304
+ return Buffer . from ( data . buffer , data . byteOffset , data . byteLength ) . toString ( "base64" ) ;
305
+ }
0 commit comments