Skip to content

Commit

Permalink
Merge branch 'development' into esm-bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniSomoza committed Jan 17, 2025
2 parents 0811f1d + fdfb6c7 commit 3c5b47b
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 33 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.

Expand Down
1 change: 1 addition & 0 deletions packages/protocol-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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 && yarn build:esm && yarn build:cjs && yarn build:types",
"build:esm": "esbuild ./src/index ./test-utils/index --format=esm --bundle --packages=external --outdir=dist/esm --out-extension:.js=.mjs",
"build:cjs": "esbuild ./src/index ./test-utils/index --format=cjs --bundle --packages=external --outdir=dist/cjs --out-extension:.js=.cjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/src/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 1 addition & 7 deletions packages/protocol-kit/src/utils/getProtocolKitVersion.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
import packageJson from '../../package.json'

function getProtocolKitVersion(): string {
return packageJson.version
}

export default getProtocolKitVersion
export const getProtocolKitVersion = () => '5.1.1'
12 changes: 9 additions & 3 deletions packages/protocol-kit/src/utils/passkeys/PasskeyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>} 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<number>): [bigint, bigint] {
const check = (x: boolean) => {
if (!x) {
throw new Error('invalid signature encoding')
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions packages/protocol-kit/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"declaration": true,
"emitDeclarationOnly": true,
"declarationMap": true,
"resolveJsonModule": true,
"composite": true,
"outDir": "dist"
},
"include": ["src/**/*", "test-utils/**/*", "package.json"],
"include": ["src/**/*", "test-utils/**/*"],
"exclude": ["dist", "test"]
}
3 changes: 1 addition & 2 deletions packages/protocol-kit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"paths": {
"@safe-global/protocol-kit/*": ["./src/*"]
},
"resolveJsonModule": true,
"composite": true,
"outDir": "dist"
},
"include": ["src/**/*", "tests/**/*", "hardhat/**/*", "hardhat.config.ts", "package.json"],
"include": ["src/**/*", "tests/**/*", "hardhat/**/*", "hardhat.config.ts"],
"exclude": ["dist"]
}
1 change: 1 addition & 0 deletions packages/relay-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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 && yarn build:esm && yarn build:cjs && yarn build:types",
"build:esm": "tsc -p tsconfig.build.json --module esnext --outDir dist/esm && tsc-alias -p tsconfig.build.json --outDir dist/esm",
"build:cjs": "tsc -p tsconfig.build.json --outDir dist/cjs && tsc-alias -p tsconfig.build.json --outDir dist/cjs",
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
import packageJson from '../../../../package.json'

function getRelayKitVersion(): string {
return packageJson.version
}

export default getRelayKitVersion
export const getRelayKitVersion = () => '3.3.1'
3 changes: 1 addition & 2 deletions packages/relay-kit/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"composite": true,
"outDir": "dist"
},
"include": ["src/**/*", "test-utils/**/*", "package.json"],
"include": ["src/**/*", "test-utils/**/*"],
"exclude": ["dist", "src/**/*.test.ts", "src/**/*.test-d.ts"]
}
3 changes: 1 addition & 2 deletions packages/relay-kit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"paths": {
"@safe-global/relay-kit/*": ["./src/*"]
},
"resolveJsonModule": true,
"composite": true,
"outDir": "dist"
},
"include": ["src/**/*", "package.json"],
"include": ["src/**/*"],
"exclude": ["dist"]
}
2 changes: 1 addition & 1 deletion playground/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
1 change: 0 additions & 1 deletion tsconfig.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
"resolveJsonModule": true,
"baseUrl": "./"
},
"exclude": ["**/dist", "**/node_modules"]
Expand Down

0 comments on commit 3c5b47b

Please sign in to comment.