diff --git a/.vscode/settings.json b/.vscode/settings.json index c46432c1bf..0145107988 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,9 @@ "liveServer.settings.port": 5502, "todo-tree.tree.scanMode": "workspace", "conventionalCommits.scopes": [ - "contracts-sdk" + "contracts-sdk", + "lit-node-client-nodejs", + "core", ], // "restoreTerminals.terminals": [ // { diff --git a/apps/html/manual_tests.html b/apps/html/manual_tests.html index 06745152d5..8ee3d22511 100644 --- a/apps/html/manual_tests.html +++ b/apps/html/manual_tests.html @@ -44,7 +44,7 @@ var CheckAndSignAuthMessageWithBlockhash = async() => { // Currently this will be undefined but later we should replace it with the hardcoded blockhash const TEST_BLOCKHASH = "0xfe88c94d860f01a17f961bf4bdfb6e0c6cd10d3fda5cc861e805ca1240c58553"; - const nonce = litNodeClient.getLatestBlockhash() || TEST_BLOCKHASH; + const nonce = await litNodeClient.getLatestBlockhash() || TEST_BLOCKHASH; const authSig = await LitJsSdk.checkAndSignAuthMessage({ chain: "ethereum", diff --git a/apps/react/src/app/lit-node-client-page.tsx b/apps/react/src/app/lit-node-client-page.tsx index 1e0ac3c2ee..047e6ed5f7 100644 --- a/apps/react/src/app/lit-node-client-page.tsx +++ b/apps/react/src/app/lit-node-client-page.tsx @@ -41,7 +41,7 @@ const LitNodeClientPage = () => { debug: true, }); - const latestBlockhash = client.getLatestBlockhash(); + const latestBlockhash = await client.getLatestBlockhash(); const authsig = await authBrowser.checkAndSignAuthMessage({ chain: 'ethereum', diff --git a/e2e-nodejs/0_manual-tests/test-block-has-update-after-exp.mjs b/e2e-nodejs/0_manual-tests/test-block-has-update-after-exp.mjs index e9e831022d..010864d571 100644 --- a/e2e-nodejs/0_manual-tests/test-block-has-update-after-exp.mjs +++ b/e2e-nodejs/0_manual-tests/test-block-has-update-after-exp.mjs @@ -18,7 +18,7 @@ export async function main() { console.log(client.hdRootPubkeys); let subnetKey = '' + client.subnetPubKey; let rootKeys = client.hdRootPubkeys; - let blockhash = client.getLatestBlockhash(); + let blockhash = await client.getLatestBlockhash(); await new Promise((resolve, _reject) => { setTimeout(resolve, 35_000); }); diff --git a/e2e-nodejs/group-connection/test-latest-blockhash.mjs b/e2e-nodejs/group-connection/test-latest-blockhash.mjs new file mode 100644 index 0000000000..13e6161533 --- /dev/null +++ b/e2e-nodejs/group-connection/test-latest-blockhash.mjs @@ -0,0 +1,32 @@ +import path from 'path'; +import { success, fail, testThis } from '../../tools/scripts/utils.mjs'; +import LITCONFIG from '../../lit.config.json' assert { type: 'json' }; +import { LitNodeClient } from '@lit-protocol/lit-node-client'; + +const LIT_NETWORK = 'cayenne'; + +export async function main() { + // ==================== Test Logic ==================== + const client = new LitNodeClient({ + litNetwork: globalThis.LitCI.network, + debug: globalThis.LitCI.debug, + checkNodeAttestation: globalThis.LitCI.sevAttestation, + }); + await client.connect(); + + const latestBlockhash = await litNodeClient.getLatestBlockhash(); + + // ==================== Post-Validation ==================== + if (!latestBlockhash) { + return fail('latest blockhash not found'); + } + + if (!latestBlockhash.startsWith('0x')) { + return fail('latest blockhash not in hex format'); + } + + // ==================== Success ==================== + return success(`Latest blockhash found: ${latestBlockhash}`); +} + +await testThis({ name: path.basename(import.meta.url), fn: main }); diff --git a/e2e-nodejs/group-hotwallet-with-blockhash/test-hotwallet-with-blockhash.mjs b/e2e-nodejs/group-hotwallet-with-blockhash/test-hotwallet-with-blockhash.mjs index 7e7ce45ff3..0770662b5d 100644 --- a/e2e-nodejs/group-hotwallet-with-blockhash/test-hotwallet-with-blockhash.mjs +++ b/e2e-nodejs/group-hotwallet-with-blockhash/test-hotwallet-with-blockhash.mjs @@ -62,7 +62,7 @@ export async function main() { }); await litNodeClient.connect(); - let nonce = litNodeClient.getLatestBlockhash(); + let nonce = await litNodeClient.getLatestBlockhash(); console.log('Eth blockhash nonce- ', nonce); if (!nonce) { diff --git a/e2e-nodejs/group-latest-blockhash-update/test-block-has-update-after-exp.mjs b/e2e-nodejs/group-latest-blockhash-update/test-block-has-update-after-exp.mjs index e9e831022d..010864d571 100644 --- a/e2e-nodejs/group-latest-blockhash-update/test-block-has-update-after-exp.mjs +++ b/e2e-nodejs/group-latest-blockhash-update/test-block-has-update-after-exp.mjs @@ -18,7 +18,7 @@ export async function main() { console.log(client.hdRootPubkeys); let subnetKey = '' + client.subnetPubKey; let rootKeys = client.hdRootPubkeys; - let blockhash = client.getLatestBlockhash(); + let blockhash = await client.getLatestBlockhash(); await new Promise((resolve, _reject) => { setTimeout(resolve, 35_000); }); diff --git a/e2e-nodejs/group-pkp-encryption-decryption/test-pkp-encryption-decryption-nodes.mjs b/e2e-nodejs/group-pkp-encryption-decryption/test-pkp-encryption-decryption-nodes.mjs index 061c4ff951..8790a72750 100644 --- a/e2e-nodejs/group-pkp-encryption-decryption/test-pkp-encryption-decryption-nodes.mjs +++ b/e2e-nodejs/group-pkp-encryption-decryption/test-pkp-encryption-decryption-nodes.mjs @@ -58,7 +58,7 @@ export async function main() { uri: 'https://localhost/login', version: '1', chainId: 1, - nonce: litNodeClient.getLatestBlockhash(), + nonce: await litNodeClient.getLatestBlockhash(), expirationTime: new Date(Date.now() + 60_000 * 60).toISOString(), }); const messageToSign = siweMessage.prepareMessage(); diff --git a/e2e-nodejs/loader.mjs b/e2e-nodejs/loader.mjs index ade935863e..fecfaca878 100644 --- a/e2e-nodejs/loader.mjs +++ b/e2e-nodejs/loader.mjs @@ -36,7 +36,7 @@ if (loadEnv) { await litNodeClient.connect(); - let nonce = litNodeClient.getLatestBlockhash(); + let nonce = await litNodeClient.getLatestBlockhash(); console.log('GENERATED NONCE: ', nonce); const domain = 'localhost'; diff --git a/packages/core/package.json b/packages/core/package.json index 2555d07688..b99558a880 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -24,7 +24,5 @@ }, "tags": [ "universal" - ], - "main": "./dist/src/index.js", - "typings": "./dist/src/index.d.ts" + ] } diff --git a/packages/core/src/lib/lit-core.ts b/packages/core/src/lib/lit-core.ts index bba32ebaa0..54234bced2 100644 --- a/packages/core/src/lib/lit-core.ts +++ b/packages/core/src/lib/lit-core.ts @@ -484,6 +484,23 @@ export class LitCore { }; /** + * Return the latest blockhash from the nodes + * @returns { Promise } latest blockhash + */ + getLatestBlockhash = async (): Promise => { + await this.connect(); + + if (!this.latestBlockhash) { + throw new Error( + `latestBlockhash is not available. Received: "${this.latestBlockhash}"` + ); + } + + return this.latestBlockhash; + }; + + /** + * * Connect to the LIT nodes * * @returns { Promise } A promise that resolves when the nodes are connected. diff --git a/packages/lit-auth-client/package.json b/packages/lit-auth-client/package.json index ef1487bed5..aacb7265e3 100644 --- a/packages/lit-auth-client/package.json +++ b/packages/lit-auth-client/package.json @@ -29,7 +29,5 @@ "@simplewebauthn/browser": "^7.2.0", "@simplewebauthn/typescript-types": "^7.0.0", "nanoid": "3.3.4" - }, - "main": "./dist/src/index.js", - "typings": "./dist/src/index.d.ts" + } } diff --git a/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts b/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts index 3c5b9de0cd..46e053b884 100644 --- a/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts +++ b/packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts @@ -28,6 +28,7 @@ import { } from '@lit-protocol/constants'; import { LitCore } from '@lit-protocol/core'; import { + checkSevSnpAttestation, combineEcdsaShares, combineSignatureShares, encrypt, @@ -80,6 +81,7 @@ import type { GetSigningShareForDecryptionRequest, GetWalletSigProps, JsonExecutionRequest, + JsonHandshakeResponse, JsonPkpSignRequest, LitClientSessionManager, LitNodeClientConfig, @@ -253,7 +255,7 @@ export class LitNodeClientNodeJs throw new Error('Failed to verify capabilities for resource'); } - const nonce = this.getLatestBlockhash(); + const nonce = await this.getLatestBlockhash(); // -- get auth sig let siweMessage = new siwe.SiweMessage({ @@ -474,25 +476,6 @@ export class LitNodeClientNodeJs return LitNodeClientNodeJs.getExpiration(); }; - /** - * returns the latest block hash. - * will call refresh if the block hash is expired - * @returns {Promise} latest block hash from `handhsake` with the lit network. - */ - getLatestBlockhash = (): string => { - if (!this.ready) { - logError('Client not connected, remember to call connect'); - throwError({ - message: 'Client not connected', - errorKind: LIT_ERROR.LIT_NODE_CLIENT_NOT_READY_ERROR.kind, - errorCode: LIT_ERROR.LIT_NODE_CLIENT_NOT_READY_ERROR.code, - }); - } - - // we are confident in this value being non null so we return - return this.latestBlockhash!; - }; - /** * * Get the signature from local storage, if not, generates one diff --git a/packages/logger/package.json b/packages/logger/package.json index f0c9a48977..3dba07e3e3 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -8,7 +8,5 @@ "publishConfig": { "access": "public", "directory": "../../dist/packages/logger" - }, - "main": "./dist/src/index.js", - "typings": "./dist/src/index.d.ts" + } } diff --git a/packages/pkp-base/package.json b/packages/pkp-base/package.json index 38668abe41..65d348ed34 100644 --- a/packages/pkp-base/package.json +++ b/packages/pkp-base/package.json @@ -24,7 +24,5 @@ }, "tags": [ "universal" - ], - "main": "./dist/src/index.js", - "typings": "./dist/src/index.d.ts" + ] } diff --git a/packages/pkp-client/package.json b/packages/pkp-client/package.json index 279c63cc19..e878e25885 100644 --- a/packages/pkp-client/package.json +++ b/packages/pkp-client/package.json @@ -24,7 +24,5 @@ }, "tags": [ "universal" - ], - "main": "./dist/src/index.js", - "typings": "./dist/src/index.d.ts" + ] } diff --git a/packages/pkp-cosmos/package.json b/packages/pkp-cosmos/package.json index e5e02b9723..a88af68255 100644 --- a/packages/pkp-cosmos/package.json +++ b/packages/pkp-cosmos/package.json @@ -24,7 +24,5 @@ }, "tags": [ "universal" - ], - "main": "./dist/src/index.js", - "typings": "./dist/src/index.d.ts" + ] } diff --git a/packages/pkp-sui/package.json b/packages/pkp-sui/package.json index 252e9c74a2..0b5cbbeb78 100644 --- a/packages/pkp-sui/package.json +++ b/packages/pkp-sui/package.json @@ -24,7 +24,5 @@ }, "tags": [ "universal" - ], - "main": "./dist/src/index.js", - "typings": "./dist/src/index.d.ts" + ] } diff --git a/packages/pkp-walletconnect/package.json b/packages/pkp-walletconnect/package.json index 3c72456bd8..9729b4d707 100644 --- a/packages/pkp-walletconnect/package.json +++ b/packages/pkp-walletconnect/package.json @@ -31,7 +31,5 @@ }, "tags": [ "universal" - ], - "main": "./dist/src/index.js", - "typings": "./dist/src/index.d.ts" + ] }