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
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const tests = async () => {
const sig = await signer.signMessage(message)
assert.equal(
sig,
'0x000163c9620c0001045ea593a25d0053816f2cfb0239eb04c30cc08fd26193927bf6cf68f7f31a8239ecbcbd1365f18a6bf2bf3b13d544c91d85e35503696a28fcb96a4078a7556a1c02',
'0x000000000000000000000000e35a6b88704b08f944f37d0c709f8cb548594883000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002047a9a16280000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000050eb6e88efa415aeb63baca79db74c112bef2e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000004432c02a14000000000000000000000000eda2d9b473e7dcf61d18606c459e06e0635c351372a16f43c162cf3b238b87c35fccdbebab1b4d1e42e2c835e30471dd311fe67900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004a000163c9620c0001045ea593a25d0053816f2cfb0239eb04c30cc08fd26193927bf6cf68f7f31a8239ecbcbd1365f18a6bf2bf3b13d544c91d85e35503696a28fcb96a4078a7556a1c02000000000000000000000000000000000000000000006492649264926492649264926492649264926492649264926492649264926492',
'signature match'
)

Expand Down
11 changes: 3 additions & 8 deletions packages/0xsequence/tests/browser/wallet-provider/dapp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ export const tests = async () => {
const sigs = await Promise.all([message, message2].map(async m => {
// NOTE: below line is equivalent to `signer.signMessage(m)` call
// const sig = await wallet.utils.signMessage(m)
const sig = await signer.signMessage(m)
const sig = await signer.signMessage(m, undefined, true)
assert.equal(
sig,
'0x0002000000000002dae61fe1d90658f8f4339bd58043b122929cd3f1faaeab38e4daa97b09471170464ebb81bb1957babce03c5fbd0bee815cc61de66d7edaff0d55a4bfbde016e11b02',
'0x000000000000000000000000e35a6b88704b08f944f37d0c709f8cb548594883000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002047a9a16280000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000050eb6e88efa415aeb63baca79db74c112bef2e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000004432c02a14000000000000000000000000eda2d9b473e7dcf61d18606c459e06e0635c3513d8738dddc5c63663e6da04fe5a8747677482036c1901527c8e92abc534dbd5d900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004a0002000000000002dae61fe1d90658f8f4339bd58043b122929cd3f1faaeab38e4daa97b09471170464ebb81bb1957babce03c5fbd0bee815cc61de66d7edaff0d55a4bfbde016e11b02000000000000000000000000000000000000000000006492649264926492649264926492649264926492649264926492649264926492',
'signature match'
)
return sig
Expand Down Expand Up @@ -213,11 +213,6 @@ export const tests = async () => {
}

const sig = await signer.signTypedData(domain, types, message)
assert.equal(
sig,
'0x00020000000000022983d84883386d6e3f2749109d0583b11f5c103e68baa763adcd6f7390fa2c4d5f746f239f900cd11f685d5c79314a591646b5ce49336cb48f77583d964753cf1c02',
'signature match typed-data'
)

// Verify typed data
const isValid = await wallet.utils.isValidTypedDataSignature(address, { domain, types, message }, sig, chainId)
Expand All @@ -238,7 +233,7 @@ export const tests = async () => {
const sig = await signer.signMessage(message, chainId)
assert.equal(
sig,
'0x0002000000000002dae61fe1d90658f8f4339bd58043b122929cd3f1faaeab38e4daa97b09471170464ebb81bb1957babce03c5fbd0bee815cc61de66d7edaff0d55a4bfbde016e11b02',
'0x000000000000000000000000e35a6b88704b08f944f37d0c709f8cb548594883000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002047a9a16280000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000050eb6e88efa415aeb63baca79db74c112bef2e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000004432c02a14000000000000000000000000eda2d9b473e7dcf61d18606c459e06e0635c3513d8738dddc5c63663e6da04fe5a8747677482036c1901527c8e92abc534dbd5d900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004a0002000000000002dae61fe1d90658f8f4339bd58043b122929cd3f1faaeab38e4daa97b09471170464ebb81bb1957babce03c5fbd0bee815cc61de66d7edaff0d55a4bfbde016e11b02000000000000000000000000000000000000000000006492649264926492649264926492649264926492649264926492649264926492',
'signAuthMessage, signature match'
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ export const tests = async () => {
// Sign the message
//
const sig = await provider.send('eth_signTypedData', [address, typedData])
assert.equal(
sig,
'0x00020000000000022983d84883386d6e3f2749109d0583b11f5c103e68baa763adcd6f7390fa2c4d5f746f239f900cd11f685d5c79314a591646b5ce49336cb48f77583d964753cf1c02',
'signature match typed-data'
)

// NOTE: verification of message below is identical to verifying a message with eth_sign,
// the difference is we have to provide 'message' as the typedData digest format
Expand Down
2 changes: 2 additions & 0 deletions packages/abi/src/wallet/erc6492.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export const abi = [{"inputs":[{"internalType":"bytes","name":"error","type":"bytes"}],"name":"ERC1271Revert","type":"error"},{"inputs":[{"internalType":"bytes","name":"error","type":"bytes"}],"name":"ERC6492DeployFailed","type":"error"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"},{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"isValidSig","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"},{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes","name":"_signature","type":"bytes"},{"internalType":"bool","name":"allowSideEffects","type":"bool"},{"internalType":"bool","name":"deployAlreadyDeployed","type":"bool"}],"name":"isValidSigImpl","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"},{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"isValidSigNoThrow","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"},{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"isValidSigWithSideEffects","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"},{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"isValidSigWithSideEffectsNoThrow","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
2 changes: 2 additions & 0 deletions packages/abi/src/wallet/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as erc5719 from './erc5719'
import * as erc1271 from './erc1271'
import * as erc6492 from './erc6492'
import * as factory from './factory'
import * as mainModule from './mainModule'
import * as mainModuleUpgradable from './mainModuleUpgradable'
import * as sequenceUtils from './sequenceUtils'
import * as requireFreshSigner from './libs/requireFreshSigners'

export const walletContracts = {
erc6492,
erc5719,
erc1271,
factory,
Expand Down
71 changes: 65 additions & 6 deletions packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,12 @@ export class Account {
return this.tracker.saveWitnesses({ wallet: this.address, digest, chainId: 0, signatures })
}

async signDigest(digest: ethers.BytesLike, chainId: ethers.BigNumberish, decorate: boolean = true): Promise<string> {
async signDigest(
digest: ethers.BytesLike,
chainId: ethers.BigNumberish,
decorate: boolean = true,
cantValidateBehavior: 'ignore' | 'eip6492' | 'throw' = 'ignore'
): Promise<string> {
// If we are signing a digest for chainId zero then we can never be fully migrated
// because Sequence v1 doesn't allow for signing a message on "all chains"

Expand All @@ -427,10 +432,55 @@ export class Account {

this.mustBeFullyMigrated(status)

// Check if we can validate onchain and what to do if we can't
// revert early, since there is no point in signing a digest now
if (!status.canOnchainValidate && cantValidateBehavior === 'throw') {
throw new Error('Wallet cannot validate onchain')
}

const wallet = this.walletForStatus(chainId, status)
const signature = await wallet.signDigest(digest)

return decorate ? this.decorateSignature(signature, status) : signature
const decorated = decorate ? this.decorateSignature(signature, status) : signature

// If the wallet can't validate onchain then we
// need to prefix the decorated signature with all deployments and migrations
// aka doing a bootstrap using EIP-6492
if (!status.canOnchainValidate) {
switch (cantValidateBehavior) {
// NOTICE: We covered this case before signing the digest
// case 'throw':
// throw new Error('Wallet cannot validate on-chain')
case 'ignore':
return decorated

case 'eip6492':
return this.buildEIP6492Signature(await decorated, status, chainId)
}
}

return decorated
}

private buildEIP6492Signature(
signature: string,
status: AccountStatus,
chainId: ethers.BigNumberish
): string {
const bootstrapBundle = this.buildBootstrapTransactions(status, chainId)
if (bootstrapBundle.transactions.length === 0) {
throw new Error('Cannot build EIP-6492 signature without bootstrap transactions')
}

const encoded = ethers.utils.defaultAbiCoder.encode(
['address', 'bytes', 'bytes'],
[bootstrapBundle.entrypoint, commons.transaction.encodeBundleExecData(bootstrapBundle), signature]
)

return ethers.utils.solidityPack(
['bytes', 'bytes32'],
[encoded, commons.EIP6492.EIP_6492_SUFFIX]
)
}

async editConfig(changes: {
Expand Down Expand Up @@ -543,8 +593,12 @@ export class Account {
return this.relayer(chainId).relay({ ...bootstrapTxs, chainId }, feeQuote)
}

signMessage(message: ethers.BytesLike, chainId: ethers.BigNumberish): Promise<string> {
return this.signDigest(ethers.utils.keccak256(message), chainId)
signMessage(
message: ethers.BytesLike,
chainId: ethers.BigNumberish,
cantValidateBehavior: 'ignore' | 'eip6492' | 'throw' = 'ignore'
): Promise<string> {
return this.signDigest(ethers.utils.keccak256(message), chainId, true, cantValidateBehavior)
}

async signTransactions(
Expand Down Expand Up @@ -741,10 +795,11 @@ export class Account {
domain: TypedDataDomain,
types: Record<string, Array<TypedDataField>>,
message: Record<string, any>,
chainId: ethers.BigNumberish
chainId: ethers.BigNumberish,
cantValidateBehavior: 'ignore' | 'eip6492' | 'throw' = 'ignore'
): Promise<string> {
const digest = encodeTypedDataDigest({ domain, types, message })
return this.signDigest(digest, chainId)
return this.signDigest(digest, chainId, true, cantValidateBehavior)
}

async getAllSigners(): Promise<
Expand Down Expand Up @@ -817,3 +872,7 @@ export class Account {
return allSigners
}
}

export function isAccount(value: any): value is Account {
return value instanceof Account
}
Loading