Skip to content

Commit dbaa75c

Browse files
Merge pull request #976 from 0xsequence/session-increment
use isIncrementCall in signCall
2 parents 86b75c0 + 948321f commit dbaa75c

2 files changed

Lines changed: 55 additions & 5 deletions

File tree

packages/wallet/core/src/signers/session/explicit.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,7 @@ export class Explicit implements ExplicitSessionSigner {
230230
): Promise<SessionSignature.SessionCallSignature> {
231231
const call = payload.calls[callIdx]!
232232
let permissionIndex: number
233-
if (
234-
Address.isEqual(call.to, sessionManagerAddress) &&
235-
Hex.size(call.data) > 4 &&
236-
Hex.isEqual(Hex.slice(call.data, 0, 4), AbiFunction.getSelector(Constants.INCREMENT_USAGE_LIMIT))
237-
) {
233+
if (isIncrementCall(call, sessionManagerAddress)) {
238234
// Permission check not required. Use the first permission
239235
permissionIndex = 0
240236
} else {

packages/wallet/core/test/session-manager.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,60 @@ for (const extension of ALL_EXTENSIONS) {
16441644
},
16451645
timeout,
16461646
)
1647+
1648+
it('signSapient handles selector-only self increment call consistently', async () => {
1649+
const identityPrivateKey = Secp256k1.randomPrivateKey()
1650+
const identityAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: identityPrivateKey }))
1651+
const stateProvider = new State.Local.Provider()
1652+
1653+
const explicitSigner = new Signers.Session.Explicit(Secp256k1.randomPrivateKey(), {
1654+
chainId: 0,
1655+
valueLimit: 0n,
1656+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
1657+
permissions: [PermissionBuilder.for(EMITTER_ADDRESS1).allowAll().build()],
1658+
})
1659+
1660+
const sessionTopology = SessionConfig.addExplicitSession(SessionConfig.emptySessionsTopology(identityAddress), {
1661+
...explicitSigner.sessionPermissions,
1662+
signer: explicitSigner.address,
1663+
})
1664+
await stateProvider.saveTree(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
1665+
const imageHash = GenericTree.hash(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
1666+
1667+
const wallet = await Wallet.fromConfiguration(
1668+
{
1669+
threshold: 1n,
1670+
checkpoint: 0n,
1671+
topology: [{ type: 'sapient-signer', address: extension.sessions, weight: 1n, imageHash }, Hex.random(32)],
1672+
},
1673+
{ stateProvider },
1674+
)
1675+
const sessionManager = new Signers.SessionManager(wallet, {
1676+
sessionManagerAddress: extension.sessions,
1677+
explicitSigners: [explicitSigner],
1678+
})
1679+
1680+
const payload: Payload.Parented = {
1681+
type: 'call',
1682+
nonce: 0n,
1683+
space: 0n,
1684+
calls: [
1685+
{
1686+
to: extension.sessions,
1687+
data: AbiFunction.getSelector(Constants.INCREMENT_USAGE_LIMIT),
1688+
value: 0n,
1689+
gasLimit: 0n,
1690+
delegateCall: false,
1691+
onlyFallback: false,
1692+
behaviorOnError: 'revert',
1693+
},
1694+
],
1695+
parentWallets: [wallet.address],
1696+
}
1697+
1698+
const signature = await sessionManager.signSapient(wallet.address, 0, payload, imageHash)
1699+
expect(signature.type).toBe('sapient')
1700+
})
16471701
})
16481702
})
16491703
}

0 commit comments

Comments
 (0)