Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8bb950

Browse files
committed
Merge branch 'master' into fix/session-sig-re-signing
2 parents 0b4822b + 278381b commit f8bb950

File tree

110 files changed

+4886
-920
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+4886
-920
lines changed

.env.sample

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#Tinny ENV Vars
2+
MAX_ATTEMTPS=1
3+
NETWORK=localchain
4+
DEBUG=true
5+
WAIT_FOR_KEY_INTERVAL=3000
6+
LIT_OFFICAL_RPC=https://chain-rpc.litprotocol.com/http
7+
TIME_TO_RELEASE_KEY=10000
8+
RUN_IN_BAND=true
9+
RUN_IN_BAND_INTERVAL=5000
10+
PRIVATE_KEYS="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d,0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a,0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6,0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a,0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba,0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e,0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356,0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97,0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6"
11+
NO_SETUP=false
12+
USE_SHIVA=false
13+
NETWORK_CONFIG=./networkContext.json
14+
15+
#Shiva Client ENV Vars
16+
STOP_TESTNET=false
17+
TESTNET_MANAGER_URL=http://0.0.0.0:8000
18+
USE_LIT_BINARIES=true
19+
LIT_NODE_BINARY_PATH=/path/to/lit_node/binary
20+
LIT_ACTION_BINARY_PATH=/path/to/lit_action_binary

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ storage.test.db
7070
.yalc
7171

7272
local-tests/build
73-
# local-tests/setup/networkContext.json
73+
# local-tests/setup/networkContext.json
74+
.env

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
/tmp
1212
/packages/*/dist
1313
.nx
14-
tools
14+
tools
15+
**/*/dist

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ If you're a tech-savvy user and wish to utilize only specific submodules that ou
8080
| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 'sev-snp-utils-sdk') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/sev-snp-utils-sdk"><img src="https://img.shields.io/npm/v/@lit-protocol/sev-snp-utils-sdk"/></a> |
8181
| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 'types') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/types"><img src="https://img.shields.io/npm/v/@lit-protocol/types"/></a> |
8282
| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 'uint8arrays') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/uint8arrays"><img src="https://img.shields.io/npm/v/@lit-protocol/uint8arrays"/></a> |
83+
| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 'wrapped-keys') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/wrapped-keys"><img src="https://img.shields.io/npm/v/@lit-protocol/wrapped-keys"/></a> |
8384
| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 'auth-browser') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/auth-browser"><img src="https://img.shields.io/npm/v/@lit-protocol/auth-browser"/></a> |
8485
| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 'misc-browser') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/misc-browser"><img src="https://img.shields.io/npm/v/@lit-protocol/misc-browser"/></a> |
8586

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
33
"useNx": true,
44
"useWorkspaces": true,
5-
"version": "6.0.3"
5+
"version": "6.0.3-wrapped-keys.beta.5"
66
}

local-tests/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ yarn test:local --filter=testExample,testBundleSpeed
3535

3636
Below is the API documentation for the `ProcessEnvs` interface, detailing the configurable environment variables and their purposes:
3737

38+
**NOTE: a `.env.sample` is contained in the repository root for the below env tables**
39+
3840
| Variable | Description |
3941
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
4042
| `MAX_ATTEMPTS` | Each test is executed in a loop with a maximum number of attempts specified by `devEnv.processEnvs.MAX_ATTEMPTS`. |
@@ -47,10 +49,18 @@ Below is the API documentation for the `ProcessEnvs` interface, detailing the co
4749
| `RUN_IN_BAND_INTERVAL` | The interval in milliseconds to run the tests in a single thread. |
4850
| `LIT_RPC_URL` | The URL of the Lit RPC server. If running locally on Anvil, it should be 'http://127.0.0.1:8545'. |
4951
| `LIT_OFFICIAL_RPC` | The URL of the official Lit RPC server, usually 'https://chain-rpc.litprotocol.com/http' but can be changed if needed. |
50-
| `SHIVA_URL` | URl to connect to Shiva (our testing tool for network management). |
51-
| `LIT_NODE_BINARY_PATH` | URl to connect to Shiva (our testing tool for network management). |
52-
| `USE_LIT_NODE_BINARY` | Flag to indicate if a binary path should be used for testnet spawning or if it should be built from source. |
53-
| `STOP_TESTNET` | Flag to stop a single running testnet after the test run concludes. |
52+
| `USE_SHIVA` | A flag to determine if `Shiva` should be used for the `localchain` network. |
53+
| `PRIVATE_KEYS` | A set of private keys to use which will be used to perform chain operations. |
54+
55+
Below is te API Documentation forthe `ProccessEnvs` interface for the `shiva-client` detailing the configurable enviorment variables and their purposes:
56+
57+
| Variable | Description |
58+
| ------------------------ | ----------------------------------------------------------------------------------------------------------- |
59+
| `TESTNET_MAANGER_URL` | URl to connect to Shiva (our testing tool for network management). |
60+
| `LIT_NODE_BINARY_PATH` | Binary path for the lit node version you wish to run. |
61+
| `LIT_Action_BINARY_PATH` | Binary path for the lit node version you wish to run. |
62+
| `USE_LIT_BINARIES` | Flag to indicate if a binary path should be used for testnet spawning or if it should be built from source. |
63+
| `STOP_TESTNET` | Flag to stop a single running testnet after the test run concludes. |
5464

5565
# Writing a test
5666

local-tests/setup/session-sigs/get-pkp-session-sigs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { TinnyPerson } from '../tinny-person';
88
export const getPkpSessionSigs = async (
99
devEnv: TinnyEnvironment,
1010
alice: TinnyPerson,
11-
resourceAbilityRequests?: LitResourceAbilityRequest[]
11+
resourceAbilityRequests?: LitResourceAbilityRequest[],
12+
expiration?: string
1213
) => {
1314
if (devEnv.litNodeClient.config.litNetwork === LitNetwork.Manzano) {
1415
console.warn(
@@ -31,6 +32,7 @@ export const getPkpSessionSigs = async (
3132
const pkpSessionSigs = await devEnv.litNodeClient.getPkpSessionSigs({
3233
pkpPublicKey: alice.authMethodOwnedPkp.publicKey,
3334
authMethods: [alice.authMethod],
35+
expiration,
3436
resourceAbilityRequests: _resourceAbilityRequests,
3537

3638
// -- only add this for manzano network
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
type ContractAbis = {
3+
litToken: string;
4+
erc20: string;
5+
backupRecovery: string;
6+
staking: string;
7+
stakingBalances: string;
8+
rateLimitNft: string;
9+
pkpnft: string;
10+
pubkeyRouter: string;
11+
pkpPermissions: string;
12+
pkpHelper: string;
13+
contractResolver: string;
14+
paymentDelegation: string;
15+
};
16+
17+
type ContractAddresses = {
18+
litToken: string;
19+
backupRecovery: string;
20+
staking: string;
21+
stakingBalances: string;
22+
rateLimitNft: string;
23+
pkpnft: string;
24+
pubkeyRouter: string;
25+
pkpPermissions: string;
26+
pkpHelper: string;
27+
contractResolver: string;
28+
keyDeriver: string;
29+
paymentDelegation: string;
30+
};
31+
32+
type TestNetCreateRequest = {
33+
nodeCount: number;
34+
pollingInterval: string;
35+
epochLength: number;
36+
customBuildPath: string | null;
37+
litActionServerCustomBuildPath: string | null;
38+
existingConfigPath: string | null;
39+
which: string | null;
40+
ecdsaRoundTimeout: string | null;
41+
enableRateLimiting: string | null;
42+
};
43+
44+
type TestNetInfo = {
45+
contractAddresses: ContractAddresses;
46+
validatorAddresses: Array<string>;
47+
contractResolverAbi: string;
48+
rpcUrl: string;
49+
epochLength: number;
50+
contractAbis: ContractAbis;
51+
};
52+
53+
type TestNetResponse<T> = {
54+
testnetId: string;
55+
command: string;
56+
wasCanceled: boolean;
57+
body: T | null;
58+
lastStateObserved: string | null;
59+
messages: Array<string> | null;
60+
errors: Array<string> | null;
61+
};
62+
63+
type TestNetState = 'Busy' | 'Active' | 'Mutating' | 'Shutdown' | 'UNKNOWN';
64+
65+
export {
66+
ContractAbis,
67+
ContractAddresses,
68+
TestNetCreateRequest,
69+
TestNetInfo,
70+
TestNetResponse,
71+
TestNetState,
72+
};

local-tests/setup/shiva-client.ts

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { LitContractResolverContext } from '@lit-protocol/types';
22
import { ethers } from 'ethers';
3+
import {
4+
TestNetCreateRequest,
5+
TestNetInfo,
6+
TestNetResponse,
7+
TestNetState,
8+
} from './shiva-client.d';
39

410
export interface ShivaEnvs {
511
/**
@@ -36,11 +42,16 @@ export interface ShivaEnvs {
3642
USE_LIT_BINARIES: boolean;
3743
}
3844

45+
/**
46+
* Client implementation for a single testnet instance managed by the Shiva tool
47+
* Is essentially a localchain setup but allows for programmatic operations to be preformed
48+
* on the network from the implementation wthin this class. Each testnet is a unique network
49+
*/
3950
export class TestnetClient {
4051
private _id: string;
41-
private _info: any;
52+
private _info: TestNetInfo;
4253
private _processEnvs: ShivaEnvs;
43-
private _currentState: string;
54+
private _currentState: TestNetState;
4455

4556
constructor(id: string, envs: ShivaEnvs) {
4657
this._processEnvs = envs;
@@ -57,7 +68,7 @@ export class TestnetClient {
5768
pub epoch_length: i32,
5869
}
5970
*/
60-
get Info(): any | undefined {
71+
get Info(): TestNetInfo | undefined {
6172
return this._info;
6273
}
6374

@@ -69,7 +80,7 @@ export class TestnetClient {
6980

7081
const contractResolverAbi: string = testNetConfig.contractResolverAbi;
7182
const contractResolverAddress =
72-
testNetConfig.contractAddresses[`contract_resolver`];
83+
testNetConfig.contractAddresses[`contractResolver`];
7384
const networkContext = {
7485
abi: JSON.parse(contractResolverAbi),
7586
resolverAddress: contractResolverAddress,
@@ -85,33 +96,32 @@ export class TestnetClient {
8596
* Polls a given testnet for the ACTIVE state
8697
* polls on a 500 milisecond interval
8798
*/
88-
public async pollTestnetForActive() {
99+
public async pollTestnetForActive(): Promise<string> {
89100
let state = 'Busy';
90-
while (state != 'Active') {
101+
while (state != 'Active' && state != `UNKNOWN`) {
91102
const pollRes = await fetch(
92103
this._processEnvs.TESTNET_MANAGER_URL + '/test/poll/testnet/' + this._id
93104
);
94105
const res = await pollRes.json();
95106
state = res.body;
96107
console.log('found state to be', res);
97-
if (state != 'Active') {
108+
if (state != 'Active' && state != 'UNKNOWN') {
98109
await new Promise<void>((res, _) => {
99110
setTimeout(() => {
100111
res();
101112
}, 500);
102113
});
114+
} else {
115+
break;
103116
}
104117
}
118+
119+
return state;
105120
}
106121

107122
/**
108123
* returns the config for a given testnet
109124
* struct reference for config
110-
* pub struct TestNetInfo {
111-
pub contract_addresses: ContractAddresses,
112-
pub validator_addresses: Vec<String>,
113-
pub epoch_length: i32,
114-
}
115125
*/
116126
public getTestnetConfig() {
117127
return fetch(
@@ -122,9 +132,9 @@ export class TestnetClient {
122132
.then((res: Response) => {
123133
return res.json();
124134
})
125-
.then((info: any) => {
135+
.then((info: TestNetResponse<TestNetInfo>) => {
126136
this._info = info.body;
127-
this._currentState = info.lastStateObserved;
137+
this._currentState = info.lastStateObserved as TestNetState;
128138
console.log('setting testnet info: ', this._info);
129139
});
130140
}
@@ -162,10 +172,13 @@ export class TestnetClient {
162172
.then((res: Response) => {
163173
if (res.status === 200) {
164174
return res.json();
175+
} else {
176+
return Promise.reject(res);
165177
}
166178
})
167-
.then((body: any) => {
179+
.then((body: TestNetResponse<boolean>) => {
168180
console.log('validator kick response: ', body);
181+
return body;
169182
});
170183
}
171184

@@ -180,7 +193,7 @@ export class TestnetClient {
180193
.then((res: Response) => {
181194
return res.json();
182195
})
183-
.then((body: any) => {
196+
.then((body: TestNetResponse<void>) => {
184197
console.log('shutdown respone: ', body);
185198
});
186199
}
@@ -195,14 +208,15 @@ export class ShivaClient {
195208
USE_LIT_BINARIES: process.env[`USE_LIT_BINARIES`] === `true`,
196209
LIT_NODE_BINARY_PATH:
197210
process.env['LIT_NODE_BINARY_PATH'] ||
198-
`./../../../lit-assets/rust/lit-node/target/debug/lit_node`,
211+
`./../../lit-assets/rust/lit-node/target/debug/lit_node`,
199212
LIT_ACTION_BINARY_PATH:
200213
process.env['LIT_ACTION_BINARY_PATH'] ||
201-
`./../../../lit-assets/rust/lit-actions/target/debug/lit_actions`,
214+
`./../../lit-assets/rust/lit-actions/target/debug/lit_actions`,
202215
};
203216

204217
constructor() {
205218
this._clients = new Map();
219+
console.log('Shiva enviorment loaded current config: ', this.processEnvs);
206220
}
207221

208222
/**
@@ -222,7 +236,9 @@ export class ShivaClient {
222236
pub enable_rate_limiting: Option<String>,
223237
}
224238
*/
225-
async startTestnetManager(): Promise<TestnetClient> {
239+
async startTestnetManager(
240+
createReq?: TestNetCreateRequest
241+
): Promise<TestnetClient> {
226242
const existingTestnetResp = await fetch(
227243
this.processEnvs.TESTNET_MANAGER_URL + '/test/get/testnets'
228244
);
@@ -242,8 +258,8 @@ export class ShivaClient {
242258
'lit action server binary path: ',
243259
this.processEnvs.LIT_ACTION_BINARY_PATH
244260
);
245-
let body: Record<string, any> = {
246-
nodeCount: 6,
261+
let body: Partial<TestNetCreateRequest> = createReq ?? {
262+
nodeCount: 3,
247263
pollingInterval: '2000',
248264
epochLength: 100,
249265
};

local-tests/setup/tinny-config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ export interface ProcessEnvs {
8181
* Ignore setup steps. Usually when you run to quickly run a single test.
8282
*/
8383
NO_SETUP: boolean;
84+
85+
/**
86+
* Use shiva as a test network which will spawn before the test run starts
87+
*/
88+
USE_SHIVA: boolean;
89+
90+
/**
91+
* The network configuration which will be used for `contract context` if provided.
92+
* it is assumed the context will work with the {@link NETWORK} provided. If the configuration
93+
* is not for the provided network then there could be undefined behavior.
94+
* If {@link USE_SHIVA} is set to true then the network configuration will be loaded implicitly and
95+
* this value will be ignored
96+
*/
97+
NETWORK_CONFIG: string;
8498
}
8599

86100
/**

0 commit comments

Comments
 (0)