Skip to content

Commit

Permalink
add index files with exports into each feature directory #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ukorvl committed May 20, 2024
1 parent eb72870 commit b267158
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-bags-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"niljs": patch
---

Added index files inside feature directories to make root index with package exports clean
2 changes: 1 addition & 1 deletion src/clients/BaseClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Client as RPCClient } from "@open-rpc/client-js";
import { createRPCClient } from "../rpc/rpcClient.js";
import type { IClientBaseConfig } from "../types/ClientConfigs.js";
import type { IClientBaseConfig } from "./types/ClientConfigs.js";

class BaseClient {
/**
Expand Down
12 changes: 0 additions & 12 deletions src/clients/PublicClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,3 @@ import { PublicClient } from "./PublicClient.js";
const client = new PublicClient({
endpoint,
});

// test("Get block by number", async () => {
// const block = await client.getBlockByNumber(1);

// expect(block).toBeDefined();
// });

// i'm not sure for now how to test it.
// there are at least 3 options:
// 1. use mock local node
// 2. use real public node
// 3. use some snapshots, but updating them every time will hurt. Anyway worth to try.
2 changes: 1 addition & 1 deletion src/clients/PublicClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IPublicClientConfig } from "../types/ClientConfigs.js";
import { BaseClient } from "./BaseClient.js";
import type { IPublicClientConfig } from "./types/ClientConfigs.js";

/**
* Public client is a class that allows you to interact with the network via JSON-RPC api.
Expand Down
13 changes: 6 additions & 7 deletions src/clients/WalletClient.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import invariant from "tiny-invariant";
import { signedTransactionToSsz, transactionToSsz } from "../encoding/toSsz.js";
import type { IWalletClientConfig } from "../types/ClientConfigs.js";
import type { ISendTransactionOptions } from "../types/ISendTransactionOptions.js";
import type { ISigner } from "../types/ISigner.js";
import type { ISigner } from "../signers/index.js";
import type { ITransaction } from "../types/ITransaction.js";
import { assertIsValidTransaction } from "../utils/assert.js";
import { BaseClient } from "./BaseClient.js";
import type { IWalletClientConfig } from "./types/ClientConfigs.js";
import type { ISendTransactionOptions } from "./types/ISendTransactionOptions.js";

/**
* Wallet client is a class that allows you to interact with the network via JSON-RPC api.
Expand Down Expand Up @@ -66,9 +66,6 @@ class WalletClient extends BaseClient {
...signature,
});

// there will be a method to get receipt by hash
// receipt - result of smart conract calling
// we should wait to receipts to be sure that transaction is included in the block
return await this.sendRawTransaction(signedTransaction);
}

Expand Down Expand Up @@ -113,7 +110,9 @@ class WalletClient extends BaseClient {
*/
public async deployContract(contract: Uint8Array): Promise<Uint8Array> {
const hash = await this.sendRawTransaction(contract);
// todo
// there will be a method to get receipt by hash
// receipt - result of smart conract calling
// we should wait to receipts to be sure that transaction is included in the block
return hash;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/clients/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./WalletClient.js";
export * from "./PublicClient.js";
export * from "./types/ClientConfigs.js";
export * from "./types/ISendTransactionOptions.js";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ISigner } from "./ISigner.js";
import type { ISigner } from "../../signers/types/ISigner.js";

/**
* Client configuration that is shared between public and private clients.
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions src/encoding/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./fromHex.js";
export * from "./toHex.js";
export * from "./fromSsz.js";
export * from "./toSsz.js";
1 change: 1 addition & 0 deletions src/encoding/toSsz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const transactionToSsz = (transaction: ITransaction): Uint8Array => {

const keypair = Keypair.defaultValue();
const serialized = Keypair.serialize(keypair);

return serialized;
};

Expand Down
27 changes: 5 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
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";
export * from "./utils/hex.js";
export * from "./utils/transaction.js";

// what is format of our transaction?
// first, serialize body of tx
// than sign it
// than serialize signature+serizalized body
// than send it to the network as hex data

// we also need a schema for ssz

// start testing with local node
// we will have something public in the future.
// or we can mock api in the future.
export * from "./clients/index.js";
export * from "./signers/index.js";
export * from "./encoding/index.js";
export * from "./types/index.js";
export * from "./utils/index.js";
6 changes: 3 additions & 3 deletions src/signers/LocalKeySigner.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { secp256k1 } from "@noble/curves/secp256k1";
import { toHex } from "../encoding/toHex.js";
import type { ILocalKeySignerConfig } from "../types/ILocalKeySignerConfig.js";
import type { ISignature } from "../types/ISignature.js";
import type { ISigner } from "../types/ISigner.js";
import { assertIsHexString, assertIsValidPrivateKey } from "../utils/assert.js";
import { getPublicKey } from "./getPublicKey.js";
import type { ILocalKeySignerConfig } from "./types/ILocalKeySignerConfig.js";
import type { ISignature } from "./types/ISignature.js";
import type { ISigner } from "./types/ISigner.js";

/**
* LocalKeySigner is a class that allows you to sign the data with the private key.
Expand Down
2 changes: 1 addition & 1 deletion src/signers/getPublicKey.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Hex, bytesToHex } from "@noble/curves/abstract/utils";
import { secp256k1 } from "@noble/curves/secp256k1";
import { addHexPrefix, removeHexPrefix } from "../index.js";
import type { IPrivateKey } from "../types/IPrivateKey.js";
import type { IPrivateKey } from "./types/IPrivateKey.js";

/**
* Returns the public key from the private key using the secp256k1 curve.
Expand Down
7 changes: 7 additions & 0 deletions src/signers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "./LocalKeySigner.js";
export * from "./verifySignature.js";
export * from "./getPublicKey.js";
export * from "./types/ILocalKeySignerConfig.js";
export * from "./types/IPrivateKey.js";
export * from "./types/ISigner.js";
export * from "./types/ISignature.js";
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 0 additions & 15 deletions src/types/IMessage.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/types/ISignedTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ISignature } from "./ISignature.js";
import type { ISignature } from "../signers/index.js";
import type { ITransaction } from "./ITransaction.js";

type ISignedTransaction = ITransaction & ISignature;
Expand Down
6 changes: 6 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "../clients/types/ClientConfigs.js";
export * from "./ITransaction.js";
export * from "../signers/types/ISigner.js";
export * from "../signers/types/IPrivateKey.js";
export * from "./IBlock.js";
export * from "../signers/types/ILocalKeySignerConfig.js";
2 changes: 1 addition & 1 deletion src/utils/assert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Hex } from "@noble/curves/abstract/utils";
import invariant from "tiny-invariant";
import type { IPrivateKey } from "../types/IPrivateKey.js";
import type { IPrivateKey } from "../signers/index.js";
import type { ITransaction } from "../types/ITransaction.js";
import { isHexString } from "./hex.js";
import { isAddress } from "./transaction.js";
Expand Down
3 changes: 3 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./assert.js";
export * from "./hex.js";
export * from "./transaction.js";
2 changes: 1 addition & 1 deletion test/mocks/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const defaultRpcEndpoint = "http://127.0.0.1:8529";

const endpoint = process.env.RPC_ENDPOINT || defaultRpcEndpoint;
const endpoint = process.env.RPC_ENDPOINT ?? defaultRpcEndpoint;

export { endpoint };
4 changes: 4 additions & 0 deletions test/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export default defineConfig({
globals: true,
},
});

// start testing with local node
// we will have something public in the future.
// or we can mock api in the future.

0 comments on commit b267158

Please sign in to comment.