utils

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const GnosisSafeSigLength = ethCrypto.SignatureLength

Variables

View Source
var (
	// MerkleLeafEncoding is (recipient, amount, contract_address, kwil_block_hash).
	// There is no point to add `kwil_chain_id` in the leaf encoding, as we cannot
	// enforce the uniqueness of it.
	MerkleLeafEncoding = []string{smt.SOL_ADDRESS, smt.SOL_UINT256, smt.SOL_ADDRESS, smt.SOL_BYTES32}
)

Functions

func EthGnosisRecoverSigner

func EthGnosisRecoverSigner(sig []byte, digest []byte) (*ethCommon.Address, error)

func EthGnosisSign

func EthGnosisSign(msg []byte, key *ecdsa.PrivateKey) ([]byte, error)

EthGnosisSign generate a Gnosis(>1.3.0) signature, which is 65-byte in [R || S || V] format where V is 31 or 32. The message is the original message.

	The Safe's expected V value for ECDSA signature is:
	- 27 or 28, for eth_sign
	- 31 or 32 if the message was signed with a EIP-191 prefix. Should be calculated as ECDSA V value + 4
	Some wallets do that, some wallets don't, V > 30 is used by contracts to differentiate between
	prefixed and non-prefixed messages. The only way to know if the message was signed with a
	prefix is to check if the signer address is the same as the recovered address.

	More info:
	https://docs.safe.global/advanced/smart-account-signatures
 SDK: safe-core-sdk/packages/protocol-kit/src/utils/signatures/utils.ts `adjustVInSignature`

Since we use EIP-191, the V should be 31(0x1f) or 32(0x20).

func EthGnosisSignDigest

func EthGnosisSignDigest(digest []byte, key *ecdsa.PrivateKey) ([]byte, error)

func EthGnosisVerify

func EthGnosisVerify(sig []byte, msg []byte, address []byte) error

EthGnosisVerify verify the given message to the Gnosis(>1.3.0) signature, which is 65-byte in [R || S || V] format and V is 31(0x1f) or 32(0x20).

func EthGnosisVerifyDigest

func EthGnosisVerifyDigest(sig []byte, digest []byte, address []byte) error

func EthZeppelinSign

func EthZeppelinSign(msg []byte, key *ecdsa.PrivateKey) ([]byte, error)

EthZeppelinSign generate a OpenZeppelin compatible signature. The produced signature is 65-byte in the [R || S || V] format where V is 27 or 28.

func GenGnosisSafeTx

func GenGnosisSafeTx(to, safe string, value int64, data hexutil.Bytes, chainID int64,
	nonce int64) (*core.GnosisSafeTx, []byte, error)

GenGnosisSafeTx returns a safe tx, and the tx hash to be used to generate signature. More info: https://docs.safe.global/sdk/protocol-kit/guides/signatures/transactions Since Gnosis 1.3.0, ChainID is a part of the EIP-712 domain.

func GenPostRewardTxData

func GenPostRewardTxData(root []byte, amount *big.Int) ([]byte, error)

func GenRewardMerkleTree

func GenRewardMerkleTree(users []string, amounts []*big.Int, contractAddress string, kwilBlockHash [32]byte) ([]byte, []byte, error)

func GetLeafAddresses

func GetLeafAddresses(mtreeJson string) ([]string, error)

func GetMTreeProof

func GetMTreeProof(mtreeJson []byte, addr string) (root []byte, proof [][]byte, leafHash []byte, blockHash []byte, amount *big.Int, err error)

GetMTreeProof returns the leaf proof along with the leaf hash, amount.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL