Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier v3 #398

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 2 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { off } = require("process")
const { off } = require('process')

module.exports = {
parser: '@typescript-eslint/parser',
Expand Down Expand Up @@ -26,13 +26,13 @@ module.exports = {
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',

'import/no-unresolved': 'off',
'import/no-default-export': 2,
'import/no-named-as-default-member': 'off',
'import/export': 'off'


// 'import/order': [
// 'warn',
// {
Expand All @@ -43,6 +43,5 @@ module.exports = {
// }
// },
// ]

}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^10.0.0",
"@types/node": "^18.16.1",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"ava": "^3.15.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"concurrently": "^7.5.0",
"eslint": "^8.39.0",
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.0.0",
"ethers": "^5.7.2",
"express": "^4.18.2",
"hardhat": "^2.12.2",
"husky": "^8.0.0",
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"prettier": "^2.8.8",
"prettier": "^3.0.0",
"puppeteer": "^19.7.2",
"rimraf": "^5.0.0",
"ts-node": "^10.9.1",
Expand Down
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