Skip to content

Commit

Permalink
cleanup turnkey service
Browse files Browse the repository at this point in the history
  • Loading branch information
MoizAhmedd committed Oct 25, 2024
1 parent 5929317 commit b04ecc0
Showing 1 changed file with 7 additions and 84 deletions.
91 changes: 7 additions & 84 deletions src/services/turnkeyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,27 @@ import {
sacdPermissionValue,
} from "@dimo-network/transactions";
import {
TurnkeyClient,
getWebAuthnAttestation,
TurnkeyApiTypes,
TurnkeyApi,
} from "@turnkey/http";
import { IframeStamper } from "@turnkey/iframe-stamper";
import { WebauthnStamper } from "@turnkey/webauthn-stamper";
import {
base64UrlEncode,
bufferToBase64,
bufferToHex,
generateRandomBuffer,
toHexSignature,
} from "../utils/authUtils";
import { verifyEmail } from "./accountsService";
import { keccak256 } from "ethers";
// import { hashMessage } from "viem";
// import { verifyEIP6492Signature } from "@zerodev/sdk";

const stamper = new WebauthnStamper({
rpId: "ab1a735dff55.ngrok.app",
rpId: "ab1a735dff55.ngrok.app", //TODO: Should not be hardcoded
});

const kernelSignerConfig = newKernelConfig({
rpcUrl:
"https://polygon-amoy.g.alchemy.com/v2/-0PsUljNtSdA31-XWj-kL_L1Mx2ArYfS",
"https://polygon-amoy.g.alchemy.com/v2/-0PsUljNtSdA31-XWj-kL_L1Mx2ArYfS", //TODO: Store in ENV
bundlerUrl:
"https://rpc.zerodev.app/api/v2/bundler/f4d1596a-edfd-4063-8f99-2d8835e07739",
"https://rpc.zerodev.app/api/v2/bundler/f4d1596a-edfd-4063-8f99-2d8835e07739", //TODO: Store in ENV
paymasterUrl:
"https://rpc.zerodev.app/api/v2/paymaster/f4d1596a-edfd-4063-8f99-2d8835e07739",
"https://rpc.zerodev.app/api/v2/paymaster/f4d1596a-edfd-4063-8f99-2d8835e07739", //TODO: Store in ENV
environment: "dev", // omit this to default to prod
});

Expand Down Expand Up @@ -100,80 +91,12 @@ export const signChallenge = async (
organizationId: string,
walletAddress: string
) => {

//This is triggering a turnkey API request to sign a raw payload
//Notes on signature, turnkey api returns an ecdsa signature, which the kernel client is handling
const signature = await kernelSigner.kernelClient.signMessage({
message: challenge,
});

// kernelSigner.turnkeyClient?.signRawPayload({
// type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2" as const, // Force literal string type
// timestampMs: Date.now().toString(), // Ensure this is a string, since the backend expects it.
// organizationId, // Example organizationId
// parameters: {
// signWith: walletAddress, // Replace with actual address or identifier
// payload: challenge, // The message you want to sign
// encoding: "PAYLOAD_ENCODING_TEXT_UTF8" as const, // Use appropriate encoding (UTF-8 or hexadecimal)
// hashFunction: "HASH_FUNCTION_NO_OP" as const, // Choose the right hash function (e.g., SHA-256 for most general purposes)
// },
// })


return signature;
// const isValid = await verifyEIP6492Signature({
// signer: kernelSigner.kernelAddress!,
// hash: hashMessage(challenge)!,
// signature: signature,
// //@ts-ignore
// client: kernelSigner.publicClient,
// });

// console.log(isValid);
// const resp = await stamper.stamp(challenge);
// console.log(resp);
// return resp;

// const client = new TurnkeyClient(
// {
// baseUrl: "https://api.turnkey.com",
// },
// stamper
// );

// const { users } = await client.getUsers({
// organizationId,
// });

// console.log(users);
// // TurnkeyApi
// // Turnk

// // TurnkeyApiTypes.

// const requestBody = {
// type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2" as const, // Force literal string type
// timestampMs: Date.now().toString(), // Ensure this is a string, since the backend expects it.
// organizationId, // Example organizationId
// parameters: {
// signWith: walletAddress, // Replace with actual address or identifier
// payload: challenge, // The message you want to sign
// encoding: "PAYLOAD_ENCODING_TEXT_UTF8" as const, // Use appropriate encoding (UTF-8 or hexadecimal)
// hashFunction: "HASH_FUNCTION_SHA256" as const, // Choose the right hash function (e.g., SHA-256 for most general purposes)
// },
// };

// console.log(requestBody);

// const r = await client.signRawPayload(requestBody);

// const signature = r.activity.result.signRawPayloadResult;

// if (signature) {
// return toHexSignature(signature?.r, signature?.s, signature?.v);
// }

// // const authenticatorsResponse = await client.getAuthenticators({
// // organizationId: subOrganizationId,
// // });
// const privateKeyResponse = await client.getPrivateKeys({
// organizationId: subOrganizationId,
// });
};

0 comments on commit b04ecc0

Please sign in to comment.