-
Notifications
You must be signed in to change notification settings - Fork 0
Development registrar client #4
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
381fc7c
implement account, farm, node services for registrar
SalmaElsoly 3010a97
refactor to take private key in the intilization of the client
SalmaElsoly 56136ee
fix return type of farm creation + add error handling in config
SalmaElsoly 41a10fb
add integration tests
SalmaElsoly 5f5f17f
add intial README
SalmaElsoly b737d50
configure eslint
SalmaElsoly a546fa6
add utils for signature and auth header + add keyed parameters to client
SalmaElsoly 809aa51
fix json writing convention
SalmaElsoly 397ab7f
update repo README
SalmaElsoly 10f5896
adjust package exports
SalmaElsoly fc8e8a0
update dirs structure + use latest js + update package.json
SalmaElsoly 232d833
add more tests and validation for node data
SalmaElsoly db36618
add scripts for usage
SalmaElsoly bec1da1
update README
SalmaElsoly 4664bac
skip failed tests because of server bug
SalmaElsoly 0d30268
update scripts to use config.json + update yarn version
SalmaElsoly 0443d0c
update declarations in tsconfig
SalmaElsoly 1b6ab88
updates tests to config.json + fix build module types
SalmaElsoly 79df76d
fix uri
SalmaElsoly 1e321b4
support stellar address in farm creation and update + fix tests
SalmaElsoly 142087d
update scripts + fix package.json
SalmaElsoly 6b287e9
disable workspace in pkg.json
SalmaElsoly f4d8f84
update readme
SalmaElsoly 1e4e107
fix scripts + update readme
SalmaElsoly 0bab692
fix requests timeout
SalmaElsoly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dist/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": false, | ||
"quoteProps": "as-needed", | ||
"jsxSingleQuote": false, | ||
"trailingComma": "all", | ||
"bracketSpacing": true, | ||
"arrowParens": "avoid", | ||
"endOfLine": "auto" | ||
} |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
# tfgridv4-sdk-ts | ||
|
||
This repo contains the typescript clients and projects for Threefold gridV4. | ||
|
||
## Packages | ||
|
||
- [registrar_client](./packages/registrar_client/README.md) | ||
|
||
## Requirements | ||
|
||
- [Node.js](https://nodejs.org/) (version 20 or higher) | ||
- [lerna](https://lerna.js.org/) (version 8.1.9 or higher) | ||
- [yarn](https://yarnpkg.com/) (version 4.7.0) | ||
|
||
## Install | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
## Build | ||
|
||
```bash | ||
yarn lerna run build | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// eslint.config.mjs | ||
import js from "@eslint/js"; | ||
import ts from "@typescript-eslint/eslint-plugin"; | ||
import tsParser from "@typescript-eslint/parser"; | ||
import prettier from "eslint-plugin-prettier"; | ||
import prettierConfig from "eslint-config-prettier"; | ||
import globals from "globals"; | ||
|
||
|
||
export default [ | ||
js.configs.recommended, | ||
{ | ||
files : ["**/*.ts"], | ||
languageOptions: { | ||
parser: tsParser, | ||
ecmaVersion: "latest", | ||
sourceType: "module", | ||
globals: { | ||
...globals.node | ||
} | ||
}, | ||
plugins: { | ||
"@typescript-eslint": ts, | ||
prettier, | ||
}, | ||
rules: { | ||
}, | ||
}, | ||
prettierConfig, | ||
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
"version": "independent", | ||
"npmClient": "yarn" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@threefold/root", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"engines": { | ||
"node": ">=20.10.0" | ||
}, | ||
"dependencies": { | ||
"cosmiconfig": "^9.0.0", | ||
"globals": "^15.15.0" | ||
}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^8.24.0", | ||
"@typescript-eslint/parser": "^8.24.0", | ||
"eslint": "^9.20.1", | ||
"eslint-config-prettier": "^10.0.1", | ||
"eslint-plugin-prettier": "^5.2.3", | ||
"lerna": "^8.1.9", | ||
"prettier": "^3.5.1", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.7.3" | ||
} | ||
} |
SalmaElsoly marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Registrar Client | ||
|
||
This package provides a client for interacting with the TFGrid v4 Node Registrar. | ||
|
||
## Prerequisites | ||
|
||
- node 20.10.0 or higher | ||
|
||
## Installation | ||
|
||
1. **Clone the Repository** | ||
|
||
```bash | ||
git clone https://github.com/threefoldtech/tfgridv4-sdk-ts | ||
cd tfgridv4-sdk-ts | ||
``` | ||
|
||
2. **Navigate to the Package Directory** | ||
|
||
```bash | ||
cd packages/registrar_client | ||
``` | ||
|
||
3. **Install Dependencies** | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
4. **Build the Package** | ||
|
||
```bash | ||
yarn build | ||
``` | ||
|
||
## Getting Started | ||
|
||
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). | ||
|
||
To generate a 64-byte ed25519 private key, you can use tweetnacl library to generate key: | ||
|
||
```typescript | ||
import nacl from "tweetnacl"; | ||
import base64 from "base64-js"; | ||
|
||
const keyPair = nacl.sign.keyPair(); | ||
const privateKey = base64.fromByteArray(keyPair.secretKey); | ||
|
||
console.log("Your 64-byte ed25519 private key:", privateKey); | ||
``` | ||
|
||
Here is an example: | ||
|
||
```typescript | ||
const client = new RegistrarClient({ baseURl: "https://registrar.dev4.grid.tf/v1", privateKey: your_private_key }); | ||
``` | ||
|
||
## Usage | ||
|
||
Here is an example of how to use the Registrar Client: | ||
|
||
```typescript | ||
const client = new RegistrarClient({ baseUrl: URl, privateKey: your_private_key }); | ||
|
||
// Example: Create an account | ||
const accountRequest: CreateAccountRequest = { | ||
SalmaElsoly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// your create account request data | ||
}; | ||
|
||
const account = await client.account.createAccount(accountRequest); | ||
|
||
// Example: Get account details | ||
const twinID = account.twin_id; | ||
const accountDetails = await client.account.getAccountByTwinId(twinID); | ||
|
||
// Example: Update account information | ||
const updateAccountRequest: UpdateAccountRequest = { | ||
// your update account request data | ||
}; | ||
|
||
const updatedAccount = await client.account.updateAccount(twinID, updateAccountRequest); | ||
``` | ||
|
||
more example script can be found [here](./scripts/) | ||
|
||
## Tests | ||
|
||
- Before running the tests set your base url in `tests/config.json` | ||
|
||
then run with: | ||
|
||
```bash | ||
yarn test | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
// jest.config.js | ||
module.exports = { | ||
preset: "ts-jest/presets/default-esm", | ||
transform: { | ||
"^.+\\.(ts|tsx)$": ["ts-jest", { useESM: true, tsconfig: "tsconfig-node.json" }], | ||
}, | ||
extensionsToTreatAsEsm: [".ts", ".tsx"], | ||
testEnvironment: "node", | ||
setupFiles: ["dotenv/config"], | ||
}; |
SalmaElsoly marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"name": "@threefold/registrar_client", | ||
"version": "0.1.0", | ||
"description": "Registrar client for the ThreeFold Grid V4", | ||
"keywords": [], | ||
"author": "Salma Elsoly <salmaelsoly@gmail.com>", | ||
"license": "ISC", | ||
"private": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./dist/node/src/index.js", | ||
"module": "./dist/es/src/index.js", | ||
"exports": { | ||
".": { | ||
"import": "./dist/es/src/index.js", | ||
"require": "./dist/node/src/index.js" | ||
} | ||
}, | ||
"types": "./dist/es/src/index.d.ts", | ||
"engines": { | ||
"node": ">=20.10.0" | ||
}, | ||
"directories": { | ||
"lib": "src", | ||
"test": "tests" | ||
}, | ||
"files": [ | ||
"/dist" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/threefoldtech/tfgridv4-sdk-ts.git" | ||
}, | ||
"scripts": { | ||
SalmaElsoly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"test": "jest", | ||
"format": "prettier --write .", | ||
"lint": "eslint src/**/*.ts", | ||
"lint:fix": "eslint src/**/*.ts --fix", | ||
"node-build": "tsc --build tsconfig-node.json", | ||
"es-build": "tsc --build tsconfig-es.json", | ||
"build": "npm run node-build && npm run es-build" | ||
}, | ||
SalmaElsoly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"bugs": { | ||
"url": "https://github.com/threefoldtech/tfgridv4-sdk-ts/issues" | ||
}, | ||
"homepage": "https://github.com/threefoldtech/tfgridv4-sdk-ts#readme", | ||
"devDependencies": { | ||
"@types/jest": "^29.5.14", | ||
"@types/node": "^22.13.4", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.2.5", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.7.3" | ||
}, | ||
"dependencies": { | ||
"@stellar/stellar-base": "^12.1.1", | ||
"@types/jest": "^29.5.14", | ||
"dotenv": "^16.4.7", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.2.5", | ||
"tweetnacl": "^1.0.3" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Registrar Client Scripts | ||
|
||
This directory contains scripts for the Registrar Client package. | ||
|
||
## Prerequisites | ||
|
||
- Node.js 20 or higher | ||
|
||
## Installation | ||
|
||
To install the necessary dependencies, run: | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
## Getting Started | ||
|
||
- Set your base url and private key in `scripts/config.json` | ||
SalmaElsoly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Usage | ||
|
||
To run any of the scripts, use the following command format: | ||
|
||
```bash | ||
yarn ts-node <script_name>.ts | ||
SalmaElsoly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"baseUrl": "http://localhost:8080/v1", "privateKey": "", "stellarAddress": ""} |
SalmaElsoly marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { log } from "console"; | ||
import { RegistrarClient } from "../src/"; | ||
import config from "./config.json"; | ||
|
||
async function createAccount(client: RegistrarClient) { | ||
const account = await client.accounts.createAccount({}); | ||
log("================= Creating Account ================="); | ||
log(account); | ||
log("================= Creating Account ================="); | ||
} | ||
|
||
async function main() { | ||
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey }); | ||
await createAccount(client); | ||
} | ||
|
||
main(); |
SalmaElsoly marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { log } from "console"; | ||
import { Account, RegistrarClient } from "../src/"; | ||
import config from "./config.json"; | ||
|
||
async function createAccount(client: RegistrarClient): Promise<Account> { | ||
const account = await client.accounts.createAccount({}); | ||
log("================= Creating Account ================="); | ||
log(account); | ||
log("================= Creating Account ================="); | ||
return account!; | ||
} | ||
|
||
async function createFarm(client: RegistrarClient, twinID: number, stellarAddress: string): Promise<number> { | ||
const res = await client.farms.createFarm(`test${Date.now()}`, false, twinID, stellarAddress); | ||
log("================= Creating Farm ================="); | ||
log(res); | ||
log("================= Creating Farm ================="); | ||
return res!.farm_id; | ||
} | ||
|
||
async function getFarm(client: RegistrarClient, farmID: number) { | ||
const farm = await client.farms.getFarm(farmID); | ||
log("================= Getting Farm ================="); | ||
log(farm); | ||
log("================= Getting Farm ================="); | ||
} | ||
|
||
async function main() { | ||
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: config.privateKey }); | ||
const account = await createAccount(client); | ||
const twinID = account.twin_id; | ||
const farmID = await createFarm(client, twinID, config.stellarAddress); | ||
await getFarm(client, farmID); | ||
} | ||
|
||
main(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.