Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/wallet/core/src/signers/session/explicit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,7 @@ export class Explicit implements ExplicitSessionSigner {
): Promise<SessionSignature.SessionCallSignature> {
const call = payload.calls[callIdx]!
let permissionIndex: number
if (
Address.isEqual(call.to, sessionManagerAddress) &&
Hex.size(call.data) > 4 &&
Hex.isEqual(Hex.slice(call.data, 0, 4), AbiFunction.getSelector(Constants.INCREMENT_USAGE_LIMIT))
) {
if (isIncrementCall(call, sessionManagerAddress)) {
// Permission check not required. Use the first permission
permissionIndex = 0
} else {
Expand Down
54 changes: 54 additions & 0 deletions packages/wallet/core/test/session-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,60 @@ for (const extension of ALL_EXTENSIONS) {
},
timeout,
)

it('signSapient handles selector-only self increment call consistently', async () => {
const identityPrivateKey = Secp256k1.randomPrivateKey()
const identityAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: identityPrivateKey }))
const stateProvider = new State.Local.Provider()

const explicitSigner = new Signers.Session.Explicit(Secp256k1.randomPrivateKey(), {
chainId: 0,
valueLimit: 0n,
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
permissions: [PermissionBuilder.for(EMITTER_ADDRESS1).allowAll().build()],
})

const sessionTopology = SessionConfig.addExplicitSession(SessionConfig.emptySessionsTopology(identityAddress), {
...explicitSigner.sessionPermissions,
signer: explicitSigner.address,
})
await stateProvider.saveTree(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))
const imageHash = GenericTree.hash(SessionConfig.sessionsTopologyToConfigurationTree(sessionTopology))

const wallet = await Wallet.fromConfiguration(
{
threshold: 1n,
checkpoint: 0n,
topology: [{ type: 'sapient-signer', address: extension.sessions, weight: 1n, imageHash }, Hex.random(32)],
},
{ stateProvider },
)
const sessionManager = new Signers.SessionManager(wallet, {
sessionManagerAddress: extension.sessions,
explicitSigners: [explicitSigner],
})

const payload: Payload.Parented = {
type: 'call',
nonce: 0n,
space: 0n,
calls: [
{
to: extension.sessions,
data: AbiFunction.getSelector(Constants.INCREMENT_USAGE_LIMIT),
value: 0n,
gasLimit: 0n,
delegateCall: false,
onlyFallback: false,
behaviorOnError: 'revert',
},
],
parentWallets: [wallet.address],
}

const signature = await sessionManager.signSapient(wallet.address, 0, payload, imageHash)
expect(signature.type).toBe('sapient')
})
})
})
}