@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.
Files changed (74) hide show
  1. package/README.md +197 -0
  2. package/dist/constants/chunks/pkp-data.d.ts +28 -0
  3. package/dist/constants/chunks/pkp-data.d.ts.map +1 -0
  4. package/dist/constants/chunks/pkp-data.js +86 -0
  5. package/dist/constants/chunks/pkp-data.js.map +1 -0
  6. package/dist/constants/index.d.ts +8 -0
  7. package/dist/constants/index.d.ts.map +1 -0
  8. package/dist/constants/index.js +25 -0
  9. package/dist/constants/index.js.map +1 -0
  10. package/dist/index.d.ts +30 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +63 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/interfaces/chunks/authentication.d.ts +29 -0
  15. package/dist/interfaces/chunks/authentication.d.ts.map +1 -0
  16. package/dist/interfaces/chunks/authentication.js +7 -0
  17. package/dist/interfaces/chunks/authentication.js.map +1 -0
  18. package/dist/interfaces/chunks/config.d.ts +52 -0
  19. package/dist/interfaces/chunks/config.d.ts.map +1 -0
  20. package/dist/interfaces/chunks/config.js +7 -0
  21. package/dist/interfaces/chunks/config.js.map +1 -0
  22. package/dist/interfaces/chunks/lit-action-execution.d.ts +27 -0
  23. package/dist/interfaces/chunks/lit-action-execution.d.ts.map +1 -0
  24. package/dist/interfaces/chunks/lit-action-execution.js +7 -0
  25. package/dist/interfaces/chunks/lit-action-execution.js.map +1 -0
  26. package/dist/interfaces/chunks/pkp-operations.d.ts +143 -0
  27. package/dist/interfaces/chunks/pkp-operations.d.ts.map +1 -0
  28. package/dist/interfaces/chunks/pkp-operations.js +3 -0
  29. package/dist/interfaces/chunks/pkp-operations.js.map +1 -0
  30. package/dist/interfaces/index.d.ts +11 -0
  31. package/dist/interfaces/index.d.ts.map +1 -0
  32. package/dist/interfaces/index.js +31 -0
  33. package/dist/interfaces/index.js.map +1 -0
  34. package/dist/modules/action-executor.module.d.ts +34 -0
  35. package/dist/modules/action-executor.module.d.ts.map +1 -0
  36. package/dist/modules/action-executor.module.js +231 -0
  37. package/dist/modules/action-executor.module.js.map +1 -0
  38. package/dist/modules/auth-manager.module.d.ts +24 -0
  39. package/dist/modules/auth-manager.module.d.ts.map +1 -0
  40. package/dist/modules/auth-manager.module.js +103 -0
  41. package/dist/modules/auth-manager.module.js.map +1 -0
  42. package/dist/modules/client-manager.module.d.ts +64 -0
  43. package/dist/modules/client-manager.module.d.ts.map +1 -0
  44. package/dist/modules/client-manager.module.js +213 -0
  45. package/dist/modules/client-manager.module.js.map +1 -0
  46. package/dist/modules/lit-ops.module.d.ts +261 -0
  47. package/dist/modules/lit-ops.module.d.ts.map +1 -0
  48. package/dist/modules/lit-ops.module.js +792 -0
  49. package/dist/modules/lit-ops.module.js.map +1 -0
  50. package/dist/modules/pkp-authorizer.module.d.ts +72 -0
  51. package/dist/modules/pkp-authorizer.module.d.ts.map +1 -0
  52. package/dist/modules/pkp-authorizer.module.js +126 -0
  53. package/dist/modules/pkp-authorizer.module.js.map +1 -0
  54. package/dist/modules/pkp-macros.module.d.ts +188 -0
  55. package/dist/modules/pkp-macros.module.d.ts.map +1 -0
  56. package/dist/modules/pkp-macros.module.js +656 -0
  57. package/dist/modules/pkp-macros.module.js.map +1 -0
  58. package/dist/modules/pkp-manager.module.d.ts +56 -0
  59. package/dist/modules/pkp-manager.module.d.ts.map +1 -0
  60. package/dist/modules/pkp-manager.module.js +304 -0
  61. package/dist/modules/pkp-manager.module.js.map +1 -0
  62. package/dist/modules/pkp-minter.module.d.ts +66 -0
  63. package/dist/modules/pkp-minter.module.d.ts.map +1 -0
  64. package/dist/modules/pkp-minter.module.js +185 -0
  65. package/dist/modules/pkp-minter.module.js.map +1 -0
  66. package/dist/modules/pkp-signer.module.d.ts +56 -0
  67. package/dist/modules/pkp-signer.module.d.ts.map +1 -0
  68. package/dist/modules/pkp-signer.module.js +148 -0
  69. package/dist/modules/pkp-signer.module.js.map +1 -0
  70. package/dist/modules/session-signature-manager.module.d.ts +32 -0
  71. package/dist/modules/session-signature-manager.module.d.ts.map +1 -0
  72. package/dist/modules/session-signature-manager.module.js +123 -0
  73. package/dist/modules/session-signature-manager.module.js.map +1 -0
  74. package/package.json +61 -0
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ /**
3
+ * PKPMinter Module (Optimized)
4
+ *
5
+ * Handles PKP minting operations using LIT Protocol SDK with cached contracts
6
+ * Provides clean, reusable functions for PKP creation and validation
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PKPMinterUtils = exports.PKPMinter = void 0;
10
+ const ethers_1 = require("ethers");
11
+ const client_manager_module_1 = require("./client-manager.module");
12
+ class PKPMinter {
13
+ constructor(options) {
14
+ // Require network to be explicitly specified - no default to prevent multi-instance issues
15
+ if (!options.network) {
16
+ throw new Error("Network must be specified in PKPMintOptions - no default network allowed");
17
+ }
18
+ this.options = {
19
+ debug: true,
20
+ ...options,
21
+ };
22
+ // Use shared client manager if provided, otherwise create instance-specific one
23
+ this.clientManager = options.clientManager || new client_manager_module_1.LitClientManager({
24
+ litNetwork: options.network,
25
+ debug: options.debug || false,
26
+ alertWhenUnauthorized: false,
27
+ minNodeCount: 2,
28
+ });
29
+ }
30
+ /**
31
+ * Get cached LIT Contracts connection (OPTIMIZED)
32
+ */
33
+ async getContractClient() {
34
+ return await this.clientManager.getContracts(this.options.signer, {
35
+ litNetwork: this.options.network,
36
+ debug: this.options.debug,
37
+ });
38
+ }
39
+ /**
40
+ * Mint a new PKP using LIT Protocol SDK (OPTIMIZED)
41
+ */
42
+ async mintPKP() {
43
+ const contractClient = await this.getContractClient();
44
+ try {
45
+ const mintResult = await contractClient.pkpNftContractUtils.write.mint();
46
+ // Wait for transaction confirmation
47
+ await mintResult.tx.wait();
48
+ const mintedPKP = mintResult.pkp;
49
+ return {
50
+ tokenId: mintedPKP.tokenId,
51
+ publicKey: mintedPKP.publicKey,
52
+ ethAddress: mintedPKP.ethAddress,
53
+ transactionHash: mintResult.tx.hash,
54
+ };
55
+ }
56
+ catch (error) {
57
+ // Handle specific "topics" undefined error from LIT SDK event parsing
58
+ if (error.message?.includes("Cannot read properties of undefined (reading 'topics')")) {
59
+ if (this.options.debug) {
60
+ console.log("โš ๏ธ LIT SDK event parsing failed, attempting manual PKP recovery...");
61
+ }
62
+ // The transaction likely succeeded but event parsing failed
63
+ // Attempt to get the most recent PKP minted by this wallet
64
+ const signerAddress = await this.options.signer.getAddress();
65
+ // Get the most recent block
66
+ const provider = this.options.signer.provider;
67
+ // Look for PKP mint events in recent blocks
68
+ const pkpContract = contractClient.pkpNftContract.read;
69
+ // Get total supply to find the latest token ID
70
+ const totalSupply = await pkpContract.totalSupply();
71
+ const latestTokenId = totalSupply.toString();
72
+ // Verify this PKP was minted by our signer
73
+ const owner = await pkpContract.ownerOf(latestTokenId);
74
+ if (owner.toLowerCase() === signerAddress.toLowerCase()) {
75
+ // Generate the PKP data from the token ID
76
+ const publicKey = await pkpContract.getPubkey(latestTokenId);
77
+ const ethAddress = await pkpContract.getEthAddress(latestTokenId);
78
+ if (this.options.debug) {
79
+ console.log("โœ… Successfully recovered PKP data after LIT SDK event parsing failure");
80
+ console.log(` Token ID: ${latestTokenId}`);
81
+ console.log(` ETH Address: ${ethAddress}`);
82
+ console.log(` Public Key: ${publicKey}`);
83
+ }
84
+ return {
85
+ tokenId: latestTokenId,
86
+ publicKey: publicKey,
87
+ ethAddress: ethAddress,
88
+ transactionHash: "0x" + "0".repeat(64), // Placeholder since we can't recover tx hash
89
+ };
90
+ }
91
+ }
92
+ // Re-throw other errors
93
+ throw error;
94
+ }
95
+ }
96
+ /**
97
+ * Verify PKP exists on blockchain using direct contract call
98
+ */
99
+ async verifyPKPOnChain(tokenId, pkpNftContract, provider) {
100
+ const PKP_NFT_ABI = [
101
+ "function ownerOf(uint256 tokenId) view returns (address owner)",
102
+ "function totalSupply() view returns (uint256)",
103
+ ];
104
+ const contract = new ethers_1.ethers.Contract(pkpNftContract, PKP_NFT_ABI, provider);
105
+ try {
106
+ const owner = await contract.ownerOf(tokenId);
107
+ return {
108
+ owner,
109
+ exists: ethers_1.ethers.utils.isAddress(owner) &&
110
+ owner !== "0x0000000000000000000000000000000000000000",
111
+ };
112
+ }
113
+ catch (error) {
114
+ if (error.message?.includes("invalid token ID")) {
115
+ return { owner: "", exists: false };
116
+ }
117
+ throw error;
118
+ }
119
+ }
120
+ /**
121
+ * Get current total PKP supply
122
+ */
123
+ async getTotalSupply(pkpNftContract, provider) {
124
+ const PKP_NFT_ABI = ["function totalSupply() view returns (uint256)"];
125
+ const contract = new ethers_1.ethers.Contract(pkpNftContract, PKP_NFT_ABI, provider);
126
+ const totalSupply = await contract.totalSupply();
127
+ return Number(totalSupply);
128
+ }
129
+ /**
130
+ * Comprehensive PKP minting with verification
131
+ */
132
+ async mintAndVerifyPKP(pkpNftContract, provider) {
133
+ // Check supply before minting
134
+ const supplyBefore = await this.getTotalSupply(pkpNftContract, provider);
135
+ // Mint PKP
136
+ const mintResult = await this.mintPKP();
137
+ // Verify on-chain
138
+ const verification = await this.verifyPKPOnChain(mintResult.tokenId, pkpNftContract, provider);
139
+ // Check supply after minting
140
+ const supplyAfter = await this.getTotalSupply(pkpNftContract, provider);
141
+ return {
142
+ ...mintResult,
143
+ verified: verification.exists && supplyAfter > supplyBefore,
144
+ owner: verification.owner,
145
+ };
146
+ }
147
+ }
148
+ exports.PKPMinter = PKPMinter;
149
+ /**
150
+ * Static helper functions for PKP minting
151
+ */
152
+ class PKPMinterUtils {
153
+ /**
154
+ * Quick PKP mint - simplified interface (OPTIMIZED: Uses shared PKPMinter if provided)
155
+ */
156
+ static async quickMint(options, sharedMinter) {
157
+ const minter = sharedMinter || new PKPMinter(options);
158
+ return await minter.mintPKP();
159
+ }
160
+ /**
161
+ * Validate that a token ID doesn't exist (for testing error conditions)
162
+ */
163
+ static async validateNonExistentToken(tokenId, pkpNftContract, provider) {
164
+ const PKP_NFT_ABI = [
165
+ "function ownerOf(uint256 tokenId) view returns (address owner)",
166
+ ];
167
+ const contract = new ethers_1.ethers.Contract(pkpNftContract, PKP_NFT_ABI, provider);
168
+ try {
169
+ await contract.ownerOf(tokenId);
170
+ return false; // Token exists, validation failed
171
+ }
172
+ catch (error) {
173
+ // Check if it's the expected "token doesn't exist" error
174
+ if (error.message?.includes("invalid token ID") ||
175
+ error.message?.includes("nonexistent token") ||
176
+ error.message?.includes("ERC721")) {
177
+ return true; // Token doesn't exist, validation passed
178
+ }
179
+ // For any other error, fail fast
180
+ throw new Error(`Failed to validate token existence for ${tokenId}: ${error.message || String(error)}`);
181
+ }
182
+ }
183
+ }
184
+ exports.PKPMinterUtils = PKPMinterUtils;
185
+ //# sourceMappingURL=pkp-minter.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pkp-minter.module.js","sourceRoot":"","sources":["../../src/modules/pkp-minter.module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,mCAA2C;AAC3C,mEAA2D;AAgB3D,MAAa,SAAS;IAIpB,YAAY,OAAuB;QACjC,2FAA2F;QAC3F,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,GAAG;YACb,KAAK,EAAE,IAAI;YACX,GAAG,OAAO;SACX,CAAC;QAEF,gFAAgF;QAChF,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,wCAAgB,CAAC;YACjE,UAAU,EAAE,OAAO,CAAC,OAAO;YAC3B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK;YAC7B,qBAAqB,EAAE,KAAK;YAC5B,YAAY,EAAE,CAAC;SAChB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB;QACrB,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI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KAAK,CAC/B,EAAE,CACH,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA9CD,wCA8CC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * PKP Signer (Optimized)
3
+ * Provides secure PKP message signing through LIT Actions with efficient state management
4
+ */
5
+ import { ethers as ethers5 } from "ethers";
6
+ import { LitClientManager } from "./client-manager.module";
7
+ import { SessionSignatureManager } from "./session-signature-manager.module";
8
+ export interface PKPSigningRequest {
9
+ /** Message to sign */
10
+ message: string;
11
+ /** PKP public key */
12
+ pkpPublicKey: string;
13
+ /** PKP ETH address (optional, will be derived from public key if not provided) */
14
+ pkpEthAddress?: string;
15
+ /** LIT Action CID to use for signing */
16
+ litActionCid: string;
17
+ /** Signer for session signatures */
18
+ signer: ethers5.Signer;
19
+ /** LIT network */
20
+ network?: string;
21
+ /** Debug mode */
22
+ debug?: boolean;
23
+ }
24
+ export interface PKPSigningResult {
25
+ success: boolean;
26
+ signature?: string;
27
+ recoveredAddress?: string;
28
+ pkpAddress?: string;
29
+ verified?: boolean;
30
+ error?: string;
31
+ rawResult?: any;
32
+ }
33
+ export declare class PKPSigner {
34
+ private sessionManager;
35
+ private clientManager?;
36
+ private network;
37
+ private debug;
38
+ constructor(network: string, debug?: boolean, sharedDependencies?: {
39
+ sessionManager?: SessionSignatureManager;
40
+ clientManager?: LitClientManager;
41
+ });
42
+ /**
43
+ * Sign a message using PKP via LIT Action (OPTIMIZED VERSION)
44
+ * Uses reusable LitNodeClient and cached session signatures
45
+ */
46
+ signMessage(request: PKPSigningRequest): Promise<PKPSigningResult>;
47
+ /**
48
+ * Utility method to verify a signature against a PKP address
49
+ */
50
+ static verifySignature(message: string, signature: string, expectedAddress: string): {
51
+ verified: boolean;
52
+ recoveredAddress: string;
53
+ messageHash: string;
54
+ };
55
+ }
56
+ //# sourceMappingURL=pkp-signer.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pkp-signer.module.d.ts","sourceRoot":"","sources":["../../src/modules/pkp-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AAO,CAAC,gBAAgB,CAAC;IA4IxE;;OAEG;IACH,MAAM,CAAC,eAAe,CACpB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;CAkBxE"}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ /**
3
+ * PKP Signer (Optimized)
4
+ * Provides secure PKP message signing through LIT Actions with efficient state management
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.PKPSigner = void 0;
8
+ const ethers_1 = require("ethers");
9
+ const client_manager_module_1 = require("./client-manager.module");
10
+ const session_signature_manager_module_1 = require("./session-signature-manager.module");
11
+ // Global client managers for each network to prevent instance sharing - LEGACY FALLBACK
12
+ const clientManagers = new Map();
13
+ function getClientManager(network) {
14
+ if (!clientManagers.has(network)) {
15
+ clientManagers.set(network, new client_manager_module_1.LitClientManager({
16
+ litNetwork: network,
17
+ debug: false,
18
+ alertWhenUnauthorized: false,
19
+ minNodeCount: 2,
20
+ }));
21
+ }
22
+ return clientManagers.get(network);
23
+ }
24
+ class PKPSigner {
25
+ constructor(network, debug = false, sharedDependencies) {
26
+ this.network = network;
27
+ this.debug = debug;
28
+ this.sessionManager = sharedDependencies?.sessionManager || new session_signature_manager_module_1.SessionSignatureManager(debug);
29
+ this.clientManager = sharedDependencies?.clientManager; // Optional - will fallback to static if not provided
30
+ }
31
+ /**
32
+ * Sign a message using PKP via LIT Action (OPTIMIZED VERSION)
33
+ * Uses reusable LitNodeClient and cached session signatures
34
+ */
35
+ async signMessage(request) {
36
+ const { message, pkpPublicKey, pkpEthAddress, litActionCid, signer, network = this.network, debug = this.debug, } = request;
37
+ if (debug) {
38
+ console.log("\n๏ฟฝ PKPSigner (OPTIMIZED): Signing message with PKP via LIT Action...");
39
+ console.log(` Message: "${message}"`);
40
+ console.log(` PKP Public Key: ${pkpPublicKey}`);
41
+ console.log(` LIT Action CID: ${litActionCid}`);
42
+ console.log(` Network: ${network}`);
43
+ }
44
+ try {
45
+ // Derive PKP address if not provided
46
+ const derivedPkpAddress = pkpEthAddress ||
47
+ ethers_1.ethers.utils.computeAddress(`0x${pkpPublicKey.replace(/^0x/, "")}`);
48
+ if (debug) {
49
+ console.log(` PKP Address: ${derivedPkpAddress}`);
50
+ }
51
+ // Get client manager - use shared if available, otherwise fallback to static
52
+ const clientManager = this.clientManager || getClientManager(network);
53
+ const litNodeClient = await clientManager.getClient({
54
+ litNetwork: network,
55
+ debug,
56
+ });
57
+ if (debug) {
58
+ console.log(" โœ… LIT Node Client obtained (reused if possible)");
59
+ }
60
+ // Step 2: Get cached session signatures (OPTIMIZED)
61
+ const sessionSigs = await this.sessionManager.getOrCreateSessionSigs(signer, litNodeClient, network, 15 // 15 minutes expiration
62
+ );
63
+ if (debug) {
64
+ console.log(" โœ… Session signatures obtained (cached if possible)");
65
+ }
66
+ // Step 3: Execute LIT Action to sign the message (same golden pattern)
67
+ const executeJsResult = await litNodeClient.executeJs({
68
+ ipfsId: litActionCid,
69
+ sessionSigs: sessionSigs,
70
+ jsParams: {
71
+ publicKey: pkpPublicKey,
72
+ messageToSign: message,
73
+ },
74
+ });
75
+ if (debug) {
76
+ console.log(" โœ… LIT Action executed");
77
+ }
78
+ // Step 4: Parse response (same as before)
79
+ if (!executeJsResult.response) {
80
+ throw new Error("No response from LIT Action");
81
+ }
82
+ const responseStr = typeof executeJsResult.response === "string"
83
+ ? executeJsResult.response
84
+ : JSON.stringify(executeJsResult.response);
85
+ const actionResult = JSON.parse(responseStr);
86
+ if (!actionResult.success) {
87
+ throw new Error(`LIT Action failed: ${actionResult.error}`);
88
+ }
89
+ // Step 5: Extract signature (same golden pattern)
90
+ const litSignature = executeJsResult.signatures?.dummySig;
91
+ if (!litSignature) {
92
+ throw new Error("No signature returned from LIT Action");
93
+ }
94
+ const signature = litSignature.signature;
95
+ if (debug) {
96
+ console.log(` ๐Ÿ“ Got signature: ${signature}`);
97
+ }
98
+ // Step 6: Verify signature (same golden pattern)
99
+ const messageHash = ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.toUtf8Bytes(message));
100
+ const recoveredAddress = ethers_1.ethers.utils.recoverAddress(messageHash, signature);
101
+ const verified = recoveredAddress.toLowerCase() === derivedPkpAddress.toLowerCase();
102
+ if (debug) {
103
+ console.log(` ๐Ÿ” Message hash: ${messageHash}`);
104
+ console.log(` ๐Ÿ  Recovered address: ${recoveredAddress}`);
105
+ console.log(` ๐ŸŽฏ Expected address: ${derivedPkpAddress}`);
106
+ console.log(` โœ… Signature verified: ${verified}`);
107
+ }
108
+ // Step 7: No disconnect needed - client is managed globally
109
+ // Client manager handles cleanup automatically
110
+ if (debug) {
111
+ console.log(" ๐Ÿ”Œ Client released back to pool");
112
+ }
113
+ return {
114
+ success: true,
115
+ signature,
116
+ recoveredAddress,
117
+ pkpAddress: derivedPkpAddress,
118
+ verified,
119
+ rawResult: executeJsResult,
120
+ };
121
+ }
122
+ catch (error) {
123
+ if (debug) {
124
+ console.error(" โŒ PKPSigner (OPTIMIZED) error:", error);
125
+ }
126
+ return {
127
+ success: false,
128
+ error: error instanceof Error ? error.message : String(error),
129
+ };
130
+ }
131
+ }
132
+ /**
133
+ * Utility method to verify a signature against a PKP address
134
+ */
135
+ static verifySignature(message, signature, expectedAddress) {
136
+ // Use the same signing method as the LIT Action (keccak256 hash)
137
+ const messageHash = ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.toUtf8Bytes(message));
138
+ const recoveredAddress = ethers_1.ethers.utils.recoverAddress(messageHash, signature);
139
+ const verified = recoveredAddress.toLowerCase() === expectedAddress.toLowerCase();
140
+ return {
141
+ verified,
142
+ recoveredAddress,
143
+ messageHash,
144
+ };
145
+ }
146
+ }
147
+ exports.PKPSigner = PKPSigner;
148
+ //# sourceMappingURL=pkp-signer.module.js.map
@@ -0,0 +1 @@
1
+ {"version":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;QACF,MAAM,QAAQ,GACZ,gBAAgB,CAAC,WAAW,EAAE,KAAK,eAAe,CAAC,WAAW,EAAE,CAAC;QAEnE,OAAO;YACL,QAAQ;YACR,gBAAgB;YAChB,WAAW;SACZ,CAAC;IACJ,CAAC;CACF;AA7LD,8BA6LC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Session Signature Manager
3
+ * Manages session signature caching for efficient reuse
4
+ */
5
+ import { LitNodeClient } from "@lit-protocol/lit-node-client";
6
+ import { ethers as ethers5 } from "ethers";
7
+ export declare class SessionSignatureManager {
8
+ private cache;
9
+ private debug;
10
+ constructor(debug?: boolean);
11
+ /**
12
+ * Get or create session signatures with caching
13
+ * Cache key format: {signerAddress}-{network}
14
+ */
15
+ getOrCreateSessionSigs(signer: ethers5.Signer, client: LitNodeClient, network: string, expirationMinutes?: number): Promise<any>;
16
+ /**
17
+ * Clear cached session signatures for a specific signer
18
+ */
19
+ clearCache(signerAddress?: string, network?: string): void;
20
+ /**
21
+ * Get cache statistics
22
+ */
23
+ getCacheStats(): {
24
+ total: number;
25
+ entries: string[];
26
+ };
27
+ /**
28
+ * Cleanup expired entries
29
+ */
30
+ cleanupExpired(): void;
31
+ }
32
+ //# sourceMappingURL=session-signature-manager.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-signature-manager.module.d.ts","sourceRoot":"","sources":["../../src/modules/session-signature-manager.module.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,QAAQ,CAAC;AAS3C,qBAAa,uBAAuB;IAClC,OAAO,CAAC,KAAK,CAAwC;IACrD,OAAO,CAAC,KAAK,CAAU;gBAEX,KAAK,GAAE,OAAe;IAIlC;;;OAGG;IACG,sBAAsB,CAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAW,GAC7B,OAAO,CAAC,GAAG,CAAC;IA4Ef;;OAEG;IACH,UAAU,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAiB1D;;OAEG;IACH,aAAa,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE;IAOrD;;OAEG;IACH,cAAc,IAAI,IAAI;CAevB"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /**
3
+ * Session Signature Manager
4
+ * Manages session signature caching for efficient reuse
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.SessionSignatureManager = void 0;
8
+ const auth_helpers_1 = require("@lit-protocol/auth-helpers");
9
+ const constants_1 = require("@lit-protocol/constants");
10
+ class SessionSignatureManager {
11
+ constructor(debug = false) {
12
+ this.cache = new Map();
13
+ this.debug = debug;
14
+ }
15
+ /**
16
+ * Get or create session signatures with caching
17
+ * Cache key format: {signerAddress}-{network}
18
+ */
19
+ async getOrCreateSessionSigs(signer, client, network, expirationMinutes = 10) {
20
+ const signerAddress = await signer.getAddress();
21
+ const cacheKey = `${signerAddress}-${network}`;
22
+ // Check if we have valid cached session sigs
23
+ const cached = this.cache.get(cacheKey);
24
+ if (cached && cached.expiry > Date.now()) {
25
+ if (this.debug) {
26
+ const remainingMinutes = Math.round((cached.expiry - Date.now()) / (1000 * 60));
27
+ console.log(`๐Ÿ”„ Reusing cached session sigs for ${signerAddress} (${remainingMinutes}m remaining)`);
28
+ }
29
+ return cached.sessionSigs;
30
+ }
31
+ if (this.debug) {
32
+ console.log(`๐Ÿ”‘ Generating new session sigs for ${signerAddress}`);
33
+ }
34
+ // Generate new session signatures
35
+ const sessionSigs = await client.getSessionSigs({
36
+ chain: "ethereum",
37
+ expiration: new Date(Date.now() + expirationMinutes * 60 * 1000).toISOString(),
38
+ resourceAbilityRequests: [
39
+ {
40
+ resource: new auth_helpers_1.LitPKPResource("*"),
41
+ ability: constants_1.LIT_ABILITY.PKPSigning,
42
+ },
43
+ {
44
+ resource: new auth_helpers_1.LitActionResource("*"),
45
+ ability: constants_1.LIT_ABILITY.LitActionExecution,
46
+ },
47
+ ],
48
+ authNeededCallback: async (params) => {
49
+ const toSign = await (0, auth_helpers_1.createSiweMessage)({
50
+ uri: params.uri,
51
+ domain: "diamond-hands.local",
52
+ expiration: params.expiration,
53
+ resources: params.resourceAbilityRequests,
54
+ walletAddress: signerAddress,
55
+ nonce: await client.getLatestBlockhash(),
56
+ statement: "Diamond Hands Protocol - LIT Action Execution Authorization",
57
+ litNodeClient: client,
58
+ });
59
+ return await (0, auth_helpers_1.generateAuthSig)({
60
+ signer: signer,
61
+ toSign,
62
+ });
63
+ },
64
+ });
65
+ // Cache the session signatures
66
+ const expiryTime = Date.now() + (expirationMinutes - 1) * 60 * 1000; // 1 minute buffer
67
+ this.cache.set(cacheKey, {
68
+ sessionSigs,
69
+ expiry: expiryTime,
70
+ signerAddress,
71
+ network,
72
+ });
73
+ if (this.debug) {
74
+ console.log(`โœ… Session sigs cached for ${signerAddress} (${expirationMinutes}m)`);
75
+ }
76
+ return sessionSigs;
77
+ }
78
+ /**
79
+ * Clear cached session signatures for a specific signer
80
+ */
81
+ clearCache(signerAddress, network) {
82
+ if (signerAddress && network) {
83
+ const cacheKey = `${signerAddress}-${network}`;
84
+ this.cache.delete(cacheKey);
85
+ if (this.debug) {
86
+ console.log(`๐Ÿ—‘๏ธ Cleared session sigs cache for ${signerAddress}-${network}`);
87
+ }
88
+ }
89
+ else {
90
+ this.cache.clear();
91
+ if (this.debug) {
92
+ console.log(`๐Ÿ—‘๏ธ Cleared all session sigs cache`);
93
+ }
94
+ }
95
+ }
96
+ /**
97
+ * Get cache statistics
98
+ */
99
+ getCacheStats() {
100
+ return {
101
+ total: this.cache.size,
102
+ entries: Array.from(this.cache.keys()),
103
+ };
104
+ }
105
+ /**
106
+ * Cleanup expired entries
107
+ */
108
+ cleanupExpired() {
109
+ const now = Date.now();
110
+ let cleaned = 0;
111
+ for (const [key, cached] of this.cache.entries()) {
112
+ if (cached.expiry <= now) {
113
+ this.cache.delete(key);
114
+ cleaned++;
115
+ }
116
+ }
117
+ if (this.debug && cleaned > 0) {
118
+ console.log(`๐Ÿงน Cleaned up ${cleaned} expired session sig entries`);
119
+ }
120
+ }
121
+ }
122
+ exports.SessionSignatureManager = SessionSignatureManager;
123
+ //# sourceMappingURL=session-signature-manager.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-signature-manager.module.js","sourceRoot":"","sources":["../../src/modules/session-signature-manager.module.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6DAKoC;AACpC,uDAAsD;AAWtD,MAAa,uBAAuB;IAIlC,YAAY,QAAiB,KAAK;QAH1B,UAAK,GAAG,IAAI,GAAG,EAA6B,CAAC;QAInD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,sBAAsB,CAC1B,MAAsB,EACtB,MAAqB,EACrB,OAAe,EACf,oBAA4B,EAAE;QAE9B,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAChD,MAAM,QAAQ,GAAG,GAAG,aAAa,IAAI,OAAO,EAAE,CAAC;QAE/C,6CAA6C;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YACzC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CACjC,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAC3C,CAAC;gBACF,OAAO,CA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AAI,OAAO,GAAG,CAAC,CAAC;QAEhB,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YACjD,IAAI,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;gBACzB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvB,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,iBAAiB,OAAO,8BAA8B,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF;AA7ID,0DA6IC"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@gvnrdao/dh-lit-ops",
3
+ "version": "0.0.1",
4
+ "description": "Diamond Hands Protocol - LIT Protocol Operations Package",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "dev": "tsc --watch",
14
+ "test": "node scripts/test-only.js",
15
+ "test:jest": "jest tests/",
16
+ "test:all": "jest tests/",
17
+ "lint": "eslint src/**/*.ts",
18
+ "clean": "rm -rf dist"
19
+ },
20
+ "keywords": [
21
+ "lit-protocol",
22
+ "pkp",
23
+ "lit-actions",
24
+ "diamond-hands",
25
+ "blockchain",
26
+ "decentralized"
27
+ ],
28
+ "author": "Diamond Hands Protocol",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/gvnrdao/diamond-hands.git",
33
+ "directory": "lit-ops"
34
+ },
35
+ "dependencies": {
36
+ "@lit-protocol/auth-helpers": "^7.3.0",
37
+ "@lit-protocol/constants": "^7.3.0",
38
+ "@lit-protocol/contracts-sdk": "^7.3.0",
39
+ "@lit-protocol/lit-auth-client": "^7.3.0",
40
+ "@lit-protocol/lit-node-client": "^7.3.0",
41
+ "@lit-protocol/types": "^7.3.0",
42
+ "axios": "^1.5.0",
43
+ "bs58": "^6.0.0",
44
+ "@gvnrdao/dh-lit-actions": "0.0.1",
45
+ "ethers": "5.8.0",
46
+ "multiformats": "^13.4.0"
47
+ },
48
+ "devDependencies": {
49
+ "@types/dotenv": "^8.2.3",
50
+ "@types/jest": "^29.5.14",
51
+ "@types/node": "^20.0.0",
52
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
53
+ "@typescript-eslint/parser": "^6.0.0",
54
+ "dotenv": "^17.2.1",
55
+ "eslint": "^8.0.0",
56
+ "jest": "^29.0.0",
57
+ "ts-jest": "^29.4.1",
58
+ "ts-node": "^10.9.2",
59
+ "typescript": "^5.0.0"
60
+ }
61
+ }