@@ -223,11 +223,11 @@ export class InvalidSignatureLeafError extends Error {
223
223
}
224
224
}
225
225
226
- // Signature validity is only checked if provider is provided
227
226
export async function recoverTopology (
228
227
unrecovered : UnrecoveredTopology ,
229
228
subdigest : string ,
230
- provider ?: ethers . Provider
229
+ provider ?: ethers . Provider ,
230
+ validateBehavior : 'ignore' | 'throw' = 'throw'
231
231
) : Promise < Topology > {
232
232
if ( isUnrecoveredNode ( unrecovered ) ) {
233
233
const [ left , right ] = await Promise . all ( [
@@ -252,7 +252,11 @@ export async function recoverTopology(
252
252
throw new Error ( 'Dynamic signature leaf without address' )
253
253
}
254
254
255
- if ( provider ) {
255
+ if ( validateBehavior !== 'ignore' ) {
256
+ if ( ! provider ) {
257
+ throw new Error ( 'Provider is required to validate EIP1271 signatures' )
258
+ }
259
+
256
260
const isValid = await isValidSignature ( unrecovered . address , subdigest , unrecovered . signature , provider )
257
261
if ( ! isValid ) {
258
262
throw new InvalidSignatureLeafError ( unrecovered )
@@ -601,7 +605,8 @@ export function setImageHashStruct(imageHash: string) {
601
605
export async function recoverSignature (
602
606
signature : UnrecoveredSignature | UnrecoveredChainedSignature ,
603
607
payload : base . SignedPayload | { subdigest : string } ,
604
- provider ?: ethers . Provider
608
+ provider ?: ethers . Provider ,
609
+ validateBehavior : 'ignore' | 'throw' = 'throw'
605
610
) : Promise < Signature | ChainedSignature > {
606
611
const signedPayload = ( payload as { subdigest : string } ) . subdigest === undefined ? ( payload as base . SignedPayload ) : undefined
607
612
@@ -613,7 +618,7 @@ export async function recoverSignature(
613
618
const subdigest = signedPayload ? base . subdigestOf ( signedPayload ) : ( payload as { subdigest : string } ) . subdigest
614
619
615
620
if ( ! isUnrecoveredChainedSignature ( signature ) ) {
616
- const tree = await recoverTopology ( signature . decoded . tree , subdigest , provider )
621
+ const tree = await recoverTopology ( signature . decoded . tree , subdigest , provider , validateBehavior )
617
622
return { version : 2 , type : signature . type , subdigest, config : { version : 2 , ...signature . decoded , tree } }
618
623
}
619
624
@@ -628,7 +633,7 @@ export async function recoverSignature(
628
633
// NOTICE: Remove the suffix from the "first" siganture
629
634
// otherwise we recurse infinitely
630
635
for ( const sig of [ { ...signature , suffix : undefined } , ...signature . suffix ] ) {
631
- const recovered = await recoverSignature ( sig , mutatedPayload , provider )
636
+ const recovered = await recoverSignature ( sig , mutatedPayload , provider , validateBehavior )
632
637
result . unshift ( recovered )
633
638
634
639
const nextMessage = setImageHashStruct ( imageHash ( deepestConfigOfSignature ( recovered ) ) )
@@ -930,9 +935,10 @@ export const SignatureCoder: base.SignatureCoder<WalletConfig, Signature, Unreco
930
935
recover : (
931
936
data : UnrecoveredSignature | UnrecoveredChainedSignature ,
932
937
payload : base . SignedPayload ,
933
- provider ?: ethers . Provider
938
+ provider ?: ethers . Provider ,
939
+ validateBehavior : 'ignore' | 'throw' = 'throw'
934
940
) : Promise < Signature > => {
935
- return recoverSignature ( data , payload , provider )
941
+ return recoverSignature ( data , payload , provider , validateBehavior )
936
942
} ,
937
943
938
944
encodeSigners : (
0 commit comments