Skip to content

Commit

Permalink
add clients and signer #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ukorvl committed May 20, 2024
1 parent b4d4aed commit 9e47236
Show file tree
Hide file tree
Showing 54 changed files with 9,480 additions and 1,564 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
16 changes: 16 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{
"repo": "NilFoundation/nil.js"
}
],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}
29 changes: 7 additions & 22 deletions .commitlintrc
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
{
"extends": [
"@commitlint/config-conventional"
],
"extends": ["@commitlint/config-conventional"],
"rules": {
"body-max-line-length": [
0,
"always",
100
],
"footer-max-line-length": [
0,
"always",
100
],
"footer-leading-blank": [
0,
"always",
100
],
"references-empty": [
2,
"never"
]
"body-max-line-length": [0, "always", 100],
"footer-max-line-length": [0, "always", 100],
"footer-leading-blank": [0, "always", 100],
"references-empty": [2, "never"],
"type-empty": [0, "never"],
"subject-empty": [0, "never"]
}
}
30 changes: 30 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Contributing

## Submitting a pull request

After you've made your changes, you can submit a pull request. Here's a quick guide on how to do that:

When you submit a pull request, you'll need to include a summary of your changes. This summary should include a description of the changes you made and why you made them. This will help the maintainers understand your changes and decide whether to accept them.

If you're fixing a bug, you should include a description of the bug and how you fixed it. If you're adding a new feature, you should include a description of the feature and how it works.

You should also include any relevant information about your changes, such as any new dependencies you added or any changes you made to the codebase.

If you're adding a new feature, you should also include tests for your changes. This will help ensure that your changes work as expected and don't introduce any new bugs.

We use changesets to manage versioning and changelogs. If your changes affect the public API or existing behavior, you'll need to create a changeset. You can do this by running `npm run changeset` and following the prompts.
The changeset will be added to the `.changeset` directory in the root of the repository. You should include the changeset file in your pull request. The changeset will be used to determine the version number for the next release and will be added to the changelog. The file will be automatically removed when the changeset is published.

For more information on changesets, see the [Changesets CLI documentation](https://github.com/changesets/changesets/blob/main/docs/command-line-options.md#add).

## Versioning

When we release a new version of the package, we use [semantic versioning](https://semver.org/). This means that each release is given a version number that indicates the type of changes that have been made.

- A major release (e.g. 2.0.0) indicates that there are breaking changes in the release. This means that the new version is not backwards-compatible with the previous version.

- A minor release (e.g. 2.1.0) indicates that there are new features in the release, but no breaking changes.

- A patch release (e.g. 2.1.1) indicates that there are bug fixes in the release, but no new features or breaking changes.

When you submit a pull request, you'll need to include a changeset that indicates the type of release that your changes should trigger. This will help to determine the version number for the next release.
20 changes: 20 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Build"
description: "Lint, test and build the project."

runs:
using: "composite"
steps:
- name: Lint
shell: bash
run: npm run lint
- name: Format
shell: bash
run: npm run format
- name: Test
shell: bash
run: npm run test:ci
- name: Build
shell: bash
run: |
npm run build
ls -lh dist
20 changes: 20 additions & 0 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Install dependencies"
description: "Prepare repository and all dependencies"

inputs:
node_version:
description: "Node.js version"
required: true

runs:
using: "composite"
steps:
- name: Setup Nodejs
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node_version }}
- name: Install dependencies
shell: bash
run: |
export SKIP_INSTALL_SIMPLE_GIT_HOOKS=1
npm ci
29 changes: 29 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build
on:
pull_request:
workflow_dispatch:
push:
branches:
- master
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
version: [18, 20]
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
node_version: ${{ matrix.version }}
- name: Build
uses: ./.github/actions/build
55 changes: 55 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Release

on:
push:
branches:
- main
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
version-pull-request:
name: Version Pull Request
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
node_version: 20
- name: Build
uses: ./.github/actions/build
- name: Create Pull Request
uses: changesets/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
title: "Version Packages"
commit: "version packages"

publish:
name: Publish
needs: version-pull-request
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
node_version: 20
- name: Publish to NPM
uses: changesets/action@v1
with:
createGithubReleases: true
publish: "npm run changeset:publish"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Close inactive issues
on:
schedule:
- cron: "30 1 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
days-before-issue-stale: 180
days-before-issue-close: 7
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 180 days with no activity."
close-issue-message: "This issue was closed because it has been inactive for 7 days since being marked as stale."
repo-token: ${{ secrets.GITHUB_TOKEN }}
exempt-issue-labels: "bug"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
node_modules
build
dist

logs
*.log
npm-debug.log*
*.tsbuildinfo

coverage

Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit"
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true
}
}
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<h1 align="center">Nil.js</h1>

<br />

<p align="center">
=nil; Foundation Typescript client to interact with the Nil network.
</p>

<p align="center">
<a href="https://github.com/NilFoundation/nil.js/actions/workflows/build.yaml">
<picture>
<img src="https://img.shields.io/github/actions/workflow/status/NilFoundation/nil.js/actions/workflows/build.yaml?color=%23212121">
</picture>
</a>
</p>

## Table of Contents

- [Installation](#installation)
- [Getting started](#getting-started)
- [License](#license)

### Installation

```bash
npm install niljs
```

### Getting started

There are two clients in the library to interact with the Nil network.
The first one is the `PublicClient` class, which is used to interact with the Nil network without the need for a private key. It is used to get information about the network, such as block number and block hash.

```typescript
import { PublicClient } from "niljs";

const endpoint = "https://localhost:8259";
const publicClient = new PublicClient({ endpoint });

publicClient.getBalance("your_address").then((balance) => {
console.log(balance);
});
```

The second one is the `WalletClient` class, which is used to interact with the Nil network with a private key. It is used to send transactions to the network.

```typescript
import { WalletClient } from "niljs";

const endpoint = "https://localhost:8259";
const walletClient = new WalletClient({ endpoint });

walletClient
.sendTransaction({
from: "your_address",
to: "recipient_address",
amount: 100,
})
.then((tx) => {
console.log(tx);
});
```

Initialize the Signer with the private key of the account you want to use to sign transactions.

```typescript
import { Signer } from "niljs";

const privateKey = "your_private_key";
const signer = new Signer({ privateKey });

signer.sign(new Uint8Array(32));
```

You can also sign transactions automatically by passing the Signer instance to the WalletClient.

```typescript
import { WalletClient } from "niljs";
import { Signer } from "niljs";

const endpoint = "https://localhost:8259";
const privateKey = "your_private_key";

const signer = new Signer({ privateKey });
const walletClient = new WalletClient({ endpoint, signer });
```

## Licence

[MIT](./LICENSE)
26 changes: 16 additions & 10 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedImports": "error"
}
}
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80
},
"files": {
"ignore": ["node_modules", "dist"]
}
}
Loading

0 comments on commit 9e47236

Please sign in to comment.