Skip to content

Commit 582c0f4

Browse files
committed
feat(parsePkpSignResponse): Determine if the object is lifted or contains a nested structure
1 parent d47de80 commit 582c0f4

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

local-tests/setup/networkContext.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8617,6 +8617,24 @@
86178617
"stateMutability": "nonpayable",
86188618
"type": "function"
86198619
},
8620+
{
8621+
"inputs": [
8622+
{
8623+
"internalType": "uint256",
8624+
"name": "realmId",
8625+
"type": "uint256"
8626+
},
8627+
{
8628+
"internalType": "uint256",
8629+
"name": "newTimeout",
8630+
"type": "uint256"
8631+
}
8632+
],
8633+
"name": "setPendingRejoinTimeout",
8634+
"outputs": [],
8635+
"stateMutability": "nonpayable",
8636+
"type": "function"
8637+
},
86208638
{
86218639
"inputs": [],
86228640
"name": "ActiveValidatorsCannotLeave",
@@ -9282,6 +9300,11 @@
92829300
"name": "port",
92839301
"type": "uint32"
92849302
},
9303+
{
9304+
"internalType": "address",
9305+
"name": "stakerAddress",
9306+
"type": "address"
9307+
},
92859308
{
92869309
"internalType": "uint256",
92879310
"name": "senderPubKey",
@@ -14596,4 +14619,4 @@
1459614619
],
1459714620
"name": "Ledger"
1459814621
}
14599-
}
14622+
}

packages/lit-node-client-nodejs/src/lib/helpers/parse-pkp-sign-response.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,32 @@ export const cleanStringValues = (obj: { [key: string]: any }): any =>
5252
export 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

Comments
 (0)