Skip to content

Commit

Permalink
chore: code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dasanra committed Sep 19, 2024
1 parent eadecb9 commit 4ec32bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
42 changes: 17 additions & 25 deletions packages/protocol-kit/src/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,12 @@ class Safe {
signingMethod: SigningMethodType = SigningMethod.ETH_SIGN_TYPED_DATA_V4,
preimageSafeAddress?: string
): Promise<SafeMessage> {
const owners = await this.getOwners()
const signerAddress = await this.#safeProvider.getSignerAddress()
if (!signerAddress) {
throw new Error('SafeProvider must be initialized with a signer to use this method')
throw new Error('The protocol-kit requires a signer to use this method')
}

const addressIsOwner = owners.some(
(owner: string) => signerAddress && sameString(owner, signerAddress)
)
const addressIsOwner = await this.isOwner(signerAddress)
if (!addressIsOwner) {
throw new Error('Messages can only be signed by Safe owners')
}
Expand Down Expand Up @@ -764,16 +761,12 @@ class Safe {
? await this.toSafeTransactionType(safeTransaction)
: safeTransaction

const owners = await this.getOwners()
const signerAddress = await this.#safeProvider.getSignerAddress()

if (!signerAddress) {
throw new Error('SafeProvider must be initialized with a signer to use this method')
throw new Error('The protocol-kit requires a signer to use this method')
}

const addressIsOwner = owners.some(
(owner: string) => signerAddress && sameString(owner, signerAddress)
)
const addressIsOwner = await this.isOwner(signerAddress)
if (!addressIsOwner) {
throw new Error('Transactions can only be signed by Safe owners')
}
Expand Down Expand Up @@ -855,14 +848,12 @@ class Safe {
throw new Error('Safe is not deployed')
}

const owners = await this.getOwners()
const signerAddress = await this.#safeProvider.getSignerAddress()
if (!signerAddress) {
throw new Error('SafeProvider must be initialized with a signer to use this method')
throw new Error('The protocol-kit requires a signer to use this method')
}
const addressIsOwner = owners.some(
(owner: string) => signerAddress && sameString(owner, signerAddress)
)

const addressIsOwner = await this.isOwner(signerAddress)
if (!addressIsOwner) {
throw new Error('Transaction hashes can only be approved by Safe owners')
}
Expand Down Expand Up @@ -1269,12 +1260,14 @@ class Safe {
for (const owner of ownersWhoApprovedTx) {
signedSafeTransaction.addSignature(generatePreValidatedSignature(owner))
}
const owners = await this.getOwners()

const signerAddress = await this.#safeProvider.getSignerAddress()
if (!signerAddress) {
throw new Error('SafeProvider must be initialized with a signer to use this method')
throw new Error('The protocol-kit requires a signer to use this method')
}
if (owners.includes(signerAddress)) {

const addressIsOwner = await this.isOwner(signerAddress)
if (addressIsOwner) {
signedSafeTransaction.addSignature(generatePreValidatedSignature(signerAddress))
}

Expand Down Expand Up @@ -1316,14 +1309,13 @@ class Safe {
for (const owner of ownersWhoApprovedTx) {
signedSafeTransaction.addSignature(generatePreValidatedSignature(owner))
}
const owners = await this.getOwners()
const threshold = await this.getThreshold()
const signerAddress = await this.#safeProvider.getSignerAddress()
if (
threshold > signedSafeTransaction.signatures.size &&
signerAddress &&
owners.includes(signerAddress)
) {
if (!signerAddress) {
throw new Error('The protocol-kit requires a signer to use this method')
}
const addressIsOwner = await this.isOwner(signerAddress)
if (threshold > signedSafeTransaction.signatures.size && addressIsOwner) {
signedSafeTransaction.addSignature(generatePreValidatedSignature(signerAddress))
}

Expand Down
2 changes: 0 additions & 2 deletions packages/protocol-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
estimateSafeDeploymentGas,
extractPasskeyCoordinates,
extractPasskeyData,
getDefaultFCLP256VerifierAddress,
validateEthereumAddress,
validateEip3770Address
} from './utils'
Expand Down Expand Up @@ -102,7 +101,6 @@ export {
getSignMessageLibContract,
getSafeWebAuthnSignerFactoryContract,
getSafeWebAuthnSharedSignerContract,
getDefaultFCLP256VerifierAddress,
isGasTokenCompatibleWithHandlePayment,
predictSafeAddress,
getPredictedSafeAddressInitCode,
Expand Down
2 changes: 1 addition & 1 deletion packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class Safe4337Pack extends RelayKitBasePack<{
version: safeModulesVersion,
network
})
addModulesLibAddress = addModulesDeployment?.networkAddresses[network] as string | undefined
addModulesLibAddress = addModulesDeployment?.networkAddresses[network]
}

let safe4337ModuleAddress = customContracts?.safe4337ModuleAddress
Expand Down

0 comments on commit 4ec32bf

Please sign in to comment.