Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: grpc migration #29

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e66de5e
feat(vms)!: re-write client for grpc network
tim-hm Oct 17, 2024
11186a8
feat(wasm)!: update bundle to `nillion_client_core` artefact
tim-hm Oct 17, 2024
ccf2053
refactor(react): lift `client-react-hooks` and `resources` to workspa…
tim-hm Oct 17, 2024
790336b
refactor!: remove obsolete packages
tim-hm Oct 17, 2024
7ceab34
refactor!: update workspace files for new structure and remove unused…
tim-hm Oct 17, 2024
0ec880d
ci: consolidate onto client-vms' jest test suite
tim-hm Oct 17, 2024
49a7d77
chore: link json and md files, tidy eslint config
tim-hm Oct 18, 2024
d78325d
fix: add `client-wasm/dist` folder and add exception to `.gitignore`
tim-hm Oct 18, 2024
17152b9
chore: flatten check commands and fix missed formatting issue
tim-hm Oct 18, 2024
124b5bf
feat(vm): add `retrievePermissions` operation
tim-hm Oct 18, 2024
1d6ff6a
chore(vm): tidy operations and collapse esbuild configs
tim-hm Oct 18, 2024
b8717d8
feat(vm): add `storeProgram` operation
tim-hm Oct 18, 2024
9582d9f
chore: separate `ValuesPermissionsBuilder`, wrap more domain primitiv…
tim-hm Oct 18, 2024
e637d10
feat(vms): add `updatePermissions` operation
tim-hm Oct 18, 2024
96ee880
feat(vms): add `invokeCompute` and `retrieveComputeResult` operations
tim-hm Oct 18, 2024
f246dd4
fix(ci): have `just pack` create `dist` dir so npm pack passes
tim-hm Oct 18, 2024
e1686c1
refactor: add getters to `VmClient` to reduce nested calls in operations
tim-hm Oct 18, 2024
0509393
chore: bump deps versions, add `update-deps` just recipe
tim-hm Oct 18, 2024
570743b
chore: set vms + wasm package versions to `0.2.0-rc0`
tim-hm Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions .github/workflows/check-build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,31 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v2
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: just check
- run: npx prettier -c "**/*.(js|jsx|mjs|ts|tsx)"
- run: npx tsc -p client-vms/tsconfig.json
- run: npx eslint -c eslint.config.mjs

test:
test-client-vms:
if: false
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
package: [ client-core, client-payments, client-vms ]
steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v2
- uses: actions/setup-node@v4
with:
node-version: '22.5'
node-version: '22'
cache: 'npm'
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: browser-actions/setup-chrome@v1
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y protobuf-compiler curl
npm ci
- uses: NillionNetwork/nillion-setup-action@main
with:
version: 'latest'
- run: |
just test-${{ matrix.package }}-ci
- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: ${{ matrix.package }}-logs
path: packages/fixture/logs
retention-days: 4
nillion-devnet --seed test-fixture &
sleep 10
just test-client-vms
killall -9 nillion-devnet
10 changes: 3 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
.idea
.vscode

packages/client-payments/src/proto/nilchain.ts # generated protobuf codec
!packages/client-wasm/dist
docs
logs
packages/**/gen-proto
!client-wasm/dist

# npm related artefacts
node_modules
dist
dist-test
**/coverage
.next

# python related artefacts
__pycache__
venv
5 changes: 3 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
packages/wasm/dist
packages/client-payments/src/gen-proto
**/dist
**/gen-proto
**/coverage
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { main } from "../resources/esbuild.base.config.mjs";
import { main } from "../esbuild.base.config.mjs";

const config = {
bundle: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const NillionProvider: React.FC<
}, []);

const context: NillionContext = {
client: nillionClient,
chainClient: nillionClient,
logout: async () => {
await nillionClient.disconnect();
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../tsconfig.base.json",
"compilerOptions": {
"jsx": "react"
}
Expand Down
20 changes: 20 additions & 0 deletions client-vms/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
NILLION_CLUSTER_ID=e0bbd78d-4b10-4fb0-b40a-70f895d2db43
NILLION_BOOTNODE_MULTIADDRESS=/ip4/127.0.0.1/tcp/56033/p2p/12D3KooWNQ3aNWQ4syzxrzZvC8PA2sH3DhYCfLePog2miw16UCA9
NILLION_BOOTNODE_WEBSOCKET=/ip4/127.0.0.1/tcp/38874/ws/p2p/12D3KooWNQ3aNWQ4syzxrzZvC8PA2sH3DhYCfLePog2miw16UCA9
NILLION_BOOTNODE_URL=http://localhost:56033
NILLION_NILCHAIN_CHAIN_ID=nillion-chain-devnet
NILLION_NILCHAIN_JSON_RPC=http://127.0.0.1:48102
NILLION_NILCHAIN_REST_API=http://localhost:26650
NILLION_NILCHAIN_GRPC=localhost:26649
NILLION_NILCHAIN_PRIVATE_KEY_0=9a975f567428d054f2bf3092812e6c42f901ce07d9711bc77ee2cd81101f42c5
NILLION_NILCHAIN_PRIVATE_KEY_1=1e491133b9408b39572a29f91644873decea554224b20e2b0b923aeb860a1c18
NILLION_NILCHAIN_PRIVATE_KEY_2=980488572f235316cdb330191f8bafe4e635efbe88b3a40f5bee9bd21047c059
NILLION_NILCHAIN_PRIVATE_KEY_3=612bb5173dc60d9e91404fcc0d1f1847fb4459a7d5160d63d84e91aacbf2ab2f
NILLION_NILCHAIN_PRIVATE_KEY_4=04f5a984eeea9dce4e5e907da69c01a61568e3071b1a91cbed89225f9fd913b5
NILLION_NILCHAIN_PRIVATE_KEY_5=5f992c58921f4af83b4c6b650c4914626664cd02020577b0ada49cfa00d2c8a4
NILLION_NILCHAIN_PRIVATE_KEY_6=8f0297d3bb647eb59b95b29550b2aebbedd9be2c954b000e772efe8c9318a42d
NILLION_NILCHAIN_PRIVATE_KEY_7=c395243df9bb68dc809668efe4125f0eb017771ed8e3747b8d6860551913fecb
NILLION_NILCHAIN_PRIVATE_KEY_8=4bb5eaa799e24ae2b48545c41331921afe7e6a8dd7a850f5fbeb20a8226664ec
NILLION_NILCHAIN_PRIVATE_KEY_9=ef4b944d4fdb0077057925fe2dde365dfa2c83cf320463b14589feccd1b2b938
NILLION_USER_SEED=test-fixture
NILLION_TEST_PROGRAMS_NAMESPACE=
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { main } from "../resources/esbuild.base.config.mjs";
import { main } from "../esbuild.base.config.mjs";

const config = {
bundle: true,
Expand Down
22 changes: 22 additions & 0 deletions client-vms/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import "dotenv/config";

import { type JestConfigWithTsJest } from "ts-jest";

const config: JestConfigWithTsJest = {
preset: "ts-jest/presets/default-esm",
testEnvironment: "node",
transform: {
"^.+\\.(ts|tsx|js|jsx|mjs)$": [
"ts-jest",
{
useESM: true,
},
],
},
moduleNameMapper: {
"^@nillion/client-vms/(.*)$": "<rootDir>/src/$1",
"^@nillion/client-wasm": "<rootDir>/../client-wasm/dist",
},
};

export default config;
53 changes: 53 additions & 0 deletions client-vms/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@nillion/client-vms",
"license": "MIT",
"author": "[email protected]",
"version": "0.2.0-rc.0",
"repository": "https://github.com/NillionNetwork/client-ts",
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"import": "./dist/index.mjs"
}
},
"scripts": {
"clean": "rm -rf dist dist-test",
"build": "node esbuild.config.mjs",
"build:watch": "node esbuild.config.mjs --watch",
"build:proto": "npx buf generate",
"test": "node --experimental-vm-modules --no-warnings ../node_modules/jest/bin/jest.js"
},
"dependencies": {
"@bufbuild/protobuf": "^2.2.0",
"@connectrpc/connect": "^2.0.0-beta.1",
"@connectrpc/connect-web": "^2.0.0-beta.1",
"@cosmjs/proto-signing": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@nillion/client-wasm": "0.2.0-rc.0",
"@noble/curves": "^1.6.0",
"@noble/hashes": "^1.5.0",
"@noble/secp256k1": "^2.1.0",
"bs58": "^6.0.0",
"debug": "^4.3.7",
"uuid": "^10.0.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@bufbuild/buf": "^1.45.0",
"@bufbuild/protoc-gen-es": "^2.2.0",
"@jest/globals": "^29.7.0",
"@keplr-wallet/types": "^0.12.141",
"@types/debug": "^4.1.12",
"@types/uuid": "^10.0.0",
"browserslist": "^4.24.0",
"dotenv": "^16.4.5",
"esbuild-plugin-browserslist": "^0.15.0",
"jest": "^29.7.0",
"ts-jest": "^29.2.5"
},
"files": [
"dist",
"src"
]
}
30 changes: 30 additions & 0 deletions client-vms/proto/nillion/auth/v1/public_key.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";

package nillion.auth.v1.public_key;

// A public key.
//
// Signatures associated to this public key must be a 64 bytes long sequence which is the result of the
// concatenation of the `r` and `s` scalars in the signature, each encoded in big endian.
message PublicKey {
// The type of this public key.
PublicKeyType key_type = 1;

// The contents of this key.
//
// This is dependent on the `key_type` in this key:
//
// * For ED25519 it should be the curve point in its 32 byte compressed form.
// * For SECP256K1 it should be the curve point in its 33 byte compressed form.
bytes contents = 2;
}

// A public key type.
enum PublicKeyType {
// An ED25519 public key.
ED25519 = 0;

// A SECP256K1 public key.
SECP256K1 = 1;
}

38 changes: 38 additions & 0 deletions client-vms/proto/nillion/auth/v1/token.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
syntax = "proto3";

package nillion.auth.v1.token;

import "google/protobuf/timestamp.proto";
import "nillion/auth/v1/public_key.proto";

// A signed authentication token.
message SignedToken {
// A `Token` serialized into bytes.
bytes serialized_token = 1;

// The public key for the private key this token is signed with.
nillion.auth.v1.public_key.PublicKey public_key = 2;

// The serialized token signature.
//
// The signature must be generated using the private key corresponding to the `public_key` field
// over `sha256(serialized_token)`.
bytes signature = 3;
}

// A token.
message Token {
// A nonce that adds entropy to this token.
//
// The nonce must be 32 bytes long and will be considered invalid otherwise.
bytes nonce = 1;

// The identifier of the node this token is meant to be used against.
//
// This needs to match the target node's identity for the token to be considered valid, and is used to prevent
// a node from taking the token and impersonating the user.
bytes target_identity = 2;

// The timestamp at which this token expires.
google.protobuf.Timestamp expires_at = 3;
}
49 changes: 49 additions & 0 deletions client-vms/proto/nillion/compute/v1/invoke.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
syntax = "proto3";

package nillion.compute.v1.invoke;

import "nillion/payments/v1/receipt.proto";

// A request to invoke a computation.
message InvokeComputeRequest {
// The receipt that proves this operation was paid for.
//
// The receipt must be for a `InvokeCompute` operation.
nillion.payments.v1.receipt.SignedReceipt signed_receipt = 1;

// The value ids for previously stored values being used as parameters to this compute operation.
repeated bytes value_ids = 2;

// The values being used as compute-time parameters, encoded in bincode format.
bytes bincode_values = 3;

// The bindings that define which input party in the program is which user in the network.
repeated InputPartyBinding input_bindings = 4;

// The bindings that define which output party in the program is which users in the network.
repeated OutputPartyBinding output_bindings = 5;
}

// A response to a request to invoke a computation.
message InvokeComputeResponse {
// An identifier for the execution of the computation.
bytes compute_id = 1;
}

// The bindings for input parties in this program.
message InputPartyBinding {
// The name of the party as defined in the program.
string party_name = 1;

// The user identity this party is being bound to.
string user_id = 2;
}

// The bindings for output parties in this program.
message OutputPartyBinding {
// The name of the party as defined in the program.
string party_name = 1;

// The user identities this party is being bound to.
repeated string user_ids = 2;
}
33 changes: 33 additions & 0 deletions client-vms/proto/nillion/compute/v1/retrieve.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
syntax = "proto3";

package nillion.compute.v1.retrieve;

import "google/protobuf/empty.proto";

// A request to retrieve the results of a computation.
message RetrieveResultsRequest {
// The instance of the computation to retrieve results for.
bytes compute_id = 1;
}

// The response to a request to retrieve the results of a computation.
message RetrieveResultsResponse {
oneof state {
// The node is waiting for the computation to end.
//
// This message may be sent 0+ times in a row until a `result` is sent.
google.protobuf.Empty waiting_computation = 1;

// The computation finished successfully and yielded these results.
ComputationResult success = 2;

// The error message if any.
string error = 3;
}
}

// The result of a computation.
message ComputationResult {
// The computation results, encoded in bincode.
bytes bincode_values = 1;
}
30 changes: 30 additions & 0 deletions client-vms/proto/nillion/compute/v1/service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";

package nillion.compute.v1;

import "google/protobuf/empty.proto";
import "nillion/compute/v1/invoke.proto";
import "nillion/compute/v1/stream.proto";
import "nillion/compute/v1/retrieve.proto";

// A service to perform compute operations.
service Compute {
// Invoke a computation.
rpc InvokeCompute(invoke.InvokeComputeRequest) returns (invoke.InvokeComputeResponse);

// Start a stream of message for a specific instance of a computation.
//
// This is meant to be used internally by nodes in the network.
rpc StreamCompute(stream stream.ComputeStreamMessage) returns (google.protobuf.Empty);

// Retrieve the result of a computation.
//
// The user invoking this operation must have been defined as an output party in the program
// the execution was tied to.
//
// This call will wait for the program execution to end if it hasn't done so already. Clients must
// wait until either a result or failure message is sent, ignoring any `Waiting` messages sent until
// that happens.
rpc RetrieveResults(retrieve.RetrieveResultsRequest) returns (stream retrieve.RetrieveResultsResponse);
}

Loading