I'd like to know either how to implement the skinny CREATE2 in Python or a package that provides it.
This is the function I'm trying to port from TypeScript to Python. It calls generateAddress2
with that particular salt (size 32):
export function getUserIdentity(walletAddr) {
const bytecode = getBytecode(walletAddr)
const addr = getAddress(
`0x${generateAddress2(ADDR_FACTORY, Buffer.alloc(32), bytecode).toString(
"hex"
)}`
)
return { bytecode, addr }
}
And this is the ethereumjs generateAddress2
implementation:
/**
* Generates an address for a contract created using CREATE2.
* @param from The address which is creating this new address
* @param salt A salt
* @param initCode The init code of the contract being created
*/
export const generateAddress2 = function(from: Buffer, salt: Buffer, initCode: Buffer): Buffer {
assertIsBuffer(from)
assertIsBuffer(salt)
assertIsBuffer(initCode)
assert(from.length === 20)
assert(salt.length === 32)
const address = keccak256(
Buffer.concat([Buffer.from('ff', 'hex'), from, salt, keccak256(initCode)]),
)
return address.slice(-20)
}
Many thanks!