Skip to content

Commit 0d30268

Browse files
committed
update scripts to use config.json + update yarn version
1 parent 4664bac commit 0d30268

21 files changed

+8370
-6111
lines changed

.yarn/install-state.gz

743 KB
Binary file not shown.

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This repo contains the typescript clients and projects for Threefold gridV4.
1010

1111
- [Node.js](https://nodejs.org/) (version 20 or higher)
1212
- [lerna](https://lerna.js.org/) (version 8.1.9 or higher)
13+
- [yarn](https://yarnpkg.com/) (version 4.7.0)
1314

1415
## Install
1516

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "root",
2+
"name": "@threefold/root",
33
"private": true,
44
"workspaces": [
55
"packages/*"
@@ -21,5 +21,6 @@
2121
"prettier": "^3.5.1",
2222
"ts-node": "^10.9.2",
2323
"typescript": "^5.7.3"
24-
}
24+
},
25+
"packageManager": "yarn@4.7.0"
2526
}

packages/registrar_client/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ This package provides a client for interacting with the TFGrid v4 Node Registrar
55
## Prerequisites
66

77
- node 20.10.0 or higher
8-
- npm 10.2.3 or higher
98

109
## Installation
1110

@@ -36,7 +35,21 @@ This package provides a client for interacting with the TFGrid v4 Node Registrar
3635

3736
## Getting Started
3837

39-
To initialize the Registrar Client, you need to provide the base url of registrar and your private key. Here is an example:
38+
To initialize the Registrar Client, you need to provide the base url of registrar and Base64-encoded, 64-byte raw Ed25519 private key (nacl format).
39+
40+
To generate a 64-byte ed25519 private key, you can use tweetnacl library to generate key:
41+
42+
```typescript
43+
import nacl from "tweetnacl";
44+
import base64 from "base64-js";
45+
46+
const keyPair = nacl.sign.keyPair();
47+
const privateKey = base64.fromByteArray(keyPair.secretKey);
48+
49+
console.log("Your 64-byte ed25519 private key:", privateKey);
50+
```
51+
52+
Here is an example:
4053

4154
```typescript
4255
const client = new RegistrarClient({ baseURl: "https://registrar.dev4.grid.tf/v1", privateKey: your_private_key });

packages/registrar_client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "registrar_client",
2+
"name": "@threefold/registrar_client",
33
"version": "0.1.0",
44
"description": "Registrar client for the ThreeFold Grid V4",
55
"keywords": [],
@@ -35,6 +35,7 @@
3535
"@types/node": "^22.13.4",
3636
"jest": "^29.7.0",
3737
"ts-jest": "^29.2.5",
38+
"ts-node": "^10.9.2",
3839
"typescript": "^5.7.3"
3940
},
4041
"dependencies": {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Registrar Client Scripts
2+
3+
This directory contains scripts for the Registrar Client package.
4+
5+
## Prerequisites
6+
7+
- Node.js 20 or higher
8+
9+
## Installation
10+
11+
To install the necessary dependencies, run:
12+
13+
```bash
14+
yarn install
15+
```
16+
17+
## Getting Started
18+
19+
- Set your base url and private key in `scripts/config.json`
20+
21+
## Usage
22+
23+
To run any of the scripts, use the following command format:
24+
25+
```bash
26+
yarn ts-node <script_name>.ts
27+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"baseUrl": "http://localhost:8080/v1", "privateKey": ""}

packages/registrar_client/scripts/create_account.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { log } from "console";
22
import { RegistrarClient } from "../src/";
3-
import tweetnacl from "tweetnacl";
4-
import base64 from "base64-js";
3+
import config from "./config.json";
54

65
async function createAccount(client: RegistrarClient) {
76
const account = await client.accounts.createAccount({});
@@ -11,9 +10,7 @@ async function createAccount(client: RegistrarClient) {
1110
}
1211

1312
async function main() {
14-
const keyPair = tweetnacl.sign.keyPair();
15-
const privateKey = base64.fromByteArray(keyPair.secretKey);
16-
const client = new RegistrarClient({ baseURL: "https://registrar.grid.tf/v1/", privateKey: privateKey });
13+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey });
1714
await createAccount(client);
1815
}
1916

packages/registrar_client/scripts/create_farm.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { log } from "console";
22
import { Account, RegistrarClient } from "../src/";
3-
import tweetnacl from "tweetnacl";
4-
import base64 from "base64-js";
3+
import config from "./config.json";
54

65
async function createAccount(client: RegistrarClient): Promise<Account> {
76
const account = await client.accounts.createAccount({});
@@ -27,9 +26,7 @@ async function getFarm(client: RegistrarClient, farmID: number) {
2726
}
2827

2928
async function main() {
30-
const keyPair = tweetnacl.sign.keyPair();
31-
const privateKey = base64.fromByteArray(keyPair.secretKey);
32-
const client = new RegistrarClient({ baseURL: "https://registrar.grid.tf/v1/", privateKey: privateKey });
29+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey });
3330
const account = await createAccount(client);
3431
const twinID = account.twin_id;
3532
const farmID = await createFarm(client, twinID);

packages/registrar_client/scripts/create_node.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { log } from "console";
22
import { Account, RegistrarClient, NodeRegistrationRequest } from "../src/";
3-
import tweetnacl from "tweetnacl";
4-
import base64 from "base64-js";
3+
import config from "./config.json";
4+
55

66
async function createAccount(client: RegistrarClient): Promise<Account> {
77
const account = await client.accounts.createAccount({});
@@ -35,10 +35,7 @@ async function getNode(client: RegistrarClient, nodeID: number) {
3535
}
3636

3737
async function main() {
38-
const keyPair = tweetnacl.sign.keyPair();
39-
const privateKey = base64.fromByteArray(keyPair.secretKey);
40-
log(privateKey);
41-
const client = new RegistrarClient({ baseURL: "https://registrar.grid.tf/v1/", privateKey: privateKey });
38+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey });
4239
const account = await createAccount(client);
4340
const twinID = account.twin_id;
4441
const farmID = await createFarm(client, twinID);

packages/registrar_client/scripts/list_farms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RegistrarClient, NodesFilter } from "../src/";
2+
import config from "./config.json";
23

34
async function listFarms(client: RegistrarClient, filter: NodesFilter) {
45
const nodes = await client.nodes.listNodes(filter);
@@ -8,8 +9,7 @@ async function listFarms(client: RegistrarClient, filter: NodesFilter) {
89
}
910

1011
async function main() {
11-
const privateKey = "private_key";
12-
const client = new RegistrarClient({ baseURL: "https://registrar.grid.tf/v1/", privateKey: privateKey });
12+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey });
1313
await listFarms(client, {});
1414
}
1515

packages/registrar_client/scripts/list_nodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RegistrarClient, NodesFilter } from "../src/";
2+
import config from "./config.json";
23

34
async function listNodes(client: RegistrarClient, filter: NodesFilter) {
45
const nodes = await client.nodes.listNodes(filter);
@@ -8,8 +9,7 @@ async function listNodes(client: RegistrarClient, filter: NodesFilter) {
89
}
910

1011
async function main() {
11-
const privateKey = "private_key";
12-
const client = new RegistrarClient({ baseURL: "https://registrar.grid.tf/v1/", privateKey: privateKey });
12+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey });
1313
const filter: NodesFilter = {
1414
farm_id: 70,
1515
};

packages/registrar_client/scripts/update_account.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { log } from "console";
22
import { RegistrarClient, UpdateAccountRequest } from "../src/";
3+
import config from "./config.json";
34

45
async function updateAccount(client: RegistrarClient, twinID: number, update: UpdateAccountRequest) {
56
const account = await client.accounts.updateAccount(twinID, update);
@@ -16,8 +17,7 @@ async function getAccount(client: RegistrarClient, twinID: number) {
1617
}
1718

1819
async function main() {
19-
const privateKey = "6KY+Ih5LLTivq4cGNrFxkNVtx0lSGbK7wfp2IP/6Wa3plMiff05OWILxBgdPDPrIvPaeBgwTe9bwt4X61Sm2fQ==";
20-
const client = new RegistrarClient({ baseURL: "https://registrar.grid.tf/v1/", privateKey: privateKey });
20+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey });
2121
const update: UpdateAccountRequest = {
2222
relays: ["relay1", "relay2"],
2323
rmb_enc_key: "rmb_enc_key",

packages/registrar_client/scripts/update_farm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { log } from "console";
22
import { RegistrarClient } from "../src/";
3+
import config from "./config.json";
34

45
async function updateFarm(client: RegistrarClient, twinID: number, farmID: number, farmName: string) {
56
const farm = await client.farms.updateFarm(farmID, twinID, farmName);
@@ -16,8 +17,7 @@ async function getFarm(client: RegistrarClient, farmID: number) {
1617
}
1718

1819
async function main() {
19-
const privateKey = "private_key";
20-
const client = new RegistrarClient({ baseURL: "https://registrar.grid.tf/v1/", privateKey: privateKey });
20+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey });
2121
const twinID = 64;
2222
const farmID = 94;
2323
const farmName = "test-farm";

packages/registrar_client/scripts/update_node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { log } from "console";
22
import { UpdateNodeRequest, RegistrarClient } from "../src/";
3+
import config from "./config.json";
34

45
async function updateNode(client: RegistrarClient, twinID: number, nodeID: number, update: UpdateNodeRequest) {
56
const account = await client.nodes.updateNode(nodeID, twinID, update);
@@ -16,8 +17,7 @@ async function getNode(client: RegistrarClient, nodeID: number) {
1617
}
1718

1819
async function main() {
19-
const privateKey = "QjWTJjjuOJ/KHRo43lKobC9q7ly+3gESVuEXm/t2PFG/d3lrmo/c/C7eRob5qIri2SqqV/tLZRhebLS3hSHRbQ==";
20-
const client = new RegistrarClient({ baseURL: "https://registrar.grid.tf/v1/", privateKey: privateKey });
20+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey });
2121
const update: UpdateNodeRequest = {
2222
farm_id: 94,
2323
interfaces: [

packages/registrar_client/src/types/farm.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { Node } from "./node";
2+
13
export interface Farm {
24
created_at: string;
35
dedicated: boolean;
46
farm_id: number;
57
farm_name: string;
6-
nodes: any[];
8+
nodes: Node[];
79
twin_id: number;
810
updated_at: string;
911
}

packages/registrar_client/tests/integration_tests/farm.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe("test farm module", () => {
4242
});
4343

4444
test("create farm with non-existing twin id", async () => {
45-
await expect(client.farms.createFarm("test",false, twinID+1)).rejects.toThrowError(
45+
await expect(client.farms.createFarm("test",false, twinID+20)).rejects.toThrowError(
4646
"Failed to create farm: 404 Not Found",
4747
);
4848
});

packages/registrar_client/tests/integration_tests/zos.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, test, expect } from "@jest/globals";
22
import { RegistrarClient } from "../../src/client/client";
33

44
describe("test zos module", () => {
5-
const client = new RegistrarClient({ baseURL: "http://localhost:8080/v1", privateKey: "private_key" });
5+
const client = new RegistrarClient({ baseURL: "https://registrar.dev4.grid.tf/v1", privateKey: "private_key" });
66

77
test("get zos version", async () => {
88
const zos = await client.zos.getZosVersion();

packages/registrar_client/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
/* Language and Environment */
44
"target": "ESNext",
5+
"resolveJsonModule": true,
56

67
/* Modules */
78
"module": "commonjs",
@@ -15,5 +16,6 @@
1516
"strict": true,
1617
"skipLibCheck": true
1718
},
18-
"include": ["./src", "./tests"]
19+
"include": ["./src", "scripts"],
20+
"exclude": ["./tests"]
1921
}

0 commit comments

Comments
 (0)