-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
307 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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,26 @@ | ||
name: "Build" | ||
description: "Install dependencies, lint, test and build the project." | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Nodejs | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20.x | ||
- name: Install dependencies | ||
run: | | ||
export SKIP_INSTALL_SIMPLE_GIT_HOOKS=1 | ||
npm ci | ||
- name: Lint | ||
run: npm run lint | ||
- name: Format | ||
run: npm run format | ||
- name: Test | ||
run: npm run test:ci | ||
- name: Build | ||
run: | | ||
npm run build | ||
ls -lh dist |
This file contains 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
This file contains 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,5 +1,4 @@ | ||
node_modules | ||
build | ||
dist | ||
|
||
logs | ||
|
This file contains 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,15 @@ | ||
<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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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
This file contains 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,23 @@ | ||
/** | ||
* Serializer class to serialize and deserialize data to and from ssz format. | ||
* @example | ||
* import { Serializer } from 'niljs'; | ||
* | ||
* const serializer = new Serializer(); | ||
* const data = { key: 'value' }; | ||
* | ||
* const serializedData = serializer.serialize(data); | ||
* const deserializedData = serializer.deserialize(serializedData); | ||
*/ | ||
class Serializer { | ||
public serialize(data: unknown): string { | ||
return JSON.stringify(data); | ||
} | ||
|
||
public deserialize(data: string): unknown { | ||
return JSON.parse(data); | ||
} | ||
} | ||
|
||
// user should have schema out of the box and be able to provide custom. | ||
export { Serializer }; |
This file contains 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,13 +1,18 @@ | ||
export { PublicClient } from "./publicClient.js"; | ||
export { WalletClient } from "./walletClient.js"; | ||
export { PublicClient } from "./clients/PublicClient.js"; | ||
export { WalletClient } from "./clients/WalletClient.js"; | ||
export type { | ||
IPublicClientConfig, | ||
IWalletClientConfig, | ||
} from "./types/ClientConfigs.ts"; | ||
export { Serializer } from "./encoding/Serializer.js"; | ||
export { LocalKeySigner } from "./signers/LocalKeySigner.js"; | ||
|
||
// what is format of our transaction? | ||
// first, serialize body, than bytes+signature, then we supply ssz as hex. | ||
// first, serialize body of tx | ||
// than sign it | ||
// than serialize signature+serizalized body | ||
// than send it to the network as hex data | ||
// we want to send as a parameter hex data of transaction. | ||
// we want to sign tx before sending it to the network. | ||
|
||
// we also need a schema from ssz | ||
// we also need a schema for ssz |
Empty file.
This file contains 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,52 @@ | ||
import type { ILocalKeySignerConfig } from "../types/ILocalKeySignerConfig.js"; | ||
import type { ISigner } from "../types/ISigner.js"; | ||
import { getPublicKey } from "./getPublicKey.js"; | ||
|
||
/** | ||
* LocalKeySigner is a class that allows you to sign the data with the private key. | ||
* It is an abstraction of signing the data with the private key. | ||
* It uses the secp256k1 curve implementation by @noble/curves/secp256k1 library under the hood. | ||
* @example | ||
* import { LocalKeySigner } from 'niljs'; | ||
* | ||
* const privateKey = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | ||
* const signer = new LocalKeySigner({ privateKey }); | ||
*/ | ||
class LocalKeySigner implements ISigner { | ||
private publicKey; | ||
|
||
constructor(config: ILocalKeySignerConfig) { | ||
this.publicKey = getPublicKey(config.privateKey); | ||
} | ||
|
||
/** | ||
* Signs the message. | ||
* Accepts valid data as an argument and returns signed message. | ||
* @example | ||
* const data = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | ||
* const signedMessage = signer.signMessage(data); | ||
*/ | ||
public signMessage(data: Uint8Array) { | ||
// | ||
} | ||
|
||
/** | ||
* Signs the transaction. | ||
* Accepts valid transaction object as an argument and returns signed transaction. | ||
* @example | ||
* const transaction = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | ||
* const signedTransaction = signer.signTransaction(transaction); | ||
*/ | ||
public signTransaction(transaction: Uint8Array) {} | ||
|
||
/** | ||
* Returns the public key. | ||
* @example | ||
* const publicKey = signer.getPublicKey(); | ||
*/ | ||
public getPublicKey() { | ||
return this.publicKey; | ||
} | ||
} | ||
|
||
export { LocalKeySigner }; |
This file contains 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 @@ | ||
import { accounts } from "../../test/mocks/accounts.js"; | ||
import { getPublicKey } from "./getPublicKey.js"; | ||
|
||
test("getPublicKey", async ({ expect }) => { | ||
const account = accounts[0]; | ||
const input = account.privateKey; | ||
|
||
const expectedOutput = account.publicKey; | ||
|
||
const result = getPublicKey(input); | ||
|
||
expect(result).toBe(expectedOutput); | ||
}); |
This file contains 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 @@ | ||
import { type Hex, bytesToHex } from "@noble/curves/abstract/utils"; | ||
import { secp256k1 } from "@noble/curves/secp256k1"; | ||
import type { IPrivateKey } from "../types/IPrivateKey.js"; | ||
|
||
/** | ||
* Returns the public key from the private key using the secp256k1 curve. | ||
*/ | ||
const getPublicKey = (privateKey: IPrivateKey): Hex => { | ||
const publicKey = secp256k1.getPublicKey(privateKey.slice(2), false); | ||
return bytesToHex(publicKey); | ||
}; | ||
|
||
export { getPublicKey }; |
Oops, something went wrong.