From 1f4777edce4cc6d3867278398d0d4665c4ac8731 Mon Sep 17 00:00:00 2001 From: himanshu Date: Wed, 6 Nov 2024 09:48:43 +0530 Subject: [PATCH] bug fixes in passkey link --- src/helpers/index.ts | 1 + src/helpers/passkeyConnectorUtils.ts | 30 ++++++++++++++-------------- src/index.ts | 1 + src/interfaces.ts | 1 + src/passkeyConnectorInterfaces.ts | 13 ++++++------ 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 92a0751..23036e0 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -4,4 +4,5 @@ export * from "./keyUtils"; export * from "./langrangeInterpolatePoly"; export * from "./metadataUtils"; export * from "./nodeUtils"; +export * from "./passkeyConnectorUtils"; export * from "./tssPubKeyUtils"; diff --git a/src/helpers/passkeyConnectorUtils.ts b/src/helpers/passkeyConnectorUtils.ts index 11219a6..9a35d80 100644 --- a/src/helpers/passkeyConnectorUtils.ts +++ b/src/helpers/passkeyConnectorUtils.ts @@ -58,11 +58,11 @@ export const getAuthMessageFromNodes = (params: GetAuthMessageFromNodesParams) = }; export const linkPasskey = async (params: LinkPasskeyParams) => { - const { endpoints, message, label, passkeyPubKey, oAuthKeySignature, keyType, passkeyAuthData } = params; + const { endpoints, messages, label, passkeyPubKey, oAuthKeySignatures, keyType, passkeyAuthData } = params; const halfThreshold = ~~(endpoints.length / 2) + 1; - if (!endpoints || endpoints.length === 0) { - throw new Error("Endpoints are required"); + if (!endpoints || endpoints.length < halfThreshold) { + throw new Error(`minimum ${halfThreshold} endpoints are required`); } const promiseArr: Promise>>[] = []; @@ -70,10 +70,10 @@ export const linkPasskey = async (params: LinkPasskeyParams) => { const p = post>>( endpoints[i], generateJsonRPCObject(JRPC_METHODS.LINK_PASSKEY, { - message, + message: messages[i], label, passkey_pub_key: passkeyPubKey, - verifier_account_signature: oAuthKeySignature, + verifier_account_signature: oAuthKeySignatures[i], key_type: keyType, passkey_auth_data: passkeyAuthData, }), @@ -107,11 +107,11 @@ export const linkPasskey = async (params: LinkPasskeyParams) => { }; export const UnlinkPasskey = async (params: UnLinkPasskeyParams) => { - const { endpoints, message, passkeyPubKey, oAuthKeySignature, keyType } = params; + const { endpoints, messages, passkeyPubKey, oAuthKeySignatures, keyType } = params; const halfThreshold = ~~(endpoints.length / 2) + 1; - if (!endpoints || endpoints.length === 0) { - throw new Error("Endpoints are required"); + if (!endpoints || endpoints.length < halfThreshold) { + throw new Error(`minimum ${halfThreshold} endpoints are required`); } const promiseArr: Promise>>[] = []; @@ -119,9 +119,9 @@ export const UnlinkPasskey = async (params: UnLinkPasskeyParams) => { const p = post>>( endpoints[i], generateJsonRPCObject(JRPC_METHODS.UNLINK_PASSKEY, { - message, + message: messages[i], passkey_pub_key: passkeyPubKey, - verifier_account_signature: oAuthKeySignature, + verifier_account_signature: oAuthKeySignatures[i], key_type: keyType, }), {}, @@ -154,11 +154,11 @@ export const UnlinkPasskey = async (params: UnLinkPasskeyParams) => { }; export const ListLinkedPasskey = async (params: ListLinkedPasskeysParams) => { - const { endpoints, message, oAuthKeySignature, keyType } = params; + const { endpoints, messages, oAuthKeySignatures, keyType } = params; const halfThreshold = ~~(endpoints.length / 2) + 1; - if (!endpoints || endpoints.length === 0) { - throw new Error("Endpoints are required"); + if (!endpoints || endpoints.length < halfThreshold) { + throw new Error(`minimum ${halfThreshold} endpoints are required`); } const promiseArr: Promise>[] = []; @@ -166,8 +166,8 @@ export const ListLinkedPasskey = async (params: ListLinkedPasskeysParams) => { const p = post>( endpoints[i], generateJsonRPCObject(JRPC_METHODS.GET_LINKED_PASSKEYS, { - message, - verifier_account_signature: oAuthKeySignature, + message: messages[i], + verifier_account_signature: oAuthKeySignatures[i], key_type: keyType, }), {}, diff --git a/src/index.ts b/src/index.ts index a7e6297..be5c551 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ export * from "./constants"; export * from "./helpers"; export * from "./interfaces"; +export * from "./passkeyConnectorInterfaces"; export { default as Point } from "./Point"; export { default as Polynomial } from "./Polynomial"; export { default as Share } from "./Share"; diff --git a/src/interfaces.ts b/src/interfaces.ts index 2fd5fed..428712b 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -92,6 +92,7 @@ export interface CommitmentRequestResult { export interface AuthMessageRequestResult { message: string; + node_index: number; } export interface JRPCResponse { id: number; diff --git a/src/passkeyConnectorInterfaces.ts b/src/passkeyConnectorInterfaces.ts index e70c70f..5483f28 100644 --- a/src/passkeyConnectorInterfaces.ts +++ b/src/passkeyConnectorInterfaces.ts @@ -1,3 +1,4 @@ +import { KeyType } from "./interfaces"; import { TorusUtilsPasskeyExtraParams } from "./TorusUtilsExtraParams"; export type GetAuthMessageFromNodesParams = { endpoints: string[]; verifier: string; verifierId?: string; passkeyPubKey?: string }; @@ -14,9 +15,9 @@ export type PasskeyAuthData = { export type LinkPasskeyParams = { endpoints: string[]; passkeyPubKey: string; - message: string; + messages: string[]; label: string; - oAuthKeySignature: string; + oAuthKeySignatures: string[]; keyType: KeyType; passkeyAuthData?: PasskeyAuthData; }; @@ -24,14 +25,14 @@ export type LinkPasskeyParams = { export type UnLinkPasskeyParams = { endpoints: string[]; passkeyPubKey: string; - message: string; - oAuthKeySignature: string; + messages: string[]; + oAuthKeySignatures: string[]; keyType: KeyType; }; export type ListLinkedPasskeysParams = { endpoints: string[]; - message: string; - oAuthKeySignature: string; + messages: string[]; + oAuthKeySignatures: string[]; keyType: KeyType; };