Skip to content
Merged
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
47 changes: 46 additions & 1 deletion packages/wallet/core/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,51 @@ export const DefaultWalletOptions: WalletOptions = {
guest: Constants.DefaultGuestAddress,
}

const FeeOptionsStubSignature: SequenceSignature.SignatureOfSignerLeaf = {
type: 'eth_sign',
r: 0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,
s: 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0n,
yParity: 0,
}

function stubFeeOptionsTopology(topology: Config.Topology): SequenceSignature.RawTopology {
if (Array.isArray(topology)) {
return [stubFeeOptionsTopology(topology[0]), stubFeeOptionsTopology(topology[1])]
}

if (Config.isSignerLeaf(topology)) {
return {
type: 'unrecovered-signer',
weight: topology.weight,
signature: FeeOptionsStubSignature,
}
}

if (Config.isNestedLeaf(topology)) {
return {
type: 'nested',
weight: topology.weight,
threshold: topology.threshold,
tree: stubFeeOptionsTopology(topology.tree),
}
}

return topology
}

function buildFeeOptionsStubSignature(status: WalletStatusWithOnchain): Hex.Hex {
return Bytes.toHex(
SequenceSignature.encodeSignature({
noChainId: status.chainId === 0,
configuration: {
...status.configuration,
topology: stubFeeOptionsTopology(status.configuration.topology),
},
suffix: status.pendingUpdates.map(({ signature }) => signature),
}),
)
}

export type WalletStatus = {
address: Address.Address
isDeployed: boolean
Expand Down Expand Up @@ -499,7 +544,7 @@ export class Wallet {
payload: Payload.Calls,
): Promise<{ to: Address.Address; data: Hex.Hex }> {
const status = await this.getStatus(provider)
const signature = '0x0001' as Hex.Hex
const signature = buildFeeOptionsStubSignature(status)

const executeData = AbiFunction.encodeData(Constants.EXECUTE, [Bytes.toHex(Payload.encode(payload)), signature])

Expand Down
9 changes: 7 additions & 2 deletions packages/wallet/core/test/wallet-fee-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { State, Wallet } from '../src/index.js'

const SIGNER = '0x1234567890123456789012345678901234567890' as Address.Address
const TARGET = '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd' as Address.Address
const FEE_OPTIONS_STUB_SIGNATURE =
'0x040001711fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0' as Hex.Hex

const configuration: Config.Config = {
threshold: 1n,
Expand Down Expand Up @@ -74,7 +76,10 @@ describe('Wallet.buildFeeOptionsTransaction', () => {
const { wallet, imageHash } = await createWallet()
const transaction = await wallet.buildFeeOptionsTransaction(providerFor({ deployed: true, imageHash }), payload)

const expectedData = AbiFunction.encodeData(Constants.EXECUTE, [Bytes.toHex(Payload.encode(payload)), '0x0001'])
const expectedData = AbiFunction.encodeData(Constants.EXECUTE, [
Bytes.toHex(Payload.encode(payload)),
FEE_OPTIONS_STUB_SIGNATURE,
])

expect(Address.isEqual(transaction.to, wallet.address)).toBe(true)
expect(transaction.data).toBe(expectedData)
Expand All @@ -88,7 +93,7 @@ describe('Wallet.buildFeeOptionsTransaction', () => {

const expectedExecuteData = AbiFunction.encodeData(Constants.EXECUTE, [
Bytes.toHex(Payload.encode(payload)),
'0x0001',
FEE_OPTIONS_STUB_SIGNATURE,
])

expect(Address.isEqual(transaction.to, Constants.DefaultGuestAddress)).toBe(true)
Expand Down
Loading