Skip to content

Commit 2d80dfe

Browse files
committed
chore: bump @lit-protocol/lit-status-sdk version to ^0.1.8 and refactor DatilHealthManager for improved readability
1 parent 9e15666 commit 2d80dfe

File tree

3 files changed

+71
-62
lines changed

3 files changed

+71
-62
lines changed

local-tests/health/DatilHealthManager.ts

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import { getEoaSessionSigs } from "local-tests/setup/session-sigs/get-eoa-session-sigs";
2-
import { getPkpSessionSigs } from "local-tests/setup/session-sigs/get-pkp-session-sigs";
3-
import { TinnyEnvironment } from "local-tests/setup/tinny-environment"
4-
import { TinnyPerson } from "local-tests/setup/tinny-person";
1+
import { getEoaSessionSigs } from 'local-tests/setup/session-sigs/get-eoa-session-sigs';
2+
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';
3+
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
4+
import { TinnyPerson } from 'local-tests/setup/tinny-person';
55
import { LIT_ABILITY } from '@lit-protocol/constants';
66
import { ILitNodeClient } from '@lit-protocol/types';
77
import { AccessControlConditions } from 'local-tests/setup/accs/accs';
88
import { LitAccessControlConditionResource } from '@lit-protocol/auth-helpers';
99
import { encryptString, decryptToString } from '@lit-protocol/encryption';
1010

1111
export class DatilHealthManager {
12-
1312
env: TinnyEnvironment;
1413
alice: TinnyPerson;
1514
eoaSessionSigs: any;
1615

17-
constructor(){
16+
constructor() {
1817
this.env = new TinnyEnvironment();
1918
}
2019

21-
async init(){
20+
async init() {
2221
await this.env.init();
2322
}
2423

@@ -27,58 +26,57 @@ export class DatilHealthManager {
2726
// this action contains chain & rpc interactions
2827
// best to cache it, but for the time being, we will create a new person for each test, since we are only running this test
2928
// once in every 30 minutes.
30-
async initPerson(){
31-
this.alice = await this.env.createNewPerson("Alice");
29+
async initPerson() {
30+
this.alice = await this.env.createNewPerson('Alice');
3231
this.eoaSessionSigs = await getEoaSessionSigs(this.env, this.alice);
3332
}
3433

35-
validatePrerequisites(){
36-
if(!this.alice){
37-
throw new Error("❌ Person not initialized");
34+
validatePrerequisites() {
35+
if (!this.alice) {
36+
throw new Error('❌ Person not initialized');
3837
}
39-
if(!this.eoaSessionSigs){
40-
throw new Error("❌ EOA Session Sigs not initialized");
38+
if (!this.eoaSessionSigs) {
39+
throw new Error('❌ EOA Session Sigs not initialized');
4140
}
4241
}
4342

44-
4543
// ========== Endpoint Tests ==========
4644
handshakeTest = async () => {
47-
try{
45+
try {
4846
await this.env.setupLitNodeClient();
49-
}catch(e){
50-
console.error("❌ Failed to setup Lit Node Client");
47+
} catch (e) {
48+
console.error('❌ Failed to setup Lit Node Client');
5149
throw e;
5250
}
53-
}
51+
};
5452

5553
pkpSignTest = async () => {
5654
this.validatePrerequisites();
57-
try{
55+
try {
5856
await this.env.litNodeClient.pkpSign({
5957
toSign: this.alice.loveLetter,
6058
pubKey: this.alice.pkp.publicKey,
6159
sessionSigs: this.eoaSessionSigs,
62-
})
63-
}catch(e){
64-
console.error("❌ Failed to run pkpSign");
60+
});
61+
} catch (e) {
62+
console.error('❌ Failed to run pkpSign');
6563
throw e;
6664
}
67-
}
65+
};
6866

6967
signSessionKeyTest = async () => {
7068
this.validatePrerequisites();
71-
try{
69+
try {
7270
await getPkpSessionSigs(this.env, this.alice);
73-
}catch(e){
74-
console.error("❌ Failed to run signSessionKey");
71+
} catch (e) {
72+
console.error('❌ Failed to run signSessionKey');
7573
throw e;
7674
}
77-
}
75+
};
7876

7977
executeJsTest = async () => {
8078
this.validatePrerequisites();
81-
try{
79+
try {
8280
await this.env.litNodeClient.executeJs({
8381
sessionSigs: this.eoaSessionSigs,
8482
code: `(async () => {
@@ -91,17 +89,17 @@ export class DatilHealthManager {
9189
jsParams: {
9290
dataToSign: this.alice.loveLetter,
9391
publicKey: this.alice.pkp.publicKey,
94-
}
95-
})
96-
}catch(e){
97-
console.error("❌ Failed to run executeJs");
92+
},
93+
});
94+
} catch (e) {
95+
console.error('❌ Failed to run executeJs');
9896
throw e;
9997
}
100-
}
98+
};
10199

102100
decryptTest = async () => {
103101
this.validatePrerequisites();
104-
try{
102+
try {
105103
// Set access control conditions for encrypting and decrypting
106104
const accs = AccessControlConditions.getEmvBasicAccessControlConditions({
107105
userAddress: this.alice.wallet.address,
@@ -156,9 +154,9 @@ export class DatilHealthManager {
156154
`Expected decryptRes to be 'Hello world' but got ${decryptRes}`
157155
);
158156
}
159-
}catch(e){
160-
console.error("❌ Failed to run decrypt");
157+
} catch (e) {
158+
console.error('❌ Failed to run decrypt');
161159
throw e;
162160
}
163-
}
164-
}
161+
};
162+
}

local-tests/health/index.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,80 @@
11
import { createLitStatusClient } from '@lit-protocol/lit-status-sdk';
22
import { DatilHealthManager } from './DatilHealthManager';
33

4+
// Fix for Node.js crypto in ESM
5+
import { webcrypto } from 'node:crypto';
6+
if (!globalThis.crypto) {
7+
globalThis.crypto = webcrypto as Crypto;
8+
}
9+
410
// Configuration
511
const NETWORK = process.env.NETWORK!;
612
const PRODUCT = 'js-sdk/datil';
713

8-
async function runHealthCheck(){
9-
10-
if(!NETWORK){
11-
throw new Error("❌ NETWORK is not set");
14+
async function runHealthCheck() {
15+
if (!NETWORK) {
16+
throw new Error('❌ NETWORK is not set');
1217
}
1318

1419
const statusClient = createLitStatusClient({
1520
url: process.env.LIT_STATUS_BACKEND_URL,
16-
apiKey: process.env.LIT_STATUS_WRITE_KEY
21+
apiKey: process.env.LIT_STATUS_WRITE_KEY,
1722
});
1823

1924
const txs = await statusClient.getOrRegisterFunctions({
2025
network: NETWORK,
2126
product: PRODUCT,
2227
functions: [
23-
'handshake',
28+
'handshake',
2429
'pkpSign',
2530
'signSessionKey',
2631
'executeJs',
27-
'decrypt'
28-
] as const
32+
'decrypt',
33+
] as const,
2934
});
30-
35+
3136
const healthManager = new DatilHealthManager();
3237
await healthManager.init();
3338

3439
// (test) /web/handshake
35-
console.log("🔄 Running handshake test");
36-
await statusClient.executeAndLog(txs.handshake.id, healthManager.handshakeTest);
40+
console.log('🔄 Running handshake test');
41+
await statusClient.executeAndLog(
42+
txs.handshake.id,
43+
healthManager.handshakeTest
44+
);
3745

3846
// after handshake, we can create a person to test
3947
await healthManager.initPerson();
4048

4149
// (test) /web/pkp/sign
42-
console.log("🔄 Running pkpSign test");
50+
console.log('🔄 Running pkpSign test');
4351
await statusClient.executeAndLog(txs.pkpSign.id, healthManager.pkpSignTest);
4452

4553
// (test) /web/sign_session_key
46-
console.log("🔄 Running signSessionKey test");
47-
await statusClient.executeAndLog(txs.signSessionKey.id, healthManager.signSessionKeyTest);
54+
console.log('🔄 Running signSessionKey test');
55+
await statusClient.executeAndLog(
56+
txs.signSessionKey.id,
57+
healthManager.signSessionKeyTest
58+
);
4859

4960
// (test) /web/execute
50-
console.log("🔄 Running executeJs test");
51-
await statusClient.executeAndLog(txs.executeJs.id, healthManager.executeJsTest);
61+
console.log('🔄 Running executeJs test');
62+
await statusClient.executeAndLog(
63+
txs.executeJs.id,
64+
healthManager.executeJsTest
65+
);
5266

5367
// (test) /web/encryption/sign
54-
console.log("🔄 Running decryptTest test");
68+
console.log('🔄 Running decryptTest test');
5569
await statusClient.executeAndLog(txs.decrypt.id, healthManager.decryptTest);
56-
57-
5870
}
5971

60-
6172
(async () => {
62-
try{
73+
try {
6374
await runHealthCheck();
6475
} catch (error) {
6576
console.error(error);
6677
} finally {
6778
process.exit();
6879
}
69-
})();
80+
})();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@dotenvx/dotenvx": "^1.6.4",
4444
"@lit-protocol/accs-schemas": "^0.0.31",
4545
"@lit-protocol/contracts": "^0.0.74",
46-
"@lit-protocol/lit-status-sdk": "^0.1.7",
46+
"@lit-protocol/lit-status-sdk": "^0.1.8",
4747
"@metamask/eth-sig-util": "5.0.2",
4848
"@mysten/sui.js": "^0.37.1",
4949
"@openagenda/verror": "^3.1.4",

0 commit comments

Comments
 (0)