@0xsequence/core
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { ethers } from "ethers"; | ||
import { ethers } from 'ethers'; | ||
export type WalletContext = { | ||
@@ -3,0 +3,0 @@ version: number; |
@@ -1,2 +0,2 @@ | ||
import { ethers } from "ethers"; | ||
import { ethers } from 'ethers'; | ||
import { commons } from "../index.js"; | ||
@@ -3,0 +3,0 @@ import { Config } from "./config.js"; |
@@ -1,2 +0,2 @@ | ||
import { ethers } from "ethers"; | ||
import { ethers } from 'ethers'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Provides stateful information about the wallet. |
@@ -1,2 +0,2 @@ | ||
import { ethers } from "ethers"; | ||
import { ethers } from 'ethers'; | ||
export declare enum SigType { | ||
@@ -3,0 +3,0 @@ EIP712 = 1, |
@@ -1,2 +0,2 @@ | ||
import { BigNumberish, BytesLike, ethers } from "ethers"; | ||
import { BigNumberish, BytesLike, ethers } from 'ethers'; | ||
export interface Transaction { | ||
@@ -3,0 +3,0 @@ to: string; |
@@ -1,2 +0,2 @@ | ||
import { ethers } from "ethers"; | ||
import { ethers } from 'ethers'; | ||
export declare function isValidEIP1271Signature(address: string, digest: string, signature: ethers.BytesLike, provider: ethers.providers.Provider): Promise<boolean>; |
@@ -1,4 +0,4 @@ | ||
import { ethers } from "ethers"; | ||
import { ethers } from 'ethers'; | ||
export declare const EIP_6492_OFFCHAIN_DEPLOY_CODE = "0x608060405234801561001057600080fd5b5060405161124a38038061124a83398101604081905261002f91610124565b600060405161003d906100dd565b604051809103906000f080158015610059573d6000803e3d6000fd5b5090506000816001600160a01b0316638f0684308686866040518463ffffffff1660e01b815260040161008e939291906101fb565b6020604051808303816000875af11580156100ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d19190610244565b9050806000526001601ff35b610fdc8061026e83390190565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561011b578181015183820152602001610103565b50506000910152565b60008060006060848603121561013957600080fd5b83516001600160a01b038116811461015057600080fd5b6020850151604086015191945092506001600160401b038082111561017457600080fd5b818601915086601f83011261018857600080fd5b81518181111561019a5761019a6100ea565b604051601f8201601f19908116603f011681019083821181831017156101c2576101c26100ea565b816040528281528960208487010111156101db57600080fd5b6101ec836020830160208801610100565b80955050505050509250925092565b60018060a01b0384168152826020820152606060408201526000825180606084015261022e816080850160208701610100565b601f01601f191691909101608001949350505050565b60006020828403121561025657600080fd5b8151801515811461026657600080fd5b939250505056fe608060405234801561001057600080fd5b50610fbc806100206000396000f3fe608060405234801561001057600080fd5b50600436106100675760003560e01c806376be4cea1161005057806376be4cea146100a65780638f068430146100b957806398ef1ed8146100cc57600080fd5b80631c6453271461006c5780633d787b6314610093575b600080fd5b61007f61007a366004610ad4565b6100df565b604051901515815260200160405180910390f35b61007f6100a1366004610ad4565b61023d565b61007f6100b4366004610b3e565b61031e565b61007f6100c7366004610ad4565b6108e1565b61007f6100da366004610ad4565b61096e565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea9061012890889088908890889088908190600401610bc3565b6020604051808303816000875af1925050508015610181575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261017e91810190610c45565b60015b610232573d8080156101af576040519150601f19603f3d011682016040523d82523d6000602084013e6101b4565b606091505b508051600181900361022757816000815181106101d3576101d3610c69565b6020910101517fff00000000000000000000000000000000000000000000000000000000000000167f0100000000000000000000000000000000000000000000000000000000000000149250610235915050565b600092505050610235565b90505b949350505050565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea906102879088908890889088906001908990600401610bc3565b6020604051808303816000875af19250505080156102e0575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019092526102dd91810190610c45565b60015b610232573d80801561030e576040519150601f19603f3d011682016040523d82523d6000602084013e610313565b606091505b506000915050610235565b600073ffffffffffffffffffffffffffffffffffffffff87163b6060827f64926492649264926492649264926492649264926492649264926492649264928888610369602082610c98565b610375928b9290610cd8565b61037e91610d02565b1490508015610484576000606089828a610399602082610c98565b926103a693929190610cd8565b8101906103b39190610e18565b955090925090508415806103c45750865b1561047d576000808373ffffffffffffffffffffffffffffffffffffffff16836040516103f19190610eb2565b6000604051808303816000865af19150503d806000811461042e576040519150601f19603f3d011682016040523d82523d6000602084013e610433565b606091505b50915091508161047a57806040517f9d0d6e2d0000000000000000000000000000000000000000000000000000000081526004016104719190610f18565b60405180910390fd5b50505b50506104be565b87878080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509294505050505b80806104ca5750600083115b156106bb576040517f1626ba7e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8b1690631626ba7e90610523908c908690600401610f2b565b602060405180830381865afa92505050801561057a575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261057791810190610f44565b60015b61060f573d8080156105a8576040519150601f19603f3d011682016040523d82523d6000602084013e6105ad565b606091505b50851580156105bc5750600084115b156105db576105d08b8b8b8b8b600161031e565b9450505050506108d7565b806040517f6f2a95990000000000000000000000000000000000000000000000000000000081526004016104719190610f18565b7fffffffff0000000000000000000000000000000000000000000000000000000081167f1626ba7e000000000000000000000000000000000000000000000000000000001480158161065f575086155b801561066b5750600085115b1561068b5761067f8c8c8c8c8c600161031e565b955050505050506108d7565b841580156106965750825b80156106a0575087155b156106af57806000526001601ffd5b94506108d79350505050565b6041871461074b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f5369676e617475726556616c696461746f72237265636f7665725369676e657260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610471565b600061075a6020828a8c610cd8565b61076391610d02565b90506000610775604060208b8d610cd8565b61077e91610d02565b905060008a8a604081811061079557610795610c69565b919091013560f81c915050601b81148015906107b557508060ff16601c14155b15610842576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602d60248201527f5369676e617475726556616c696461746f723a20696e76616c6964207369676e60448201527f617475726520762076616c7565000000000000000000000000000000000000006064820152608401610471565b6040805160008152602081018083528e905260ff831691810191909152606081018490526080810183905273ffffffffffffffffffffffffffffffffffffffff8e169060019060a0016020604051602081039080840390855afa1580156108ad573d6000803e3d6000fd5b5050506020604051035173ffffffffffffffffffffffffffffffffffffffff161496505050505050505b9695505050505050565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea9061092b9088908890889088906001908990600401610bc3565b6020604051808303816000875af115801561094a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102329190610c45565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea906109b790889088908890889088908190600401610bc3565b6020604051808303816000875af1925050508015610a10575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252610a0d91810190610c45565b60015b610232573d808015610a3e576040519150601f19603f3d011682016040523d82523d6000602084013e610a43565b606091505b5080516001819003610a6257816000815181106101d3576101d3610c69565b8082fd5b73ffffffffffffffffffffffffffffffffffffffff81168114610a8857600080fd5b50565b60008083601f840112610a9d57600080fd5b50813567ffffffffffffffff811115610ab557600080fd5b602083019150836020828501011115610acd57600080fd5b9250929050565b60008060008060608587031215610aea57600080fd5b8435610af581610a66565b935060208501359250604085013567ffffffffffffffff811115610b1857600080fd5b610b2487828801610a8b565b95989497509550505050565b8015158114610a8857600080fd5b60008060008060008060a08789031215610b5757600080fd5b8635610b6281610a66565b955060208701359450604087013567ffffffffffffffff811115610b8557600080fd5b610b9189828a01610a8b565b9095509350506060870135610ba581610b30565b91506080870135610bb581610b30565b809150509295509295509295565b73ffffffffffffffffffffffffffffffffffffffff8716815285602082015260a060408201528360a0820152838560c0830137600060c085830181019190915292151560608201529015156080820152601f9092017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016909101019392505050565b600060208284031215610c5757600080fd5b8151610c6281610b30565b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b81810381811115610cd2577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b60008085851115610ce857600080fd5b83861115610cf557600080fd5b5050820193919092039150565b80356020831015610cd2577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602084900360031b1b1692915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f830112610d7e57600080fd5b813567ffffffffffffffff80821115610d9957610d99610d3e565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610ddf57610ddf610d3e565b81604052838152866020858801011115610df857600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600060608486031215610e2d57600080fd5b8335610e3881610a66565b9250602084013567ffffffffffffffff80821115610e5557600080fd5b610e6187838801610d6d565b93506040860135915080821115610e7757600080fd5b50610e8486828701610d6d565b9150509250925092565b60005b83811015610ea9578181015183820152602001610e91565b50506000910152565b60008251610ec4818460208701610e8e565b9190910192915050565b60008151808452610ee6816020860160208601610e8e565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b602081526000610c626020830184610ece565b8281526040602082015260006102356040830184610ece565b600060208284031215610f5657600080fd5b81517fffffffff0000000000000000000000000000000000000000000000000000000081168114610c6257600080fdfea26469706673582212201a72aed4b15ffb05b6502997a9bb655992e06590bd26b336dfbb153d7ff6f34b64736f6c63430008120033"; | ||
export declare const EIP_6492_SUFFIX = "0x6492649264926492649264926492649264926492649264926492649264926492"; | ||
export declare function validateEIP6492Offchain(provider: ethers.providers.Provider, signer: string, hash: ethers.utils.BytesLike, signature: ethers.utils.BytesLike): Promise<boolean>; |
@@ -1,2 +0,2 @@ | ||
import { ethers } from "ethers"; | ||
import { ethers } from 'ethers'; | ||
export declare const SetImageHashPrefix = "0x8713a7c4465f6fbee2b6e9d6646d1d9f83fec929edfc4baf661f3c865bdd04d1"; | ||
@@ -3,0 +3,0 @@ export declare function hashSetImageHash(imageHash: string): string; |
@@ -1,2 +0,2 @@ | ||
import { ethers } from "ethers"; | ||
import { ethers } from 'ethers'; | ||
import { commons } from "../index.js"; | ||
@@ -3,0 +3,0 @@ export type SignerLeaf = { |
@@ -1,2 +0,2 @@ | ||
import { BigNumberish, ethers } from "ethers"; | ||
import { BigNumberish, ethers } from 'ethers'; | ||
import { Leaf, WalletConfig, SignerLeaf, Topology } from "./config.js"; | ||
@@ -3,0 +3,0 @@ import * as base from "../commons/signature.js"; |
{ | ||
"name": "@0xsequence/core", | ||
"version": "0.0.0-20230801194854", | ||
"version": "0.0.0-20230802161854", | ||
"description": "core primitives for interacting with the sequence wallet contracts", | ||
@@ -23,3 +23,3 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/core", | ||
"dependencies": { | ||
"@0xsequence/abi": "0.0.0-20230801194854" | ||
"@0xsequence/abi": "0.0.0-20230802161854" | ||
}, | ||
@@ -26,0 +26,0 @@ "scripts": { |
@@ -1,2 +0,1 @@ | ||
import { ethers } from 'ethers' | ||
@@ -10,7 +9,7 @@ import { WalletContext } from './context' | ||
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[] | ||
@@ -29,3 +28,3 @@ } | ||
signersOf: (config: T) => { address: string, weight: number }[] | ||
signersOf: (config: T) => { address: string; weight: number }[] | ||
@@ -37,14 +36,14 @@ toJSON: (config: T) => string | ||
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 | ||
@@ -55,3 +54,3 @@ | ||
update: { | ||
isKindUsed: boolean, | ||
isKindUsed: boolean | ||
@@ -66,4 +65,4 @@ buildTransaction: ( | ||
decodeTransaction: (tx: transaction.TransactionBundle) => { | ||
address: string, | ||
newImageHash: string, | ||
address: string | ||
newImageHash: string | ||
kind: 'first' | 'later' | undefined | ||
@@ -70,0 +69,0 @@ } |
@@ -1,12 +0,12 @@ | ||
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 | ||
} | ||
@@ -16,13 +16,7 @@ | ||
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]) | ||
) | ||
@@ -43,38 +37,48 @@ | ||
// 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 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 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) | ||
const imageHash = version.config.ConfigCoder.imageHashOf(recovered1.config as any) | ||
const counterfactualAddress = addressOf(contexts[version.version], imageHash) | ||
if (counterfactualAddress.toLowerCase() === wallet.toLowerCase()) { | ||
return true | ||
} | ||
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) | ||
// 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) | ||
const imageHash2 = version.config.ConfigCoder.imageHashOf(recovered2.config as any) | ||
const counterfactualAddress2 = addressOf(contexts[version.version], imageHash2) | ||
return counterfactualAddress2.toLowerCase() === wallet.toLowerCase() | ||
} catch {} | ||
return counterfactualAddress2.toLowerCase() === wallet.toLowerCase() | ||
} catch {} | ||
// We most likely failed to decode the signature | ||
return false | ||
})) | ||
// We most likely failed to decode the signature | ||
return false | ||
}) | ||
) | ||
return res.some((r) => r) | ||
return res.some(r => r) | ||
} | ||
@@ -81,0 +85,0 @@ |
@@ -1,2 +0,1 @@ | ||
export * as config from './config' | ||
@@ -3,0 +2,0 @@ export * as signature from './signature' |
@@ -1,4 +0,4 @@ | ||
import { ethers } from "ethers" | ||
import { commons } from ".." | ||
import { Config } from "./config" | ||
import { ethers } from 'ethers' | ||
import { commons } from '..' | ||
import { Config } from './config' | ||
@@ -10,9 +10,9 @@ /** | ||
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> | ||
@@ -19,0 +19,0 @@ // TODO: We can add a "percentage" field to the orchestrator to indicate |
@@ -1,5 +0,5 @@ | ||
import { walletContracts } from "@0xsequence/abi" | ||
import { ethers } from "ethers" | ||
import { commons } from ".." | ||
import { validateEIP6492Offchain } from "./validateEIP6492" | ||
import { walletContracts } from '@0xsequence/abi' | ||
import { ethers } from 'ethers' | ||
import { commons } from '..' | ||
import { validateEIP6492Offchain } from './validateEIP6492' | ||
@@ -14,7 +14,3 @@ /** | ||
nonce(wallet: string, space: ethers.BigNumberish): Promise<ethers.BigNumberish> | ||
isValidSignature( | ||
wallet: string, | ||
digest: ethers.BytesLike, | ||
signature: ethers.BytesLike | ||
): Promise<boolean> | ||
isValidSignature(wallet: string, digest: ethers.BytesLike, signature: ethers.BytesLike): Promise<boolean> | ||
} | ||
@@ -26,9 +22,7 @@ | ||
*/ | ||
export class OnChainReader implements Reader { | ||
export class OnChainReader implements Reader { | ||
// Simple cache to avoid re-fetching the same data | ||
private isDeployedCache: Set<string> = new Set() | ||
constructor( | ||
public readonly provider: ethers.providers.Provider | ||
) {} | ||
constructor(public readonly provider: ethers.providers.Provider) {} | ||
@@ -38,7 +32,3 @@ private module(address: string) { | ||
address, | ||
[ | ||
...walletContracts.mainModuleUpgradable.abi, | ||
...walletContracts.mainModule.abi, | ||
...walletContracts.erc1271.abi | ||
], | ||
[...walletContracts.mainModuleUpgradable.abi, ...walletContracts.mainModule.abi, ...walletContracts.erc1271.abi], | ||
this.provider | ||
@@ -54,3 +44,3 @@ ) | ||
const code = await this.provider.getCode(wallet).then((c) => ethers.utils.arrayify(c)) | ||
const code = await this.provider.getCode(wallet).then(c => ethers.utils.arrayify(c)) | ||
const isDeployed = code.length !== 0 | ||
@@ -66,3 +56,3 @@ if (isDeployed) { | ||
const position = ethers.utils.defaultAbiCoder.encode(['address'], [wallet]) | ||
const val = await this.provider.getStorageAt(wallet, position).then((c) => ethers.utils.arrayify(c)) | ||
const val = await this.provider.getStorageAt(wallet, position).then(c => ethers.utils.arrayify(c)) | ||
@@ -105,9 +95,5 @@ if (val.length === 20) { | ||
// must be prefixed with a transaction that deploys the wallet | ||
async isValidSignature( | ||
wallet: string, | ||
digest: ethers.BytesLike, | ||
signature: ethers.BytesLike | ||
): Promise<boolean> { | ||
async isValidSignature(wallet: string, digest: ethers.BytesLike, signature: ethers.BytesLike): Promise<boolean> { | ||
return validateEIP6492Offchain(this.provider, wallet, digest, signature) | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
import { ethers } from 'ethers' | ||
@@ -6,3 +5,3 @@ import * as config from './config' | ||
export type SignaturePart = { | ||
signature: string, | ||
signature: string | ||
isDynamic: boolean | ||
@@ -12,5 +11,5 @@ } | ||
export type Signature<T extends config.Config> = { | ||
version: number, | ||
config: T, | ||
subdigest: string, | ||
version: number | ||
config: T | ||
subdigest: string | ||
payload?: SignedPayload | ||
@@ -24,5 +23,5 @@ } | ||
export type SignedPayload = { | ||
message?: ethers.BytesLike, | ||
digest: string, | ||
chainId: ethers.BigNumberish, | ||
message?: ethers.BytesLike | ||
digest: string | ||
chainId: ethers.BigNumberish | ||
address: string | ||
@@ -36,12 +35,8 @@ } | ||
> { | ||
decode: (data: string) => Z, | ||
encode: (data: T | Z | ethers.BytesLike) => string, | ||
decode: (data: string) => Z | ||
encode: (data: T | Z | ethers.BytesLike) => string | ||
trim: (data: string) => Promise<string>, | ||
trim: (data: string) => Promise<string> | ||
recover: ( | ||
data: Z, | ||
payload: SignedPayload, | ||
provider: ethers.providers.Provider | ||
) => Promise<T> | ||
recover: (data: Z, payload: SignedPayload, provider: ethers.providers.Provider) => Promise<T> | ||
@@ -56,27 +51,15 @@ supportsNoChainId: boolean | ||
) => { | ||
encoded: string, | ||
encoded: string | ||
weight: ethers.BigNumber | ||
} | ||
hasEnoughSigningPower: ( | ||
config: Y, | ||
signatures: Map<string, SignaturePart> | ||
) => boolean | ||
hasEnoughSigningPower: (config: Y, signatures: Map<string, SignaturePart>) => boolean | ||
chainSignatures: ( | ||
main: T | Z | ethers.BytesLike, | ||
suffixes: (T | Z | ethers.BytesLike)[] | ||
) => string | ||
chainSignatures: (main: T | Z | ethers.BytesLike, suffixes: (T | Z | ethers.BytesLike)[]) => string | ||
hashSetImageHash: ( | ||
imageHash: string | ||
) => string | ||
hashSetImageHash: (imageHash: string) => string | ||
signaturesOf: ( | ||
config: Y, | ||
) => { address: string, signature: string }[] | ||
signaturesOf: (config: Y) => { address: string; signature: string }[] | ||
signaturesOfDecoded: ( | ||
decoded: Z | ||
) => string[] | ||
signaturesOfDecoded: (decoded: Z) => string[] | ||
} | ||
@@ -83,0 +66,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { ethers } from "ethers" | ||
import { isValidEIP1271Signature } from "./validateEIP1271" | ||
import { ethers } from 'ethers' | ||
import { isValidEIP1271Signature } from './validateEIP1271' | ||
@@ -64,6 +64,3 @@ export enum SigType { | ||
export function tryRecoverSigner( | ||
digest: ethers.BytesLike, | ||
signature: ethers.BytesLike | ||
): string | undefined { | ||
export function tryRecoverSigner(digest: ethers.BytesLike, signature: ethers.BytesLike): string | undefined { | ||
const bytes = ethers.utils.arrayify(signature) | ||
@@ -70,0 +67,0 @@ if (bytes.length !== 66) return undefined |
@@ -1,4 +0,4 @@ | ||
import { BigNumberish, BytesLike, ethers } from "ethers" | ||
import { subdigestOf } from "./signature" | ||
import { walletContracts } from "@0xsequence/abi" | ||
import { BigNumberish, BytesLike, ethers } from 'ethers' | ||
import { subdigestOf } from './signature' | ||
import { walletContracts } from '@0xsequence/abi' | ||
@@ -32,3 +32,7 @@ export interface Transaction { | ||
export type Transactionish = ethers.providers.TransactionRequest | ethers.providers.TransactionRequest[] | Transaction | Transaction[] | ||
export type Transactionish = | ||
| ethers.providers.TransactionRequest | ||
| ethers.providers.TransactionRequest[] | ||
| Transaction | ||
| Transaction[] | ||
@@ -40,4 +44,4 @@ export interface TransactionResponse<R = any> extends ethers.providers.TransactionResponse { | ||
export type TransactionBundle = { | ||
entrypoint: string, | ||
transactions: Transaction[], | ||
entrypoint: string | ||
transactions: Transaction[] | ||
nonce?: BigNumberish | ||
@@ -47,5 +51,5 @@ } | ||
export type IntendedTransactionBundle = TransactionBundle & { | ||
chainId: BigNumberish, | ||
chainId: BigNumberish | ||
intent: { | ||
id: string, | ||
id: string | ||
wallet: string | ||
@@ -56,3 +60,3 @@ } | ||
export type SignedTransactionBundle = IntendedTransactionBundle & { | ||
signature: string, | ||
signature: string | ||
nonce: BigNumberish | ||
@@ -108,3 +112,8 @@ } | ||
export function subdigestOfTransactions(address: string, chainId: BigNumberish, nonce: ethers.BigNumberish, txs: Transaction[]): string { | ||
export function subdigestOfTransactions( | ||
address: string, | ||
chainId: BigNumberish, | ||
nonce: ethers.BigNumberish, | ||
txs: Transaction[] | ||
): string { | ||
return subdigestOf({ address, chainId, digest: digestOfTransactions(nonce, txs) }) | ||
@@ -118,6 +127,3 @@ } | ||
digest: ethers.utils.keccak256( | ||
ethers.utils.defaultAbiCoder.encode( | ||
['string', MetaTransactionsType], | ||
['guest:', sequenceTxAbiEncode(txs)] | ||
) | ||
ethers.utils.defaultAbiCoder.encode(['string', MetaTransactionsType], ['guest:', sequenceTxAbiEncode(txs)]) | ||
) | ||
@@ -130,3 +136,3 @@ }) | ||
txs: (Transaction | ethers.providers.TransactionRequest)[] | ||
): { nonce?: ethers.BigNumberish, transaction: Transaction }[] { | ||
): { nonce?: ethers.BigNumberish; transaction: Transaction }[] { | ||
return txs.map(tx => toSequenceTransaction(wallet, tx)) | ||
@@ -138,3 +144,3 @@ } | ||
tx: ethers.providers.TransactionRequest | ||
): { nonce?: ethers.BigNumberish, transaction: Transaction } { | ||
): { nonce?: ethers.BigNumberish; transaction: Transaction } { | ||
if (tx.to) { | ||
@@ -149,3 +155,3 @@ return { | ||
value: tx.value || 0, | ||
data: tx.data || '0x', | ||
data: tx.data || '0x' | ||
} | ||
@@ -226,6 +232,3 @@ } | ||
export function fromTransactionish( | ||
wallet: string, | ||
transaction: Transactionish | ||
): Transaction[] { | ||
export function fromTransactionish(wallet: string, transaction: Transactionish): Transaction[] { | ||
if (Array.isArray(transaction)) { | ||
@@ -261,8 +264,3 @@ if (hasSequenceTransactions(transaction)) { | ||
export function isSignedTransactionBundle(cand: any): cand is SignedTransactionBundle { | ||
return ( | ||
cand !== undefined && | ||
cand.signature !== undefined && | ||
cand.signature !== '' && | ||
isTransactionBundle(cand) | ||
) | ||
return cand !== undefined && cand.signature !== undefined && cand.signature !== '' && isTransactionBundle(cand) | ||
} | ||
@@ -272,14 +270,17 @@ | ||
const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi) | ||
return walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), | ||
isSignedTransactionBundle(bundle) ? [ | ||
// Signed transaction bundle has all 3 parameters | ||
sequenceTxAbiEncode(bundle.transactions), | ||
bundle.nonce, | ||
bundle.signature | ||
] : [ | ||
// Unsigned bundle may be a GuestModule call, so signature and nonce are missing | ||
sequenceTxAbiEncode(bundle.transactions), | ||
0, | ||
[] | ||
] | ||
return walletInterface.encodeFunctionData( | ||
walletInterface.getFunction('execute'), | ||
isSignedTransactionBundle(bundle) | ||
? [ | ||
// Signed transaction bundle has all 3 parameters | ||
sequenceTxAbiEncode(bundle.transactions), | ||
bundle.nonce, | ||
bundle.signature | ||
] | ||
: [ | ||
// Unsigned bundle may be a GuestModule call, so signature and nonce are missing | ||
sequenceTxAbiEncode(bundle.transactions), | ||
0, | ||
[] | ||
] | ||
) | ||
@@ -312,3 +313,8 @@ } | ||
const decoded = ethers.utils.defaultAbiCoder.decode([selfExecuteAbi], data)[0] | ||
unwound.push(...unwind(tx.to, decoded.map((d: TransactionEncoded) => ({ ...d, to: d.target })))) | ||
unwound.push( | ||
...unwind( | ||
tx.to, | ||
decoded.map((d: TransactionEncoded) => ({ ...d, to: d.target })) | ||
) | ||
) | ||
} else { | ||
@@ -315,0 +321,0 @@ try { |
@@ -0,23 +1,29 @@ | ||
import { ethers } from 'ethers' | ||
import { ethers } from "ethers" | ||
const EIP1271_MAGIC_VALUE = '0x1626ba7e' | ||
const EIP1271_MAGIC_VALUE = "0x1626ba7e" | ||
const EIP1271_ABI = [ | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: 'bytes32', | ||
type: 'bytes32' | ||
}, | ||
{ | ||
internalType: 'bytes', | ||
type: 'bytes' | ||
} | ||
], | ||
name: 'isValidSignature', | ||
outputs: [ | ||
{ | ||
internalType: 'bytes4', | ||
type: 'bytes4' | ||
} | ||
], | ||
stateMutability: 'view', | ||
type: 'function' | ||
} | ||
] | ||
const EIP1271_ABI = [{ | ||
"inputs": [{ | ||
"internalType": "bytes32", | ||
"type": "bytes32" | ||
}, { | ||
"internalType": "bytes", | ||
"type": "bytes" | ||
}], | ||
"name": "isValidSignature", | ||
"outputs": [{ | ||
"internalType": "bytes4", | ||
"type": "bytes4" | ||
}], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}] | ||
export async function isValidEIP1271Signature( | ||
@@ -24,0 +30,0 @@ address: string, |
@@ -1,2 +0,2 @@ | ||
import { ethers } from "ethers"; | ||
import { ethers } from 'ethers' | ||
@@ -175,4 +175,5 @@ /* Source of Offchain EIP-6492 validation: | ||
export const EIP_6492_OFFCHAIN_DEPLOY_CODE = "0x608060405234801561001057600080fd5b5060405161124a38038061124a83398101604081905261002f91610124565b600060405161003d906100dd565b604051809103906000f080158015610059573d6000803e3d6000fd5b5090506000816001600160a01b0316638f0684308686866040518463ffffffff1660e01b815260040161008e939291906101fb565b6020604051808303816000875af11580156100ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d19190610244565b9050806000526001601ff35b610fdc8061026e83390190565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561011b578181015183820152602001610103565b50506000910152565b60008060006060848603121561013957600080fd5b83516001600160a01b038116811461015057600080fd5b6020850151604086015191945092506001600160401b038082111561017457600080fd5b818601915086601f83011261018857600080fd5b81518181111561019a5761019a6100ea565b604051601f8201601f19908116603f011681019083821181831017156101c2576101c26100ea565b816040528281528960208487010111156101db57600080fd5b6101ec836020830160208801610100565b80955050505050509250925092565b60018060a01b0384168152826020820152606060408201526000825180606084015261022e816080850160208701610100565b601f01601f191691909101608001949350505050565b60006020828403121561025657600080fd5b8151801515811461026657600080fd5b939250505056fe608060405234801561001057600080fd5b50610fbc806100206000396000f3fe608060405234801561001057600080fd5b50600436106100675760003560e01c806376be4cea1161005057806376be4cea146100a65780638f068430146100b957806398ef1ed8146100cc57600080fd5b80631c6453271461006c5780633d787b6314610093575b600080fd5b61007f61007a366004610ad4565b6100df565b604051901515815260200160405180910390f35b61007f6100a1366004610ad4565b61023d565b61007f6100b4366004610b3e565b61031e565b61007f6100c7366004610ad4565b6108e1565b61007f6100da366004610ad4565b61096e565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea9061012890889088908890889088908190600401610bc3565b6020604051808303816000875af1925050508015610181575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261017e91810190610c45565b60015b610232573d8080156101af576040519150601f19603f3d011682016040523d82523d6000602084013e6101b4565b606091505b508051600181900361022757816000815181106101d3576101d3610c69565b6020910101517fff00000000000000000000000000000000000000000000000000000000000000167f0100000000000000000000000000000000000000000000000000000000000000149250610235915050565b600092505050610235565b90505b949350505050565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea906102879088908890889088906001908990600401610bc3565b6020604051808303816000875af19250505080156102e0575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019092526102dd91810190610c45565b60015b610232573d80801561030e576040519150601f19603f3d011682016040523d82523d6000602084013e610313565b606091505b506000915050610235565b600073ffffffffffffffffffffffffffffffffffffffff87163b6060827f64926492649264926492649264926492649264926492649264926492649264928888610369602082610c98565b610375928b9290610cd8565b61037e91610d02565b1490508015610484576000606089828a610399602082610c98565b926103a693929190610cd8565b8101906103b39190610e18565b955090925090508415806103c45750865b1561047d576000808373ffffffffffffffffffffffffffffffffffffffff16836040516103f19190610eb2565b6000604051808303816000865af19150503d806000811461042e576040519150601f19603f3d011682016040523d82523d6000602084013e610433565b606091505b50915091508161047a57806040517f9d0d6e2d0000000000000000000000000000000000000000000000000000000081526004016104719190610f18565b60405180910390fd5b50505b50506104be565b87878080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509294505050505b80806104ca5750600083115b156106bb576040517f1626ba7e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8b1690631626ba7e90610523908c908690600401610f2b565b602060405180830381865afa92505050801561057a575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261057791810190610f44565b60015b61060f573d8080156105a8576040519150601f19603f3d011682016040523d82523d6000602084013e6105ad565b606091505b50851580156105bc5750600084115b156105db576105d08b8b8b8b8b600161031e565b9450505050506108d7565b806040517f6f2a95990000000000000000000000000000000000000000000000000000000081526004016104719190610f18565b7fffffffff0000000000000000000000000000000000000000000000000000000081167f1626ba7e000000000000000000000000000000000000000000000000000000001480158161065f575086155b801561066b5750600085115b1561068b5761067f8c8c8c8c8c600161031e565b955050505050506108d7565b841580156106965750825b80156106a0575087155b156106af57806000526001601ffd5b94506108d79350505050565b6041871461074b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f5369676e617475726556616c696461746f72237265636f7665725369676e657260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610471565b600061075a6020828a8c610cd8565b61076391610d02565b90506000610775604060208b8d610cd8565b61077e91610d02565b905060008a8a604081811061079557610795610c69565b919091013560f81c915050601b81148015906107b557508060ff16601c14155b15610842576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602d60248201527f5369676e617475726556616c696461746f723a20696e76616c6964207369676e60448201527f617475726520762076616c7565000000000000000000000000000000000000006064820152608401610471565b6040805160008152602081018083528e905260ff831691810191909152606081018490526080810183905273ffffffffffffffffffffffffffffffffffffffff8e169060019060a0016020604051602081039080840390855afa1580156108ad573d6000803e3d6000fd5b5050506020604051035173ffffffffffffffffffffffffffffffffffffffff161496505050505050505b9695505050505050565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea9061092b9088908890889088906001908990600401610bc3565b6020604051808303816000875af115801561094a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102329190610c45565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea906109b790889088908890889088908190600401610bc3565b6020604051808303816000875af1925050508015610a10575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252610a0d91810190610c45565b60015b610232573d808015610a3e576040519150601f19603f3d011682016040523d82523d6000602084013e610a43565b606091505b5080516001819003610a6257816000815181106101d3576101d3610c69565b8082fd5b73ffffffffffffffffffffffffffffffffffffffff81168114610a8857600080fd5b50565b60008083601f840112610a9d57600080fd5b50813567ffffffffffffffff811115610ab557600080fd5b602083019150836020828501011115610acd57600080fd5b9250929050565b60008060008060608587031215610aea57600080fd5b8435610af581610a66565b935060208501359250604085013567ffffffffffffffff811115610b1857600080fd5b610b2487828801610a8b565b95989497509550505050565b8015158114610a8857600080fd5b60008060008060008060a08789031215610b5757600080fd5b8635610b6281610a66565b955060208701359450604087013567ffffffffffffffff811115610b8557600080fd5b610b9189828a01610a8b565b9095509350506060870135610ba581610b30565b91506080870135610bb581610b30565b809150509295509295509295565b73ffffffffffffffffffffffffffffffffffffffff8716815285602082015260a060408201528360a0820152838560c0830137600060c085830181019190915292151560608201529015156080820152601f9092017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016909101019392505050565b600060208284031215610c5757600080fd5b8151610c6281610b30565b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b81810381811115610cd2577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b60008085851115610ce857600080fd5b83861115610cf557600080fd5b5050820193919092039150565b80356020831015610cd2577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602084900360031b1b1692915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f830112610d7e57600080fd5b813567ffffffffffffffff80821115610d9957610d99610d3e565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610ddf57610ddf610d3e565b81604052838152866020858801011115610df857600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600060608486031215610e2d57600080fd5b8335610e3881610a66565b9250602084013567ffffffffffffffff80821115610e5557600080fd5b610e6187838801610d6d565b93506040860135915080821115610e7757600080fd5b50610e8486828701610d6d565b9150509250925092565b60005b83811015610ea9578181015183820152602001610e91565b50506000910152565b60008251610ec4818460208701610e8e565b9190910192915050565b60008151808452610ee6816020860160208601610e8e565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b602081526000610c626020830184610ece565b8281526040602082015260006102356040830184610ece565b600060208284031215610f5657600080fd5b81517fffffffff0000000000000000000000000000000000000000000000000000000081168114610c6257600080fdfea26469706673582212201a72aed4b15ffb05b6502997a9bb655992e06590bd26b336dfbb153d7ff6f34b64736f6c63430008120033" | ||
export const EIP_6492_SUFFIX = "0x6492649264926492649264926492649264926492649264926492649264926492" | ||
export const EIP_6492_OFFCHAIN_DEPLOY_CODE = | ||
'0x608060405234801561001057600080fd5b5060405161124a38038061124a83398101604081905261002f91610124565b600060405161003d906100dd565b604051809103906000f080158015610059573d6000803e3d6000fd5b5090506000816001600160a01b0316638f0684308686866040518463ffffffff1660e01b815260040161008e939291906101fb565b6020604051808303816000875af11580156100ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d19190610244565b9050806000526001601ff35b610fdc8061026e83390190565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561011b578181015183820152602001610103565b50506000910152565b60008060006060848603121561013957600080fd5b83516001600160a01b038116811461015057600080fd5b6020850151604086015191945092506001600160401b038082111561017457600080fd5b818601915086601f83011261018857600080fd5b81518181111561019a5761019a6100ea565b604051601f8201601f19908116603f011681019083821181831017156101c2576101c26100ea565b816040528281528960208487010111156101db57600080fd5b6101ec836020830160208801610100565b80955050505050509250925092565b60018060a01b0384168152826020820152606060408201526000825180606084015261022e816080850160208701610100565b601f01601f191691909101608001949350505050565b60006020828403121561025657600080fd5b8151801515811461026657600080fd5b939250505056fe608060405234801561001057600080fd5b50610fbc806100206000396000f3fe608060405234801561001057600080fd5b50600436106100675760003560e01c806376be4cea1161005057806376be4cea146100a65780638f068430146100b957806398ef1ed8146100cc57600080fd5b80631c6453271461006c5780633d787b6314610093575b600080fd5b61007f61007a366004610ad4565b6100df565b604051901515815260200160405180910390f35b61007f6100a1366004610ad4565b61023d565b61007f6100b4366004610b3e565b61031e565b61007f6100c7366004610ad4565b6108e1565b61007f6100da366004610ad4565b61096e565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea9061012890889088908890889088908190600401610bc3565b6020604051808303816000875af1925050508015610181575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261017e91810190610c45565b60015b610232573d8080156101af576040519150601f19603f3d011682016040523d82523d6000602084013e6101b4565b606091505b508051600181900361022757816000815181106101d3576101d3610c69565b6020910101517fff00000000000000000000000000000000000000000000000000000000000000167f0100000000000000000000000000000000000000000000000000000000000000149250610235915050565b600092505050610235565b90505b949350505050565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea906102879088908890889088906001908990600401610bc3565b6020604051808303816000875af19250505080156102e0575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019092526102dd91810190610c45565b60015b610232573d80801561030e576040519150601f19603f3d011682016040523d82523d6000602084013e610313565b606091505b506000915050610235565b600073ffffffffffffffffffffffffffffffffffffffff87163b6060827f64926492649264926492649264926492649264926492649264926492649264928888610369602082610c98565b610375928b9290610cd8565b61037e91610d02565b1490508015610484576000606089828a610399602082610c98565b926103a693929190610cd8565b8101906103b39190610e18565b955090925090508415806103c45750865b1561047d576000808373ffffffffffffffffffffffffffffffffffffffff16836040516103f19190610eb2565b6000604051808303816000865af19150503d806000811461042e576040519150601f19603f3d011682016040523d82523d6000602084013e610433565b606091505b50915091508161047a57806040517f9d0d6e2d0000000000000000000000000000000000000000000000000000000081526004016104719190610f18565b60405180910390fd5b50505b50506104be565b87878080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509294505050505b80806104ca5750600083115b156106bb576040517f1626ba7e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8b1690631626ba7e90610523908c908690600401610f2b565b602060405180830381865afa92505050801561057a575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261057791810190610f44565b60015b61060f573d8080156105a8576040519150601f19603f3d011682016040523d82523d6000602084013e6105ad565b606091505b50851580156105bc5750600084115b156105db576105d08b8b8b8b8b600161031e565b9450505050506108d7565b806040517f6f2a95990000000000000000000000000000000000000000000000000000000081526004016104719190610f18565b7fffffffff0000000000000000000000000000000000000000000000000000000081167f1626ba7e000000000000000000000000000000000000000000000000000000001480158161065f575086155b801561066b5750600085115b1561068b5761067f8c8c8c8c8c600161031e565b955050505050506108d7565b841580156106965750825b80156106a0575087155b156106af57806000526001601ffd5b94506108d79350505050565b6041871461074b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f5369676e617475726556616c696461746f72237265636f7665725369676e657260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610471565b600061075a6020828a8c610cd8565b61076391610d02565b90506000610775604060208b8d610cd8565b61077e91610d02565b905060008a8a604081811061079557610795610c69565b919091013560f81c915050601b81148015906107b557508060ff16601c14155b15610842576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602d60248201527f5369676e617475726556616c696461746f723a20696e76616c6964207369676e60448201527f617475726520762076616c7565000000000000000000000000000000000000006064820152608401610471565b6040805160008152602081018083528e905260ff831691810191909152606081018490526080810183905273ffffffffffffffffffffffffffffffffffffffff8e169060019060a0016020604051602081039080840390855afa1580156108ad573d6000803e3d6000fd5b5050506020604051035173ffffffffffffffffffffffffffffffffffffffff161496505050505050505b9695505050505050565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea9061092b9088908890889088906001908990600401610bc3565b6020604051808303816000875af115801561094a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102329190610c45565b6040517f76be4cea00000000000000000000000000000000000000000000000000000000815260009030906376be4cea906109b790889088908890889088908190600401610bc3565b6020604051808303816000875af1925050508015610a10575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252610a0d91810190610c45565b60015b610232573d808015610a3e576040519150601f19603f3d011682016040523d82523d6000602084013e610a43565b606091505b5080516001819003610a6257816000815181106101d3576101d3610c69565b8082fd5b73ffffffffffffffffffffffffffffffffffffffff81168114610a8857600080fd5b50565b60008083601f840112610a9d57600080fd5b50813567ffffffffffffffff811115610ab557600080fd5b602083019150836020828501011115610acd57600080fd5b9250929050565b60008060008060608587031215610aea57600080fd5b8435610af581610a66565b935060208501359250604085013567ffffffffffffffff811115610b1857600080fd5b610b2487828801610a8b565b95989497509550505050565b8015158114610a8857600080fd5b60008060008060008060a08789031215610b5757600080fd5b8635610b6281610a66565b955060208701359450604087013567ffffffffffffffff811115610b8557600080fd5b610b9189828a01610a8b565b9095509350506060870135610ba581610b30565b91506080870135610bb581610b30565b809150509295509295509295565b73ffffffffffffffffffffffffffffffffffffffff8716815285602082015260a060408201528360a0820152838560c0830137600060c085830181019190915292151560608201529015156080820152601f9092017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016909101019392505050565b600060208284031215610c5757600080fd5b8151610c6281610b30565b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b81810381811115610cd2577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b60008085851115610ce857600080fd5b83861115610cf557600080fd5b5050820193919092039150565b80356020831015610cd2577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602084900360031b1b1692915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f830112610d7e57600080fd5b813567ffffffffffffffff80821115610d9957610d99610d3e565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610ddf57610ddf610d3e565b81604052838152866020858801011115610df857600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600060608486031215610e2d57600080fd5b8335610e3881610a66565b9250602084013567ffffffffffffffff80821115610e5557600080fd5b610e6187838801610d6d565b93506040860135915080821115610e7757600080fd5b50610e8486828701610d6d565b9150509250925092565b60005b83811015610ea9578181015183820152602001610e91565b50506000910152565b60008251610ec4818460208701610e8e565b9190910192915050565b60008151808452610ee6816020860160208601610e8e565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b602081526000610c626020830184610ece565b8281526040602082015260006102356040830184610ece565b600060208284031215610f5657600080fd5b81517fffffffff0000000000000000000000000000000000000000000000000000000081168114610c6257600080fdfea26469706673582212201a72aed4b15ffb05b6502997a9bb655992e06590bd26b336dfbb153d7ff6f34b64736f6c63430008120033' | ||
export const EIP_6492_SUFFIX = '0x6492649264926492649264926492649264926492649264926492649264926492' | ||
@@ -188,8 +189,11 @@ // TODO: This is a length payload, we can lower the load by deploying | ||
): Promise<boolean> { | ||
return '0x01' === await provider.call({ | ||
data: ethers.utils.concat([ | ||
EIP_6492_OFFCHAIN_DEPLOY_CODE, | ||
(new ethers.utils.AbiCoder()).encode(['address', 'bytes32', 'bytes'], [signer, hash, signature]) | ||
]) | ||
}) | ||
return ( | ||
'0x01' === | ||
(await provider.call({ | ||
data: ethers.utils.concat([ | ||
EIP_6492_OFFCHAIN_DEPLOY_CODE, | ||
new ethers.utils.AbiCoder().encode(['address', 'bytes32', 'bytes'], [signer, hash, signature]) | ||
]) | ||
})) | ||
) | ||
} |
@@ -1,10 +0,9 @@ | ||
export * as v1 from './v1' | ||
export * as v2 from "./v2" | ||
export * as commons from "./commons" | ||
export * as v2 from './v2' | ||
export * as commons from './commons' | ||
export * as universal from './universal' | ||
import * as v1 from './v1' | ||
import * as v2 from "./v2" | ||
import * as v2 from './v2' | ||
export const allVersions = [v1, v2] |
@@ -0,5 +1,3 @@ | ||
import { commons, v1, v2 } from '..' | ||
import { commons, v1, v2 } from ".." | ||
export const ALL_CODERS = [ | ||
@@ -23,3 +21,3 @@ { config: v1.config.ConfigCoder, signature: v1.signature.SignatureCoder }, | ||
export function genericCoderFor(version: number): { | ||
config: commons.config.ConfigCoder, | ||
config: commons.config.ConfigCoder | ||
signature: commons.signature.SignatureCoder | ||
@@ -26,0 +24,0 @@ } { |
@@ -1,2 +0,1 @@ | ||
import { ethers } from 'ethers' | ||
@@ -7,6 +6,5 @@ import { walletContracts } from '@0xsequence/abi' | ||
export type AddressMember = { | ||
weight: ethers.BigNumberish, | ||
address: string, | ||
weight: ethers.BigNumberish | ||
address: string | ||
signature?: string | ||
@@ -16,3 +14,3 @@ } | ||
export type WalletConfig = commons.config.Config & { | ||
threshold: ethers.BigNumberish, | ||
threshold: ethers.BigNumberish | ||
signers: AddressMember[] | ||
@@ -24,5 +22,3 @@ } | ||
return ( | ||
config.version === 1 && | ||
(config as WalletConfig).threshold !== undefined && | ||
(config as WalletConfig).signers !== undefined | ||
config.version === 1 && (config as WalletConfig).threshold !== undefined && (config as WalletConfig).signers !== undefined | ||
) | ||
@@ -33,8 +29,6 @@ }, | ||
return config.signers.reduce( | ||
(imageHash, signer) => ethers.utils.keccak256( | ||
ethers.utils.defaultAbiCoder.encode( | ||
['bytes32', 'uint8', 'address'], | ||
[imageHash, signer.weight, signer.address] | ||
) | ||
), | ||
(imageHash, signer) => | ||
ethers.utils.keccak256( | ||
ethers.utils.defaultAbiCoder.encode(['bytes32', 'uint8', 'address'], [imageHash, signer.weight, signer.address]) | ||
), | ||
ethers.utils.solidityPack(['uint256'], [config.threshold]) | ||
@@ -58,4 +52,4 @@ ) | ||
signersOf: (config: WalletConfig): { address: string, weight: number }[] => { | ||
return config.signers.map((s) => ({ address: s.address, weight: ethers.BigNumber.from(s.weight).toNumber() })) | ||
signersOf: (config: WalletConfig): { address: string; weight: number }[] => { | ||
return config.signers.map(s => ({ address: s.address, weight: ethers.BigNumber.from(s.weight).toNumber() })) | ||
}, | ||
@@ -66,3 +60,3 @@ | ||
checkpoint: ethers.BigNumberish | ||
signers: { address: string; weight: ethers.BigNumberish} [] | ||
signers: { address: string; weight: ethers.BigNumberish }[] | ||
}): WalletConfig => { | ||
@@ -89,6 +83,3 @@ if (!ethers.constants.Zero.eq(config.checkpoint)) { | ||
): commons.transaction.TransactionBundle => { | ||
const module = new ethers.utils.Interface([ | ||
...walletContracts.mainModule.abi, | ||
...walletContracts.mainModuleUpgradable.abi | ||
]) | ||
const module = new ethers.utils.Interface([...walletContracts.mainModule.abi, ...walletContracts.mainModuleUpgradable.abi]) | ||
@@ -100,5 +91,3 @@ const transactions: commons.transaction.Transaction[] = [] | ||
to: wallet, | ||
data: module.encodeFunctionData(module.getFunction('updateImplementation'), [ | ||
context.mainModuleUpgradable | ||
]), | ||
data: module.encodeFunctionData(module.getFunction('updateImplementation'), [context.mainModuleUpgradable]), | ||
gasLimit: 0, | ||
@@ -113,5 +102,3 @@ delegateCall: false, | ||
to: wallet, | ||
data: module.encodeFunctionData(module.getFunction('updateImageHash'), [ | ||
ConfigCoder.imageHashOf(config) | ||
]), | ||
data: module.encodeFunctionData(module.getFunction('updateImageHash'), [ConfigCoder.imageHashOf(config)]), | ||
gasLimit: 0, | ||
@@ -128,4 +115,8 @@ delegateCall: false, | ||
}, | ||
decodeTransaction: function (tx: commons.transaction.TransactionBundle): { address: string; newImageHash: string; kind: "first" | "later" | undefined} { | ||
throw new Error("Function not implemented.") | ||
decodeTransaction: function (tx: commons.transaction.TransactionBundle): { | ||
address: string | ||
newImageHash: string | ||
kind: 'first' | 'later' | undefined | ||
} { | ||
throw new Error('Function not implemented.') | ||
} | ||
@@ -135,3 +126,3 @@ }, | ||
toJSON: function (config: WalletConfig): string { | ||
const plainMembers = config.signers.map((signer) => { | ||
const plainMembers = config.signers.map(signer => { | ||
return { | ||
@@ -170,5 +161,5 @@ weight: ethers.BigNumber.from(signer.weight).toString(), | ||
action: { | ||
add?: commons.config.SimpleSigner[]; | ||
remove?: string[]; | ||
threshold?: ethers.BigNumberish, | ||
add?: commons.config.SimpleSigner[] | ||
remove?: string[] | ||
threshold?: ethers.BigNumberish | ||
checkpoint?: ethers.BigNumberish | ||
@@ -185,3 +176,3 @@ } | ||
for (const signer of action.add) { | ||
if (newSigners.find((s) => s.address === signer.address)) { | ||
if (newSigners.find(s => s.address === signer.address)) { | ||
continue | ||
@@ -199,3 +190,3 @@ } | ||
for (const address of action.remove) { | ||
const index = newSigners.findIndex((signer) => signer.address === address) | ||
const index = newSigners.findIndex(signer => signer.address === address) | ||
if (index >= 0) { | ||
@@ -214,6 +205,3 @@ newSigners.splice(index, 1) | ||
buildStubSignature: function ( | ||
config: WalletConfig, | ||
overrides: Map<string, string> | ||
) { | ||
buildStubSignature: function (config: WalletConfig, overrides: Map<string, string>) { | ||
const parts = new Map<string, commons.signature.SignaturePart>() | ||
@@ -234,3 +222,4 @@ | ||
for (const { address } of signers.sort(({ weight: a }, { weight: b }) => ethers.BigNumber.from(a).sub(b).toNumber())) { | ||
const signature = '0x4e82f02f388a12b5f9d29eaf2452dd040c0ee5804b4e504b4dd64e396c6c781f2c7624195acba242dd825bfd25a290912e3c230841fd55c9a734c4de8d9899451b02' | ||
const signature = | ||
'0x4e82f02f388a12b5f9d29eaf2452dd040c0ee5804b4e504b4dd64e396c6c781f2c7624195acba242dd825bfd25a290912e3c230841fd55c9a734c4de8d9899451b02' | ||
parts.set(address, { signature, isDynamic: false }) | ||
@@ -237,0 +226,0 @@ |
@@ -14,3 +14,3 @@ import { WalletContext } from '../commons/context' | ||
mainModuleUpgradable: '0x7EFE6cE415956c5f80C6530cC6cc81b4808F6118', | ||
walletCreationCode: '0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3', | ||
walletCreationCode: '0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3' | ||
} |
@@ -1,6 +0,5 @@ | ||
import { ethers } from 'ethers' | ||
import * as base from '../commons/signature' | ||
import { AddressMember, WalletConfig } from './config' | ||
import { isValidSignature, recoverSigner } from "../commons/signer" | ||
import { isValidSignature, recoverSigner } from '../commons/signer' | ||
@@ -16,6 +15,6 @@ export enum SignaturePartType { | ||
export type UnrecoveredSignatureMember = { | ||
unrecovered: true, | ||
weight: ethers.BigNumberish, | ||
signature: string, | ||
address?: string, | ||
unrecovered: true | ||
weight: ethers.BigNumberish | ||
signature: string | ||
address?: string | ||
isDynamic: boolean | ||
@@ -27,3 +26,3 @@ } | ||
export type UnrecoveredSignature = base.UnrecoveredSignature & { | ||
threshold: ethers.BigNumberish, | ||
threshold: ethers.BigNumberish | ||
signers: UnrecoveredMember[] | ||
@@ -33,6 +32,3 @@ } | ||
export function isAddressMember(member: any): member is AddressMember { | ||
return ( | ||
(member as AddressMember).address !== undefined && | ||
!isUnrecoveredSignatureMember(member) | ||
) | ||
return (member as AddressMember).address !== undefined && !isUnrecoveredSignatureMember(member) | ||
} | ||
@@ -49,6 +45,3 @@ | ||
export function isUnrecoveredSignature(signature: Signature | UnrecoveredSignature): signature is UnrecoveredSignature { | ||
return ( | ||
(signature as UnrecoveredSignature).threshold !== undefined && | ||
(signature as UnrecoveredSignature).signers !== undefined | ||
) | ||
return (signature as UnrecoveredSignature).threshold !== undefined && (signature as UnrecoveredSignature).signers !== undefined | ||
} | ||
@@ -59,6 +52,6 @@ | ||
const threshold = bytes[0] << 8 | bytes[1] | ||
const threshold = (bytes[0] << 8) | bytes[1] | ||
const signers: UnrecoveredMember[] = [] | ||
for (let i = 2; i < bytes.length;) { | ||
for (let i = 2; i < bytes.length; ) { | ||
const type = bytes[i++] | ||
@@ -90,3 +83,3 @@ const weight = bytes[i++] | ||
const size = bytes[i] << 8 | bytes[i + 1] | ||
const size = (bytes[i] << 8) | bytes[i + 1] | ||
i += 2 | ||
@@ -117,8 +110,5 @@ | ||
const encodedSigners = signers.map((s) => { | ||
const encodedSigners = signers.map(s => { | ||
if (isAddressMember(s)) { | ||
return ethers.utils.solidityPack( | ||
['uint8', 'uint8', 'address'], | ||
[SignaturePartType.Address, s.weight, s.address] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'uint8', 'address'], [SignaturePartType.Address, s.weight, s.address]) | ||
} | ||
@@ -134,12 +124,6 @@ | ||
return ethers.utils.solidityPack( | ||
['uint8', 'uint8', 'bytes'], | ||
[SignaturePartType.EOASignature, s.weight, s.signature] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'uint8', 'bytes'], [SignaturePartType.EOASignature, s.weight, s.signature]) | ||
}) | ||
return ethers.utils.solidityPack( | ||
['uint16', ...new Array(encodedSigners.length).fill('bytes')], | ||
[threshold, ...encodedSigners] | ||
) | ||
return ethers.utils.solidityPack(['uint16', ...new Array(encodedSigners.length).fill('bytes')], [threshold, ...encodedSigners]) | ||
} | ||
@@ -153,20 +137,22 @@ | ||
const subdigest = base.subdigestOf(payload) | ||
const signers = await Promise.all(data.signers.map(async (s) => { | ||
if (isAddressMember(s)) { | ||
return s | ||
} | ||
const signers = await Promise.all( | ||
data.signers.map(async s => { | ||
if (isAddressMember(s)) { | ||
return s | ||
} | ||
if (s.isDynamic) { | ||
if (!s.address) throw new Error('Dynamic signature part must have address') | ||
if (!isValidSignature(s.address, subdigest, s.signature, provider)) { | ||
throw new Error(`Invalid dynamic signature part ${s.address}`) | ||
if (s.isDynamic) { | ||
if (!s.address) throw new Error('Dynamic signature part must have address') | ||
if (!isValidSignature(s.address, subdigest, s.signature, provider)) { | ||
throw new Error(`Invalid dynamic signature part ${s.address}`) | ||
} | ||
return { address: s.address, weight: s.weight, signature: s.signature } | ||
} else { | ||
const address = recoverSigner(subdigest, s.signature) | ||
return { address, weight: s.weight, signature: s.signature } | ||
} | ||
}) | ||
) | ||
return { address: s.address, weight: s.weight, signature: s.signature } | ||
} else { | ||
const address = recoverSigner(subdigest, s.signature) | ||
return { address, weight: s.weight, signature: s.signature } | ||
} | ||
})) | ||
return { | ||
@@ -189,3 +175,3 @@ version: 1, | ||
_: ethers.BigNumberish | ||
): { encoded: string, weight: ethers.BigNumber } { | ||
): { encoded: string; weight: ethers.BigNumber } { | ||
if (subdigests.length !== 0) { | ||
@@ -196,3 +182,3 @@ throw new Error('Explicit subdigests not supported on v1') | ||
let weight = ethers.BigNumber.from(0) | ||
const parts = config.signers.map((s) => { | ||
const parts = config.signers.map(s => { | ||
if (!signatures.has(s.address)) { | ||
@@ -227,7 +213,3 @@ return s | ||
export const SignatureCoder: base.SignatureCoder< | ||
WalletConfig, | ||
Signature, | ||
UnrecoveredSignature | ||
> = { | ||
export const SignatureCoder: base.SignatureCoder<WalletConfig, Signature, UnrecoveredSignature> = { | ||
decode: (data: string): UnrecoveredSignature => { | ||
@@ -247,7 +229,3 @@ return decodeSignature(data) | ||
recover: ( | ||
data: UnrecoveredSignature, | ||
payload: base.SignedPayload, | ||
provider: ethers.providers.Provider | ||
): Promise<Signature> => { | ||
recover: (data: UnrecoveredSignature, payload: base.SignedPayload, provider: ethers.providers.Provider): Promise<Signature> => { | ||
return recoverSignature(data, payload, provider) | ||
@@ -284,13 +262,9 @@ }, | ||
signaturesOf(config: WalletConfig): { address: string; signature: string} [] { | ||
return config.signers | ||
.filter((s) => s.signature !== undefined) | ||
.map((s) => ({ address: s.address, signature: s.signature! })) | ||
signaturesOf(config: WalletConfig): { address: string; signature: string }[] { | ||
return config.signers.filter(s => s.signature !== undefined).map(s => ({ address: s.address, signature: s.signature! })) | ||
}, | ||
signaturesOfDecoded: function (data: UnrecoveredSignature): string[] { | ||
return data.signers | ||
.map((s) => s.signature) | ||
.filter((s) => s !== undefined) as string[] | ||
return data.signers.map(s => s.signature).filter(s => s !== undefined) as string[] | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { ethers } from "ethers" | ||
import { ethers } from 'ethers' | ||
@@ -11,6 +11,3 @@ // = keccak256("SetImageHash(bytes32 imageHash)") | ||
export function messageSetImageHash(imageHash: string) { | ||
return ethers.utils.solidityPack( | ||
['bytes32', 'bytes32'], | ||
[SetImageHashPrefix, imageHash] | ||
) | ||
return ethers.utils.solidityPack(['bytes32', 'bytes32'], [SetImageHashPrefix, imageHash]) | ||
} | ||
@@ -17,0 +14,0 @@ |
@@ -0,7 +1,6 @@ | ||
import { ethers } from 'ethers' | ||
import { walletContracts } from '@0xsequence/abi' | ||
import { commons } from '..' | ||
import { encodeSigners } from './signature' | ||
import { ethers } from "ethers" | ||
import { walletContracts } from "@0xsequence/abi" | ||
import { commons } from ".." | ||
import { encodeSigners } from "./signature" | ||
// | ||
@@ -12,4 +11,4 @@ // Tree typings - leaves | ||
export type SignerLeaf = { | ||
address: string, | ||
weight: ethers.BigNumberish, | ||
address: string | ||
weight: ethers.BigNumberish | ||
signature?: string | ||
@@ -23,4 +22,4 @@ } | ||
export type NestedLeaf = { | ||
tree: Topology, | ||
weight: ethers.BigNumberish, | ||
tree: Topology | ||
weight: ethers.BigNumberish | ||
threshold: ethers.BigNumberish | ||
@@ -39,6 +38,3 @@ } | ||
export function isSignerLeaf(leaf: any): leaf is SignerLeaf { | ||
return ( | ||
(leaf as SignerLeaf).address !== undefined && | ||
(leaf as SignerLeaf).weight !== undefined | ||
) | ||
return (leaf as SignerLeaf).address !== undefined && (leaf as SignerLeaf).weight !== undefined | ||
} | ||
@@ -125,3 +121,3 @@ | ||
export type Node = { | ||
left: Node | Leaf, | ||
left: Node | Leaf | ||
right: Node | Leaf | ||
@@ -133,6 +129,3 @@ } | ||
export function isNode(node: any): node is Node { | ||
return ( | ||
(node as Node).left !== undefined && | ||
(node as Node).right !== undefined | ||
) | ||
return (node as Node).left !== undefined && (node as Node).right !== undefined | ||
} | ||
@@ -145,17 +138,14 @@ | ||
export function encodeSignerLeaf(leaf: SignerLeaf): string { | ||
return ethers.utils.solidityPack( | ||
['uint96', 'address'], | ||
[leaf.weight, leaf.address] | ||
) | ||
return ethers.utils.solidityPack(['uint96', 'address'], [leaf.weight, leaf.address]) | ||
} | ||
export function decodeSignerLeaf(encoded: string): SignerLeaf { | ||
const bytes = ethers.utils.arrayify(encoded); | ||
const bytes = ethers.utils.arrayify(encoded) | ||
if (bytes.length !== 32) { | ||
throw new Error('Invalid encoded string length'); | ||
throw new Error('Invalid encoded string length') | ||
} | ||
const weight = ethers.BigNumber.from(bytes.slice(0, 12)); | ||
const address = ethers.utils.getAddress(ethers.utils.hexlify(bytes.slice(12))); | ||
const weight = ethers.BigNumber.from(bytes.slice(0, 12)) | ||
const address = ethers.utils.getAddress(ethers.utils.hexlify(bytes.slice(12))) | ||
@@ -173,3 +163,3 @@ return { weight, address } | ||
const prefix = bytes.slice(0, 11) | ||
return prefix.every((byte) => byte === 0) | ||
return prefix.every(byte => byte === 0) | ||
} | ||
@@ -183,6 +173,3 @@ | ||
if (isSubdigestLeaf(node)) { | ||
return ethers.utils.solidityKeccak256( | ||
['string', 'bytes32'], | ||
['Sequence static digest:\n', node.subdigest] | ||
) | ||
return ethers.utils.solidityKeccak256(['string', 'bytes32'], ['Sequence static digest:\n', node.subdigest]) | ||
} | ||
@@ -202,6 +189,3 @@ | ||
return ethers.utils.solidityKeccak256( | ||
['bytes32', 'bytes32'], | ||
[hashNode(node.left), hashNode(node.right)] | ||
) | ||
return ethers.utils.solidityKeccak256(['bytes32', 'bytes32'], [hashNode(node.left), hashNode(node.right)]) | ||
} | ||
@@ -228,4 +212,4 @@ | ||
export type WalletConfig = commons.config.Config & { | ||
threshold: ethers.BigNumberish, | ||
checkpoint: ethers.BigNumberish, | ||
threshold: ethers.BigNumberish | ||
checkpoint: ethers.BigNumberish | ||
tree: Topology | ||
@@ -247,12 +231,3 @@ } | ||
['bytes32', 'uint256'], | ||
[ | ||
ethers.utils.solidityKeccak256( | ||
['bytes32', 'uint256'], | ||
[ | ||
hashNode(config.tree), | ||
config.threshold | ||
] | ||
), | ||
config.checkpoint | ||
] | ||
[ethers.utils.solidityKeccak256(['bytes32', 'uint256'], [hashNode(config.tree), config.threshold]), config.checkpoint] | ||
) | ||
@@ -272,4 +247,4 @@ } | ||
export type SimpleNestedMember = { | ||
threshold: ethers.BigNumberish, | ||
weight: ethers.BigNumberish, | ||
threshold: ethers.BigNumberish | ||
weight: ethers.BigNumberish | ||
members: SimpleConfigMember[] | ||
@@ -281,4 +256,4 @@ } | ||
export type SimpleWalletConfig = { | ||
threshold: ethers.BigNumberish, | ||
checkpoint: ethers.BigNumberish, | ||
threshold: ethers.BigNumberish | ||
checkpoint: ethers.BigNumberish | ||
members: SimpleConfigMember[] | ||
@@ -301,7 +276,9 @@ } | ||
if (isNestedLeaf(tree)) { | ||
return [{ | ||
threshold: tree.threshold, | ||
weight: tree.weight, | ||
members: topologyToMembers(tree.tree) | ||
}] | ||
return [ | ||
{ | ||
threshold: tree.threshold, | ||
weight: tree.weight, | ||
members: topologyToMembers(tree.tree) | ||
} | ||
] | ||
} | ||
@@ -315,6 +292,3 @@ | ||
return [ | ||
...topologyToMembers(tree.left), | ||
...topologyToMembers(tree.right) | ||
] | ||
return [...topologyToMembers(tree.left), ...topologyToMembers(tree.right)] | ||
} | ||
@@ -345,3 +319,3 @@ | ||
const membersAsTopologies = (members: SimpleConfigMember[], builder: TopologyBuilder): Topology[] => { | ||
return members.map((member) => { | ||
return members.map(member => { | ||
if (isSimpleNestedMember(member)) { | ||
@@ -410,3 +384,2 @@ return { | ||
): WalletConfig { | ||
return { | ||
@@ -432,5 +405,5 @@ version: 2, | ||
export function signersOf(tree: Topology): { address: string, weight: number }[] { | ||
export function signersOf(tree: Topology): { address: string; weight: number }[] { | ||
const stack: Topology[] = [tree] | ||
const signers = new Set<{ address: string, weight: number }>() | ||
const signers = new Set<{ address: string; weight: number }>() | ||
@@ -463,7 +436,3 @@ while (stack.length > 0) { | ||
isWalletConfig: (config: commons.config.Config): config is WalletConfig => { | ||
return ( | ||
config.version === 2 && | ||
(config as WalletConfig).threshold !== undefined && | ||
(config as WalletConfig).tree !== undefined | ||
) | ||
return config.version === 2 && (config as WalletConfig).threshold !== undefined && (config as WalletConfig).tree !== undefined | ||
}, | ||
@@ -483,3 +452,3 @@ | ||
signersOf: (config: WalletConfig): { address: string, weight: number }[] => { | ||
signersOf: (config: WalletConfig): { address: string; weight: number }[] => { | ||
return signersOf(config.tree) | ||
@@ -491,3 +460,3 @@ }, | ||
checkpoint: ethers.BigNumberish | ||
signers: { address: string; weight: ethers.BigNumberish} [] | ||
signers: { address: string; weight: ethers.BigNumberish }[] | ||
}): WalletConfig => { | ||
@@ -497,3 +466,3 @@ return toWalletConfig({ | ||
checkpoint: config.checkpoint, | ||
members: config.signers.map((signer) => { | ||
members: config.signers.map(signer => { | ||
return { | ||
@@ -532,15 +501,19 @@ address: signer.address, | ||
entrypoint: wallet, | ||
transactions: [{ | ||
to: wallet, | ||
data: module.encodeFunctionData(module.getFunction('updateImageHash'), [ | ||
ConfigCoder.imageHashOf(config) | ||
]), | ||
gasLimit: 0, | ||
delegateCall: false, | ||
revertOnError: true, | ||
value: 0 | ||
}] | ||
transactions: [ | ||
{ | ||
to: wallet, | ||
data: module.encodeFunctionData(module.getFunction('updateImageHash'), [ConfigCoder.imageHashOf(config)]), | ||
gasLimit: 0, | ||
delegateCall: false, | ||
revertOnError: true, | ||
value: 0 | ||
} | ||
] | ||
} | ||
}, | ||
decodeTransaction: function (tx: commons.transaction.TransactionBundle): { address: string; newImageHash: string; kind: "first" | "later" | undefined} { | ||
decodeTransaction: function (tx: commons.transaction.TransactionBundle): { | ||
address: string | ||
newImageHash: string | ||
kind: 'first' | 'later' | undefined | ||
} { | ||
const module = new ethers.utils.Interface(walletContracts.mainModuleUpgradable.abi) | ||
@@ -612,5 +585,5 @@ | ||
action: { | ||
add?: commons.config.SimpleSigner[]; | ||
remove?: string[]; | ||
threshold?: ethers.BigNumberish, | ||
add?: commons.config.SimpleSigner[] | ||
remove?: string[] | ||
threshold?: ethers.BigNumberish | ||
checkpoint?: ethers.BigNumberish | ||
@@ -623,3 +596,3 @@ } | ||
for (const signer of action.add) { | ||
if (members.find((s) => isSignerLeaf(s) && s.address === signer.address)) { | ||
if (members.find(s => isSignerLeaf(s) && s.address === signer.address)) { | ||
continue | ||
@@ -637,3 +610,3 @@ } | ||
for (const address of action.remove) { | ||
const index = members.findIndex((s) => isSignerLeaf(s) && s.address === address) | ||
const index = members.findIndex(s => isSignerLeaf(s) && s.address === address) | ||
if (index >= 0) { | ||
@@ -653,6 +626,3 @@ members.splice(index, 1) | ||
buildStubSignature: function ( | ||
config: WalletConfig, | ||
overrides: Map<string, string> | ||
) { | ||
buildStubSignature: function (config: WalletConfig, overrides: Map<string, string>) { | ||
const parts = new Map<string, commons.signature.SignaturePart>() | ||
@@ -673,3 +643,4 @@ | ||
for (const { address } of signers.sort(({ weight: a }, { weight: b }) => a - b)) { | ||
const signature = '0x4e82f02f388a12b5f9d29eaf2452dd040c0ee5804b4e504b4dd64e396c6c781f2c7624195acba242dd825bfd25a290912e3c230841fd55c9a734c4de8d9899451b02' | ||
const signature = | ||
'0x4e82f02f388a12b5f9d29eaf2452dd040c0ee5804b4e504b4dd64e396c6c781f2c7624195acba242dd825bfd25a290912e3c230841fd55c9a734c4de8d9899451b02' | ||
parts.set(address, { signature, isDynamic: false }) | ||
@@ -676,0 +647,0 @@ |
@@ -1,2 +0,1 @@ | ||
import { WalletContext as BaseContext } from '../commons/context' | ||
@@ -3,0 +2,0 @@ |
import { WalletContext } from '../commons/context' | ||
export * as config from "./config" | ||
export * as signature from "./signature" | ||
export * as config from './config' | ||
export * as signature from './signature' | ||
export * as context from './context' | ||
export * as chained from './chained' | ||
import { ConfigCoder } from "./config" | ||
import { SignatureCoder } from "./signature" | ||
import { ConfigCoder } from './config' | ||
import { SignatureCoder } from './signature' | ||
export const coders = { | ||
config: ConfigCoder, | ||
signature: SignatureCoder, | ||
signature: SignatureCoder | ||
} | ||
@@ -24,3 +24,3 @@ | ||
mainModuleUpgradable: '0x4222dcA3974E39A8b41c411FeDDE9b09Ae14b911', | ||
walletCreationCode: '0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3', | ||
walletCreationCode: '0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3' | ||
} |
@@ -1,7 +0,21 @@ | ||
import { BigNumberish, ethers } from "ethers" | ||
import { isValidSignature, recoverSigner, tryRecoverSigner } from "../commons/signer" | ||
import { hashNode, isNestedLeaf, isNode, isNodeLeaf, isSignerLeaf, isSubdigestLeaf, Leaf, WalletConfig, SignerLeaf, Topology, imageHash, NodeLeaf, decodeSignerLeaf, isEncodedSignerLeaf } from "./config" | ||
import { BigNumberish, ethers } from 'ethers' | ||
import { isValidSignature, recoverSigner, tryRecoverSigner } from '../commons/signer' | ||
import { | ||
hashNode, | ||
isNestedLeaf, | ||
isNode, | ||
isNodeLeaf, | ||
isSignerLeaf, | ||
isSubdigestLeaf, | ||
Leaf, | ||
WalletConfig, | ||
SignerLeaf, | ||
Topology, | ||
imageHash, | ||
NodeLeaf, | ||
decodeSignerLeaf, | ||
isEncodedSignerLeaf | ||
} from './config' | ||
import * as base from '../commons/signature' | ||
import { hashSetImageHash } from "./chained" | ||
import { hashSetImageHash } from './chained' | ||
@@ -28,13 +42,14 @@ export enum SignatureType { | ||
export type SignatureLeaf = SignerLeaf & { | ||
signature: string, | ||
signature: string | ||
isDynamic: boolean | ||
} | ||
export type UnrecoveredSignatureLeaf = Omit<SignatureLeaf, 'address'> & Pick<Partial<SignatureLeaf>, 'address'> & { | ||
unrecovered: true | ||
} | ||
export type UnrecoveredSignatureLeaf = Omit<SignatureLeaf, 'address'> & | ||
Pick<Partial<SignatureLeaf>, 'address'> & { | ||
unrecovered: true | ||
} | ||
export type UnrecoveredNestedLeaf = { | ||
tree: UnrecoveredTopology, | ||
weight: BigNumberish, | ||
tree: UnrecoveredTopology | ||
weight: BigNumberish | ||
threshold: BigNumberish | ||
@@ -46,3 +61,3 @@ } | ||
export type UnrecoveredNode = { | ||
left: UnrecoveredNode | UnrecoveredLeaf, | ||
left: UnrecoveredNode | UnrecoveredLeaf | ||
right: UnrecoveredNode | UnrecoveredLeaf | ||
@@ -99,86 +114,93 @@ } | ||
switch (type) { | ||
case SignaturePartType.Signature: { | ||
const weight = arr[0] | ||
const signature = ethers.utils.hexlify(arr.slice(1, SignaturePartTypeLength + 1)) | ||
case SignaturePartType.Signature: | ||
{ | ||
const weight = arr[0] | ||
const signature = ethers.utils.hexlify(arr.slice(1, SignaturePartTypeLength + 1)) | ||
pointer = append(pointer, { | ||
signature, | ||
weight, | ||
unrecovered: true, | ||
isDynamic: false | ||
}) | ||
arr = arr.slice(SignaturePartTypeLength + 1) | ||
pointer = append(pointer, { | ||
signature, | ||
weight, | ||
unrecovered: true, | ||
isDynamic: false | ||
}) | ||
arr = arr.slice(SignaturePartTypeLength + 1) | ||
} | ||
break | ||
} break | ||
case SignaturePartType.Address: | ||
{ | ||
const weight = arr[0] | ||
const address = ethers.utils.getAddress(ethers.utils.hexlify(arr.slice(1, 21))) | ||
case SignaturePartType.Address: { | ||
const weight = arr[0] | ||
const address = ethers.utils.getAddress(ethers.utils.hexlify(arr.slice(1, 21))) | ||
pointer = append(pointer, { | ||
address, | ||
weight | ||
}) | ||
arr = arr.slice(21) | ||
} | ||
break | ||
pointer = append(pointer, { | ||
address, | ||
weight, | ||
}) | ||
arr = arr.slice(21) | ||
case SignaturePartType.DynamicSignature: | ||
{ | ||
const weight = arr[0] | ||
const address = ethers.utils.getAddress(ethers.utils.hexlify(arr.slice(1, 21))) | ||
const size = (arr[21] << 16) | (arr[22] << 8) | arr[23] | ||
const signature = ethers.utils.hexlify(arr.slice(24, 24 + size)) | ||
} break | ||
pointer = append(pointer, { | ||
address, | ||
signature, | ||
weight, | ||
unrecovered: true, | ||
isDynamic: true | ||
}) | ||
arr = arr.slice(24 + size) | ||
} | ||
break | ||
case SignaturePartType.DynamicSignature: { | ||
const weight = arr[0] | ||
const address = ethers.utils.getAddress(ethers.utils.hexlify(arr.slice(1, 21))) | ||
const size = arr[21] << 16 | arr[22] << 8 | arr[23] | ||
const signature = ethers.utils.hexlify(arr.slice(24, 24 + size)) | ||
case SignaturePartType.Node: | ||
{ | ||
const nodeHash = ethers.utils.hexlify(arr.slice(0, 32)) | ||
pointer = append(pointer, { | ||
address, | ||
signature, | ||
weight, | ||
unrecovered: true, | ||
isDynamic: true | ||
}) | ||
arr = arr.slice(24 + size) | ||
pointer = append(pointer, { nodeHash }) | ||
arr = arr.slice(32) | ||
} | ||
break | ||
} break | ||
case SignaturePartType.Branch: | ||
{ | ||
const size = (arr[0] << 16) | (arr[1] << 8) | arr[2] | ||
const branch = decodeSignatureTree(arr.slice(3, 3 + size)) | ||
case SignaturePartType.Node: { | ||
const nodeHash = ethers.utils.hexlify(arr.slice(0, 32)) | ||
pointer = append(pointer, branch) | ||
arr = arr.slice(3 + size) | ||
} | ||
break | ||
pointer = append(pointer, { nodeHash }) | ||
arr = arr.slice(32) | ||
case SignaturePartType.Subdigest: | ||
{ | ||
const subdigest = ethers.utils.hexlify(arr.slice(0, 32)) | ||
} break | ||
pointer = append(pointer, { subdigest }) | ||
arr = arr.slice(32) | ||
} | ||
break | ||
case SignaturePartType.Branch: { | ||
const size = arr[0] << 16 | arr[1] << 8 | arr[2] | ||
const branch = decodeSignatureTree(arr.slice(3, 3 + size)) | ||
case SignaturePartType.Nested: | ||
{ | ||
const weight = arr[0] | ||
const threshold = (arr[1] << 8) | arr[2] | ||
const size = (arr[3] << 16) | (arr[4] << 8) | arr[5] | ||
pointer = append(pointer, branch) | ||
arr = arr.slice(3 + size) | ||
const tree = decodeSignatureTree(arr.slice(6, 6 + size)) | ||
} break | ||
pointer = append(pointer, { | ||
weight, | ||
threshold, | ||
tree | ||
}) | ||
arr = arr.slice(6 + size) | ||
} | ||
break | ||
case SignaturePartType.Subdigest: { | ||
const subdigest = ethers.utils.hexlify(arr.slice(0, 32)) | ||
pointer = append(pointer, { subdigest }) | ||
arr = arr.slice(32) | ||
} break | ||
case SignaturePartType.Nested: { | ||
const weight = arr[0] | ||
const threshold = arr[1] << 8 | arr[2] | ||
const size = arr[3] << 16 | arr[4] << 8 | arr[5] | ||
const tree = decodeSignatureTree(arr.slice(6, 6 + size)) | ||
pointer = append(pointer, { | ||
weight, | ||
threshold, | ||
tree | ||
}) | ||
arr = arr.slice(6 + size) | ||
} break | ||
default: | ||
@@ -265,13 +287,7 @@ throw new Error(`Unknown signature part type: ${type}: ${ethers.utils.hexlify(arr)}`) | ||
node: (nodeHash: ethers.BytesLike): string => { | ||
return ethers.utils.solidityPack( | ||
['uint8', 'bytes32'], | ||
[SignaturePartType.Node, nodeHash] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'bytes32'], [SignaturePartType.Node, nodeHash]) | ||
}, | ||
branch: (tree: ethers.BytesLike): string => { | ||
const arr = ethers.utils.arrayify(tree) | ||
return ethers.utils.solidityPack( | ||
['uint8', 'uint24', 'bytes'], | ||
[SignaturePartType.Branch, arr.length, arr] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'uint24', 'bytes'], [SignaturePartType.Branch, arr.length, arr]) | ||
}, | ||
@@ -286,12 +302,6 @@ nested: (weight: ethers.BigNumberish, threshold: ethers.BigNumberish, tree: ethers.BytesLike): string => { | ||
subdigest: (subdigest: ethers.BytesLike): string => { | ||
return ethers.utils.solidityPack( | ||
['uint8', 'bytes32'], | ||
[SignaturePartType.Subdigest, subdigest] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'bytes32'], [SignaturePartType.Subdigest, subdigest]) | ||
}, | ||
signature: (weight: ethers.BigNumberish, signature: ethers.BytesLike): string => { | ||
return ethers.utils.solidityPack( | ||
['uint8', 'uint8', 'bytes'], | ||
[SignaturePartType.Signature, weight, signature] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'uint8', 'bytes'], [SignaturePartType.Signature, weight, signature]) | ||
}, | ||
@@ -306,6 +316,3 @@ dynamicSignature: (weight: ethers.BigNumberish, address: ethers.BytesLike, signature: ethers.BytesLike): string => { | ||
address: (weight: ethers.BigNumberish, address: ethers.BytesLike): string => { | ||
return ethers.utils.solidityPack( | ||
['uint8', 'uint8', 'address'], | ||
[SignaturePartType.Address, weight, address] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'uint8', 'address'], [SignaturePartType.Address, weight, address]) | ||
} | ||
@@ -315,3 +322,3 @@ } | ||
export type EncodingOptions = { | ||
forceDynamicEncoding?: boolean, | ||
forceDynamicEncoding?: boolean | ||
disableTrim?: boolean | ||
@@ -327,3 +334,3 @@ } | ||
): { | ||
encoded: string, | ||
encoded: string | ||
weight: ethers.BigNumber | ||
@@ -368,3 +375,3 @@ } { | ||
): { | ||
encoded: string, | ||
encoded: string | ||
weight: ethers.BigNumber | ||
@@ -394,6 +401,3 @@ } { | ||
// but we still need to include the left node encoded | ||
encoded: partEncoder.concat( | ||
left.encoded, | ||
partEncoder.node(hashNode(topology.right)) | ||
), | ||
encoded: partEncoder.concat(left.encoded, partEncoder.node(hashNode(topology.right))), | ||
weight: left.weight | ||
@@ -408,6 +412,3 @@ } | ||
// we need to create a new "branch" | ||
encoded: partEncoder.concat( | ||
partEncoder.node(hashNode(topology.left)), | ||
partEncoder.branch(right.encoded) | ||
), | ||
encoded: partEncoder.concat(partEncoder.node(hashNode(topology.left)), partEncoder.branch(right.encoded)), | ||
weight: right.weight | ||
@@ -420,6 +421,3 @@ } | ||
// the right one must be a branch | ||
encoded: partEncoder.concat( | ||
left.encoded, | ||
partEncoder.branch(right.encoded) | ||
), | ||
encoded: partEncoder.concat(left.encoded, partEncoder.branch(right.encoded)), | ||
weight: left.weight.add(right.weight) | ||
@@ -478,3 +476,2 @@ } | ||
} | ||
} else { | ||
@@ -492,4 +489,4 @@ return { | ||
export type UnrecoveredConfig = { | ||
tree: UnrecoveredTopology, | ||
threshold: ethers.BigNumberish, | ||
tree: UnrecoveredTopology | ||
threshold: ethers.BigNumberish | ||
checkpoint: ethers.BigNumberish | ||
@@ -499,3 +496,3 @@ } | ||
export type UnrecoveredSignature = base.UnrecoveredSignature & { | ||
type: SignatureType, | ||
type: SignatureType | ||
decoded: UnrecoveredConfig | ||
@@ -517,12 +514,9 @@ } | ||
export function deepestConfigOfSignature(signature: Signature | ChainedSignature): WalletConfig { | ||
return isChainedSignature(signature) ? deepestConfigOfSignature(signature.suffix[signature.suffix.length - 1]) : signature.config | ||
return isChainedSignature(signature) | ||
? deepestConfigOfSignature(signature.suffix[signature.suffix.length - 1]) | ||
: signature.config | ||
} | ||
export function isUnrecoveredSignature(sig: any): sig is UnrecoveredSignature { | ||
return ( | ||
sig.type !== undefined && | ||
sig.decoded !== undefined && | ||
sig.version !== undefined && | ||
sig.version === 2 | ||
) | ||
return sig.type !== undefined && sig.decoded !== undefined && sig.version !== undefined && sig.version === 2 | ||
} | ||
@@ -573,4 +567,4 @@ | ||
const threshold = bytes[0] << 8 | bytes[1] | ||
const checkpoint = bytes[2] << 24 | bytes[3] << 16 | bytes[4] << 8 | bytes[5] | ||
const threshold = (bytes[0] << 8) | bytes[1] | ||
const checkpoint = (bytes[2] << 24) | (bytes[3] << 16) | (bytes[4] << 8) | bytes[5] | ||
@@ -594,3 +588,3 @@ const tree = decodeSignatureTree(bytes.slice(6)) | ||
while (index < arr.length) { | ||
const size = arr[index] << 16 | arr[index + 1] << 8 | arr[index + 2] | ||
const size = (arr[index] << 16) | (arr[index + 1] << 8) | arr[index + 2] | ||
index += 3 | ||
@@ -626,3 +620,3 @@ | ||
): Promise<Signature | ChainedSignature> { | ||
const signedPayload = (payload as { subdigest: string}).subdigest === undefined ? payload as base.SignedPayload : undefined | ||
const signedPayload = (payload as { subdigest: string }).subdigest === undefined ? (payload as base.SignedPayload) : undefined | ||
@@ -644,3 +638,3 @@ const isNoChainId = signature.type === SignatureType.NoChainIdDynamic | ||
} | ||
const result: (Signature | ChainedSignature)[] = [] | ||
@@ -656,5 +650,3 @@ let mutatedPayload = signedPayload | ||
const nextMessage = setImageHashStruct( | ||
imageHash(deepestConfigOfSignature(recovered)) | ||
) | ||
const nextMessage = setImageHashStruct(imageHash(deepestConfigOfSignature(recovered))) | ||
@@ -676,17 +668,14 @@ mutatedPayload = { | ||
const allSignatures = [main, ...(suffix || [])] | ||
const encodedMap = allSignatures.map((s) => ethers.utils.arrayify(encodeSignature(s))) | ||
const encodedMap = allSignatures.map(s => ethers.utils.arrayify(encodeSignature(s))) | ||
const body = ethers.utils.solidityPack( | ||
encodedMap.map(() => ['uint24', 'bytes']).flat(), | ||
encodedMap.map((s) => [s.length, s]).flat() | ||
encodedMap.map(s => [s.length, s]).flat() | ||
) | ||
return ethers.utils.solidityPack( | ||
['uint8', 'bytes'], | ||
[SignatureType.Chained, body] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'bytes'], [SignatureType.Chained, body]) | ||
} | ||
export function encodeSignature( | ||
decoded: UnrecoveredChainedSignature | ChainedSignature | UnrecoveredSignature | Signature | ethers.BytesLike, | ||
decoded: UnrecoveredChainedSignature | ChainedSignature | UnrecoveredSignature | Signature | ethers.BytesLike | ||
): string { | ||
@@ -696,6 +685,3 @@ if (ethers.utils.isBytesLike(decoded)) return ethers.utils.hexlify(decoded) | ||
if (isUnrecoveredChainedSignature(decoded) || isChainedSignature(decoded)) { | ||
return encodeChain( | ||
encodeSignature(decoded), | ||
(decoded.suffix || []).map(encodeSignature) | ||
) | ||
return encodeChain(encodeSignature(decoded), (decoded.suffix || []).map(encodeSignature)) | ||
} | ||
@@ -715,8 +701,4 @@ | ||
case SignatureType.Dynamic: | ||
return ethers.utils.solidityPack( | ||
['uint8', 'bytes'], | ||
[decoded.type, encodeSignatureBody(body)] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'bytes'], [decoded.type, encodeSignatureBody(body)]) | ||
case SignatureType.Chained: | ||
@@ -749,6 +731,3 @@ throw new Error(`Unreachable code: Chained signature should be handled above`) | ||
} else { | ||
return ethers.utils.solidityPack( | ||
['bytes', 'bytes'], | ||
[encodedLeft, encodedRight] | ||
) | ||
return ethers.utils.solidityPack(['bytes', 'bytes'], [encodedLeft, encodedRight]) | ||
} | ||
@@ -776,6 +755,3 @@ } | ||
} else { | ||
return ethers.utils.solidityPack( | ||
['uint8', 'uint8', 'bytes'], | ||
[SignaturePartType.Signature, tree.weight, signature] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'uint8', 'bytes'], [SignaturePartType.Signature, tree.weight, signature]) | ||
} | ||
@@ -785,20 +761,11 @@ } | ||
if (isSignerLeaf(tree)) { | ||
return ethers.utils.solidityPack( | ||
['uint8', 'uint8', 'address'], | ||
[SignaturePartType.Address, tree.weight, tree.address] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'uint8', 'address'], [SignaturePartType.Address, tree.weight, tree.address]) | ||
} | ||
if (isNodeLeaf(tree)) { | ||
return ethers.utils.solidityPack( | ||
['uint8', 'bytes32'], | ||
[SignaturePartType.Node, tree.nodeHash] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'bytes32'], [SignaturePartType.Node, tree.nodeHash]) | ||
} | ||
if (isSubdigestLeaf(tree)) { | ||
return ethers.utils.solidityPack( | ||
['uint8', 'bytes32'], | ||
[SignaturePartType.Subdigest, tree.subdigest] | ||
) | ||
return ethers.utils.solidityPack(['uint8', 'bytes32'], [SignaturePartType.Subdigest, tree.subdigest]) | ||
} | ||
@@ -809,3 +776,3 @@ | ||
export function signaturesOf(topology: Topology): { address: string, signature: string }[] { | ||
export function signaturesOf(topology: Topology): { address: string; signature: string }[] { | ||
if (isNode(topology)) { | ||
@@ -865,3 +832,3 @@ return [...signaturesOf(topology.left), ...signaturesOf(topology.right)] | ||
trimSignature({ ...decoded, suffix: undefined } as UnrecoveredSignature), | ||
...decoded.suffix.map((s) => trimSignature(s)) | ||
...decoded.suffix.map(s => trimSignature(s)) | ||
]) | ||
@@ -873,14 +840,14 @@ | ||
const { trimmed } = await trimUnrecoveredTree(decoded.decoded.tree) | ||
return encodeSignature({ ...decoded, decoded: { ...decoded.decoded, tree: trimmed }}) | ||
return encodeSignature({ ...decoded, decoded: { ...decoded.decoded, tree: trimmed } }) | ||
} | ||
export async function trimUnrecoveredTree(tree: UnrecoveredTopology, trimStaticDigest: boolean = true): Promise<{ | ||
weight: number, | ||
export async function trimUnrecoveredTree( | ||
tree: UnrecoveredTopology, | ||
trimStaticDigest: boolean = true | ||
): Promise<{ | ||
weight: number | ||
trimmed: UnrecoveredTopology | ||
}> { | ||
if (isUnrecoveredNode(tree)) { | ||
const [left, right] = await Promise.all([ | ||
trimUnrecoveredTree(tree.left), | ||
trimUnrecoveredTree(tree.right) | ||
]) | ||
const [left, right] = await Promise.all([trimUnrecoveredTree(tree.left), trimUnrecoveredTree(tree.right)]) | ||
@@ -893,3 +860,3 @@ if (left.weight === 0 && right.weight === 0) { | ||
const recovered = await recoverTopology(tree, ethers.constants.HashZero, undefined as any) | ||
return { | ||
@@ -924,3 +891,3 @@ weight: 0, | ||
const recovered = await recoverTopology(tree, ethers.constants.HashZero, undefined as any) | ||
return { | ||
@@ -954,3 +921,3 @@ weight: 0, | ||
trimmed: { | ||
...decodeSignerLeaf(tree.nodeHash), | ||
...decodeSignerLeaf(tree.nodeHash) | ||
} as SignerLeaf | ||
@@ -980,7 +947,3 @@ } | ||
export const SignatureCoder: base.SignatureCoder< | ||
WalletConfig, | ||
Signature, | ||
UnrecoveredChainedSignature | UnrecoveredSignature | ||
> = { | ||
export const SignatureCoder: base.SignatureCoder<WalletConfig, Signature, UnrecoveredChainedSignature | UnrecoveredSignature> = { | ||
decode: (data: string): UnrecoveredSignature => { | ||
@@ -1041,3 +1004,3 @@ return decodeSignature(data) | ||
signaturesOf(config: WalletConfig): { address: string, signature: string }[] { | ||
signaturesOf(config: WalletConfig): { address: string; signature: string }[] { | ||
return signaturesOf(config.tree) | ||
@@ -1044,0 +1007,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
427570
-0.12%10352
-0.99%+ Added
- Removed