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

chore(release): client-vms and client-react-hooks 0.2.1 #43

Merged
merged 8 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
registry-url: "https://registry.npmjs.org"
- uses: pnpm/action-setup@v4
- run: pnpm install
- run: pnpm --filter "@nillion/client-vms" build:proto
- run: pnpm --filter "@nillion/client-vms" build
- env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ jobs:
node-version: "23"
- uses: pnpm/action-setup@v4
- run: pnpm install
- run: pnpm --filter "@nillion/client-vms" build:proto
- run: pnpm --filter "@nillion/client-vms" build
- run: pnpm --filter "@nillion/client-react-hooks" build
- run: pnpm exec biome format
- run: pnpm exec biome lint
- run: pnpm exec tsc -p client-vms/tsconfig.json
- run: pnpm exec tsc -p client-react-hooks/tsconfig.json

test-client-vms:
needs: check
Expand All @@ -36,7 +40,7 @@ jobs:
aws-region: "eu-west-1"
- uses: NillionNetwork/nillion-setup-action@main
with:
version: "v0.7.0-rc.55"
version: "v0.7.0"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
.vscode
.husky

**/gen-proto
node_modules
dist
**/coverage
.next
!client-wasm/dist
tsconfig.tsbuildinfo

__pycache__
venv
4 changes: 0 additions & 4 deletions client-react-hooks/README.md

This file was deleted.

20 changes: 12 additions & 8 deletions client-react-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nillion/client-react-hooks",
"license": "MIT",
"author": "[email protected]",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "https://nillion.pub/client-ts",
"repository": {
"type": "git",
Expand All @@ -11,30 +11,34 @@
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
}
},
"scripts": {
"typecheck": "tsc",
"build": "node esbuild.config.mjs",
"build:watch": "node esbuild.config.mjs --watch"
"test": "echo \"@nillion/client-react-hooks has no tests\"",
"clean": "rm -rf dist",
"build": "pnpm clean && node esbuild.config.mjs && tsc -p tsconfig.build.json",
"watch:esbuild": "node esbuild.config.mjs --watch",
"watch:types": "tsc -p tsconfig.build.json --watch",
"build:watch": "pnpm clean && pnpm watch:esbuild & pnpm watch:types"
},
"dependencies": {
"@nillion/client-vms": "workspace:^",
"@tanstack/react-query": "^5.59.20",
"debug": "^4.3.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"zod": "^3.23.8"
"react-dom": "^18.3.1"
},
"devDependencies": {
"@tsconfig/vite-react": "^3.0.2",
"@cosmjs/proto-signing": "^0.32.4",
"@keplr-wallet/types": "^0.12.154",
"@types/debug": "^4.1.12",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"browserslist": "^4.24.2",
"esbuild-plugin-browserslist": "^0.15.0"
},
"files": ["dist", "src"]
"files": ["dist"]
}
108 changes: 61 additions & 47 deletions client-react-hooks/src/create-client.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,79 @@
import {
PrivateKeyBase16,
VmClientBuilder,
createSignerFromKey,
} from "@nillion/client-vms";
import { z } from "zod";
import type { OfflineSigner } from "@cosmjs/proto-signing";
import type { Keplr } from "@keplr-wallet/types";
import { VmClientBuilder } from "@nillion/client-vms";
import { createSignerFromKey } from "@nillion/client-vms";

export type Network = "testnet" | "devnet" | "custom";
export type TestnetOptions = {
network: "testnet";
seed: string;
keplr: Keplr;
};

export type DevnetOptions = {
network: "devnet";
seed?: string;
signer?: Keplr | OfflineSigner;
};

export const ClientConfig = z.object({
bootnodeUrl: z.string().url(),
chainUrl: z.string().url(),
seed: z.string().min(1),
nilchainPrivateKey0: PrivateKeyBase16,
});
export type ClientConfig = z.infer<typeof ClientConfig>;
type Options = DevnetOptions | TestnetOptions;

const DevnetConfig = {
bootnodeUrl: "http://127.0.0.1:37939",
chainUrl: "http://127.0.0.1:48102",
chainId: "nillion-chain-devnet",
seed: "user-devnet-seed",
nilchainPrivateKey0:
"9a975f567428d054f2bf3092812e6c42f901ce07d9711bc77ee2cd81101f42c5",
};

const NamedConfig = {
// use with `$ nillion-devnet` default seed
devnet: {
bootnodeUrl: "http://127.0.0.1:37939",
chainUrl: "http://127.0.0.1:48102",
seed: "user-devnet-seed",
nilchainPrivateKey0:
"9a975f567428d054f2bf3092812e6c42f901ce07d9711bc77ee2cd81101f42c5",
},
const TestnetConfig = {
bootnodeUrl: "https://node-1.photon2.nillion-network.nilogy.xyz:14311/",
chainUrl: "http://rpc.testnet.nilchain-rpc-proxy.nilogy.xyz",
chainId: "nillion-chain-testnet-1",
};

export async function createClient(
network: Network,
overrides?: Partial<ClientConfig>,
) {
export async function createClient(options: Options) {
const builder = new VmClientBuilder();
switch (network.toLowerCase()) {
switch (options.network.toLowerCase()) {
case "devnet": {
const config = { ...NamedConfig.devnet };
const singer = await createSignerFromKey(config.nilchainPrivateKey0);
builder
.seed(config.seed)
.bootnodeUrl(config.bootnodeUrl)
.chainUrl(config.chainUrl)
.signer(singer);
break;
}
case "custom": {
const { nilchainPrivateKey0, seed, bootnodeUrl, chainUrl } =
ClientConfig.parse(overrides);
const config = options as DevnetOptions;

if (!nilchainPrivateKey0 || !seed || !bootnodeUrl || !chainUrl) {
throw new Error("Missing required config");
let signer: OfflineSigner;

if (config.signer) {
if ("getOfflineSigner" in config.signer) {
signer = config.signer.getOfflineSigner(DevnetConfig.chainId);
} else {
signer = config.signer;
}
} else {
signer = await createSignerFromKey(DevnetConfig.nilchainPrivateKey0);
}

const singer = await createSignerFromKey(nilchainPrivateKey0);
const seed = config.seed ? config.seed : DevnetConfig.seed;

builder
.seed(seed)
.bootnodeUrl(bootnodeUrl)
.chainUrl(chainUrl)
.signer(singer);
.bootnodeUrl(DevnetConfig.bootnodeUrl)
.chainUrl(DevnetConfig.chainUrl)
.signer(signer);

break;
}
case "testnet": {
const config = options as TestnetOptions;
const signer = config.keplr.getOfflineSigner(TestnetConfig.chainId);

builder
.seed(config.seed)
.bootnodeUrl(TestnetConfig.bootnodeUrl)
.chainUrl(TestnetConfig.chainUrl)
.signer(signer);

break;
}
default: {
throw new Error(`Unsupported network: ${network}`);
throw new Error(`Unknown network: ${options.network}`);
}
}

Expand Down
1 change: 1 addition & 0 deletions client-react-hooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { NillionProvider } from "./nillion-provider";
export { createClient } from "./create-client";
export { getKeplr } from "./keplr";
export { useNilDeleteValues } from "./use-nil-delete-values";
export { useNilInvokeCompute } from "./use-nil-invoke-compute";
export { useNilOverwritePermissions } from "./use-nil-overwrite-permissions";
Expand Down
34 changes: 34 additions & 0 deletions client-react-hooks/src/keplr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Keplr } from "@keplr-wallet/types";
import type { Window as KeplrWindow } from "@keplr-wallet/types/build/window";

declare global {
interface Window extends KeplrWindow {}
}

export const getKeplr = async (): Promise<Keplr> => {
if (window.keplr) {
return window.keplr;
}

if (document.readyState === "complete" && window.keplr) {
return window.keplr;
}

return new Promise((resolve) => {
const documentStateChange = (event: Event) => {
if (
event.target &&
(event.target as Document).readyState === "complete"
) {
if (window.keplr) {
resolve(window.keplr);
document.removeEventListener("readystatechange", documentStateChange);
} else {
throw new Error("Failed to find keplr");
}
}
};

document.addEventListener("readystatechange", documentStateChange);
});
};
2 changes: 1 addition & 1 deletion client-react-hooks/src/use-nil-overwrite-permissions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Uuid, ValuesPermissions } from "@nillion/client-vms/types";
import type { Uuid, ValuesPermissions } from "@nillion/client-vms";
import { useMutation } from "@tanstack/react-query";
import { nilHookBaseResult } from "./nil-hook-base";
import type { UseNilHook } from "./nil-hook-base";
Expand Down
11 changes: 11 additions & 0 deletions client-react-hooks/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*"]
}
22 changes: 17 additions & 5 deletions client-react-hooks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
{
"extends": "@tsconfig/vite-react/tsconfig.json",
"compilerOptions": {
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"noUnusedLocals": false,
"baseUrl": ".",
"target": "es2022",
"lib": ["es2022", "dom", "DOM.Iterable"],
"module": "esnext",

"noEmit": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "react-jsx",

"skipLibCheck": true,
"strict": true,

"baseUrl": "./src",
"paths": {
"@nillion/client-vms/*": ["../client-vms/src/*"]
"#/*": ["/*"]
}
}
}
1 change: 1 addition & 0 deletions client-vms/esbuild.config.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
18 changes: 10 additions & 8 deletions client-vms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
"name": "@nillion/client-vms",
"license": "MIT",
"author": "[email protected]",
"version": "0.2.0",
"version": "0.2.1",
"repository": "https://github.com/NillionNetwork/client-ts",
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
}
},
"scripts": {
"typecheck": "tsc",
"build": "node esbuild.config.mjs",
"build:watch": "node esbuild.config.mjs --watch",
"build:proto": "npx buf generate",
"test": "vitest test"
"test": "vitest test",
"clean": "rm -rf dist",
"watch:esbuild": "node esbuild.config.mjs --watch",
"watch:types": "tsc -p tsconfig.build.json --watch",
"build": "pnpm clean && node esbuild.config.mjs && tsc -p tsconfig.build.json",
"build:watch": "pnpm clean && pnpm watch:esbuild & pnpm watch:types",
"build:proto": "npx buf generate"
},
"dependencies": {
"@bufbuild/protobuf": "^2.2.2",
Expand All @@ -37,7 +40,6 @@
"devDependencies": {
"@bufbuild/buf": "^1.46.0",
"@bufbuild/protoc-gen-es": "^2.2.2",
"@keplr-wallet/types": "^0.12.154",
"@types/debug": "^4.1.12",
"@types/node": "^22.9.0",
"@types/uuid": "^10.0.0",
Expand All @@ -50,5 +52,5 @@
"vite-tsconfig-paths": "^5.1.2",
"vitest": "^2.1.4"
},
"files": ["dist", "src"]
"files": ["dist"]
}
3 changes: 3 additions & 0 deletions client-vms/proto/nillion/payments/v1/quote.proto
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ message StoreValues {

// The size of the payload to be stored.
uint64 ecdsa_private_key_shares_count = 6;

// The size of the payload to be stored.
uint64 ecdsa_signature_shares_count = 7;
}

// An invoke compute operation.
Expand Down
4 changes: 3 additions & 1 deletion client-vms/proto/nillion/permissions/v1/permissions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ message Permissions {
repeated nillion.auth.v1.user.UserId delete = 4;

// The list of compute permissions.
repeated ComputePermissions compute = 5;
repeated ComputePermissions compute = 5;
}

// The permissions to execute a program.
Expand All @@ -30,3 +30,5 @@ message ComputePermissions {
// The program ids this user is allowed to use the stored values in.
repeated string program_ids = 2;
}


3 changes: 2 additions & 1 deletion client-vms/proto/nillion/preprocessing/v1/element.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ enum PreprocessingElement {
MODULO = 7;
TRUNC = 8;
TRUNC_PR = 9;
RANDOM_INTEGER = 10;
RANDOM_BOOLEAN = 11;
}

Loading