Created
January 25, 2025 03:07
-
-
Save iboss-ptk/59ab7a2f9298876f9f81b087a3d336e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LitActionResource } from "@lit-protocol/auth-helpers"; | |
import { | |
AUTH_METHOD_SCOPE, | |
AUTH_METHOD_TYPE, | |
LIT_ABILITY, | |
LIT_NETWORK, | |
LIT_RPC, | |
} from "@lit-protocol/constants"; | |
import { LitContracts } from "@lit-protocol/contracts-sdk"; | |
import { EthWalletProvider } from "@lit-protocol/lit-auth-client"; | |
import { | |
LitNodeClient, | |
LitNodeClientNodeJs, | |
} from "@lit-protocol/lit-node-client"; | |
import { describe, it } from "bun:test"; | |
import { ethers } from "ethers"; | |
import { generateWrappedKeys } from "../generate-wrapped-keys"; | |
describe("generateWrappedKeys", () => { | |
it("should generate a wrapped key with the correct public key", async () => { | |
// setup lit node client | |
const ethereumPrivateKey = | |
"f21d3fafe29fa10d26092ce4e91cd7108b734b98393f79b3c2cd04de24ca6817"; | |
const ethersSigner = new ethers.Wallet( | |
ethereumPrivateKey, | |
new ethers.providers.JsonRpcProvider(LIT_RPC.CHRONICLE_YELLOWSTONE) | |
); | |
const litNodeClient = new LitNodeClientNodeJs({ | |
litNetwork: LIT_NETWORK.DatilDev, | |
debug: false, | |
}); | |
await litNodeClient.connect(); | |
// mint pkp | |
const contractClient = new LitContracts({ | |
signer: ethersSigner, | |
network: LIT_NETWORK.DatilDev, | |
debug: true, | |
}); | |
await contractClient.connect(); | |
const authMethod = { | |
authMethodType: AUTH_METHOD_TYPE.EthWallet, | |
accessToken: JSON.stringify({ | |
sig: "0x137b66529678d1fc58ab5b340ad036082af5b9912f823ba22c2851b8f50990a666ad8f2ab2328e8c94414c0a870163743bde91a5f96e9f967fd45d5e0c17c3911b", | |
derivedVia: "web3.eth.personal.sign", | |
signedMessage: | |
"localhost wants you to sign in with your Ethereum account:\n0xeF71c2604f17Ec6Fc13409DF24EfdC440D240d37\n\nTESTING TESTING 123\n\nURI: https://localhost/login\nVersion: 1\nChain ID: 1\nNonce: eoeo0dsvyLL2gcHsC\nIssued At: 2023-11-17T15:04:20.324Z\nExpiration Time: 2215-07-14T15:04:20.323Z", | |
address: "0xeF71c2604f17Ec6Fc13409DF24EfdC440D240d37", | |
}), | |
}; | |
const mintInfo = await contractClient.mintWithAuth({ | |
authMethod, | |
scopes: [AUTH_METHOD_SCOPE.SignAnything], | |
}); | |
console.log(mintInfo.pkp.tokenId); | |
// --- | |
const pkpPublicKey = mintInfo.pkp.publicKey; | |
const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ | |
pkpPublicKey, | |
authMethods: [ | |
await EthWalletProvider.authenticate({ | |
signer: ethersSigner, | |
litNodeClient: litNodeClient as LitNodeClient, | |
expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes | |
}), | |
], | |
resourceAbilityRequests: [ | |
{ | |
resource: new LitActionResource("*"), | |
ability: LIT_ABILITY.LitActionExecution, | |
}, | |
], | |
expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(), // 10 minutes | |
}); | |
const result = await generateWrappedKeys( | |
litNodeClient, | |
pkpSessionSigs, | |
"K256", | |
"test memo" | |
); | |
console.log(result); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment