Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds mav2 webauthn signer #1313

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
packUOSignature,
pack1271Signature,
DEFAULT_OWNER_ENTITY_ID,
SignatureType,
} from "../utils.js";
/**
* Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.
Expand Down Expand Up @@ -82,6 +83,7 @@ export const nativeSMASigner = (
primaryType: "ReplaySafeHash",
}),
entityId: DEFAULT_OWNER_ENTITY_ID,
signatureType: SignatureType.EOA,
});
},

Expand Down Expand Up @@ -115,6 +117,7 @@ export const nativeSMASigner = (
primaryType: "ReplaySafeHash",
}),
entityId: DEFAULT_OWNER_ENTITY_ID,
signatureType: SignatureType.EOA,
});
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
} from "viem";
import { getDefaultSingleSignerValidationModuleAddress } from "../utils.js";

import { packUOSignature, pack1271Signature } from "../../utils.js";
import {
packUOSignature,
pack1271Signature,
SignatureType,
} from "../../utils.js";
/**
* Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.
*
Expand Down Expand Up @@ -84,6 +88,7 @@ export const singleSignerMessageSigner = (
primaryType: "ReplaySafeHash",
}),
entityId,
signatureType: SignatureType.EOA,
});
},

Expand Down Expand Up @@ -121,6 +126,7 @@ export const singleSignerMessageSigner = (
: pack1271Signature({
validationSignature,
entityId,
signatureType: SignatureType.EOA,
});
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { encodeAbiParameters, type Hex } from "viem";

export const WebAuthnValidationModule = {
encodeOnInstallData: (args: {
entityId: number;
x: bigint;
y: bigint;
}): Hex => {
const { entityId, x, y } = args;
return encodeAbiParameters(
[{ type: "uint32" }, { type: "uint256" }, { type: "uint256" }],
[entityId, x, y]
);
},

encodeOnUninstallData: (args: { entityId: number }): Hex => {
const { entityId } = args;

return encodeAbiParameters(
[
{
type: "uint32",
},
],
[entityId]
);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Assume:
// const webauthnnSigner = () => ({
// sign: async (message: string): string => "0x" /** as WebauthnAuthn */
// signTypedData: async (message: TypedDataThing): string => "0x" /** as WebauthnAuthn */
// })
// where all methods on webauthnSigner return validationSignature as Hex
//
// TODO: write webauthnSigner

import type { Address, Chain, Hex } from "viem";
import { pack1271Signature, SignatureType } from "../../utils.js";

export const webauthnMessageSigner = (
validationSignature: Hex,
chain: Chain,
accountAddress: Address,
entityId: number
) => {
return pack1271Signature({
validationSignature,
entityId,
signatureType: SignatureType.NONE,
});
};
27 changes: 20 additions & 7 deletions account-kit/smart-contracts/src/ma-v2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ export type PackUOSignatureParams = {
validationSignature: Hex;
};

export enum SignatureType {
EOA = "0x00",
NONE = "",
}
// TODO: direct call validation 1271
export type Pack1271SignatureParams = {
validationSignature: Hex;
entityId: number;
signatureType: SignatureType;
};

// Signature packing utility for user operations
Expand All @@ -37,14 +42,22 @@ export const packUOSignature = ({
export const pack1271Signature = ({
validationSignature,
entityId,
signatureType,
}: Pack1271SignatureParams): Hex => {
return concat([
"0x00",
toHex(entityId, { size: 4 }),
"0xFF",
"0x00", // EOA type signature
validationSignature,
]);
return signatureType
? concat([
"0x00",
toHex(entityId, { size: 4 }),
"0xFF",
signatureType,
validationSignature,
])
: concat([
"0x00",
toHex(entityId, { size: 4 }),
"0xFF",
validationSignature,
]);
};

export const getDefaultMAV2FactoryAddress = (chain: Chain): Address => {
Expand Down
Loading