Skip to content

Commit 5ce14ed

Browse files
Dargon789tolgahan-arikantaylanpincecorbanbrookgemini-code-assist[bot]
authored
2.3.7 (#131) (#132) (#239)
* 3.0.0-beta.10 (#237) * Fix apple auth scope (0xsequence#950) * Fix apple auth scope * Fix Apple auth scope test * 3.0.0-beta.7 * Update apple auth scope (0xsequence#951) * 3.0.0-beta.8 * dapp-client: export TransportMessage and MessageType * Adding eoa LoginMethod to dapp-client * 3.0.0-beta.9 * chore(dapp-client): re-export network/util helpers and add explicit session config helper * 3.0.0-beta.10 --------- Co-authored-by: tolgahan-arikan <tolgahan.arikan@gmail.com> Co-authored-by: Taylan Pince <taylanpince@gmail.com> Co-authored-by: Corban Riley <corbanbrook@gmail.com> * Update packages/wallet/dapp-client/src/utils/index.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com> * 3.0.0-beta.12 (#276) * fix(dapp-client): tighten transport message source validation * feat(dapp-client): cache signed calls from fee options * Add new userdata client (0xsequence#954) * Fix build error * 3.0.0-beta.10 * fix(dapp-client): remove _refreshExplicitSession use that causes blocked pop up * 3.0.0-beta.12 --------- Co-authored-by: Tolgahan Arikan <tolgahan.arikan@gmail.com> Co-authored-by: Ahmet Buğra Yiğiter <yigiterahmetbugra@gmail.com> Co-authored-by: Taylan Pince <taylanpince@gmail.com> * submodule lib/signals-implicit-mode submodule lib/signals-implicit-mode --------- Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com> Co-authored-by: tolgahan-arikan <tolgahan.arikan@gmail.com> Co-authored-by: Taylan Pince <taylanpince@gmail.com> Co-authored-by: Corban Riley <corbanbrook@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Ahmet Buğra Yiğiter <yigiterahmetbugra@gmail.com>
1 parent 588f2ba commit 5ce14ed

3 files changed

Lines changed: 56 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ yarn-error.log*
3838
*.pem
3939

4040
# Husky
41-
.husky/
41+
.husky/
42+
/lib/signals-implicit-mode/Counter
43+
/lib/signals-implicit-mode/lib/signals-implicit-mode

packages/wallet/dapp-client/src/ChainSessionManager.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export class ChainSessionManager {
6969
public loginMethod: LoginMethod | null = null
7070
public userEmail: string | null = null
7171
private guard?: GuardConfig
72+
private lastSignedCallCache?: {
73+
fingerprint: string
74+
signedCall: { to: Address.Address; data: Hex.Hex }
75+
createdAtMs: number
76+
}
7277

7378
/**
7479
* @param chainId The ID of the chain this manager is responsible for.
@@ -753,6 +758,14 @@ export class ChainSessionManager {
753758
}))
754759
try {
755760
const signedCall = await this._buildAndSignCalls(callsToSend)
761+
const fingerprint = this._fingerprintCalls(callsToSend)
762+
if (fingerprint) {
763+
this.lastSignedCallCache = {
764+
fingerprint,
765+
signedCall,
766+
createdAtMs: Date.now(),
767+
}
768+
}
756769
const feeOptions = await this.relayer.feeOptions(signedCall.to, this.chainId, callsToSend)
757770
return feeOptions.options
758771
} catch (err) {
@@ -809,7 +822,7 @@ export class ChainSessionManager {
809822
callsToSend.unshift(transferCall)
810823
}
811824
}
812-
const signedCalls = await this._buildAndSignCalls(callsToSend)
825+
const signedCalls = this._getCachedSignedCall(callsToSend) ?? (await this._buildAndSignCalls(callsToSend))
813826
const hash = await this.relayer.relay(signedCalls.to, signedCalls.data, this.chainId)
814827
const status = await this._waitForTransactionReceipt(hash.opHash, this.chainId)
815828
if (status.status === 'confirmed') {
@@ -988,4 +1001,42 @@ export class ChainSessionManager {
9881001
await this.sequenceStorage.clearImplicitSession()
9891002
await this.sequenceStorage.clearExplicitSessions()
9901003
}
1004+
1005+
private _getCachedSignedCall(calls: Payload.Call[]): { to: Address.Address; data: Hex.Hex } | null {
1006+
if (!this.lastSignedCallCache) {
1007+
return null
1008+
}
1009+
const ttlMs = 30_000
1010+
if (Date.now() - this.lastSignedCallCache.createdAtMs > ttlMs) {
1011+
this.lastSignedCallCache = undefined
1012+
return null
1013+
}
1014+
const fingerprint = this._fingerprintCalls(calls)
1015+
if (!fingerprint) {
1016+
return null
1017+
}
1018+
if (fingerprint !== this.lastSignedCallCache.fingerprint) {
1019+
return null
1020+
}
1021+
return this.lastSignedCallCache.signedCall
1022+
}
1023+
1024+
private _fingerprintCalls(calls: Payload.Call[]): string | null {
1025+
try {
1026+
return JSON.stringify(
1027+
calls.map((call) => ({
1028+
to: call.to,
1029+
value: call.value?.toString() ?? '0',
1030+
data: call.data ?? '0x',
1031+
gasLimit: call.gasLimit?.toString() ?? '0',
1032+
delegateCall: call.delegateCall ?? false,
1033+
onlyFallback: call.onlyFallback ?? false,
1034+
behaviorOnError: call.behaviorOnError ?? 'revert',
1035+
})),
1036+
)
1037+
} catch (error) {
1038+
console.warn('ChainSessionManager._fingerprintCalls failed:', error)
1039+
return null
1040+
}
1041+
}
9911042
}

packages/wallet/dapp-client/src/DappTransport.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,7 @@ export class DappTransport {
328328
return
329329
}
330330

331-
const isPotentiallyValidSource =
332-
this.walletWindow && (event.source === this.walletWindow || !this.walletWindow.closed)
333-
334-
if (!isPotentiallyValidSource && event.data?.type !== MessageType.WALLET_OPENED) {
331+
if (!this.walletWindow || event.source !== this.walletWindow) {
335332
return
336333
}
337334

0 commit comments

Comments
 (0)