From 162db3891232851bada5ba361efbff9d7a66f901 Mon Sep 17 00:00:00 2001 From: Iyk Azorji Date: Mon, 18 Nov 2024 14:17:11 -0500 Subject: [PATCH] feat: update type definitions for consistency --- .../NativeTEKStamperModule.kt | 2 +- account-kit/rn-signer/example/metro.config.js | 2 +- account-kit/rn-signer/src/client.ts | 11 ++++-- account-kit/rn-signer/src/signer.ts | 39 +++++++++++++++++++ account-kit/signer/src/index.ts | 5 ++- 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 account-kit/rn-signer/src/signer.ts diff --git a/account-kit/rn-signer/android/src/main/java/com/accountkit/reactnativesigner/NativeTEKStamperModule.kt b/account-kit/rn-signer/android/src/main/java/com/accountkit/reactnativesigner/NativeTEKStamperModule.kt index 90b15a325e..a107e2c6b7 100644 --- a/account-kit/rn-signer/android/src/main/java/com/accountkit/reactnativesigner/NativeTEKStamperModule.kt +++ b/account-kit/rn-signer/android/src/main/java/com/accountkit/reactnativesigner/NativeTEKStamperModule.kt @@ -44,7 +44,7 @@ class NativeTEKStamperModule(reactContext: ReactApplicationContext) : MasterKey.Builder(context.applicationContext) .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) // requires that the phone be unlocked - .setUserAuthenticationRequired(true) + .setUserAuthenticationRequired(false) .build() /** diff --git a/account-kit/rn-signer/example/metro.config.js b/account-kit/rn-signer/example/metro.config.js index f0c9b6e60c..00bc69a4ea 100644 --- a/account-kit/rn-signer/example/metro.config.js +++ b/account-kit/rn-signer/example/metro.config.js @@ -5,7 +5,7 @@ const pkg = require("../package.json"); const root = path.resolve(__dirname, ".."); // handles the hoisted modules -const repoRoot = path.resolve(__dirname, "../../../node_modules"); +const repoRoot = path.resolve(__dirname, "../../.."); /** * Metro configuration diff --git a/account-kit/rn-signer/src/client.ts b/account-kit/rn-signer/src/client.ts index bb3a2aef68..49c36b123e 100644 --- a/account-kit/rn-signer/src/client.ts +++ b/account-kit/rn-signer/src/client.ts @@ -14,11 +14,14 @@ import { type User, } from "@account-kit/signer"; import NativeTEKStamper from "./NativeTEKStamper"; +import { z } from "zod"; -export type RNSignerClientParams = { - connection: ConnectionConfig; - rootOrgId?: string; -}; +export const RNSignerClientParamsSchema = z.object({ + connection: z.custom(), + rootOrgId: z.string().optional(), +}); + +export type RNSignerClientParams = z.input; // TODO: need to emit events export class RNSignerClient extends BaseSignerClient { diff --git a/account-kit/rn-signer/src/signer.ts b/account-kit/rn-signer/src/signer.ts new file mode 100644 index 0000000000..0fbced4403 --- /dev/null +++ b/account-kit/rn-signer/src/signer.ts @@ -0,0 +1,39 @@ +import { z } from "zod"; +import { + BaseAlchemySigner, + SessionManagerParamsSchema, +} from "@account-kit/signer"; +// eslint-disable-next-line import/extensions +import { RNSignerClient, RNSignerClientParamsSchema } from "./client"; + +const RNAlchemySignerParamsSchema = z + .object({ + client: z.custom().or(RNSignerClientParamsSchema), + }) + .extend({ + sessionConfig: SessionManagerParamsSchema.omit({ + client: true, + storage: true, + }).optional(), + }); + +export type RNAlchemySignerParams = z.input; + +export class RNAlchemySigner extends BaseAlchemySigner { + constructor(params: RNAlchemySignerParams) { + const { sessionConfig, ...params_ } = + RNAlchemySignerParamsSchema.parse(params); + + let client: RNSignerClient; + + if ("connection" in params_.client) { + client = new RNSignerClient(params_.client); + } else { + client = params_.client; + } + super({ + client, + sessionConfig, + }); + } +} diff --git a/account-kit/signer/src/index.ts b/account-kit/signer/src/index.ts index 7fbca21262..c68a131b24 100644 --- a/account-kit/signer/src/index.ts +++ b/account-kit/signer/src/index.ts @@ -6,7 +6,10 @@ export { OauthFailedError, } from "./client/index.js"; export type * from "./client/types.js"; -export { DEFAULT_SESSION_MS } from "./session/manager.js"; +export { + DEFAULT_SESSION_MS, + SessionManagerParamsSchema, +} from "./session/manager.js"; export type * from "./signer.js"; export { AlchemyWebSigner } from "./signer.js"; export type * from "./types.js";