Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare release #1074

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion guides/integrating-the-safe-core-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ type SafeMultisigTransactionResponse = {
transactionHash?: string
confirmationType?: string
signature: string
signatureType?: string
signatureType?: SignatureType
},
// ...
]
Expand Down
8 changes: 4 additions & 4 deletions packages/api-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/api-kit",
"version": "2.5.4",
"version": "2.5.5",
"description": "SDK that facilitates the interaction with the Safe Transaction Service API",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -39,7 +39,7 @@
],
"homepage": "https://github.com/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@safe-global/relay-kit": "^3.2.4",
"@safe-global/relay-kit": "^3.3.0",
"@safe-global/testing-kit": "^0.1.1",
"@types/chai": "^4.3.19",
"@types/chai-as-promised": "^7.1.8",
Expand All @@ -58,8 +58,8 @@
"web3": "^4.12.1"
},
"dependencies": {
"@safe-global/protocol-kit": "^5.0.4",
"@safe-global/types-kit": "^1.0.0",
"@safe-global/protocol-kit": "^5.1.0",
"@safe-global/types-kit": "^1.0.1",
"node-fetch": "^2.7.0",
"viem": "^2.21.8"
}
Expand Down
14 changes: 11 additions & 3 deletions packages/api-kit/src/SafeApiKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,28 @@
/**
* Decodes the specified Safe transaction data.
*
* @param data - The Safe transaction data
* @param data - The Safe transaction data. '0x' prefixed hexadecimal string.
* @param to - The address of the receiving contract. If provided, the decoded data will be more accurate, as in case of an ABI collision the Safe Transaction Service would know which ABI to use
* @returns The transaction data decoded
* @throws "Invalid data"
* @throws "Not Found"
* @throws "Ensure this field has at least 1 hexadecimal chars (not counting 0x)."
*/
async decodeData(data: string): Promise<any> {
async decodeData(data: string, to?: string): Promise<any> {

Check warning on line 125 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type

Check warning on line 125 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
if (data === '') {
throw new Error('Invalid data')
}

const dataDecoderRequest: { data: string; to?: string } = { data }

if (to) {
dataDecoderRequest.to = to
}

return sendRequest({
url: `${this.#txServiceBaseUrl}/v1/data-decoder/`,
method: HttpMethod.Post,
body: { data }
body: dataDecoderRequest
})
}

Expand Down Expand Up @@ -331,7 +339,7 @@
const { address: delegator } = this.#getEip3770Address(delegatorAddress)
const signature = await signDelegate(signer, delegate, this.#chainId)

const body: any = {

Check warning on line 342 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type

Check warning on line 342 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
safe: safeAddress ? this.#getEip3770Address(safeAddress).address : null,
delegate,
delegator,
Expand Down
5 changes: 3 additions & 2 deletions packages/api-kit/src/types/safeTransactionServiceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
SafeTransactionData,
UserOperation,
SafeOperationResponse,
ListResponse
ListResponse,
SignatureType
} from '@safe-global/types-kit'

export type ListOptions = {
Expand Down Expand Up @@ -231,7 +232,7 @@ export type SafeMessageConfirmation = {
readonly modified: string
readonly owner: string
readonly signature: string
readonly signatureType: string
readonly signatureType: SignatureType
}

export type SafeMessage = {
Expand Down
18 changes: 18 additions & 0 deletions packages/api-kit/tests/e2e/decodeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,22 @@ describe('decodeData', () => {
})
)
})

it('should decode the data and allow to specify the receiving contract', async () => {
const data = '0x610b592500000000000000000000000090F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
const to = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
const decodedData = await safeApiKit.decodeData(data, to)
chai.expect(JSON.stringify(decodedData)).to.be.equal(
JSON.stringify({
method: 'enableModule',
parameters: [
{
name: 'module',
type: 'address',
value: '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
}
]
})
)
})
})
11 changes: 7 additions & 4 deletions packages/protocol-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/protocol-kit",
"version": "5.0.4",
"version": "5.1.0",
"description": "SDK that facilitates the interaction with Safe Smart Accounts",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down Expand Up @@ -66,12 +66,15 @@
"web3": "^4.12.1"
},
"dependencies": {
"@noble/hashes": "^1.3.3",
"@safe-global/safe-deployments": "^1.37.14",
"@safe-global/safe-deployments": "^1.37.20",
"@safe-global/safe-modules-deployments": "^2.2.4",
"@safe-global/types-kit": "^1.0.0",
"@safe-global/types-kit": "^1.0.1",
"abitype": "^1.0.2",
"semver": "^7.6.3",
"viem": "^2.21.8"
},
"optionalDependencies": {
"@noble/curves": "^1.6.0",
"@peculiar/asn1-schema": "^2.3.13"
}
}
15 changes: 13 additions & 2 deletions packages/protocol-kit/src/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import {
SigningMethodType,
SwapOwnerTxParams,
SafeModulesPaginated,
RemovePasskeyOwnerTxParams
RemovePasskeyOwnerTxParams,
PasskeyArgType
} from './types'
import {
EthSafeSignature,
Expand All @@ -59,7 +60,8 @@ import {
generateSignature,
preimageSafeMessageHash,
preimageSafeTransactionHash,
adjustVInSignature
adjustVInSignature,
extractPasskeyData
} from './utils'
import EthSafeTransaction from './utils/transactions/SafeTransaction'
import { SafeTransactionOptionalProps } from './utils/transactions/types'
Expand Down Expand Up @@ -1698,6 +1700,15 @@ class Safe {
}): ContractInfo | undefined => {
return getContractInfo(contractAddress)
}

/**
* This method creates a signer to be used with the init method
* @param {Credential} credential - The credential to be used to create the signer. Can be generated in the web with navigator.credentials.create
* @returns {PasskeyArgType} - The signer to be used with the init method
*/
static createPasskeySigner = async (credential: Credential): Promise<PasskeyArgType> => {
return extractPasskeyData(credential)
}
}

export default Safe
42 changes: 28 additions & 14 deletions packages/protocol-kit/src/contracts/safeDeploymentContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ export async function getCompatibilityFallbackHandlerContract({
export async function getMultiSendContract({
safeProvider,
safeVersion,
customContracts
customContracts,
deploymentType
}: GetContractInstanceProps): Promise<MultiSendContractImplementationType> {
const multiSendContract = await getMultiSendContractInstance(
safeVersion,
safeProvider,
customContracts?.multiSendAddress,
customContracts?.multiSendAbi
customContracts?.multiSendAbi,
deploymentType
)

const isContractDeployed = await safeProvider.isContractDeployed(multiSendContract.getAddress())
Expand All @@ -131,13 +133,15 @@ export async function getMultiSendContract({
export async function getMultiSendCallOnlyContract({
safeProvider,
safeVersion,
customContracts
customContracts,
deploymentType
}: GetContractInstanceProps): Promise<MultiSendCallOnlyContractImplementationType> {
const multiSendCallOnlyContract = await getMultiSendCallOnlyContractInstance(
safeVersion,
safeProvider,
customContracts?.multiSendCallOnlyAddress,
customContracts?.multiSendCallOnlyAbi
customContracts?.multiSendCallOnlyAbi,
deploymentType
)

const isContractDeployed = await safeProvider.isContractDeployed(
Expand All @@ -152,13 +156,15 @@ export async function getMultiSendCallOnlyContract({
export async function getSignMessageLibContract({
safeProvider,
safeVersion,
customContracts
customContracts,
deploymentType
}: GetContractInstanceProps): Promise<SignMessageLibContractImplementationType> {
const signMessageLibContract = await getSignMessageLibContractInstance(
safeVersion,
safeProvider,
customContracts?.signMessageLibAddress,
customContracts?.signMessageLibAbi
customContracts?.signMessageLibAbi,
deploymentType
)

const isContractDeployed = await safeProvider.isContractDeployed(
Expand All @@ -173,13 +179,15 @@ export async function getSignMessageLibContract({
export async function getCreateCallContract({
safeProvider,
safeVersion,
customContracts
customContracts,
deploymentType
}: GetContractInstanceProps): Promise<CreateCallContractImplementationType> {
const createCallContract = await getCreateCallContractInstance(
safeVersion,
safeProvider,
customContracts?.createCallAddress,
customContracts?.createCallAbi
customContracts?.createCallAbi,
deploymentType
)

const isContractDeployed = await safeProvider.isContractDeployed(createCallContract.getAddress())
Expand All @@ -192,13 +200,15 @@ export async function getCreateCallContract({
export async function getSimulateTxAccessorContract({
safeProvider,
safeVersion,
customContracts
customContracts,
deploymentType
}: GetContractInstanceProps): Promise<SimulateTxAccessorContractImplementationType> {
const simulateTxAccessorContract = await getSimulateTxAccessorContractInstance(
safeVersion,
safeProvider,
customContracts?.simulateTxAccessorAddress,
customContracts?.simulateTxAccessorAbi
customContracts?.simulateTxAccessorAbi,
deploymentType
)

const isContractDeployed = await safeProvider.isContractDeployed(
Expand All @@ -213,13 +223,15 @@ export async function getSimulateTxAccessorContract({
export async function getSafeWebAuthnSignerFactoryContract({
safeProvider,
safeVersion,
customContracts
customContracts,
deploymentType
}: GetContractInstanceProps): Promise<SafeWebAuthnSignerFactoryContractImplementationType> {
const safeWebAuthnSignerFactoryContract = await getSafeWebAuthnSignerFactoryContractInstance(
safeVersion,
safeProvider,
customContracts?.safeWebAuthnSignerFactoryAddress,
customContracts?.safeWebAuthnSignerFactoryAbi
customContracts?.safeWebAuthnSignerFactoryAbi,
deploymentType
)

const isContractDeployed = await safeProvider.isContractDeployed(
Expand All @@ -234,13 +246,15 @@ export async function getSafeWebAuthnSignerFactoryContract({
export async function getSafeWebAuthnSharedSignerContract({
safeProvider,
safeVersion,
customContracts
customContracts,
deploymentType
}: GetContractInstanceProps): Promise<SafeWebAuthnSharedSignerContractImplementationType> {
const safeWebAuthnSharedSignerContract = await getSafeWebAuthnSharedSignerContractInstance(
safeVersion,
safeProvider,
customContracts?.safeWebAuthnSharedSignerAddress,
customContracts?.safeWebAuthnSharedSignerAbi
customContracts?.safeWebAuthnSharedSignerAbi,
deploymentType
)

const isContractDeployed = await safeProvider.isContractDeployed(
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 @@ -35,7 +35,6 @@ import {
estimateTxGas,
estimateSafeTxGas,
estimateSafeDeploymentGas,
extractPasskeyCoordinates,
extractPasskeyData,
validateEthereumAddress,
validateEip3770Address
Expand Down Expand Up @@ -74,7 +73,6 @@ export {
estimateSafeTxGas,
estimateSafeDeploymentGas,
extractPasskeyData,
extractPasskeyCoordinates,
ContractManager,
CreateCallBaseContract,
createERC20TokenTransferTransaction,
Expand Down
6 changes: 4 additions & 2 deletions packages/protocol-kit/src/managers/contractManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ class ContractManager {
this.#multiSendContract = await getMultiSendContract({
safeProvider,
safeVersion,
customContracts
customContracts,
deploymentType: predictedSafe?.safeDeploymentConfig?.deploymentType
})

this.#multiSendCallOnlyContract = await getMultiSendCallOnlyContract({
safeProvider,
safeVersion,
customContracts
customContracts,
deploymentType: predictedSafe?.safeDeploymentConfig?.deploymentType
})
}

Expand Down
5 changes: 4 additions & 1 deletion packages/protocol-kit/src/types/passkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ export type PasskeyCoordinates = {
y: string
}

export type GetPasskeyCredentialFn = (options?: CredentialRequestOptions) => Promise<Credential>

export type PasskeyArgType = {
rawId: string // required to sign data
coordinates: PasskeyCoordinates // required to sign data
customVerifierAddress?: string // optional
customVerifierAddress?: string
getFn?: GetPasskeyCredentialFn
}
2 changes: 1 addition & 1 deletion packages/protocol-kit/src/types/safeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type HexAddress = string
export type PrivateKey = string
export type HttpTransport = string
export type SocketTransport = string
export type SafeSigner = HexAddress | PrivateKey | PasskeyClient
export type SafeSigner = HexAddress | PrivateKey | PasskeyArgType | PasskeyClient

export type SafeProviderConfig = {
/** signerOrProvider - Ethers signer or provider */
Expand Down
Loading
Loading