diff --git a/.changeset/shaggy-bags-run.md b/.changeset/shaggy-bags-run.md new file mode 100644 index 00000000..9c37ea70 --- /dev/null +++ b/.changeset/shaggy-bags-run.md @@ -0,0 +1,5 @@ +--- +"niljs": patch +--- + +Added index files inside feature directories to make root index with package exports clean diff --git a/src/clients/BaseClient.ts b/src/clients/BaseClient.ts index 17af5b0a..c9552fb5 100644 --- a/src/clients/BaseClient.ts +++ b/src/clients/BaseClient.ts @@ -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 { /** diff --git a/src/clients/PublicClient.test.ts b/src/clients/PublicClient.test.ts index 8d7d4506..619cd54e 100644 --- a/src/clients/PublicClient.test.ts +++ b/src/clients/PublicClient.test.ts @@ -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. diff --git a/src/clients/PublicClient.ts b/src/clients/PublicClient.ts index 4873cfe2..14ae3c80 100644 --- a/src/clients/PublicClient.ts +++ b/src/clients/PublicClient.ts @@ -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. diff --git a/src/clients/WalletClient.ts b/src/clients/WalletClient.ts index 60466d53..3cfac92b 100644 --- a/src/clients/WalletClient.ts +++ b/src/clients/WalletClient.ts @@ -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. @@ -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); } @@ -113,7 +110,9 @@ class WalletClient extends BaseClient { */ public async deployContract(contract: Uint8Array): Promise { 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; } } diff --git a/src/clients/index.ts b/src/clients/index.ts new file mode 100644 index 00000000..0bacc02b --- /dev/null +++ b/src/clients/index.ts @@ -0,0 +1,4 @@ +export * from "./WalletClient.js"; +export * from "./PublicClient.js"; +export * from "./types/ClientConfigs.js"; +export * from "./types/ISendTransactionOptions.js"; diff --git a/src/types/ClientConfigs.ts b/src/clients/types/ClientConfigs.ts similarity index 92% rename from src/types/ClientConfigs.ts rename to src/clients/types/ClientConfigs.ts index ad71ae37..19151ec4 100644 --- a/src/types/ClientConfigs.ts +++ b/src/clients/types/ClientConfigs.ts @@ -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. diff --git a/src/types/ISendTransactionOptions.ts b/src/clients/types/ISendTransactionOptions.ts similarity index 100% rename from src/types/ISendTransactionOptions.ts rename to src/clients/types/ISendTransactionOptions.ts diff --git a/src/encoding/index.ts b/src/encoding/index.ts new file mode 100644 index 00000000..9a184328 --- /dev/null +++ b/src/encoding/index.ts @@ -0,0 +1,4 @@ +export * from "./fromHex.js"; +export * from "./toHex.js"; +export * from "./fromSsz.js"; +export * from "./toSsz.js"; diff --git a/src/encoding/toSsz.ts b/src/encoding/toSsz.ts index 8f64c0e2..bef3dada 100644 --- a/src/encoding/toSsz.ts +++ b/src/encoding/toSsz.ts @@ -14,6 +14,7 @@ const transactionToSsz = (transaction: ITransaction): Uint8Array => { const keypair = Keypair.defaultValue(); const serialized = Keypair.serialize(keypair); + return serialized; }; diff --git a/src/index.ts b/src/index.ts index e40c9889..1d2a20ec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; diff --git a/src/signers/LocalKeySigner.ts b/src/signers/LocalKeySigner.ts index f9091e88..b4495821 100644 --- a/src/signers/LocalKeySigner.ts +++ b/src/signers/LocalKeySigner.ts @@ -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. diff --git a/src/signers/getPublicKey.ts b/src/signers/getPublicKey.ts index eeb1c411..8c373225 100644 --- a/src/signers/getPublicKey.ts +++ b/src/signers/getPublicKey.ts @@ -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. diff --git a/src/signers/index.ts b/src/signers/index.ts new file mode 100644 index 00000000..b1620bb7 --- /dev/null +++ b/src/signers/index.ts @@ -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"; diff --git a/src/types/ILocalKeySignerConfig.ts b/src/signers/types/ILocalKeySignerConfig.ts similarity index 100% rename from src/types/ILocalKeySignerConfig.ts rename to src/signers/types/ILocalKeySignerConfig.ts diff --git a/src/types/IPrivateKey.ts b/src/signers/types/IPrivateKey.ts similarity index 100% rename from src/types/IPrivateKey.ts rename to src/signers/types/IPrivateKey.ts diff --git a/src/types/ISignature.ts b/src/signers/types/ISignature.ts similarity index 100% rename from src/types/ISignature.ts rename to src/signers/types/ISignature.ts diff --git a/src/types/ISigner.ts b/src/signers/types/ISigner.ts similarity index 100% rename from src/types/ISigner.ts rename to src/signers/types/ISigner.ts diff --git a/src/types/IMessage.ts b/src/types/IMessage.ts deleted file mode 100644 index f56c8cb5..00000000 --- a/src/types/IMessage.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * The message type. - */ -type IMessage = { - index: number; - shardId: number; - from: string; - to: string; - value: number; - data: string; - seqno: number; - signature: string; -}; - -export type { IMessage }; diff --git a/src/types/ISignedTransaction.ts b/src/types/ISignedTransaction.ts index 9a4adc62..6a441d58 100644 --- a/src/types/ISignedTransaction.ts +++ b/src/types/ISignedTransaction.ts @@ -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; diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 00000000..5c687896 --- /dev/null +++ b/src/types/index.ts @@ -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"; diff --git a/src/utils/assert.ts b/src/utils/assert.ts index 1544b0a0..39b11850 100644 --- a/src/utils/assert.ts +++ b/src/utils/assert.ts @@ -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"; diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 00000000..8bb9654a --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,3 @@ +export * from "./assert.js"; +export * from "./hex.js"; +export * from "./transaction.js"; diff --git a/test/mocks/endpoint.ts b/test/mocks/endpoint.ts index f94b683f..cc15d13d 100644 --- a/test/mocks/endpoint.ts +++ b/test/mocks/endpoint.ts @@ -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 }; diff --git a/test/vitest.config.ts b/test/vitest.config.ts index f597e81b..15eb3d44 100644 --- a/test/vitest.config.ts +++ b/test/vitest.config.ts @@ -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.