Skip to content

Commit

Permalink
added 6492 signature and fixed deps issue (in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabiDev45 committed Apr 11, 2024
1 parent f7e5420 commit bbbfede
Show file tree
Hide file tree
Showing 9 changed files with 1,210 additions and 1,110 deletions.
2 changes: 1 addition & 1 deletion packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"typedoc": "^0.25.7"
},
"dependencies": {
"@alchemy/aa-core": "^3.1.1",
"@alchemy/aa-core": "3.1.1",
"@biconomy/bundler": "^4.1.1",
"@biconomy/common": "^4.1.1",
"@biconomy/modules": "^4.1.1",
Expand Down
67 changes: 48 additions & 19 deletions packages/account/src/BiconomySmartAccountV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
decodeFunctionData,
parseAbi,
formatUnits,
concat,
} from "viem";
import {
BaseSmartContractAccount,
Expand Down Expand Up @@ -66,6 +67,7 @@ import {
DEFAULT_ENTRYPOINT_ADDRESS,
ERROR_MESSAGES,
ERC20_ABI,
MAGIC_BYTES,
} from "./utils/Constants.js";
import { BiconomyFactoryAbi } from "./abi/Factory.js";
import { BiconomyAccountAbi } from "./abi/SmartAccount.js";
Expand Down Expand Up @@ -172,11 +174,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* import { createClient } from "viem"
* import { createSmartAccountClient, BiconomySmartAccountV2 } from "@biconomy/account"
* import { createWalletClient, http } from "viem";
* import { polygonMumbai } from "viem/chains";
* import { polygonAmoy } from "viem/chains";
*
* const signer = createWalletClient({
* account,
* chain: polygonMumbai,
* chain: polygonAmoy,
* transport: http(),
* });
*
Expand Down Expand Up @@ -284,11 +286,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* import { createClient } from "viem"
* import { createSmartAccountClient } from "@biconomy/account"
* import { createWalletClient, http } from "viem";
* import { polygonMumbai } from "viem/chains";
* import { polygonAmoy } from "viem/chains";
*
* const signer = createWalletClient({
* account,
* chain: polygonMumbai,
* chain: polygonAmoy,
* transport: http(),
* });
*
Expand Down Expand Up @@ -791,11 +793,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* import { createClient } from "viem"
* import { createSmartAccountClient } from "@biconomy/account"
* import { createWalletClient, http } from "viem";
* import { polygonMumbai } from "viem/chains";
* import { polygonAmoy } from "viem/chains";
*
* const signer = createWalletClient({
* account,
* chain: polygonMumbai,
* chain: polygonAmoy,
* transport: http(),
* });
*
Expand Down Expand Up @@ -845,11 +847,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* import { createClient } from "viem"
* import { createSmartAccountClient } from "@biconomy/account"
* import { createWalletClient, http } from "viem";
* import { polygonMumbai } from "viem/chains";
* import { polygonAmoy } from "viem/chains";
*
* const signer = createWalletClient({
* account,
* chain: polygonMumbai,
* chain: polygonAmoy,
* transport: http(),
* });
*
Expand Down Expand Up @@ -899,11 +901,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* import { createClient } from "viem"
* import { createSmartAccountClient } from "@biconomy/account"
* import { createWalletClient, http } from "viem";
* import { polygonMumbai } from "viem/chains";
* import { polygonAmoy } from "viem/chains";
*
* const signer = createWalletClient({
* account,
* chain: polygonMumbai,
* chain: polygonAmoy,
* transport: http(),
* });
*
Expand Down Expand Up @@ -1050,11 +1052,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* import { createClient } from "viem"
* import { createSmartAccountClient } from "@biconomy/account"
* import { createWalletClient, http } from "viem";
* import { polygonMumbai } from "viem/chains";
* import { polygonAmoy } from "viem/chains";
*
* const signer = createWalletClient({
* account,
* chain: polygonMumbai,
* chain: polygonAmoy,
* transport: http(),
* });
*
Expand Down Expand Up @@ -1092,11 +1094,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* import { createClient } from "viem"
* import { createSmartAccountClient } from "@biconomy/account"
* import { createWalletClient, http } from "viem";
* import { polygonMumbai } from "viem/chains";
* import { polygonAmoy } from "viem/chains";
*
* const signer = createWalletClient({
* account,
* chain: polygonMumbai,
* chain: polygonAmoy,
* transport: http(),
* });
*
Expand Down Expand Up @@ -1314,11 +1316,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* import { createClient } from "viem"
* import { createSmartAccountClient } from "@biconomy/account"
* import { createWalletClient, http } from "viem";
* import { polygonMumbai } from "viem/chains";
* import { polygonAmoy } from "viem/chains";
*
* const signer = createWalletClient({
* account,
* chain: polygonMumbai,
* chain: polygonAmoy,
* transport: http(),
* });
*
Expand Down Expand Up @@ -1371,9 +1373,10 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
}

async signMessage(message: string | Uint8Array): Promise<Hex> {
let signature: any;
this.isActiveValidationModuleDefined();
const dataHash = typeof message === "string" ? toBytes(message) : message;
let signature = await this.activeValidationModule.signMessage(dataHash);
signature = await this.activeValidationModule.signMessage(dataHash);

const potentiallyIncorrectV = parseInt(signature.slice(-2), 16);
if (![27, 28].includes(potentiallyIncorrectV)) {
Expand All @@ -1383,8 +1386,34 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
if (signature.slice(0, 2) !== "0x") {
signature = "0x" + signature;
}
signature = encodeAbiParameters(parseAbiParameters("bytes, address"), [signature as Hex, this.defaultValidationModule.getAddress()]);
return signature as Hex;
signature = encodeAbiParameters([{ type: "bytes" }, { type: "address" }], [signature as Hex, this.defaultValidationModule.getAddress()]);
if (await this.isAccountDeployed()) {
return signature as Hex;
} else {
const abiEncodedMessage = encodeAbiParameters(
[
{
type: "address",
name: "create2Factory",
},
{
type: "bytes",
name: "factoryCalldata",
},
{
type: "bytes",
name: "originalERC1271Signature",
},
],
[
this.getFactoryAddress() ?? "0x", // "0x should never happen if it's deployed"
(await this.getAccountInitCode()) ?? "0x", // "0x should never happen if it's deployed"
signature,
],
);

return concat([abiEncodedMessage, MAGIC_BYTES]);
}
}

async getIsValidSignatureData(messageHash: Hex, signature: Hex): Promise<Hex> {
Expand Down
2 changes: 2 additions & 0 deletions packages/account/src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {

export const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";

export const MAGIC_BYTES = "0x6492649264926492649264926492649264926492649264926492649264926492";

// will always be latest entrypoint address
export const DEFAULT_ENTRYPOINT_ADDRESS = "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789";
export const ENTRYPOINT_ADDRESSES: EntryPointAddresses = {
Expand Down
Loading

0 comments on commit bbbfede

Please sign in to comment.