From ade2a9b60836faea749965caf0a0bf80b844888f Mon Sep 17 00:00:00 2001 From: Richard Henry Date: Wed, 15 Jan 2025 07:53:23 -0800 Subject: [PATCH 1/3] fix(protocol-kit): Fix non-ArrayBuffer passkey signature error (#1054) (#1094) --- .../protocol-kit/src/utils/passkeys/PasskeyClient.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/protocol-kit/src/utils/passkeys/PasskeyClient.ts b/packages/protocol-kit/src/utils/passkeys/PasskeyClient.ts index 40bec29dd..10eb5290a 100644 --- a/packages/protocol-kit/src/utils/passkeys/PasskeyClient.ts +++ b/packages/protocol-kit/src/utils/passkeys/PasskeyClient.ts @@ -200,11 +200,11 @@ function extractClientDataFields(clientDataJSON: ArrayBuffer): Hex { * Extracts the numeric values r and s from a DER-encoded ECDSA signature. * This function decodes the signature based on a specific format and validates the encoding at each step. * - * @param {ArrayBuffer} signature - The DER-encoded signature to be decoded. + * @param {ArrayBuffer | Uint8Array | Array} signature - The DER-encoded signature to be decoded. The WebAuthn standard expects the signature to be an ArrayBuffer, but some password managers (including Bitwarden) provide a Uint8Array or an array of numbers instead. * @returns {[bigint, bigint]} A tuple containing two BigInt values, r and s, which are the numeric values extracted from the signature. * @throws {Error} Throws an error if the signature encoding is invalid or does not meet expected conditions. */ -function extractSignature(signature: ArrayBuffer): [bigint, bigint] { +function extractSignature(signature: ArrayBuffer | Uint8Array | Array): [bigint, bigint] { const check = (x: boolean) => { if (!x) { throw new Error('invalid signature encoding') @@ -214,7 +214,13 @@ function extractSignature(signature: ArrayBuffer): [bigint, bigint] { // Decode the DER signature. Note that we assume that all lengths fit into 8-bit integers, // which is true for the kinds of signatures we are decoding but generally false. I.e. this // code should not be used in any serious application. - const view = new DataView(signature) + const view = new DataView( + signature instanceof ArrayBuffer + ? signature + : signature instanceof Uint8Array + ? signature.buffer + : new Uint8Array(signature).buffer + ) // check that the sequence header is valid check(view.getUint8(0) === 0x30) From 6d75e96289b48d126a1dca236c6825d2f10778ab Mon Sep 17 00:00:00 2001 From: Daniel <25051234+dasanra@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:57:03 +0100 Subject: [PATCH 2/3] chore: fix typos (#1096) --- CONTRIBUTING.md | 4 ++-- playground/README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3af627092..62fb3dcb6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ You will need to agree to [our CLA](https://safe.global/cla) in order to be poss ### Starting Guide -By following the steps bellow you will understand the development process and worflow. +By following the steps below you will understand the development process and workflow. 1. [Forking the repository](#forking-the-repository) 2. [Installing Node and Yarn](#installing-node-and-yarn) 3. [Installing dependencies](#installing-dependencies) @@ -44,7 +44,7 @@ yarn -v #### Installing dependencies -The Safe{Core} SDK uses a mono-repository structure managed by [Yarn Workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/) and [Lerna](https://lerna.js.org). From the root of the repository you will need to install the whole dependency stack and do the project build. Some packages depend on each other, so even when modifiying only one package it's better to run the full build. +The Safe{Core} SDK uses a mono-repository structure managed by [Yarn Workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/) and [Lerna](https://lerna.js.org). From the root of the repository you will need to install the whole dependency stack and do the project build. Some packages depend on each other, so even when modifying only one package it's better to run the full build. Install all dependencies and build the whole project by using the following commands at the project root. diff --git a/playground/README.md b/playground/README.md index 8558750a2..fa08b7625 100644 --- a/playground/README.md +++ b/playground/README.md @@ -55,7 +55,7 @@ In case you want to execute the transaction via a transaction relay, this script yarn play relay-sponsored-transaction ``` -#### Generate a custon Safe address +#### Generate a custom Safe address This script allows to find the right `saltNonce` to generate a vanity Safe address with any given configuration: From fdfb6c7e28b0b52f31f9885fdc43fdcb33670b68 Mon Sep 17 00:00:00 2001 From: Dani Somoza Date: Thu, 16 Jan 2025 15:48:19 +0100 Subject: [PATCH 3/3] fix Generate getProtocolKitVersion dynamically via prebuild script (#1098) --- packages/protocol-kit/package.json | 1 + packages/protocol-kit/src/Safe.ts | 2 +- packages/protocol-kit/src/utils/getProtocolKitVersion.ts | 8 +------- packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts | 5 +++-- packages/protocol-kit/tsconfig.build.json | 3 +-- packages/protocol-kit/tsconfig.json | 3 +-- packages/relay-kit/package.json | 1 + packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts | 2 +- .../src/packs/safe-4337/utils/getRelayKitVersion.ts | 8 +------- packages/relay-kit/tsconfig.build.json | 3 +-- packages/relay-kit/tsconfig.json | 3 +-- 11 files changed, 13 insertions(+), 26 deletions(-) diff --git a/packages/protocol-kit/package.json b/packages/protocol-kit/package.json index 865e511d9..445205ae7 100644 --- a/packages/protocol-kit/package.json +++ b/packages/protocol-kit/package.json @@ -35,6 +35,7 @@ "format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"", "format": "prettier --write \"*/**/*.{js,json,md,ts}\"", "unbuild": "rimraf dist artifacts deployments cache .nyc_output *.tsbuildinfo", + "prebuild": "node -p \"'export const getProtocolKitVersion = () => \\'' + require('./package.json').version.split('-')[0] + '\\''\" > src/utils/getProtocolKitVersion.ts", "build": "yarn unbuild && yarn check-safe-deployments && NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json" }, "repository": { diff --git a/packages/protocol-kit/src/Safe.ts b/packages/protocol-kit/src/Safe.ts index c578ac8af..b9482711f 100644 --- a/packages/protocol-kit/src/Safe.ts +++ b/packages/protocol-kit/src/Safe.ts @@ -88,7 +88,7 @@ import { Hash, Hex, SendTransactionParameters } from 'viem' import getPasskeyOwnerAddress from './utils/passkeys/getPasskeyOwnerAddress' import createPasskeyDeploymentTransaction from './utils/passkeys/createPasskeyDeploymentTransaction' import generateOnChainIdentifier from './utils/on-chain-tracking/generateOnChainIdentifier' -import getProtocolKitVersion from './utils/getProtocolKitVersion' +import { getProtocolKitVersion } from './utils/getProtocolKitVersion' const EQ_OR_GT_1_4_1 = '>=1.4.1' const EQ_OR_GT_1_3_0 = '>=1.3.0' diff --git a/packages/protocol-kit/src/utils/getProtocolKitVersion.ts b/packages/protocol-kit/src/utils/getProtocolKitVersion.ts index 3abd3bdb4..1b0fb92fd 100644 --- a/packages/protocol-kit/src/utils/getProtocolKitVersion.ts +++ b/packages/protocol-kit/src/utils/getProtocolKitVersion.ts @@ -1,7 +1 @@ -import packageJson from '../../package.json' - -function getProtocolKitVersion(): string { - return packageJson.version -} - -export default getProtocolKitVersion +export const getProtocolKitVersion = () => '5.1.1' diff --git a/packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts b/packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts index b45f47769..c18f6050c 100644 --- a/packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts +++ b/packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts @@ -10,7 +10,8 @@ import Sinon from 'sinon' import chaiAsPromised from 'chai-as-promised' import { generateHash } from '@safe-global/protocol-kit/utils/on-chain-tracking/generateOnChainIdentifier' -import getProtocolKitVersion, * as getProtocolKitVersionModule from '@safe-global/protocol-kit/utils/getProtocolKitVersion' +import * as getProtocolKitVersionModule from '@safe-global/protocol-kit/utils/getProtocolKitVersion' +import { getProtocolKitVersion } from '@safe-global/protocol-kit/utils/getProtocolKitVersion' import { getEip1193Provider } from './utils/setupProvider' import { waitSafeTxReceipt } from './utils/transactions' @@ -47,7 +48,7 @@ describe('On-chain analytics', () => { platform: 'Web' } - const stub = Sinon.stub(getProtocolKitVersionModule, 'default').returns('5.0.4') + const stub = Sinon.stub(getProtocolKitVersionModule, 'getProtocolKitVersion').returns('5.0.4') const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address diff --git a/packages/protocol-kit/tsconfig.build.json b/packages/protocol-kit/tsconfig.build.json index 416bcce06..c05e497c4 100644 --- a/packages/protocol-kit/tsconfig.build.json +++ b/packages/protocol-kit/tsconfig.build.json @@ -1,9 +1,8 @@ { "extends": "../../tsconfig.settings.json", "compilerOptions": { - "resolveJsonModule": true, "composite": true, "outDir": "dist" }, - "include": ["src/**/*", "package.json"] + "include": ["src/**/*"] } diff --git a/packages/protocol-kit/tsconfig.json b/packages/protocol-kit/tsconfig.json index 77c78ede6..5f6bc90a7 100644 --- a/packages/protocol-kit/tsconfig.json +++ b/packages/protocol-kit/tsconfig.json @@ -1,9 +1,8 @@ { "extends": "../../tsconfig.settings.json", "compilerOptions": { - "resolveJsonModule": true, "composite": true, "outDir": "dist" }, - "include": ["package.json", "src/**/*", "tests/**/*", "hardhat/**/*", "hardhat.config.ts"] + "include": ["src/**/*", "tests/**/*", "hardhat/**/*", "hardhat.config.ts"] } diff --git a/packages/relay-kit/package.json b/packages/relay-kit/package.json index 51313a3e6..4522c6033 100644 --- a/packages/relay-kit/package.json +++ b/packages/relay-kit/package.json @@ -19,6 +19,7 @@ "format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"", "format": "prettier --write \"*/**/*.{js,json,md,ts}\"", "unbuild": "rimraf dist .nyc_output cache", + "prebuild": "node -p \"'export const getRelayKitVersion = () => \\'' + require('./package.json').version.split('-')[0] + '\\''\" > src/packs/safe-4337/utils/getRelayKitVersion.ts", "build": "yarn unbuild && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json" }, "repository": { diff --git a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts index e45507f4a..5162c88f2 100644 --- a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts +++ b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts @@ -53,7 +53,7 @@ import { } from './utils' import { entryPointToSafeModules, EQ_OR_GT_0_3_0 } from './utils/entrypoint' import { PimlicoFeeEstimator } from './estimators/PimlicoFeeEstimator' -import getRelayKitVersion from './utils/getRelayKitVersion' +import { getRelayKitVersion } from './utils/getRelayKitVersion' const MAX_ERC20_AMOUNT_TO_APPROVE = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn diff --git a/packages/relay-kit/src/packs/safe-4337/utils/getRelayKitVersion.ts b/packages/relay-kit/src/packs/safe-4337/utils/getRelayKitVersion.ts index 8f90e8f67..33ed10cdc 100644 --- a/packages/relay-kit/src/packs/safe-4337/utils/getRelayKitVersion.ts +++ b/packages/relay-kit/src/packs/safe-4337/utils/getRelayKitVersion.ts @@ -1,7 +1 @@ -import packageJson from '../../../../package.json' - -function getRelayKitVersion(): string { - return packageJson.version -} - -export default getRelayKitVersion +export const getRelayKitVersion = () => '3.3.1' diff --git a/packages/relay-kit/tsconfig.build.json b/packages/relay-kit/tsconfig.build.json index 9c287382b..cc22498f1 100644 --- a/packages/relay-kit/tsconfig.build.json +++ b/packages/relay-kit/tsconfig.build.json @@ -1,10 +1,9 @@ { "extends": "../../tsconfig.settings.json", "compilerOptions": { - "resolveJsonModule": true, "composite": true, "outDir": "dist" }, - "include": ["src/**/*", "package.json"], + "include": ["src/**/*"], "exclude": ["src/**/*.test.ts", "src/**/*.test-d.ts"] } diff --git a/packages/relay-kit/tsconfig.json b/packages/relay-kit/tsconfig.json index 416bcce06..c05e497c4 100644 --- a/packages/relay-kit/tsconfig.json +++ b/packages/relay-kit/tsconfig.json @@ -1,9 +1,8 @@ { "extends": "../../tsconfig.settings.json", "compilerOptions": { - "resolveJsonModule": true, "composite": true, "outDir": "dist" }, - "include": ["src/**/*", "package.json"] + "include": ["src/**/*"] }