Skip to content

Commit

Permalink
feat: session_dx
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Jul 16, 2024
1 parent 29983b5 commit fa33d7e
Show file tree
Hide file tree
Showing 45 changed files with 2,572 additions and 1,549 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ E2E_BICO_PAYMASTER_KEY_BASE=
CHAIN_ID=80002
CODECOV_TOKEN=
TESTING=false
SILENCE_LABS_NPM_TOKEN=npm_XXX
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ jobs:

- name: Build
uses: ./.github/actions/build
env:
SILENCE_LABS_NPM_TOKEN: ${{ secrets.SILENCE_LABS_NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:

- name: Install dependencies
uses: ./.github/actions/install-dependencies
env:
SILENCE_LABS_NPM_TOKEN: ${{ secrets.SILENCE_LABS_NPM_TOKEN }}

- name: Run the tests
run: bun run test:coverage
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:

- name: Install dependencies
uses: ./.github/actions/install-dependencies
env:
SILENCE_LABS_NPM_TOKEN: ${{ secrets.SILENCE_LABS_NPM_TOKEN }}

- name: Set remote url
run: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/bcnmy/biconomy-client-sdk.git
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:

- name: Install dependencies
uses: ./.github/actions/install-dependencies
env:
SILENCE_LABS_NPM_TOKEN: ${{ secrets.SILENCE_LABS_NPM_TOKEN }}

- name: Use commitlint to check PR title
run: echo "${{ github.event.pull_request.title }}" | bun commitlint
10 changes: 5 additions & 5 deletions .github/workflows/size-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 22

- name: Set up Bun
uses: oven-sh/setup-bun@v1

- name: Install dependencies
shell: bash
run: |
bun install --frozen-lockfile
- name: Build
uses: ./.github/actions/build
env:
SILENCE_LABS_NPM_TOKEN: ${{ secrets.SILENCE_LABS_NPM_TOKEN }}

- name: Report bundle size
uses: andresz1/size-limit-action@master
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-read.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:

- name: Install dependencies
uses: ./.github/actions/install-dependencies
env:
SILENCE_LABS_NPM_TOKEN: ${{ secrets.SILENCE_LABS_NPM_TOKEN }}

- name: Run the tests
run: bun run test:ci -t=Read
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test-write.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v4
with:
node-version: 22

- name: Install dependencies
uses: ./.github/actions/install-dependencies
env:
SILENCE_LABS_NPM_TOKEN: ${{ secrets.SILENCE_LABS_NPM_TOKEN }}

- name: Run the account tests
run: bun run test:ci -t=Account:Write
Expand Down
8 changes: 4 additions & 4 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
{
"name": "core (esm)",
"path": "./dist/_esm/index.js",
"limit": "65 kB",
"limit": "80 kB",
"import": "*",
"ignore": ["node:fs", "fs"]
},
{
"name": "core (cjs)",
"path": "./dist/_cjs/index.js",
"limit": "65 kB",
"limit": "80 kB",
"ignore": ["node:fs", "fs"]
},
{
"name": "account (tree-shaking)",
"path": "./dist/_esm/index.js",
"limit": "65 kB",
"limit": "80 kB",
"import": "{ createSmartAccountClient }",
"ignore": ["node:fs", "fs"]
},
Expand All @@ -36,7 +36,7 @@
{
"name": "modules (tree-shaking)",
"path": "./dist/_esm/modules/index.js",
"limit": "60 kB",
"limit": "80 kB",
"import": "{ createSessionKeyManagerModule }",
"ignore": ["node:fs", "fs"]
}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @biconomy/account

## 4.6.0

### Minor Changes

- Distributed Sessions

## 4.5.2

### Patch Changes
Expand Down
7 changes: 4 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"files": {
"ignore": [
"package.json",
Expand All @@ -14,7 +14,8 @@
"_types",
"bun.lockb",
"docs",
"dist"
"dist",
"walletprovider-sdk"
]
},
"organizeImports": {
Expand Down Expand Up @@ -42,7 +43,7 @@
"javascript": {
"formatter": {
"semicolons": "asNeeded",
"trailingComma": "none"
"enabled": false
}
}
}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[install.scopes]
silencelaboratories = { token = "$SILENCE_LABS_NPM_TOKEN", url = "https://registry.npmjs.org" }
19 changes: 5 additions & 14 deletions examples/CREATE_AND_USE_A_BATCH_SESSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ const smartAccountWithSession = await createSessionSmartAccountClient(
paymasterUrl,
chainId,
},
smartAccountAddress // Storage client, full Session or smartAccount address if using default storage
true // if batching
"DEFAULT_STORE", // Storage client, full Session or smartAccount address if using default storage
"BATCHED"
);

const transferTx: Transaction = {
Expand All @@ -117,21 +117,12 @@ const nftMintTx: Transaction = {
};

const txs = [nftMintTx, transferTx];
const correspondingIndexes = [1, 0]; // The order of the txs from the sessionBatch

const batchSessionParams = await getBatchSessionTxParams(
txs,
correspondingIndexes,
smartAccountAddress, // Storage client, full Session or smartAccount address if using default storage
chain
);
const leafIndexes = [1, 0]; // The order of the txs from the sessionBatch

const { wait: sessionWait } = await smartAccountWithSession.sendTransaction(
txs,
{
...batchSessionParams,
...withSponsorship,
}
withSponsorship,
{ leafIndex: leafIndexes },
);

const { success } = await sessionWait();
Expand Down
30 changes: 11 additions & 19 deletions examples/CREATE_AND_USE_A_SESSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { createWalletClient, http, createPublicClient } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { mainnet as chain } from "viem/chains";

const withSponsorship = {
paymasterServiceData: { mode: PaymasterMode.SPONSORED },
};

const account = privateKeyToAccount(generatePrivateKey());
const signer = createWalletClient({ account, chain, transport: http() });
const smartAccount = await createSmartAccountClient({
Expand All @@ -26,12 +30,6 @@ const smartAccount = await createSmartAccountClient({
}); // Retrieve bundler and pymaster urls from dashboard
const smartAccountAddress = await smartAccount.getAccountAddress();

// creates a store for the session, and saves the keys to it to be later retrieved
const { sessionKeyAddress, sessionStorageClient } = await createSessionKeyEOA(
smartAccount,
chain
);

/**
* Rule
*
Expand Down Expand Up @@ -78,7 +76,7 @@ const rules: Rule = [
/** The policy is made up of a list of rules applied to the contract method with and interval */
const policy: Policy[] = [
{
/** The address of the sessionKey upon which the policy is to be imparted */
/** The address of the sessionKey upon which the policy is to be imparted. Can be optional if creating from scratch */
sessionKeyAddress,
/** The address of the contract to be included in the policy */
contractAddress: nftAddress,
Expand All @@ -96,14 +94,9 @@ const policy: Policy[] = [
},
];

const { wait, session } = await createSession(
smartAccount,
policy,
sessionStorageClient,
{
paymasterServiceData: { mode: PaymasterMode.SPONSORED },
}
);
const { wait, session } = await createSession(smartAccount, policy, null, {
paymasterServiceData: { mode: PaymasterMode.SPONSORED },
});

const {
receipt: { transactionHash },
Expand All @@ -116,7 +109,7 @@ const smartAccountWithSession = await createSessionSmartAccountClient(
paymasterUrl,
chainId,
},
smartAccountAddress // Storage client, full Session or smartAccount address if using default storage
"DEFAULT_STORE" // Storage client, full Session or smartAccount address if using default storage
);

const { wait: mintWait } = await smartAccountWithSession.sendTransaction(
Expand All @@ -128,9 +121,8 @@ const { wait: mintWait } = await smartAccountWithSession.sendTransaction(
args: [smartAccountAddress],
}),
},
{
paymasterServiceData: { mode: PaymasterMode.SPONSORED },
}
withSponsorship,
{ leafIndex: "LAST_LEAF" },
);

const { success } = await mintWait();
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sideEffects": false,
"name": "@biconomy/account",
"author": "Biconomy",
"version": "4.5.2",
"version": "4.6.0",
"description": "SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.",
"keywords": [
"erc-7579",
Expand Down Expand Up @@ -54,7 +54,7 @@
"format": "biome format . --write",
"lint": "biome check .",
"lint:fix": "bun run lint --apply",
"dev": "bun link && concurrently \"bun run esm:watch\" \"bun run cjs:watch\" \"bun run esm:watch:aliases\" \"bun run cjs:watch:aliases\"",
"dev": "bun link && concurrently \"bun run esm:watch\" \"bun run cjs:watch\" \"bun run types:watch\" \"bun run esm:watch:aliases\" \"bun run cjs:watch:aliases\" \"bun run types:watch:aliases\"",
"build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types",
"clean": "rimraf ./dist/_esm ./dist/_cjs ./dist/_types ./dist/tsconfig",
"test": "vitest dev -c ./tests/vitest.config.ts",
Expand All @@ -72,14 +72,16 @@
"changeset:version": "changeset version && bun install --lockfile-only",
"esm:watch": "tsc --project ./tsconfig/tsconfig.esm.json --watch",
"cjs:watch": "tsc --project ./tsconfig/tsconfig.cjs.json --watch",
"types:watch": "tsc --project ./tsconfig/tsconfig.types.json --watch",
"esm:watch:aliases": "tsc-alias -p ./tsconfig/tsconfig.esm.json --watch",
"cjs:watch:aliases": "tsc-alias -p ./tsconfig/tsconfig.cjs.json --watch",
"types:watch:aliases": "tsc-alias -p ./tsconfig/tsconfig.types.json --watch",
"build:cjs": "tsc --project ./tsconfig/tsconfig.cjs.json && tsc-alias -p ./tsconfig/tsconfig.cjs.json && echo > ./dist/_cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project ./tsconfig/tsconfig.esm.json && tsc-alias -p ./tsconfig/tsconfig.esm.json && echo > ./dist/_esm/package.json '{\"type\": \"module\",\"sideEffects\":false}'",
"build:types": "tsc --project ./tsconfig/tsconfig.types.json && tsc-alias -p ./tsconfig/tsconfig.types.json"
},
"devDependencies": {
"@biomejs/biome": "1.6.0",
"@biomejs/biome": "^1.8.3",
"@changesets/cli": "^2.27.1",
"@commitlint/cli": "^19.0.3",
"@commitlint/config-conventional": "^19.0.3",
Expand All @@ -91,6 +93,7 @@
"@types/bun": "latest",
"@vitest/coverage-v8": "^1.3.1",
"buffer": "^6.0.3",
"changeset": "^0.2.6",
"concurrently": "^8.2.2",
"dotenv": "^16.4.5",
"ethers": "^6.12.0",
Expand All @@ -117,6 +120,8 @@
"commit-msg": "npx --no -- commitlint --edit ${1}"
},
"dependencies": {
"@noble/ed25519": "^2.1.0",
"@noble/secp256k1": "^2.1.0",
"merkletreejs": "^0.3.11"
}
}
Loading

0 comments on commit fa33d7e

Please sign in to comment.