@gvnrdao/dh-lit-ops 0.0.1
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.
- package/README.md +197 -0
- package/dist/constants/chunks/pkp-data.d.ts +28 -0
- package/dist/constants/chunks/pkp-data.d.ts.map +1 -0
- package/dist/constants/chunks/pkp-data.js +86 -0
- package/dist/constants/chunks/pkp-data.js.map +1 -0
- package/dist/constants/index.d.ts +8 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +25 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/chunks/authentication.d.ts +29 -0
- package/dist/interfaces/chunks/authentication.d.ts.map +1 -0
- package/dist/interfaces/chunks/authentication.js +7 -0
- package/dist/interfaces/chunks/authentication.js.map +1 -0
- package/dist/interfaces/chunks/config.d.ts +52 -0
- package/dist/interfaces/chunks/config.d.ts.map +1 -0
- package/dist/interfaces/chunks/config.js +7 -0
- package/dist/interfaces/chunks/config.js.map +1 -0
- package/dist/interfaces/chunks/lit-action-execution.d.ts +27 -0
- package/dist/interfaces/chunks/lit-action-execution.d.ts.map +1 -0
- package/dist/interfaces/chunks/lit-action-execution.js +7 -0
- package/dist/interfaces/chunks/lit-action-execution.js.map +1 -0
- package/dist/interfaces/chunks/pkp-operations.d.ts +143 -0
- package/dist/interfaces/chunks/pkp-operations.d.ts.map +1 -0
- package/dist/interfaces/chunks/pkp-operations.js +3 -0
- package/dist/interfaces/chunks/pkp-operations.js.map +1 -0
- package/dist/interfaces/index.d.ts +11 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +31 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/modules/action-executor.module.d.ts +34 -0
- package/dist/modules/action-executor.module.d.ts.map +1 -0
- package/dist/modules/action-executor.module.js +231 -0
- package/dist/modules/action-executor.module.js.map +1 -0
- package/dist/modules/auth-manager.module.d.ts +24 -0
- package/dist/modules/auth-manager.module.d.ts.map +1 -0
- package/dist/modules/auth-manager.module.js +103 -0
- package/dist/modules/auth-manager.module.js.map +1 -0
- package/dist/modules/client-manager.module.d.ts +64 -0
- package/dist/modules/client-manager.module.d.ts.map +1 -0
- package/dist/modules/client-manager.module.js +213 -0
- package/dist/modules/client-manager.module.js.map +1 -0
- package/dist/modules/lit-ops.module.d.ts +261 -0
- package/dist/modules/lit-ops.module.d.ts.map +1 -0
- package/dist/modules/lit-ops.module.js +792 -0
- package/dist/modules/lit-ops.module.js.map +1 -0
- package/dist/modules/pkp-authorizer.module.d.ts +72 -0
- package/dist/modules/pkp-authorizer.module.d.ts.map +1 -0
- package/dist/modules/pkp-authorizer.module.js +126 -0
- package/dist/modules/pkp-authorizer.module.js.map +1 -0
- package/dist/modules/pkp-macros.module.d.ts +188 -0
- package/dist/modules/pkp-macros.module.d.ts.map +1 -0
- package/dist/modules/pkp-macros.module.js +656 -0
- package/dist/modules/pkp-macros.module.js.map +1 -0
- package/dist/modules/pkp-manager.module.d.ts +56 -0
- package/dist/modules/pkp-manager.module.d.ts.map +1 -0
- package/dist/modules/pkp-manager.module.js +304 -0
- package/dist/modules/pkp-manager.module.js.map +1 -0
- package/dist/modules/pkp-minter.module.d.ts +66 -0
- package/dist/modules/pkp-minter.module.d.ts.map +1 -0
- package/dist/modules/pkp-minter.module.js +185 -0
- package/dist/modules/pkp-minter.module.js.map +1 -0
- package/dist/modules/pkp-signer.module.d.ts +56 -0
- package/dist/modules/pkp-signer.module.d.ts.map +1 -0
- package/dist/modules/pkp-signer.module.js +148 -0
- package/dist/modules/pkp-signer.module.js.map +1 -0
- package/dist/modules/session-signature-manager.module.d.ts +32 -0
- package/dist/modules/session-signature-manager.module.d.ts.map +1 -0
- package/dist/modules/session-signature-manager.module.js +123 -0
- package/dist/modules/session-signature-manager.module.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PKP Macros - High-Level PKP Operations
|
|
4
|
+
*
|
|
5
|
+
* Provides simple macro functions for common PKP workflows:
|
|
6
|
+
* 1. Create PKP + Authorize + Burn (Test Workflow)
|
|
7
|
+
* 2. Create PKP + Authorize (Production Workflow)
|
|
8
|
+
* 3. Individual operations with smart defaults
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.PKPMacroUtils = exports.PKPMacros = exports.DEFAULT_RPC_ENDPOINT = exports.DEFAULT_PKP_NFT_CONTRACT = exports.AUTHORIZATION_DUMMY_CID = void 0;
|
|
12
|
+
const dh_lit_actions_1 = require("@gvnrdao/dh-lit-actions");
|
|
13
|
+
const ethers_1 = require("ethers");
|
|
14
|
+
const action_executor_module_1 = require("./action-executor.module");
|
|
15
|
+
const client_manager_module_1 = require("./client-manager.module");
|
|
16
|
+
const pkp_authorizer_module_1 = require("./pkp-authorizer.module");
|
|
17
|
+
const pkp_minter_module_1 = require("./pkp-minter.module");
|
|
18
|
+
// Import the working CID from lit-actions package
|
|
19
|
+
exports.AUTHORIZATION_DUMMY_CID = dh_lit_actions_1.DH_LIT_ACTIONS.authorizationDummy.cid;
|
|
20
|
+
// Default PKP NFT contract (datil-test)
|
|
21
|
+
exports.DEFAULT_PKP_NFT_CONTRACT = "0x6a0f439f064B7167A8Ea6B22AcC07ae5360ee0d1";
|
|
22
|
+
// Default RPC endpoint
|
|
23
|
+
exports.DEFAULT_RPC_ENDPOINT = "https://yellowstone-rpc.litprotocol.com";
|
|
24
|
+
class PKPMacros {
|
|
25
|
+
constructor(config, sharedDependencies) {
|
|
26
|
+
// Require network to be explicitly specified - no default to prevent multi-instance issues
|
|
27
|
+
if (!config.network) {
|
|
28
|
+
throw new Error("Network must be specified in PKPMacroConfig - no default network allowed");
|
|
29
|
+
}
|
|
30
|
+
this.config = {
|
|
31
|
+
pkpNftContract: exports.DEFAULT_PKP_NFT_CONTRACT,
|
|
32
|
+
debug: false,
|
|
33
|
+
...config,
|
|
34
|
+
};
|
|
35
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider(exports.DEFAULT_RPC_ENDPOINT);
|
|
36
|
+
// Use shared client manager if provided, otherwise create new one
|
|
37
|
+
this.clientManager =
|
|
38
|
+
sharedDependencies?.clientManager ||
|
|
39
|
+
new client_manager_module_1.LitClientManager({
|
|
40
|
+
litNetwork: config.network,
|
|
41
|
+
debug: config.debug || false,
|
|
42
|
+
alertWhenUnauthorized: false,
|
|
43
|
+
minNodeCount: 2,
|
|
44
|
+
});
|
|
45
|
+
// Ensure all dependencies exist - create if not provided via shared dependencies
|
|
46
|
+
this.pkpMinter =
|
|
47
|
+
sharedDependencies?.pkpMinter ||
|
|
48
|
+
new pkp_minter_module_1.PKPMinter({
|
|
49
|
+
signer: this.config.signer,
|
|
50
|
+
network: this.config.network,
|
|
51
|
+
debug: this.config.debug,
|
|
52
|
+
clientManager: this.clientManager,
|
|
53
|
+
});
|
|
54
|
+
this.pkpAuthorizer =
|
|
55
|
+
sharedDependencies?.pkpAuthorizer ||
|
|
56
|
+
new pkp_authorizer_module_1.PKPAuthorizer({
|
|
57
|
+
signer: this.config.signer,
|
|
58
|
+
network: this.config.network,
|
|
59
|
+
debug: this.config.debug,
|
|
60
|
+
clientManager: this.clientManager,
|
|
61
|
+
});
|
|
62
|
+
this.actionExecutor =
|
|
63
|
+
sharedDependencies?.actionExecutor ||
|
|
64
|
+
new action_executor_module_1.LitActionExecutor("standalone", this.config.debug, sharedDependencies?.authManager);
|
|
65
|
+
this.authManager = sharedDependencies?.authManager;
|
|
66
|
+
if (config.debug) {
|
|
67
|
+
console.log("š§ PKPMacros initialized with shared dependencies:", {
|
|
68
|
+
clientManager: !!sharedDependencies?.clientManager,
|
|
69
|
+
pkpMinter: !!sharedDependencies?.pkpMinter,
|
|
70
|
+
pkpAuthorizer: !!sharedDependencies?.pkpAuthorizer,
|
|
71
|
+
actionExecutor: !!sharedDependencies?.actionExecutor,
|
|
72
|
+
authManager: !!sharedDependencies?.authManager,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* MACRO 1: Complete PKP Test Workflow
|
|
78
|
+
* Creates PKP -> Authorizes dummy action -> Burns PKP
|
|
79
|
+
* Perfect for testing and validation
|
|
80
|
+
*/
|
|
81
|
+
async createAuthorizeAndBurn(litActionCid) {
|
|
82
|
+
const startTime = Date.now();
|
|
83
|
+
const cid = litActionCid || exports.AUTHORIZATION_DUMMY_CID;
|
|
84
|
+
if (this.config.debug) {
|
|
85
|
+
console.log("\nš MACRO: Create + Authorize + Burn PKP");
|
|
86
|
+
console.log("=========================================");
|
|
87
|
+
console.log(` Network: ${this.config.network}`);
|
|
88
|
+
console.log(` LIT Action CID: ${cid}`);
|
|
89
|
+
console.log(` Signer: ${this.config.signer.address}`);
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
// Step 1: Create PKP
|
|
93
|
+
if (this.config.debug) {
|
|
94
|
+
console.log("\nā” Step 1: Creating PKP...");
|
|
95
|
+
}
|
|
96
|
+
const minter = this.pkpMinter;
|
|
97
|
+
const pkpResult = await minter.mintAndVerifyPKP(this.config.pkpNftContract, this.provider);
|
|
98
|
+
if (this.config.debug) {
|
|
99
|
+
console.log(` ā
PKP Created: ${pkpResult.tokenId}`);
|
|
100
|
+
console.log(` š Address: ${pkpResult.ethAddress}`);
|
|
101
|
+
}
|
|
102
|
+
// Step 2: Authorize LIT Action
|
|
103
|
+
if (this.config.debug) {
|
|
104
|
+
console.log("\nā” Step 2: Authorizing LIT Action...");
|
|
105
|
+
}
|
|
106
|
+
const authorizer = this.pkpAuthorizer;
|
|
107
|
+
const authResult = await authorizer.authorizeAndVerify(pkpResult.tokenId, cid);
|
|
108
|
+
if (this.config.debug) {
|
|
109
|
+
console.log(` ā
Authorization Complete: ${authResult.isPermitted}`);
|
|
110
|
+
console.log(` š Permitted Actions: ${authResult.permittedActions.length}`);
|
|
111
|
+
}
|
|
112
|
+
// Step 3: Burn PKP
|
|
113
|
+
if (this.config.debug) {
|
|
114
|
+
console.log("\nā” Step 3: Burning PKP...");
|
|
115
|
+
}
|
|
116
|
+
const burnResult = await this.burnPKP(pkpResult.tokenId);
|
|
117
|
+
if (this.config.debug) {
|
|
118
|
+
console.log(` ā
PKP Burned: ${burnResult.burned}`);
|
|
119
|
+
const duration = Date.now() - startTime;
|
|
120
|
+
console.log(`\nšÆ COMPLETE WORKFLOW FINISHED in ${duration}ms`);
|
|
121
|
+
console.log(" ā
Create PKP");
|
|
122
|
+
console.log(" ā
Authorize LIT Action");
|
|
123
|
+
console.log(" ā
Burn PKP");
|
|
124
|
+
console.log(" š„ PKP lifecycle completed successfully!");
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
// PKP Creation
|
|
128
|
+
tokenId: pkpResult.tokenId,
|
|
129
|
+
publicKey: pkpResult.publicKey,
|
|
130
|
+
ethAddress: pkpResult.ethAddress,
|
|
131
|
+
mintTransactionHash: pkpResult.transactionHash,
|
|
132
|
+
verified: pkpResult.verified,
|
|
133
|
+
owner: pkpResult.owner,
|
|
134
|
+
// Authorization
|
|
135
|
+
authTransactionHash: authResult.transactionHash,
|
|
136
|
+
isPermitted: authResult.isPermitted,
|
|
137
|
+
permittedActions: authResult.permittedActions,
|
|
138
|
+
// Burn
|
|
139
|
+
burnTransactionHash: burnResult.transactionHash,
|
|
140
|
+
burned: burnResult.burned,
|
|
141
|
+
// Metadata
|
|
142
|
+
workflow: "create-authorize-burn",
|
|
143
|
+
timestamp: startTime,
|
|
144
|
+
duration: Date.now() - startTime,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (this.config.debug) {
|
|
149
|
+
console.error("ā MACRO FAILED:", error);
|
|
150
|
+
}
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* MACRO 2: Create, Authorize, and Burn PKP (Production Workflow)
|
|
156
|
+
* Creates PKP -> Authorizes Diamond Hands action -> Burns PKP for immutability
|
|
157
|
+
* This makes the PKP production-ready: only the authorized LIT action can sign
|
|
158
|
+
*/
|
|
159
|
+
async createAuthorizeDhActionAndBurn(litActionCid) {
|
|
160
|
+
const startTime = Date.now();
|
|
161
|
+
const cid = litActionCid || exports.AUTHORIZATION_DUMMY_CID;
|
|
162
|
+
if (this.config.debug) {
|
|
163
|
+
console.log("\nš MACRO: Create + Authorize + Burn PKP (Production Ready)");
|
|
164
|
+
console.log("=========================================================");
|
|
165
|
+
console.log(` Network: ${this.config.network}`);
|
|
166
|
+
console.log(` Diamond Hands Action CID: ${cid}`);
|
|
167
|
+
console.log(` Signer: ${this.config.signer.address}`);
|
|
168
|
+
console.log(" š Burn = Production Security (makes PKP immutable)");
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
// Step 1: Create PKP
|
|
172
|
+
if (this.config.debug) {
|
|
173
|
+
console.log("\nā” Step 1: Creating PKP...");
|
|
174
|
+
}
|
|
175
|
+
const minter = this.pkpMinter;
|
|
176
|
+
const pkpResult = await minter.mintAndVerifyPKP(this.config.pkpNftContract, this.provider);
|
|
177
|
+
if (this.config.debug) {
|
|
178
|
+
console.log(` ā
PKP Created: ${pkpResult.tokenId}`);
|
|
179
|
+
console.log(` š Address: ${pkpResult.ethAddress}`);
|
|
180
|
+
}
|
|
181
|
+
// Step 2: Authorize Diamond Hands LIT Action
|
|
182
|
+
if (this.config.debug) {
|
|
183
|
+
console.log("\nā” Step 2: Authorizing Diamond Hands Action...");
|
|
184
|
+
}
|
|
185
|
+
const authorizer = this.pkpAuthorizer;
|
|
186
|
+
const authResult = await authorizer.authorizeAndVerify(pkpResult.tokenId, cid);
|
|
187
|
+
if (this.config.debug) {
|
|
188
|
+
console.log(` ā
Authorization Complete: ${authResult.isPermitted}`);
|
|
189
|
+
console.log(` š Permitted Actions: ${authResult.permittedActions.length}`);
|
|
190
|
+
}
|
|
191
|
+
// Step 3: Make PKP Immutable (Transfer to Burn Address)
|
|
192
|
+
if (this.config.debug) {
|
|
193
|
+
console.log("\nā” Step 3: Making PKP Immutable (Transfer to Burn Address)...");
|
|
194
|
+
console.log(" š This makes the PKP immutable and production-ready");
|
|
195
|
+
console.log(" š Only the authorized LIT action can sign");
|
|
196
|
+
console.log(" š Creator can no longer modify or add signers");
|
|
197
|
+
console.log(" šÆ PKP will exist on-chain but be permanently locked");
|
|
198
|
+
}
|
|
199
|
+
const burnResult = await this.burnPKP(pkpResult.tokenId);
|
|
200
|
+
// Step 4: Wait for network propagation before verification
|
|
201
|
+
if (this.config.debug) {
|
|
202
|
+
console.log("\nā” Step 4: Waiting for network propagation before verification...");
|
|
203
|
+
console.log(` ā³ Delay: ${this.config.pkpImmutabilityVerificationDelayMs || 5000}ms`);
|
|
204
|
+
}
|
|
205
|
+
await new Promise((resolve) => setTimeout(resolve, this.config.pkpImmutabilityVerificationDelayMs || 5000));
|
|
206
|
+
// Step 5: VERIFY the PKP is immutable (transferred to burn address)
|
|
207
|
+
if (this.config.debug) {
|
|
208
|
+
console.log("\nā” Step 5: VERIFYING PKP is actually immutable...");
|
|
209
|
+
}
|
|
210
|
+
const burnVerified = await this.verifyPKPBurned(pkpResult.tokenId);
|
|
211
|
+
if (!burnVerified) {
|
|
212
|
+
throw new Error(`IMMUTABILITY VERIFICATION FAILED: PKP ${pkpResult.tokenId} is not immutable!`);
|
|
213
|
+
}
|
|
214
|
+
if (this.config.debug) {
|
|
215
|
+
console.log(` ā
PKP IMMUTABILITY VERIFIED: ${burnResult.burned} (on-chain confirmed)`);
|
|
216
|
+
const duration = Date.now() - startTime;
|
|
217
|
+
console.log(`\nšÆ PRODUCTION WORKFLOW FINISHED in ${duration}ms`);
|
|
218
|
+
console.log(" ā
Create PKP");
|
|
219
|
+
console.log(" ā
Authorize Diamond Hands Action");
|
|
220
|
+
console.log(" ā
Make PKP Immutable (Transfer to Burn Address)");
|
|
221
|
+
console.log(" ā
VERIFY PKP Immutability (On-chain Confirmation)");
|
|
222
|
+
console.log(` š PKP ${pkpResult.tokenId} is now PRODUCTION READY and IMMUTABLE!`);
|
|
223
|
+
console.log(" šÆ PKP exists on-chain and can be validated by address");
|
|
224
|
+
console.log(" š Ready to be added to smart contract for validation");
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
// PKP Creation
|
|
228
|
+
tokenId: pkpResult.tokenId,
|
|
229
|
+
publicKey: pkpResult.publicKey,
|
|
230
|
+
ethAddress: pkpResult.ethAddress,
|
|
231
|
+
mintTransactionHash: pkpResult.transactionHash,
|
|
232
|
+
verified: pkpResult.verified,
|
|
233
|
+
owner: pkpResult.owner,
|
|
234
|
+
// Authorization
|
|
235
|
+
authTransactionHash: authResult.transactionHash,
|
|
236
|
+
isPermitted: authResult.isPermitted,
|
|
237
|
+
permittedActions: authResult.permittedActions,
|
|
238
|
+
// Production Security Burn
|
|
239
|
+
burnTransactionHash: burnResult.transactionHash,
|
|
240
|
+
burned: burnResult.burned,
|
|
241
|
+
// Metadata
|
|
242
|
+
workflow: "create-authorize-burn",
|
|
243
|
+
timestamp: startTime,
|
|
244
|
+
duration: Date.now() - startTime,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
if (this.config.debug) {
|
|
249
|
+
console.error("ā PRODUCTION MACRO FAILED:", error);
|
|
250
|
+
}
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* MACRO 3: Quick PKP Creation
|
|
256
|
+
* Just creates a PKP with verification
|
|
257
|
+
*/
|
|
258
|
+
async quickCreatePKP() {
|
|
259
|
+
if (this.config.debug) {
|
|
260
|
+
console.log("\nā” MACRO: Quick Create PKP");
|
|
261
|
+
}
|
|
262
|
+
const minter = this.pkpMinter;
|
|
263
|
+
const result = await minter.mintAndVerifyPKP(this.config.pkpNftContract, this.provider);
|
|
264
|
+
if (this.config.debug) {
|
|
265
|
+
console.log(` ā
Quick PKP Created: ${result.tokenId}`);
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* MACRO 4: Quick Authorization
|
|
271
|
+
* Just authorizes a LIT Action for an existing PKP
|
|
272
|
+
*/
|
|
273
|
+
async quickAuthorize(tokenId, litActionCid) {
|
|
274
|
+
const cid = litActionCid || exports.AUTHORIZATION_DUMMY_CID;
|
|
275
|
+
if (this.config.debug) {
|
|
276
|
+
console.log(`\nā” MACRO: Quick Authorize PKP ${tokenId}`);
|
|
277
|
+
}
|
|
278
|
+
const authorizer = this.pkpAuthorizer;
|
|
279
|
+
const result = await authorizer.authorizeAndVerify(tokenId, cid);
|
|
280
|
+
if (this.config.debug) {
|
|
281
|
+
console.log(` ā
Quick Authorization: ${result.isPermitted}`);
|
|
282
|
+
}
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* MACRO 5: PKP Immutability via Transfer
|
|
287
|
+
* Makes PKP immutable by transferring to burn address (instead of burning)
|
|
288
|
+
* This achieves the same security goal: PKP exists but cannot be modified
|
|
289
|
+
*/
|
|
290
|
+
async burnPKP(tokenId) {
|
|
291
|
+
if (this.config.debug) {
|
|
292
|
+
console.log(`\nļæ½ MACRO: Making PKP Immutable ${tokenId}`);
|
|
293
|
+
console.log(" š TRANSFER TO BURN ADDRESS - PKP exists but locked forever");
|
|
294
|
+
console.log(" šÆ This achieves same security as burn: PKP cannot be modified");
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
// Initialize contracts for transfer operation (OPTIMIZED)
|
|
298
|
+
const contractClient = await this.clientManager.getContracts(this.config.signer, {
|
|
299
|
+
litNetwork: this.config.network,
|
|
300
|
+
debug: this.config.debug,
|
|
301
|
+
});
|
|
302
|
+
// Use the PKP NFT contract for transfer
|
|
303
|
+
const pkpNftContract = contractClient.pkpNftContract.write;
|
|
304
|
+
// Get current owner
|
|
305
|
+
const currentOwner = await pkpNftContract.ownerOf(tokenId);
|
|
306
|
+
// Burn address - no one can control this address
|
|
307
|
+
const BURN_ADDRESS = "0x000000000000000000000000000000000000dEaD";
|
|
308
|
+
if (this.config.debug) {
|
|
309
|
+
console.log(` š Current owner: ${currentOwner}`);
|
|
310
|
+
console.log(` šÆ Transferring to burn address: ${BURN_ADDRESS}`);
|
|
311
|
+
console.log(" š After transfer, PKP will be immutable forever");
|
|
312
|
+
}
|
|
313
|
+
// Transfer PKP to burn address (makes it immutable)
|
|
314
|
+
const transferTransaction = await pkpNftContract.transferFrom(currentOwner, BURN_ADDRESS, tokenId);
|
|
315
|
+
if (this.config.debug) {
|
|
316
|
+
console.log(` š¤ Transfer transaction sent: ${transferTransaction.hash}`);
|
|
317
|
+
console.log(" ā³ Waiting for transaction confirmation...");
|
|
318
|
+
}
|
|
319
|
+
// Wait for confirmation
|
|
320
|
+
const receipt = await transferTransaction.wait();
|
|
321
|
+
// Verify the transfer worked
|
|
322
|
+
const newOwner = await pkpNftContract.ownerOf(tokenId);
|
|
323
|
+
const isImmutable = newOwner.toLowerCase() === BURN_ADDRESS.toLowerCase();
|
|
324
|
+
if (this.config.debug) {
|
|
325
|
+
console.log(` ā
PKP NOW IMMUTABLE: ${tokenId}`);
|
|
326
|
+
console.log(` š New owner: ${newOwner}`);
|
|
327
|
+
console.log(` šÆ Is immutable: ${isImmutable}`);
|
|
328
|
+
console.log(` ļæ½ Transaction confirmed: ${transferTransaction.hash}`);
|
|
329
|
+
console.log(` ā½ Gas used: ${receipt.gasUsed.toString()}`);
|
|
330
|
+
console.log(" š PKP exists on-chain but can never be modified!");
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
burned: isImmutable, // "burned" means immutable in our context
|
|
334
|
+
transactionHash: transferTransaction.hash,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
if (this.config.debug) {
|
|
339
|
+
console.error(` ā Transfer to burn address failed: ${error}`);
|
|
340
|
+
}
|
|
341
|
+
throw new Error(`Failed to make PKP immutable ${tokenId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* UTILITY: Get PKP information and verify if it exists
|
|
346
|
+
*/
|
|
347
|
+
async getPKPInfo(tokenId) {
|
|
348
|
+
const PKP_NFT_ABI = [
|
|
349
|
+
"function ownerOf(uint256 tokenId) view returns (address owner)",
|
|
350
|
+
"function exists(uint256 tokenId) view returns (bool)",
|
|
351
|
+
];
|
|
352
|
+
// Get contract address dynamically from the LIT SDK
|
|
353
|
+
const contractClient = await this.clientManager.getContracts(this.config.signer, {
|
|
354
|
+
litNetwork: this.config.network,
|
|
355
|
+
debug: this.config.debug,
|
|
356
|
+
});
|
|
357
|
+
// Use the correct contract address for the current network
|
|
358
|
+
const pkpNftContractAddress = contractClient.pkpNftContract.read.address;
|
|
359
|
+
const contract = new ethers_1.ethers.Contract(pkpNftContractAddress, PKP_NFT_ABI, this.provider);
|
|
360
|
+
try {
|
|
361
|
+
if (this.config.debug) {
|
|
362
|
+
console.log(` š Querying PKP info for token ${tokenId}`);
|
|
363
|
+
console.log(` š Contract address: ${pkpNftContractAddress}`);
|
|
364
|
+
console.log(` š Network: ${this.config.network}`);
|
|
365
|
+
}
|
|
366
|
+
const owner = await contract.ownerOf(tokenId);
|
|
367
|
+
if (this.config.debug) {
|
|
368
|
+
console.log(` ā
PKP owner query successful: ${owner}`);
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
tokenId,
|
|
372
|
+
owner,
|
|
373
|
+
exists: owner !== "0x0000000000000000000000000000000000000000",
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
if (this.config.debug) {
|
|
378
|
+
console.log(` ā PKP owner query failed: ${error.message}`);
|
|
379
|
+
console.log(` š Error code: ${error.code}`);
|
|
380
|
+
console.log(` š Error reason: ${error.reason}`);
|
|
381
|
+
}
|
|
382
|
+
// If error contains "invalid token ID" or "ERC721: owner query for nonexistent token"
|
|
383
|
+
// then the PKP has been burned or never existed
|
|
384
|
+
if (error.message?.includes("invalid token") ||
|
|
385
|
+
error.message?.includes("nonexistent token") ||
|
|
386
|
+
error.message?.includes("ERC721")) {
|
|
387
|
+
return {
|
|
388
|
+
tokenId,
|
|
389
|
+
owner: null,
|
|
390
|
+
exists: false,
|
|
391
|
+
burned: true, // PKP was burned
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
throw error;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* UTILITY: Verify PKP is immutable (transferred to burn address)
|
|
399
|
+
*/
|
|
400
|
+
async verifyPKPBurned(tokenId) {
|
|
401
|
+
try {
|
|
402
|
+
const info = await this.getPKPInfo(tokenId);
|
|
403
|
+
// For immutable PKPs, check if owner is burn address
|
|
404
|
+
const BURN_ADDRESS = "0x000000000000000000000000000000000000dEaD";
|
|
405
|
+
const isImmutable = info.exists &&
|
|
406
|
+
info.owner &&
|
|
407
|
+
info.owner.toLowerCase() === BURN_ADDRESS.toLowerCase();
|
|
408
|
+
if (this.config.debug) {
|
|
409
|
+
console.log(` š Immutability verification: ${isImmutable ? "CONFIRMED" : "FAILED"}`);
|
|
410
|
+
console.log(` š PKP ${tokenId} exists: ${info.exists}`);
|
|
411
|
+
console.log(` š¤ Owner: ${info.owner}`);
|
|
412
|
+
console.log(` š Is owned by burn address: ${isImmutable}`);
|
|
413
|
+
console.log(` šÆ PKP is ${isImmutable ? "IMMUTABLE" : "still modifiable"}`);
|
|
414
|
+
}
|
|
415
|
+
return isImmutable;
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
if (this.config.debug) {
|
|
419
|
+
console.error(` ā Immutability verification error: ${error}`);
|
|
420
|
+
}
|
|
421
|
+
// Don't hide errors - let caller handle them
|
|
422
|
+
throw new Error(`Failed to verify PKP immutability for ${tokenId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
exports.PKPMacros = PKPMacros;
|
|
427
|
+
/**
|
|
428
|
+
* PKP Macro Utils - Proper Instantiated Class with Shared Dependencies
|
|
429
|
+
* No more instantiating new dependencies every function call!
|
|
430
|
+
*/
|
|
431
|
+
class PKPMacroUtils {
|
|
432
|
+
constructor(network, debug = false, sharedDependencies, pkpImmutabilityVerificationDelayMs = 5000) {
|
|
433
|
+
this.network = network;
|
|
434
|
+
this.debug = debug;
|
|
435
|
+
this.pkpImmutabilityVerificationDelayMs = pkpImmutabilityVerificationDelayMs;
|
|
436
|
+
// Use shared dependencies if provided, otherwise create new ones
|
|
437
|
+
this.clientManager =
|
|
438
|
+
sharedDependencies?.clientManager ||
|
|
439
|
+
new client_manager_module_1.LitClientManager({
|
|
440
|
+
litNetwork: network,
|
|
441
|
+
debug,
|
|
442
|
+
alertWhenUnauthorized: false,
|
|
443
|
+
minNodeCount: 2,
|
|
444
|
+
});
|
|
445
|
+
this.actionExecutor =
|
|
446
|
+
sharedDependencies?.actionExecutor ||
|
|
447
|
+
new action_executor_module_1.LitActionExecutor("standalone", debug, sharedDependencies?.authManager);
|
|
448
|
+
// Store shared PKPMinter if provided
|
|
449
|
+
this.pkpMinter = sharedDependencies?.pkpMinter;
|
|
450
|
+
// Store shared PKPAuthorizer if provided
|
|
451
|
+
this.pkpAuthorizer = sharedDependencies?.pkpAuthorizer;
|
|
452
|
+
if (debug) {
|
|
453
|
+
console.log("š§ PKPMacroUtils initialized with shared dependencies");
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Quick test workflow: Create + Authorize + Burn
|
|
458
|
+
*/
|
|
459
|
+
async quickTestWorkflow(signer, options = {}) {
|
|
460
|
+
const macros = new PKPMacros({
|
|
461
|
+
signer,
|
|
462
|
+
network: this.network,
|
|
463
|
+
debug: this.debug,
|
|
464
|
+
}, {
|
|
465
|
+
clientManager: this.clientManager,
|
|
466
|
+
actionExecutor: this.actionExecutor,
|
|
467
|
+
});
|
|
468
|
+
return await macros.createAuthorizeAndBurn(options.litActionCid);
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Quick production workflow: Create + Authorize + Burn (Production Ready)
|
|
472
|
+
*/
|
|
473
|
+
async quickCreatePkpAuthorizeDhActionAndBurn(signer, options = {}) {
|
|
474
|
+
const macros = new PKPMacros({
|
|
475
|
+
signer,
|
|
476
|
+
network: this.network,
|
|
477
|
+
debug: this.debug,
|
|
478
|
+
pkpImmutabilityVerificationDelayMs: this.pkpImmutabilityVerificationDelayMs,
|
|
479
|
+
}, {
|
|
480
|
+
clientManager: this.clientManager,
|
|
481
|
+
actionExecutor: this.actionExecutor,
|
|
482
|
+
});
|
|
483
|
+
return await macros.createAuthorizeDhActionAndBurn(options.litActionCid);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Quick burn (cleanup utility)
|
|
487
|
+
*/
|
|
488
|
+
static async quickBurn(signer, tokenId, options = {}) {
|
|
489
|
+
const macros = new PKPMacros({
|
|
490
|
+
signer,
|
|
491
|
+
network: options.network,
|
|
492
|
+
debug: options.debug,
|
|
493
|
+
});
|
|
494
|
+
return await macros.burnPKP(tokenId);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* PKP Validator Macro - Validate PKP Security via LIT Action
|
|
498
|
+
*
|
|
499
|
+
* This is the optimized macro that validates a PKP is created, granted, and burned
|
|
500
|
+
* correctly against a specific CID by executing the pkp-validator LIT Action and
|
|
501
|
+
* verifying the signature returned.
|
|
502
|
+
*
|
|
503
|
+
* @param targetPkpTokenId - The PKP token ID to validate
|
|
504
|
+
* @param expectedCid - The expected CID in hex format that the PKP should be authorized for
|
|
505
|
+
* @param signer - The wallet to use for session signatures
|
|
506
|
+
* @param options - Configuration options
|
|
507
|
+
* @returns PKP validation result with signature verification
|
|
508
|
+
*/
|
|
509
|
+
static async validatePKPSecurity(targetPkpTokenId, expectedCid, signer, options = {}) {
|
|
510
|
+
const debug = options.debug || false;
|
|
511
|
+
const network = options.network;
|
|
512
|
+
if (!network) {
|
|
513
|
+
throw new Error("Network must be specified - no default network allowed");
|
|
514
|
+
}
|
|
515
|
+
if (debug) {
|
|
516
|
+
console.log("\nš PKP Security Validation Macro");
|
|
517
|
+
console.log(` Target PKP: ${targetPkpTokenId}`);
|
|
518
|
+
console.log(` Expected CID: ${expectedCid}`);
|
|
519
|
+
console.log(` Network: ${network}`);
|
|
520
|
+
}
|
|
521
|
+
try {
|
|
522
|
+
// Initialize LitActionExecutor with configuration
|
|
523
|
+
const actionExecutor = new action_executor_module_1.LitActionExecutor("standalone", debug);
|
|
524
|
+
// Create a client manager for this static method
|
|
525
|
+
const clientManager = new client_manager_module_1.LitClientManager({
|
|
526
|
+
litNetwork: network,
|
|
527
|
+
debug: debug || false,
|
|
528
|
+
alertWhenUnauthorized: false,
|
|
529
|
+
minNodeCount: 2,
|
|
530
|
+
});
|
|
531
|
+
// Get LIT client
|
|
532
|
+
const litClient = await clientManager.getClient({
|
|
533
|
+
litNetwork: network,
|
|
534
|
+
debug: debug,
|
|
535
|
+
});
|
|
536
|
+
// Get PKP Validator CID and signer PKP
|
|
537
|
+
const pkpValidatorCid = dh_lit_actions_1.DH_LIT_ACTIONS.pkpValidator.cid;
|
|
538
|
+
const signerPkp = options.signerPkp || {
|
|
539
|
+
tokenId: "0x1234", // Default fallback
|
|
540
|
+
publicKey: "041a4c73c35215b50fb3708e4ad8cbd0ebf67231fb25e4e095f9f1dcb70f408ab24d28a8460ef436786e66c967d7ebf1d3f3e6441fd661afd9dc7d4f2c1d416f59",
|
|
541
|
+
ethAddress: "0x5449b0C085Fbd9D1A5F02d30b02aA042016A8756",
|
|
542
|
+
};
|
|
543
|
+
if (debug) {
|
|
544
|
+
console.log(` PKP Validator CID: ${pkpValidatorCid}`);
|
|
545
|
+
console.log(` Signer PKP: ${signerPkp.tokenId}`);
|
|
546
|
+
}
|
|
547
|
+
// Execute PKP Validator LIT Action
|
|
548
|
+
const litResult = await actionExecutor.executeAction({
|
|
549
|
+
cid: pkpValidatorCid,
|
|
550
|
+
pkpPublicKey: signerPkp.publicKey,
|
|
551
|
+
params: {
|
|
552
|
+
targetPkpTokenId,
|
|
553
|
+
expectedCid,
|
|
554
|
+
message: `PKP validation via macro: ${Date.now()}`,
|
|
555
|
+
},
|
|
556
|
+
signer,
|
|
557
|
+
}, litClient);
|
|
558
|
+
if (debug) {
|
|
559
|
+
console.log(` LIT Action Success: ${litResult.success}`);
|
|
560
|
+
console.log(` Response: ${litResult.response || "NONE"}`);
|
|
561
|
+
console.log(` Error: ${litResult.error || "NONE"}`);
|
|
562
|
+
}
|
|
563
|
+
// Parse response and verify signature
|
|
564
|
+
if (litResult.success && litResult.response) {
|
|
565
|
+
try {
|
|
566
|
+
const responseData = JSON.parse(litResult.response);
|
|
567
|
+
// Verify signature if present
|
|
568
|
+
let signatureValid = false;
|
|
569
|
+
let pkpAddress = "";
|
|
570
|
+
let recoveredAddress = "";
|
|
571
|
+
if (responseData.signature) {
|
|
572
|
+
if (debug) {
|
|
573
|
+
console.log(" š Verifying signature authenticity...");
|
|
574
|
+
}
|
|
575
|
+
try {
|
|
576
|
+
// Compute PKP address from public key
|
|
577
|
+
pkpAddress = ethers_1.ethers.utils.computeAddress(`0x${signerPkp.publicKey}`);
|
|
578
|
+
// Recover address from signature
|
|
579
|
+
const signedMessage = responseData.signedMessage;
|
|
580
|
+
if (signedMessage) {
|
|
581
|
+
recoveredAddress = ethers_1.ethers.utils.verifyMessage(signedMessage, responseData.signature);
|
|
582
|
+
signatureValid =
|
|
583
|
+
pkpAddress.toLowerCase() === recoveredAddress.toLowerCase();
|
|
584
|
+
if (debug) {
|
|
585
|
+
console.log(` PKP Address: ${pkpAddress}`);
|
|
586
|
+
console.log(` Recovered Address: ${recoveredAddress}`);
|
|
587
|
+
console.log(` Signature Valid: ${signatureValid ? "ā
" : "ā"}`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
throw new Error("No signed message found for verification");
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
catch (verifyError) {
|
|
595
|
+
if (debug) {
|
|
596
|
+
console.log(` ā Signature verification failed: ${verifyError}`);
|
|
597
|
+
}
|
|
598
|
+
throw new Error(`Signature verification failed: ${verifyError instanceof Error
|
|
599
|
+
? verifyError.message
|
|
600
|
+
: verifyError}`);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
// Return parsed result
|
|
604
|
+
return {
|
|
605
|
+
success: responseData.success || false,
|
|
606
|
+
signature: responseData.signature,
|
|
607
|
+
error: responseData.error,
|
|
608
|
+
signatureValid,
|
|
609
|
+
pkpAddress,
|
|
610
|
+
recoveredAddress,
|
|
611
|
+
validationResult: responseData.validated
|
|
612
|
+
? {
|
|
613
|
+
exists: responseData.validated.exists || false,
|
|
614
|
+
isImmutable: responseData.validated.immutable || false,
|
|
615
|
+
hasOnlyOneAction: responseData.validated.singleAction || false,
|
|
616
|
+
matchesExpectedCID: responseData.validated.correctCid || false,
|
|
617
|
+
allValid: responseData.validated.exists &&
|
|
618
|
+
responseData.validated.immutable &&
|
|
619
|
+
responseData.validated.singleAction &&
|
|
620
|
+
responseData.validated.correctCid,
|
|
621
|
+
}
|
|
622
|
+
: undefined,
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
catch (parseError) {
|
|
626
|
+
if (debug) {
|
|
627
|
+
console.log(" Response is not JSON, treating as execution error");
|
|
628
|
+
}
|
|
629
|
+
return {
|
|
630
|
+
success: false,
|
|
631
|
+
error: "Failed to parse LIT Action response",
|
|
632
|
+
signatureValid: false,
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
// LIT Action execution failed
|
|
637
|
+
return {
|
|
638
|
+
success: false,
|
|
639
|
+
error: litResult.error || "LIT Action execution failed",
|
|
640
|
+
signatureValid: false,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
catch (error) {
|
|
644
|
+
if (debug) {
|
|
645
|
+
console.error(" ā PKP validation macro failed:", error);
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
success: false,
|
|
649
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
650
|
+
signatureValid: false,
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
exports.PKPMacroUtils = PKPMacroUtils;
|
|
656
|
+
//# sourceMappingURL=pkp-macros.module.js.map
|