@gvnrdao/dh-lit-actions 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ 1fe87da4a194b745c0bfe18364a9470a07ac33500461457b5baa5c425df8e882
@@ -0,0 +1,43 @@
1
+ (() => {
2
+ // src/authorization-dummy-b.ts
3
+ var authorizationGoB = async () => {
4
+ try {
5
+ const message = globalThis.messageToSign || "diamond-hands-test-signature-b";
6
+ if (!globalThis.publicKey) {
7
+ Lit.Actions.setResponse({
8
+ response: JSON.stringify({
9
+ success: false,
10
+ error: "PKP public key not available"
11
+ })
12
+ });
13
+ return;
14
+ }
15
+ const signature = await Lit.Actions.signEcdsa({
16
+ toSign: ethers.utils.arrayify(
17
+ ethers.utils.keccak256(ethers.utils.toUtf8Bytes(message))
18
+ ),
19
+ publicKey: globalThis.publicKey,
20
+ sigName: "dummySig"
21
+ });
22
+ Lit.Actions.setResponse({
23
+ response: JSON.stringify({
24
+ success: true,
25
+ signature,
26
+ message,
27
+ pkpPublicKey: globalThis.publicKey,
28
+ timestamp: Date.now(),
29
+ action: "dummy-authorization-sign-b"
30
+ })
31
+ });
32
+ } catch (error) {
33
+ Lit.Actions.setResponse({
34
+ response: JSON.stringify({
35
+ success: false,
36
+ error: error.message || error.toString(),
37
+ timestamp: Date.now()
38
+ })
39
+ });
40
+ }
41
+ };
42
+ authorizationGoB();
43
+ })();
@@ -0,0 +1 @@
1
+ dea7f902cb3991f6c86c79afbe2b8a9e0d9208af4d6762f5985a71908164c461
@@ -0,0 +1,63 @@
1
+ (() => {
2
+ // src/authorization-dummy.ts
3
+ var authorizationGo = async () => {
4
+ try {
5
+ if (!globalThis.publicKey) {
6
+ Lit.Actions.setResponse({
7
+ response: JSON.stringify({
8
+ success: false,
9
+ error: "PKP public key not available"
10
+ })
11
+ });
12
+ return;
13
+ }
14
+ const rawToSign = globalThis.toSign;
15
+ const messageToSign = globalThis.messageToSign || "diamond-hands-test-signature";
16
+ let toSignData;
17
+ let signatureType;
18
+ if (rawToSign) {
19
+ if (typeof rawToSign === "string") {
20
+ toSignData = ethers.utils.arrayify(rawToSign);
21
+ } else if (rawToSign instanceof Uint8Array) {
22
+ toSignData = rawToSign;
23
+ } else if (Array.isArray(rawToSign)) {
24
+ toSignData = new Uint8Array(rawToSign);
25
+ } else {
26
+ throw new Error("Invalid toSign format");
27
+ }
28
+ signatureType = "bitcoin-raw-bytes";
29
+ } else {
30
+ toSignData = ethers.utils.arrayify(
31
+ ethers.utils.keccak256(ethers.utils.toUtf8Bytes(messageToSign))
32
+ );
33
+ signatureType = "ethereum-message-hash";
34
+ }
35
+ const signature = await Lit.Actions.signEcdsa({
36
+ toSign: toSignData,
37
+ publicKey: globalThis.publicKey,
38
+ sigName: "dummySig"
39
+ });
40
+ Lit.Actions.setResponse({
41
+ response: JSON.stringify({
42
+ success: true,
43
+ signature,
44
+ signatureType,
45
+ message: messageToSign,
46
+ rawDataSigned: rawToSign ? true : false,
47
+ pkpPublicKey: globalThis.publicKey,
48
+ timestamp: Date.now(),
49
+ action: "dummy-authorization-sign"
50
+ })
51
+ });
52
+ } catch (error) {
53
+ Lit.Actions.setResponse({
54
+ response: JSON.stringify({
55
+ success: false,
56
+ error: error.message || error.toString(),
57
+ timestamp: Date.now()
58
+ })
59
+ });
60
+ }
61
+ };
62
+ authorizationGo();
63
+ })();
@@ -0,0 +1 @@
1
+ a896d4cf1366bfbc789006b66545b0080b841b92f539dfcc28c562ba74344b00
@@ -0,0 +1,231 @@
1
+ (() => {
2
+ // src/pkp-validator-datil.ts
3
+ var go = async () => {
4
+ const targetPkpTokenId = globalThis.targetPkpTokenId;
5
+ const expectedCid = globalThis.expectedCid;
6
+ const network = globalThis.network;
7
+ try {
8
+ if (!targetPkpTokenId) {
9
+ throw new Error("targetPkpTokenId is required in parameters");
10
+ }
11
+ if (!expectedCid) {
12
+ throw new Error("expectedCid is required in parameters");
13
+ }
14
+ console.log("\n\u{1F512} PKP SECURITY VALIDATION");
15
+ console.log(
16
+ " Using EXACT same logic as validatePKPSecurity test function"
17
+ );
18
+ console.log(" Making direct smart contract calls to verify security");
19
+ console.log(` Target PKP: ${targetPkpTokenId}`);
20
+ console.log(` Expected CID: ${expectedCid}`);
21
+ console.log(` Network: ${network}`);
22
+ const LIT_DATIL_TEST_CONTRACTS = {
23
+ PKPNFT: "0x6a0f439f064B7167A8Ea6B22AcC07ae5360ee0d1",
24
+ PKPPermissions: "0x60C1ddC8b9e38F730F0e7B70A2F84C1A98A69167"
25
+ };
26
+ const LIT_DATIL_CONTRACTS = {
27
+ PKPNFT: "0x487A9D096BB4B7Ac1520Cb12370e31e677B175EA",
28
+ PKPPermissions: "0x213Db6E1446928E19588269bEF7dFc9187c4829A"
29
+ };
30
+ const LIT_CONTRACTS = network === "datil-test" ? LIT_DATIL_TEST_CONTRACTS : LIT_DATIL_CONTRACTS;
31
+ console.log("\n\u{1F50D} Step 1: PKP Existence Check...");
32
+ const existsCalldata = ethers.utils.concat([
33
+ ethers.utils.id("exists(uint256)").substring(0, 10),
34
+ // function selector
35
+ ethers.utils.defaultAbiCoder.encode(["uint256"], [targetPkpTokenId])
36
+ ]);
37
+ const existsCall = {
38
+ to: LIT_CONTRACTS.PKPNFT,
39
+ data: ethers.utils.hexlify(existsCalldata)
40
+ };
41
+ const existsRpcPayload = {
42
+ method: "eth_call",
43
+ params: [existsCall, "latest"],
44
+ id: 1,
45
+ jsonrpc: "2.0"
46
+ };
47
+ const existsResponse = await fetch(
48
+ "https://yellowstone-rpc.litprotocol.com",
49
+ {
50
+ method: "POST",
51
+ headers: { "Content-Type": "application/json" },
52
+ body: JSON.stringify(existsRpcPayload)
53
+ }
54
+ );
55
+ const existsResult = await existsResponse.json();
56
+ if (existsResult.error) {
57
+ throw new Error(
58
+ `RPC Error checking exists: ${existsResult.error.message}`
59
+ );
60
+ }
61
+ const exists = ethers.utils.defaultAbiCoder.decode(
62
+ ["bool"],
63
+ existsResult.result
64
+ )[0];
65
+ console.log(` PKP exists: ${exists}`);
66
+ console.log("\n\u{1F50D} Step 2: PKP Immutability Check...");
67
+ const ownerOfCalldata = ethers.utils.concat([
68
+ ethers.utils.id("ownerOf(uint256)").substring(0, 10),
69
+ // function selector
70
+ ethers.utils.defaultAbiCoder.encode(["uint256"], [targetPkpTokenId])
71
+ ]);
72
+ const ownerOfCall = {
73
+ to: LIT_CONTRACTS.PKPNFT,
74
+ data: ethers.utils.hexlify(ownerOfCalldata)
75
+ };
76
+ const ownerOfRpcPayload = {
77
+ method: "eth_call",
78
+ params: [ownerOfCall, "latest"],
79
+ id: 2,
80
+ jsonrpc: "2.0"
81
+ };
82
+ let owner = "0x0000000000000000000000000000000000000000";
83
+ let isImmutable = false;
84
+ if (exists) {
85
+ const ownerOfResponse = await fetch(
86
+ "https://yellowstone-rpc.litprotocol.com",
87
+ {
88
+ method: "POST",
89
+ headers: { "Content-Type": "application/json" },
90
+ body: JSON.stringify(ownerOfRpcPayload)
91
+ }
92
+ );
93
+ const ownerOfResult = await ownerOfResponse.json();
94
+ if (ownerOfResult.error) {
95
+ throw new Error(
96
+ `RPC Error checking owner: ${ownerOfResult.error.message}`
97
+ );
98
+ }
99
+ owner = ethers.utils.defaultAbiCoder.decode(
100
+ ["address"],
101
+ ownerOfResult.result
102
+ )[0];
103
+ const BURN_ADDRESS = "0x000000000000000000000000000000000000dEaD";
104
+ isImmutable = owner.toLowerCase() === BURN_ADDRESS.toLowerCase();
105
+ }
106
+ console.log(` PKP owner: ${owner}`);
107
+ console.log(` Is immutable (burned to dead address): ${isImmutable}`);
108
+ console.log("\n\u{1F510} Step 3: Authorization Check...");
109
+ const getPermittedActionsCalldata = ethers.utils.concat([
110
+ ethers.utils.id("getPermittedActions(uint256)").substring(0, 10),
111
+ // function selector
112
+ ethers.utils.defaultAbiCoder.encode(["uint256"], [targetPkpTokenId])
113
+ ]);
114
+ const getPermittedActionsCall = {
115
+ to: LIT_CONTRACTS.PKPPermissions,
116
+ data: ethers.utils.hexlify(getPermittedActionsCalldata)
117
+ };
118
+ const getPermittedActionsRpcPayload = {
119
+ method: "eth_call",
120
+ params: [getPermittedActionsCall, "latest"],
121
+ id: 3,
122
+ jsonrpc: "2.0"
123
+ };
124
+ let actionsBytes = [];
125
+ let hasOnlyOneAction = false;
126
+ let matchesExpectedCID = false;
127
+ let foundCid = null;
128
+ if (exists) {
129
+ const getPermittedActionsResponse = await fetch(
130
+ "https://yellowstone-rpc.litprotocol.com",
131
+ {
132
+ method: "POST",
133
+ headers: { "Content-Type": "application/json" },
134
+ body: JSON.stringify(getPermittedActionsRpcPayload)
135
+ }
136
+ );
137
+ const getPermittedActionsResult = await getPermittedActionsResponse.json();
138
+ if (getPermittedActionsResult.error) {
139
+ throw new Error(
140
+ `RPC Error getting permitted actions: ${getPermittedActionsResult.error.message}`
141
+ );
142
+ }
143
+ actionsBytes = ethers.utils.defaultAbiCoder.decode(
144
+ ["bytes[]"],
145
+ getPermittedActionsResult.result
146
+ )[0];
147
+ hasOnlyOneAction = actionsBytes.length === 1;
148
+ foundCid = actionsBytes[0] || null;
149
+ matchesExpectedCID = foundCid?.toLowerCase() === expectedCid.toLowerCase();
150
+ }
151
+ console.log(` Permitted actions count: ${actionsBytes.length}`);
152
+ console.log(` Actions bytes:`, actionsBytes);
153
+ console.log(` Has exactly one action: ${hasOnlyOneAction}`);
154
+ console.log(` Matches expected CID: ${matchesExpectedCID}`);
155
+ console.log(` Expected CID: ${expectedCid}`);
156
+ console.log(` Found CID: ${foundCid || "NONE"}`);
157
+ const allValid = exists && isImmutable && hasOnlyOneAction && matchesExpectedCID;
158
+ const validationSummary = {
159
+ pkpExists: `${exists} ${exists ? "\u2705" : "\u274C"}`,
160
+ pkpImmutable: `${isImmutable} ${isImmutable ? "\u2705" : "\u274C"}`,
161
+ singleAction: `${hasOnlyOneAction} ${hasOnlyOneAction ? "\u2705" : "\u274C"}`,
162
+ correctCID: `${matchesExpectedCID} ${matchesExpectedCID ? "\u2705" : "\u274C"}`,
163
+ overallSecurity: `${allValid} ${allValid ? "\u{1F512} SECURE" : "\u26A0\uFE0F INSECURE"}`
164
+ };
165
+ console.log("\n\u{1F512} COMPLETE SECURITY VALIDATION RESULT:");
166
+ console.log(` PKP exists: ${validationSummary.pkpExists}`);
167
+ console.log(` PKP immutable: ${validationSummary.pkpImmutable}`);
168
+ console.log(` Single action: ${validationSummary.singleAction}`);
169
+ console.log(` Correct CID: ${validationSummary.correctCID}`);
170
+ console.log(` OVERALL SECURITY: ${validationSummary.overallSecurity}`);
171
+ if (!allValid) {
172
+ throw new Error(
173
+ "PKP security validation failed - not all conditions met"
174
+ );
175
+ }
176
+ console.log("\n\u{1F389} PKP IS FULLY SECURE!");
177
+ console.log(" \u2705 Exists on-chain");
178
+ console.log(" \u2705 Immutable (cannot be modified)");
179
+ console.log(" \u2705 Only authorized for expected LIT Action");
180
+ console.log(" \u{1F512} READY FOR PRODUCTION USE");
181
+ console.log("Step 3: Signing certification of PKP-CID relationship...");
182
+ const pkpIdBigInt = BigInt(`0x${targetPkpTokenId}`);
183
+ const pkpIdDecimal = `0x${pkpIdBigInt.toString(10)}`;
184
+ const cidHex = expectedCid.toLowerCase();
185
+ const certificationMessage = `PKP::${pkpIdDecimal}::CID::${cidHex}::SECURE`;
186
+ console.log(` Certification message: ${certificationMessage}`);
187
+ const messageHash = ethers.utils.arrayify(
188
+ ethers.utils.hashMessage(certificationMessage)
189
+ );
190
+ console.log(` Message hash (with Ethereum prefix): ${ethers.utils.hexlify(messageHash)}`);
191
+ const signature = await Lit.Actions.signEcdsa({
192
+ toSign: messageHash,
193
+ publicKey: globalThis.publicKey,
194
+ sigName: "pkpValidation"
195
+ });
196
+ console.log("\u2705 PKP-CID relationship certification signature generated");
197
+ Lit.Actions.setResponse({
198
+ response: JSON.stringify({
199
+ success: true,
200
+ validated: {
201
+ pkpTokenId: targetPkpTokenId,
202
+ exists,
203
+ immutable: isImmutable,
204
+ singleAction: hasOnlyOneAction,
205
+ correctCid: matchesExpectedCID,
206
+ expectedCid,
207
+ foundCidHex: actionsBytes[0]
208
+ },
209
+ validatorPkp: globalThis.publicKey,
210
+ signedMessage: certificationMessage,
211
+ signature,
212
+ timestamp: Date.now(),
213
+ network
214
+ })
215
+ });
216
+ } catch (error) {
217
+ console.error("\u274C PKP Validation failed:", error.message);
218
+ Lit.Actions.setResponse({
219
+ response: JSON.stringify({
220
+ success: false,
221
+ error: error.message || error.toString(),
222
+ targetPkpTokenId: globalThis.targetPkpTokenId || "unknown",
223
+ validatorPkp: globalThis.publicKey || "unknown",
224
+ timestamp: Date.now(),
225
+ network
226
+ })
227
+ });
228
+ }
229
+ };
230
+ go();
231
+ })();
@@ -0,0 +1 @@
1
+ 6569485d942310b4b8095be09ca16cadc2ec88c737c27e32c3dac001998a5dfb