@@ -2,7 +2,7 @@ import { commons, universal, v1, v2 } from '@0xsequence/core'
22import { migrator } from '@0xsequence/migration'
33import { ethers } from 'ethers'
44import { ConfigTracker , PresignedConfig , PresignedConfigLink , SignerSignature } from '../../tracker'
5- import { Sessions , SignatureType , Transaction } from './sessions.gen'
5+ import { Sessions , SignatureType , Transaction , SignerSignature as SessionsSignerSignature } from './sessions.gen'
66
77export class RemoteConfigTracker implements ConfigTracker , migrator . PresignedMigrationTracker {
88 private readonly sessions : Sessions
@@ -58,36 +58,27 @@ export class RemoteConfigTracker implements ConfigTracker, migrator.PresignedMig
5858 chainId : ethers . BigNumberish
5959 signatures : string [ ] | SignerSignature [ ]
6060 } ) : Promise < void > {
61- let filteredSignatures = args . signatures
62- if ( this . onlyRecoverable ) {
63- filteredSignatures = filteredSignatures . filter ( signature => {
64- if ( typeof signature === 'string' ) {
65- return commons . signer . canRecover ( signature )
66- } else {
67- return ! ! signature . address
61+ const signerSignatures : SessionsSignerSignature [ ] = [ ]
62+ for ( const signature of args . signatures ) {
63+ if ( typeof signature === 'string' ) {
64+ if ( ! this . onlyRecoverable || commons . signer . canRecover ( signature ) ) {
65+ signerSignatures . push ( { signature } )
6866 }
69- } ) as string [ ] | SignerSignature [ ]
67+ } else {
68+ signerSignatures . push ( {
69+ signer : signature . address ,
70+ signature : signature . signature ,
71+ referenceChainID : signature . referenceChainId ?. toString ( )
72+ } )
73+ }
7074 }
7175
72- if ( filteredSignatures . some ( sig => typeof sig === 'string' ) && filteredSignatures . some ( sig => typeof sig === 'object' ) ) {
73- throw new Error ( 'Signatures must be string[] | SignerSignature[]' )
74- }
75- if ( filteredSignatures . length === 0 || typeof args . signatures [ 0 ] === 'string' ) {
76- await this . sessions . saveSignerSignatures ( {
77- wallet : args . wallet ,
78- digest : args . digest ,
79- chainID : numberString ( args . chainId ) ,
80- signatures : filteredSignatures as string [ ]
81- } )
82- } else {
83- await this . sessions . saveSignerSignatures2 ( {
84- wallet : args . wallet ,
85- digest : args . digest ,
86- chainID : numberString ( args . chainId ) ,
87- // Rename "address" to "signer"
88- signatures : ( filteredSignatures as SignerSignature [ ] ) . map ( ( { address, signature, referenceChainId } ) => ( { signer : address , signature, referenceChainId : referenceChainId ?. toString ( ) } ) )
89- } )
90- }
76+ await this . sessions . saveSignerSignatures2 ( {
77+ wallet : args . wallet ,
78+ digest : args . digest ,
79+ chainID : numberString ( args . chainId ) ,
80+ signatures : signerSignatures
81+ } )
9182 }
9283
9384 async configOfImageHash ( args : { imageHash : string } ) : Promise < commons . config . Config | undefined > {
0 commit comments