@@ -52,8 +52,32 @@ export const cleanStringValues = (obj: { [key: string]: any }): any =>
5252export const parsePkpSignResponse = (
5353 responseData : PKPSignEndpointResponse [ ]
5454) : EcdsaSignedMessageShareParsed [ ] => {
55+
5556 const ecdsaSignedMessageShares = responseData . map ( ( { signatureShare } ) => {
56- const camelCaseShare = convertKeysToCamelCase ( signatureShare ) ;
57+
58+ // Determine if the object is lifted or contains a nested structure
59+ // Example scenarios this logic handles:
60+ // 1. If `signatureShare` is nested (e.g., { EcdsaSignedMessageShare: { ... } }),
61+ // it will extract the nested object (i.e., the value of `EcdsaSignedMessageShare`).
62+ // NOTE: against `f8047310fd4ac97ac01ff07a7cd1213808a3396e` in this case
63+ // 2. If `signatureShare` is directly lifted (e.g., { digest: "...", result: "...", share_id: "..." }),
64+ // it will treat `signatureShare` itself as the resolved object.
65+ // NOTE: against `60318791258d273df8209b912b386680d25d0df3` in this case
66+ // 3. If `signatureShare` is null, not an object, or does not match expected patterns,
67+ // it will throw an error later for invalid structure.
68+ const resolvedShare =
69+ typeof signatureShare === "object" &&
70+ ! Array . isArray ( signatureShare ) &&
71+ Object . keys ( signatureShare ) . length === 1 &&
72+ typeof signatureShare [ Object . keys ( signatureShare ) [ 0 ] as keyof typeof signatureShare ] === "object"
73+ ? signatureShare [ Object . keys ( signatureShare ) [ 0 ] as keyof typeof signatureShare ]
74+ : signatureShare ;
75+
76+ if ( ! resolvedShare || typeof resolvedShare !== "object" ) {
77+ throw new Error ( "Invalid signatureShare structure." ) ;
78+ }
79+
80+ const camelCaseShare = convertKeysToCamelCase ( resolvedShare ) ;
5781 const parsedShareMessage = cleanStringValues ( camelCaseShare ) ;
5882
5983 // Rename `digest` to `dataSigned`
0 commit comments