Skip to content

Commit

Permalink
Merge branch 'alchemyplatform:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 authored Feb 14, 2024
2 parents a271a50 + 947f3ff commit f1e1d64
Show file tree
Hide file tree
Showing 56 changed files with 307 additions and 222 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [3.0.0-alpha.12](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.11...v3.0.0-alpha.12) (2024-02-14)

### Bug Fixes

- export the session key ACL type enum ([bd9d75e](https://github.com/alchemyplatform/aa-sdk/commit/bd9d75e0b0b93acdf8e0dce8f461157a0832500b))

# [3.0.0-alpha.11](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.10...v3.0.0-alpha.11) (2024-02-14)

### Bug Fixes

- session key extension was missing plugin overrides ([#458](https://github.com/alchemyplatform/aa-sdk/issues/458)) ([dc5536c](https://github.com/alchemyplatform/aa-sdk/commit/dc5536c8565de216d0c1ca16d72ca4bfdefe7147))

# [3.0.0-alpha.10](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.9...v3.0.0-alpha.10) (2024-02-14)

### Bug Fixes

- update the docs for using a custom account ([#456](https://github.com/alchemyplatform/aa-sdk/issues/456)) ([fb2a541](https://github.com/alchemyplatform/aa-sdk/commit/fb2a5417c19b4f9c335ed86438b7ba81fbb8472d))

# [3.0.0-alpha.9](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.8...v3.0.0-alpha.9) (2024-02-13)

### Features
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "3.0.0-alpha.9",
"version": "3.0.0-alpha.12",
"npmClient": "yarn",
"conventionalCommits": true,
"conventionalPrerelease": true,
Expand Down
16 changes: 16 additions & 0 deletions packages/accounts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [3.0.0-alpha.12](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.11...v3.0.0-alpha.12) (2024-02-14)

### Bug Fixes

- export the session key ACL type enum ([bd9d75e](https://github.com/alchemyplatform/aa-sdk/commit/bd9d75e0b0b93acdf8e0dce8f461157a0832500b))

# [3.0.0-alpha.11](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.10...v3.0.0-alpha.11) (2024-02-14)

### Bug Fixes

- session key extension was missing plugin overrides ([#458](https://github.com/alchemyplatform/aa-sdk/issues/458)) ([dc5536c](https://github.com/alchemyplatform/aa-sdk/commit/dc5536c8565de216d0c1ca16d72ca4bfdefe7147))

# [3.0.0-alpha.10](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.9...v3.0.0-alpha.10) (2024-02-14)

**Note:** Version bump only for package @alchemy/aa-accounts

# [3.0.0-alpha.9](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.8...v3.0.0-alpha.9) (2024-02-13)

### Features
Expand Down
4 changes: 2 additions & 2 deletions packages/accounts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alchemy/aa-accounts",
"version": "3.0.0-alpha.9",
"version": "3.0.0-alpha.12",
"description": "A collection of ERC-4337 compliant smart contract account interfaces",
"author": "Alchemy",
"license": "MIT",
Expand Down Expand Up @@ -74,7 +74,7 @@
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
"gitHead": "ee46e8bb857de3b631044fa70714ea706d9e317d",
"dependencies": {
"@alchemy/aa-core": "^3.0.0-alpha.9",
"@alchemy/aa-core": "^3.0.0-alpha.10",
"viem": "^2.7.8"
}
}
5 changes: 4 additions & 1 deletion packages/accounts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export {
export type * from "./msca/plugins/session-key/index.js";
export { sessionKeyPluginActions } from "./msca/plugins/session-key/index.js";
export type * from "./msca/plugins/session-key/permissions.js";
export { SessionKeyPermissionsBuilder } from "./msca/plugins/session-key/permissions.js";
export {
SessionKeyAccessListType,
SessionKeyPermissionsBuilder,
} from "./msca/plugins/session-key/permissions.js";
export {
SessionKeyPlugin,
SessionKeyPluginAbi,
Expand Down
16 changes: 7 additions & 9 deletions packages/accounts/src/light-account/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type CreateLightAccountParams<
"transport" | "chain" | "entryPoint" | "accountAddress"
> & {
owner: TOwner;
index?: bigint;
salt?: bigint;
factoryAddress?: Address;
initCode?: Hex;
version?: LightAccountVersion;
Expand All @@ -72,7 +72,7 @@ export async function createLightAccount({
entryPoint = getVersion060EntryPoint(chain),
accountAddress,
factoryAddress = getDefaultLightAccountFactoryAddress(chain, version),
index: index_ = 0n,
salt: salt_ = 0n,
}: CreateLightAccountParams): Promise<LightAccount> {
let owner = owner_;
const client = createBundlerClient({
Expand All @@ -83,18 +83,18 @@ export async function createLightAccount({
const getAccountInitCode = async () => {
if (initCode) return initCode;

const index = LightAccountUnsupported1271Factories.has(
const salt = LightAccountUnsupported1271Factories.has(
factoryAddress.toLowerCase() as Address
)
? 0n
: index_;
: salt_;

return concatHex([
factoryAddress,
encodeFunctionData({
abi: LightAccountFactoryAbi,
functionName: "createAccount",
args: [await owner.getAddress(), index],
args: [await owner.getAddress(), salt],
}),
]);
};
Expand Down Expand Up @@ -196,15 +196,13 @@ export async function createLightAccount({
});
},
signUserOperationHash: async (uoHash: Hex) => {
return owner.signMessage(uoHash);
return owner.signMessage({ raw: uoHash });
},
async signMessage({ message }) {
const version = await getLightAccountVersion(account);
switch (version) {
case "v1.0.1":
return owner.signMessage(
typeof message === "string" ? message : message.raw
);
return owner.signMessage(message);
case "v1.0.2":
throw new Error(
`Version ${version} of LightAccount doesn't support 1271`
Expand Down
6 changes: 3 additions & 3 deletions packages/accounts/src/msca/account/multiOwnerAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type CreateMultiOwnerModularAccountParams<
transport: TTransport;
chain: Chain;
owner: TOwner;
index?: bigint;
salt?: bigint;
factoryAddress?: Address;
owners?: Address[];
entryPoint?: EntryPointDef<UserOperationRequest>;
Expand All @@ -57,7 +57,7 @@ export async function createMultiOwnerModularAccount({
entryPoint = getVersion060EntryPoint(chain),
factoryAddress = getDefaultMultiOwnerModularAccountFactoryAddress(chain),
owners = [],
index = 0n,
salt = 0n,
}: CreateMultiOwnerModularAccountParams): Promise<MultiOwnerModularAccount> {
let owner = owner_;
const client = createBundlerClient({
Expand Down Expand Up @@ -85,7 +85,7 @@ export async function createMultiOwnerModularAccount({
encodeFunctionData({
abi: MultiOwnerModularAccountFactoryAbi,
functionName: "createAccount",
args: [index, owners_],
args: [salt, owners_],
}),
]);
};
Expand Down
3 changes: 1 addition & 2 deletions packages/accounts/src/msca/plugins/multi-owner/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
import {
hashMessage,
hashTypedData,
hexToBytes,
type Hash,
type Hex,
type SignableMessage,
Expand Down Expand Up @@ -58,7 +57,7 @@ export const multiOwnerMessageSigner = <
},

signUserOperationHash: (uoHash: `0x${string}`): Promise<`0x${string}`> => {
return owner().signMessage(hexToBytes(uoHash));
return owner().signMessage({ raw: uoHash });
},

signMessage({
Expand Down
31 changes: 25 additions & 6 deletions packages/accounts/src/msca/plugins/session-key/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
AccountNotFoundError,
type GetAccountParameter,
type IsUndefined,
type SendUserOperationResult,
type SmartContractAccount,
type UserOperationOverrides,
Expand Down Expand Up @@ -50,6 +51,7 @@ export type SessionKeyPluginActions<
key: Address;
permissions: Hex[];
tag: Hex;
pluginAddress?: Address;
overrides?: UserOperationOverrides;
} & GetAccountParameter<TAccount>
) => Promise<SendUserOperationResult>;
Expand All @@ -67,10 +69,19 @@ export type SessionKeyPluginActions<
args: {
key: Address;
permissions: Hex[];
pluginAddress?: Address;
overrides?: UserOperationOverrides;
} & GetAccountParameter<TAccount>
) => Promise<SendUserOperationResult>;
};
} & (IsUndefined<TAccount> extends false
? {
getAccountSessionKeys: (
args?: {
pluginAddress?: Address;
} & GetAccountParameter<TAccount>
) => Promise<ReadonlyArray<Address>>;
}
: {});

export const sessionKeyPluginActions: <
TTransport extends Transport = Transport,
Expand Down Expand Up @@ -111,13 +122,16 @@ export const sessionKeyPluginActions: <
return await contract.read.isSessionKeyOf([account.address, key]);
},

getAccountSessionKeys: async ({
pluginAddress,
account = client.account,
}) => {
getAccountSessionKeys: async (
args: { pluginAddress?: Address } & GetAccountParameter<TAccount>
) => {
const account = args?.account ?? client.account;
if (!account) throw new AccountNotFoundError();

const contract = SessionKeyPlugin.getContract(client, pluginAddress);
const contract = SessionKeyPlugin.getContract(
client,
args?.pluginAddress
);

return await contract.read.sessionKeysOf([account.address]);
},
Expand Down Expand Up @@ -148,6 +162,7 @@ export const sessionKeyPluginActions: <
tag,
permissions,
overrides,
pluginAddress,
account = client.account,
}) => {
if (!account) throw new AccountNotFoundError();
Expand All @@ -156,6 +171,7 @@ export const sessionKeyPluginActions: <
args: [key, tag, permissions],
overrides,
account,
pluginAddress,
});
},

Expand All @@ -179,13 +195,15 @@ export const sessionKeyPluginActions: <
args: [oldKey, predecessor, newKey],
overrides,
account,
pluginAddress,
});
},

updateSessionKeyPermissions: async ({
key,
permissions,
overrides,
pluginAddress,
account = client.account,
}) => {
if (!account) throw new AccountNotFoundError();
Expand All @@ -194,6 +212,7 @@ export const sessionKeyPluginActions: <
args: [key, permissions],
overrides,
account,
pluginAddress,
});
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SessionKeyPermissionsUpdatesAbi } from "./SessionKeyPermissionsUpdatesA
export enum SessionKeyAccessListType {
ALLOWLIST = 0,
DENYLIST = 1,
NONE = 2,
ALLOW_ALL_ACCESS = 2,
}

export type ContractAccessEntry = {
Expand Down
3 changes: 2 additions & 1 deletion packages/accounts/src/msca/plugins/session-key/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core";
import type {
Hex,
PrivateKeyAccount,
SignableMessage,
TypedData,
TypedDataDefinition,
} from "viem";
Expand Down Expand Up @@ -61,7 +62,7 @@ export class SessionKeySigner
return this.inner.getAddress();
};

signMessage: (msg: string | Uint8Array) => Promise<`0x${string}`> = async (
signMessage: (msg: SignableMessage) => Promise<`0x${string}`> = async (
msg
) => {
return this.inner.signMessage(msg);
Expand Down
12 changes: 4 additions & 8 deletions packages/accounts/src/nani-account/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
concatHex,
decodeFunctionResult,
encodeFunctionData,
hexToBytes,
isHex,
numberToHex,
type Address,
type Chain,
Expand Down Expand Up @@ -128,13 +128,9 @@ class NaniAccount_<
}

signMessage(msg: Uint8Array | string): Promise<Hex> {
if (typeof msg === "string" && msg.startsWith("0x")) {
msg = hexToBytes(msg as Hex);
} else if (typeof msg === "string") {
msg = new TextEncoder().encode(msg);
}

return this.owner.signMessage(msg);
return this.owner.signMessage(
typeof msg === "string" && !isHex(msg) ? msg : { raw: msg }
);
}

async encodeExecute(target: Hex, value: bigint, data: Hex): Promise<Hex> {
Expand Down
4 changes: 4 additions & 0 deletions packages/alchemy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [3.0.0-alpha.10](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.9...v3.0.0-alpha.10) (2024-02-14)

**Note:** Version bump only for package @alchemy/aa-alchemy

# [3.0.0-alpha.9](https://github.com/alchemyplatform/aa-sdk/compare/v3.0.0-alpha.8...v3.0.0-alpha.9) (2024-02-13)

### Features
Expand Down
4 changes: 2 additions & 2 deletions packages/alchemy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alchemy/aa-alchemy",
"version": "3.0.0-alpha.9",
"version": "3.0.0-alpha.10",
"description": "adapters for @alchemy/aa-core for interacting with alchemy services",
"author": "Alchemy",
"license": "MIT",
Expand Down Expand Up @@ -46,7 +46,7 @@
"vitest": "^0.31.0"
},
"dependencies": {
"@alchemy/aa-core": "^3.0.0-alpha.9",
"@alchemy/aa-core": "^3.0.0-alpha.10",
"@turnkey/http": "^2.6.2",
"@turnkey/iframe-stamper": "^1.0.0",
"@turnkey/viem": "^0.4.8",
Expand Down
13 changes: 3 additions & 10 deletions packages/alchemy/src/signer/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type { SmartAccountAuthenticator } from "@alchemy/aa-core";
import {
hashMessage,
hashTypedData,
isHex,
toHex,
type Hex,
type SignableMessage,
type TypedData,
type TypedDataDefinition,
} from "viem";
Expand Down Expand Up @@ -112,16 +111,10 @@ export class AlchemySigner
return address;
};

signMessage: (msg: string | Uint8Array) => Promise<`0x${string}`> = async (
signMessage: (msg: SignableMessage) => Promise<`0x${string}`> = async (
msg
) => {
const messageHash = hashMessage(
typeof msg === "string" && !isHex(msg)
? msg
: {
raw: isHex(msg) ? msg : toHex(msg),
}
);
const messageHash = hashMessage(msg);

return this.inner.signRawMessage(messageHash);
};
Expand Down
Loading

0 comments on commit f1e1d64

Please sign in to comment.