Skip to content

Commit

Permalink
Merge branch 'master' into fix/session-sig-re-signing
Browse files Browse the repository at this point in the history
  • Loading branch information
glitch003 committed Jul 2, 2024
2 parents 0b4822b + 278381b commit f8bb950
Show file tree
Hide file tree
Showing 110 changed files with 4,886 additions and 920 deletions.
20 changes: 20 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Tinny ENV Vars
MAX_ATTEMTPS=1
NETWORK=localchain
DEBUG=true
WAIT_FOR_KEY_INTERVAL=3000
LIT_OFFICAL_RPC=https://chain-rpc.litprotocol.com/http
TIME_TO_RELEASE_KEY=10000
RUN_IN_BAND=true
RUN_IN_BAND_INTERVAL=5000
PRIVATE_KEYS="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d,0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a,0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6,0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a,0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba,0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e,0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356,0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97,0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6"
NO_SETUP=false
USE_SHIVA=false
NETWORK_CONFIG=./networkContext.json

#Shiva Client ENV Vars
STOP_TESTNET=false
TESTNET_MANAGER_URL=http://0.0.0.0:8000
USE_LIT_BINARIES=true
LIT_NODE_BINARY_PATH=/path/to/lit_node/binary
LIT_ACTION_BINARY_PATH=/path/to/lit_action_binary
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ storage.test.db
.yalc

local-tests/build
# local-tests/setup/networkContext.json
# local-tests/setup/networkContext.json
.env
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
/tmp
/packages/*/dist
.nx
tools
tools
**/*/dist
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ If you're a tech-savvy user and wish to utilize only specific submodules that ou
| [@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> |
| [@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> |
| [@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> |
| [@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> |
| [@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> |
| [@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> |

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"useWorkspaces": true,
"version": "6.0.3"
"version": "6.0.3-wrapped-keys.beta.5"
}
18 changes: 14 additions & 4 deletions local-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ yarn test:local --filter=testExample,testBundleSpeed

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

**NOTE: a `.env.sample` is contained in the repository root for the below env tables**

| Variable | Description |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `MAX_ATTEMPTS` | Each test is executed in a loop with a maximum number of attempts specified by `devEnv.processEnvs.MAX_ATTEMPTS`. |
Expand All @@ -47,10 +49,18 @@ Below is the API documentation for the `ProcessEnvs` interface, detailing the co
| `RUN_IN_BAND_INTERVAL` | The interval in milliseconds to run the tests in a single thread. |
| `LIT_RPC_URL` | The URL of the Lit RPC server. If running locally on Anvil, it should be 'http://127.0.0.1:8545'. |
| `LIT_OFFICIAL_RPC` | The URL of the official Lit RPC server, usually 'https://chain-rpc.litprotocol.com/http' but can be changed if needed. |
| `SHIVA_URL` | URl to connect to Shiva (our testing tool for network management). |
| `LIT_NODE_BINARY_PATH` | URl to connect to Shiva (our testing tool for network management). |
| `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. |
| `STOP_TESTNET` | Flag to stop a single running testnet after the test run concludes. |
| `USE_SHIVA` | A flag to determine if `Shiva` should be used for the `localchain` network. |
| `PRIVATE_KEYS` | A set of private keys to use which will be used to perform chain operations. |

Below is te API Documentation forthe `ProccessEnvs` interface for the `shiva-client` detailing the configurable enviorment variables and their purposes:

| Variable | Description |
| ------------------------ | ----------------------------------------------------------------------------------------------------------- |
| `TESTNET_MAANGER_URL` | URl to connect to Shiva (our testing tool for network management). |
| `LIT_NODE_BINARY_PATH` | Binary path for the lit node version you wish to run. |
| `LIT_Action_BINARY_PATH` | Binary path for the lit node version you wish to run. |
| `USE_LIT_BINARIES` | Flag to indicate if a binary path should be used for testnet spawning or if it should be built from source. |
| `STOP_TESTNET` | Flag to stop a single running testnet after the test run concludes. |

# Writing a test

Expand Down
4 changes: 3 additions & 1 deletion local-tests/setup/session-sigs/get-pkp-session-sigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { TinnyPerson } from '../tinny-person';
export const getPkpSessionSigs = async (
devEnv: TinnyEnvironment,
alice: TinnyPerson,
resourceAbilityRequests?: LitResourceAbilityRequest[]
resourceAbilityRequests?: LitResourceAbilityRequest[],
expiration?: string
) => {
if (devEnv.litNodeClient.config.litNetwork === LitNetwork.Manzano) {
console.warn(
Expand All @@ -31,6 +32,7 @@ export const getPkpSessionSigs = async (
const pkpSessionSigs = await devEnv.litNodeClient.getPkpSessionSigs({
pkpPublicKey: alice.authMethodOwnedPkp.publicKey,
authMethods: [alice.authMethod],
expiration,
resourceAbilityRequests: _resourceAbilityRequests,

// -- only add this for manzano network
Expand Down
72 changes: 72 additions & 0 deletions local-tests/setup/shiva-client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
type ContractAbis = {
litToken: string;
erc20: string;
backupRecovery: string;
staking: string;
stakingBalances: string;
rateLimitNft: string;
pkpnft: string;
pubkeyRouter: string;
pkpPermissions: string;
pkpHelper: string;
contractResolver: string;
paymentDelegation: string;
};

type ContractAddresses = {
litToken: string;
backupRecovery: string;
staking: string;
stakingBalances: string;
rateLimitNft: string;
pkpnft: string;
pubkeyRouter: string;
pkpPermissions: string;
pkpHelper: string;
contractResolver: string;
keyDeriver: string;
paymentDelegation: string;
};

type TestNetCreateRequest = {
nodeCount: number;
pollingInterval: string;
epochLength: number;
customBuildPath: string | null;
litActionServerCustomBuildPath: string | null;
existingConfigPath: string | null;
which: string | null;
ecdsaRoundTimeout: string | null;
enableRateLimiting: string | null;
};

type TestNetInfo = {
contractAddresses: ContractAddresses;
validatorAddresses: Array<string>;
contractResolverAbi: string;
rpcUrl: string;
epochLength: number;
contractAbis: ContractAbis;
};

type TestNetResponse<T> = {
testnetId: string;
command: string;
wasCanceled: boolean;
body: T | null;
lastStateObserved: string | null;
messages: Array<string> | null;
errors: Array<string> | null;
};

type TestNetState = 'Busy' | 'Active' | 'Mutating' | 'Shutdown' | 'UNKNOWN';

export {
ContractAbis,
ContractAddresses,
TestNetCreateRequest,
TestNetInfo,
TestNetResponse,
TestNetState,
};
58 changes: 37 additions & 21 deletions local-tests/setup/shiva-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { LitContractResolverContext } from '@lit-protocol/types';
import { ethers } from 'ethers';
import {
TestNetCreateRequest,
TestNetInfo,
TestNetResponse,
TestNetState,
} from './shiva-client.d';

export interface ShivaEnvs {
/**
Expand Down Expand Up @@ -36,11 +42,16 @@ export interface ShivaEnvs {
USE_LIT_BINARIES: boolean;
}

/**
* Client implementation for a single testnet instance managed by the Shiva tool
* Is essentially a localchain setup but allows for programmatic operations to be preformed
* on the network from the implementation wthin this class. Each testnet is a unique network
*/
export class TestnetClient {
private _id: string;
private _info: any;
private _info: TestNetInfo;
private _processEnvs: ShivaEnvs;
private _currentState: string;
private _currentState: TestNetState;

constructor(id: string, envs: ShivaEnvs) {
this._processEnvs = envs;
Expand All @@ -57,7 +68,7 @@ export class TestnetClient {
pub epoch_length: i32,
}
*/
get Info(): any | undefined {
get Info(): TestNetInfo | undefined {
return this._info;
}

Expand All @@ -69,7 +80,7 @@ export class TestnetClient {

const contractResolverAbi: string = testNetConfig.contractResolverAbi;
const contractResolverAddress =
testNetConfig.contractAddresses[`contract_resolver`];
testNetConfig.contractAddresses[`contractResolver`];
const networkContext = {
abi: JSON.parse(contractResolverAbi),
resolverAddress: contractResolverAddress,
Expand All @@ -85,33 +96,32 @@ export class TestnetClient {
* Polls a given testnet for the ACTIVE state
* polls on a 500 milisecond interval
*/
public async pollTestnetForActive() {
public async pollTestnetForActive(): Promise<string> {
let state = 'Busy';
while (state != 'Active') {
while (state != 'Active' && state != `UNKNOWN`) {
const pollRes = await fetch(
this._processEnvs.TESTNET_MANAGER_URL + '/test/poll/testnet/' + this._id
);
const res = await pollRes.json();
state = res.body;
console.log('found state to be', res);
if (state != 'Active') {
if (state != 'Active' && state != 'UNKNOWN') {
await new Promise<void>((res, _) => {
setTimeout(() => {
res();
}, 500);
});
} else {
break;
}
}

return state;
}

/**
* returns the config for a given testnet
* struct reference for config
* pub struct TestNetInfo {
pub contract_addresses: ContractAddresses,
pub validator_addresses: Vec<String>,
pub epoch_length: i32,
}
*/
public getTestnetConfig() {
return fetch(
Expand All @@ -122,9 +132,9 @@ export class TestnetClient {
.then((res: Response) => {
return res.json();
})
.then((info: any) => {
.then((info: TestNetResponse<TestNetInfo>) => {
this._info = info.body;
this._currentState = info.lastStateObserved;
this._currentState = info.lastStateObserved as TestNetState;
console.log('setting testnet info: ', this._info);
});
}
Expand Down Expand Up @@ -162,10 +172,13 @@ export class TestnetClient {
.then((res: Response) => {
if (res.status === 200) {
return res.json();
} else {
return Promise.reject(res);
}
})
.then((body: any) => {
.then((body: TestNetResponse<boolean>) => {
console.log('validator kick response: ', body);
return body;
});
}

Expand All @@ -180,7 +193,7 @@ export class TestnetClient {
.then((res: Response) => {
return res.json();
})
.then((body: any) => {
.then((body: TestNetResponse<void>) => {
console.log('shutdown respone: ', body);
});
}
Expand All @@ -195,14 +208,15 @@ export class ShivaClient {
USE_LIT_BINARIES: process.env[`USE_LIT_BINARIES`] === `true`,
LIT_NODE_BINARY_PATH:
process.env['LIT_NODE_BINARY_PATH'] ||
`./../../../lit-assets/rust/lit-node/target/debug/lit_node`,
`./../../lit-assets/rust/lit-node/target/debug/lit_node`,
LIT_ACTION_BINARY_PATH:
process.env['LIT_ACTION_BINARY_PATH'] ||
`./../../../lit-assets/rust/lit-actions/target/debug/lit_actions`,
`./../../lit-assets/rust/lit-actions/target/debug/lit_actions`,
};

constructor() {
this._clients = new Map();
console.log('Shiva enviorment loaded current config: ', this.processEnvs);
}

/**
Expand All @@ -222,7 +236,9 @@ export class ShivaClient {
pub enable_rate_limiting: Option<String>,
}
*/
async startTestnetManager(): Promise<TestnetClient> {
async startTestnetManager(
createReq?: TestNetCreateRequest
): Promise<TestnetClient> {
const existingTestnetResp = await fetch(
this.processEnvs.TESTNET_MANAGER_URL + '/test/get/testnets'
);
Expand All @@ -242,8 +258,8 @@ export class ShivaClient {
'lit action server binary path: ',
this.processEnvs.LIT_ACTION_BINARY_PATH
);
let body: Record<string, any> = {
nodeCount: 6,
let body: Partial<TestNetCreateRequest> = createReq ?? {
nodeCount: 3,
pollingInterval: '2000',
epochLength: 100,
};
Expand Down
14 changes: 14 additions & 0 deletions local-tests/setup/tinny-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ export interface ProcessEnvs {
* Ignore setup steps. Usually when you run to quickly run a single test.
*/
NO_SETUP: boolean;

/**
* Use shiva as a test network which will spawn before the test run starts
*/
USE_SHIVA: boolean;

/**
* The network configuration which will be used for `contract context` if provided.
* it is assumed the context will work with the {@link NETWORK} provided. If the configuration
* is not for the provided network then there could be undefined behavior.
* If {@link USE_SHIVA} is set to true then the network configuration will be loaded implicitly and
* this value will be ignored
*/
NETWORK_CONFIG: string;
}

/**
Expand Down
Loading

0 comments on commit f8bb950

Please sign in to comment.