Skip to content

Commit

Permalink
bug fixes in passkey link
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshuchawla009 committed Nov 6, 2024
1 parent 0c741e5 commit 1f4777e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from "./keyUtils";
export * from "./langrangeInterpolatePoly";
export * from "./metadataUtils";
export * from "./nodeUtils";
export * from "./passkeyConnectorUtils";
export * from "./tssPubKeyUtils";
30 changes: 15 additions & 15 deletions src/helpers/passkeyConnectorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ 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<JRPCResponse<Record<string, never>>>[] = [];
for (let i = 0; i < endpoints.length; i++) {
const p = post<JRPCResponse<Record<string, never>>>(
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,
}),
Expand Down Expand Up @@ -107,21 +107,21 @@ 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<JRPCResponse<Record<string, never>>>[] = [];
for (let i = 0; i < endpoints.length; i++) {
const p = post<JRPCResponse<Record<string, never>>>(
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,
}),
{},
Expand Down Expand Up @@ -154,20 +154,20 @@ 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<JRPCResponse<ListLinkedPasskeysResponse>>[] = [];
for (let i = 0; i < endpoints.length; i++) {
const p = post<JRPCResponse<ListLinkedPasskeysResponse>>(
endpoints[i],
generateJsonRPCObject(JRPC_METHODS.GET_LINKED_PASSKEYS, {
message,
verifier_account_signature: oAuthKeySignature,
message: messages[i],
verifier_account_signature: oAuthKeySignatures[i],
key_type: keyType,
}),
{},
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface CommitmentRequestResult {

export interface AuthMessageRequestResult {
message: string;
node_index: number;
}
export interface JRPCResponse<T> {
id: number;
Expand Down
13 changes: 7 additions & 6 deletions src/passkeyConnectorInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { KeyType } from "./interfaces";
import { TorusUtilsPasskeyExtraParams } from "./TorusUtilsExtraParams";

export type GetAuthMessageFromNodesParams = { endpoints: string[]; verifier: string; verifierId?: string; passkeyPubKey?: string };
Expand All @@ -14,24 +15,24 @@ export type PasskeyAuthData = {
export type LinkPasskeyParams = {
endpoints: string[];
passkeyPubKey: string;
message: string;
messages: string[];
label: string;
oAuthKeySignature: string;
oAuthKeySignatures: string[];
keyType: KeyType;
passkeyAuthData?: PasskeyAuthData;
};

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;
};

Expand Down

0 comments on commit 1f4777e

Please sign in to comment.