@@ -110,8 +110,9 @@ export function isAssertionConfig(obj: unknown): obj is AssertionConfig {
110110 */
111111export async function verify (
112112 thiz : Assertion ,
113- aggregateHash : string ,
114- key : AssertionKey
113+ aggregateHash : Uint8Array ,
114+ key : AssertionKey ,
115+ isLegacyTDF : boolean
115116) : Promise < void > {
116117 let payload : AssertionPayload ;
117118 try {
@@ -126,14 +127,23 @@ export async function verify(
126127
127128 // Get the hash of the assertion
128129 const hashOfAssertion = await hash ( thiz ) ;
129- const combinedHash = aggregateHash + hashOfAssertion ;
130- const encodedHash = base64 . encode ( combinedHash ) ;
131130
132131 // check if assertionHash is same as hashOfAssertion
133132 if ( hashOfAssertion !== assertionHash ) {
134133 throw new IntegrityError ( 'Assertion hash mismatch' ) ;
135134 }
136135
136+ let encodedHash : string ;
137+ if ( isLegacyTDF ) {
138+ const aggregateHashAsStr = new TextDecoder ( 'utf-8' ) . decode ( aggregateHash ) ;
139+ const combinedHash = aggregateHashAsStr + hashOfAssertion ;
140+ encodedHash = base64 . encode ( combinedHash ) ;
141+ } else {
142+ const combinedHash = concatenateUint8Arrays ( aggregateHash ,
143+ new Uint8Array ( hex . decodeArrayBuffer ( assertionHash ) ) ) ;
144+ encodedHash = base64 . encodeArrayBuffer ( combinedHash ) ;
145+ }
146+
137147 // check if assertionSig is same as encodedHash
138148 if ( assertionSig !== encodedHash ) {
139149 throw new IntegrityError ( 'Failed integrity check on assertion signature' ) ;
@@ -144,7 +154,7 @@ export async function verify(
144154 * Creates an Assertion object with the specified properties.
145155 */
146156export async function CreateAssertion (
147- aggregateHash : string ,
157+ aggregateHash : Uint8Array ,
148158 assertionConfig : AssertionConfig
149159) : Promise < Assertion > {
150160 if ( ! assertionConfig . signingKey ) {
@@ -162,8 +172,8 @@ export async function CreateAssertion(
162172 } ;
163173
164174 const assertionHash = await hash ( a ) ;
165- const combinedHash = aggregateHash + assertionHash ;
166- const encodedHash = base64 . encode ( combinedHash ) ;
175+ const combinedHash = concatenateUint8Arrays ( aggregateHash , new Uint8Array ( hex . decodeArrayBuffer ( assertionHash ) ) ) ;
176+ const encodedHash = base64 . encodeArrayBuffer ( combinedHash ) ;
167177
168178 return await sign ( a , assertionHash , encodedHash , assertionConfig . signingKey ) ;
169179}
@@ -189,3 +199,13 @@ export type AssertionVerificationKeys = {
189199 DefaultKey ?: AssertionKey ;
190200 Keys : Record < string , AssertionKey > ;
191201} ;
202+
203+ function concatenateUint8Arrays ( array1 : Uint8Array , array2 : Uint8Array ) : Uint8Array {
204+ const combinedLength = array1 . length + array2 . length ;
205+ const combinedArray = new Uint8Array ( combinedLength ) ;
206+
207+ combinedArray . set ( array1 , 0 ) ;
208+ combinedArray . set ( array2 , array1 . length ) ;
209+
210+ return combinedArray ;
211+ }
0 commit comments