Skip to content

Commit

Permalink
Formatting codebase with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Jul 20, 2023
1 parent 3df6ea7 commit 786e230
Show file tree
Hide file tree
Showing 46 changed files with 1,771 additions and 1,774 deletions.
35 changes: 17 additions & 18 deletions packages/abi/src/wallet/erc5719.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@

export const abi = [
{
"inputs": [
{
"internalType": "bytes32",
"type": "bytes32"
}
],
"name": "getAlternativeSignature",
"outputs": [
{
"internalType": "string",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
{
inputs: [
{
internalType: 'bytes32',
type: 'bytes32'
}
],
name: 'getAlternativeSignature',
outputs: [
{
internalType: 'string',
type: 'string'
}
],
stateMutability: 'view',
type: 'function'
}
]
63 changes: 61 additions & 2 deletions packages/abi/src/wallet/erc6492.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,61 @@

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"}]
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'
}
]
35 changes: 17 additions & 18 deletions packages/core/src/commons/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { ethers } from 'ethers'
import { WalletContext } from './context'
import * as transaction from './transaction'
Expand All @@ -7,11 +6,11 @@ export type Config = {
version: number
}

export type SimpleSigner = { address: string, weight: ethers.BigNumberish }
export type SimpleSigner = { address: string; weight: ethers.BigNumberish }

export type SimpleConfig = {
threshold: ethers.BigNumberish,
checkpoint: ethers.BigNumberish,
threshold: ethers.BigNumberish
checkpoint: ethers.BigNumberish
signers: SimpleSigner[]
}

Expand All @@ -25,31 +24,31 @@ export interface ConfigCoder<T extends Config = Config> {

fromSimple: (config: SimpleConfig) => T

signersOf: (config: T) => { address: string, weight: number }[]
signersOf: (config: T) => { address: string; weight: number }[]

toJSON: (config: T) => string
fromJSON: (json: string) => T

isComplete: (config: T) => boolean

editConfig: (config: T, action: {
add?: SimpleSigner[],
remove?: string[],
threshold?: ethers.BigNumberish,
checkpoint?: ethers.BigNumberish
}) => T

buildStubSignature: (
editConfig: (
config: T,
overrides: Map<string, string>
) => string
action: {
add?: SimpleSigner[]
remove?: string[]
threshold?: ethers.BigNumberish
checkpoint?: ethers.BigNumberish
}
) => T

buildStubSignature: (config: T, overrides: Map<string, string>) => string

// isValid: (config: T) => boolean

// TODO: This may not be the best place for this
// maybe it could go in the migration classes?
update: {
isKindUsed: boolean,
isKindUsed: boolean

buildTransaction: (
address: string,
Expand All @@ -59,8 +58,8 @@ export interface ConfigCoder<T extends Config = Config> {
) => transaction.TransactionBundle

decodeTransaction: (tx: transaction.TransactionBundle) => {
address: string,
newImageHash: string,
address: string
newImageHash: string
kind: 'first' | 'later' | undefined
}
}
Expand Down
108 changes: 56 additions & 52 deletions packages/core/src/commons/context.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import { ethers } from "ethers"
import { allVersions } from ".."
import { ethers } from 'ethers'
import { allVersions } from '..'

export type WalletContext = {
version: number,
factory: string,
mainModule: string,
mainModuleUpgradable: string,
guestModule: string,
version: number
factory: string
mainModule: string
mainModuleUpgradable: string
guestModule: string

walletCreationCode: string,
walletCreationCode: string
}

export function addressOf(context: WalletContext, imageHash: ethers.BytesLike) {
const codeHash = ethers.utils.keccak256(
ethers.utils.solidityPack(
['bytes', 'bytes32'],
[context.walletCreationCode, ethers.utils.hexZeroPad(context.mainModule, 32)]
)
ethers.utils.solidityPack(['bytes', 'bytes32'], [context.walletCreationCode, ethers.utils.hexZeroPad(context.mainModule, 32)])
)

const hash = ethers.utils.keccak256(
ethers.utils.solidityPack(
['bytes1', 'address', 'bytes32', 'bytes32'],
['0xff', context.factory, imageHash, codeHash]
)
ethers.utils.solidityPack(['bytes1', 'address', 'bytes32', 'bytes32'], ['0xff', context.factory, imageHash, codeHash])
)

return ethers.utils.getAddress(ethers.utils.hexDataSlice(hash, 12))
Expand All @@ -39,42 +33,52 @@ export async function isValidCounterfactual(
) {
// We don't know the version of the signature
// so we need to try all of them
const res = await Promise.all(allVersions.map(async (version) => {
try {
const decoded = version.signature.SignatureCoder.decode(ethers.utils.hexlify(signature))

const recovered1 = await version.signature.SignatureCoder.recover(decoded as any, {
address: wallet,
digest: ethers.utils.hexlify(digest),
chainId,
}, provider)

const imageHash = version.config.ConfigCoder.imageHashOf(recovered1.config as any)
const counterfactualAddress = addressOf(contexts[version.version], imageHash)

if (counterfactualAddress.toLowerCase() === wallet.toLowerCase()) {
return true
}

// chainId=0 means no chainId, so the signature is valid for all chains
// we need to check that case too
const recovered2 = await version.signature.SignatureCoder.recover(decoded as any, {
address: wallet,
digest: ethers.utils.hexlify(digest),
chainId,
}, provider)

const imageHash2 = version.config.ConfigCoder.imageHashOf(recovered2.config as any)
const counterfactualAddress2 = addressOf(contexts[version.version], imageHash2)

return counterfactualAddress2.toLowerCase() === wallet.toLowerCase()
} catch {}

// We most likely failed to decode the signature
return false
}))

return res.some((r) => r)
const res = await Promise.all(
allVersions.map(async version => {
try {
const decoded = version.signature.SignatureCoder.decode(ethers.utils.hexlify(signature))

const recovered1 = await version.signature.SignatureCoder.recover(
decoded as any,
{
address: wallet,
digest: ethers.utils.hexlify(digest),
chainId
},
provider
)

const imageHash = version.config.ConfigCoder.imageHashOf(recovered1.config as any)
const counterfactualAddress = addressOf(contexts[version.version], imageHash)

if (counterfactualAddress.toLowerCase() === wallet.toLowerCase()) {
return true
}

// chainId=0 means no chainId, so the signature is valid for all chains
// we need to check that case too
const recovered2 = await version.signature.SignatureCoder.recover(
decoded as any,
{
address: wallet,
digest: ethers.utils.hexlify(digest),
chainId
},
provider
)

const imageHash2 = version.config.ConfigCoder.imageHashOf(recovered2.config as any)
const counterfactualAddress2 = addressOf(contexts[version.version], imageHash2)

return counterfactualAddress2.toLowerCase() === wallet.toLowerCase()
} catch {}

// We most likely failed to decode the signature
return false
})
)

return res.some(r => r)
}

export type VersionedContext = { [key: number]: WalletContext }
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/commons/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export * as config from './config'
export * as signature from './signature'
export * as context from './context'
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/commons/orchestrator.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ethers } from "ethers"
import { commons } from ".."
import { Config } from "./config"
import { ethers } from 'ethers'
import { commons } from '..'
import { Config } from './config'

/**
* Request metadata, used to by the wallet to pass additional information to the
* orchestrator.
*/
export type WalletSignRequestMetadata = {
address: string,
digest: ethers.utils.BytesLike,
chainId: ethers.BigNumberish,
address: string
digest: ethers.utils.BytesLike
chainId: ethers.BigNumberish

config: Config,
config: Config

parts?: Map<string, commons.signature.SignaturePart>,
parts?: Map<string, commons.signature.SignaturePart>

// TODO: We can add a "percentage" field to the orchestrator to indicate
// how close are we to the threshold. This can be used to display
Expand Down
Loading

0 comments on commit 786e230

Please sign in to comment.