-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: increase refinement test coverage (#2431)
Adds extensive test coverage to refinement of proposal/confirmation and API transactions/messages. It also includes small fixes that we found due to adding test coverage: - Increase test coverage of `TransactionVerifier` and `MessageVerifier` - Propagate similar test coverage to respective controller tests for transactions/messages
- Loading branch information
Showing
26 changed files
with
5,869 additions
and
4,105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,64 @@ | ||
export function getApprovedHashSignature(owner: `0x${string}`): `0x${string}` { | ||
import { SignatureType } from '@/domain/common/entities/signature-type.entity'; | ||
import type { PrivateKeyAccount } from 'viem'; | ||
|
||
export async function getSignature(args: { | ||
signer: PrivateKeyAccount; | ||
hash: `0x${string}`; | ||
signatureType: SignatureType; | ||
}): Promise<`0x${string}`> { | ||
switch (args.signatureType) { | ||
case SignatureType.ContractSignature: { | ||
return getContractSignature(args.signer.address); | ||
} | ||
case SignatureType.ApprovedHash: { | ||
return getApprovedHashSignature(args.signer.address); | ||
} | ||
case SignatureType.Eoa: { | ||
return await getEoaSignature({ signer: args.signer, hash: args.hash }); | ||
} | ||
case SignatureType.EthSign: { | ||
return await getEthSignSignature({ | ||
signer: args.signer, | ||
hash: args.hash, | ||
}); | ||
} | ||
default: { | ||
throw new Error(`Unknown signature type: ${args.signatureType}`); | ||
} | ||
} | ||
} | ||
|
||
function getApprovedHashSignature(owner: `0x${string}`): `0x${string}` { | ||
return ('0x000000000000000000000000' + | ||
owner.slice(2) + | ||
'0000000000000000000000000000000000000000000000000000000000000000' + | ||
'01') as `0x${string}`; | ||
} | ||
|
||
export function getContractSignature(owner: `0x${string}`): `0x${string}` { | ||
function getContractSignature(owner: `0x${string}`): `0x${string}` { | ||
return ('0x000000000000000000000000' + | ||
owner.slice(2) + | ||
'0000000000000000000000000000000000000000000000000000000000000000' + | ||
'00') as `0x${string}`; | ||
} | ||
|
||
export function adjustEthSignSignature( | ||
signature: `0x${string}`, | ||
): `0x${string}` { | ||
async function getEoaSignature(args: { | ||
signer: PrivateKeyAccount; | ||
hash: `0x${string}`; | ||
}): Promise<`0x${string}`> { | ||
return await args.signer.sign({ hash: args.hash }); | ||
} | ||
|
||
async function getEthSignSignature(args: { | ||
signer: PrivateKeyAccount; | ||
hash: `0x${string}`; | ||
}): Promise<`0x${string}`> { | ||
const signature = await args.signer.signMessage({ | ||
message: { raw: args.hash }, | ||
}); | ||
|
||
// To differentiate signature types, eth_sign signatures have v value increased by 4 | ||
// @see https://docs.safe.global/advanced/smart-account-signatures#eth_sign-signature | ||
const v = parseInt(signature.slice(-2), 16); | ||
return (signature.slice(0, 130) + (v + 4).toString(16)) as `0x${string}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.