Skip to content

Commit

Permalink
feat(providers): yet another refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Oct 27, 2024
1 parent 90c0a38 commit 3749b61
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions apps/klesia/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicKeySchema, TransactionPayload } from "@mina-js/utils";
import { PublicKeySchema, TransactionBodySchema } from "@mina-js/utils";
import { z } from "zod";
import { SendZkappInput } from "./zkapp";

Expand All @@ -12,7 +12,7 @@ export const SignatureSchema = z.union([
z.object({ field: z.string(), scalar: z.string() }),
]);
export const SendTransactionBodySchema = z.object({
input: TransactionPayload,
input: TransactionBodySchema,
signature: SignatureSchema,
});
export const SendZkAppBodySchema = z.object({
Expand Down
4 changes: 2 additions & 2 deletions packages/accounts/src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FieldSchema, TransactionBody } from "@mina-js/utils";
import { FieldSchema, TransactionBodySchema } from "@mina-js/utils";
import { z } from "zod";

export const SignFieldsParamsSchema = z
Expand All @@ -21,6 +21,6 @@ export const CreateNullifierParamsSchema = z

export const SignTransactionParamsSchema = z
.object({
transaction: TransactionBody,
transaction: TransactionBodySchema,
})
.strict();
6 changes: 2 additions & 4 deletions packages/connect/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
SignTransaction,
} from "@mina-js/accounts";
import { createClient } from "@mina-js/klesia-sdk";
import type { PartiallyFormedTransactionProperties } from "@mina-js/utils";
import type { PartialTransaction } from "@mina-js/utils";
import { match } from "ts-pattern";
import { createStore } from "./store";

Expand Down Expand Up @@ -117,9 +117,7 @@ export const createWalletClient = ({
if (account.type !== "local") throw new Error("Account type not supported");
return account.createNullifier(params);
};
const prepareTransactionRequest = async (
transaction: PartiallyFormedTransactionProperties,
) => {
const prepareTransactionRequest = async (transaction: PartialTransaction) => {
let fee = transaction.fee;
let nonce = transaction.nonce;
if (!nonce) {
Expand Down
4 changes: 2 additions & 2 deletions packages/providers/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SignedFieldsSchema,
SignedMessageSchema,
SignedTransactionSchema,
TransactionPayload,
TransactionPayloadSchema,
TransactionReceiptSchema,
} from "@mina-js/utils";
import { z } from "zod";
Expand Down Expand Up @@ -57,7 +57,7 @@ export const SignFieldsRequestParamsSchema = RequestWithContext.extend({
}).strict();
export const SignTransactionRequestParamsSchema = RequestWithContext.extend({
method: z.literal("mina_signTransaction"),
params: z.array(z.union([TransactionPayload, ZkAppCommandPayload])),
params: z.array(z.union([TransactionPayloadSchema, ZkAppCommandPayload])),
}).strict();
export const SendTransactionRequestParamsSchema = RequestWithContext.extend({
method: z.literal("mina_sendTransaction"),
Expand Down
12 changes: 6 additions & 6 deletions packages/utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import type { z } from "zod";
import type {
LiteralSchema,
NullifierSchema,
PartiallyFormedTransactionPayload,
PartialTransactionSchema,
PrivateKeySchema,
PublicKeySchema,
SignedFieldsSchema,
SignedMessageSchema,
SignedTransactionSchema,
TransactionPayload,
TransactionBodySchema,
TransactionPayloadSchema,
TransactionReceiptSchema,
ZkAppCommandPayload,
} from "./validation";
Expand All @@ -20,10 +21,9 @@ export type Literal = z.infer<typeof LiteralSchema>;
export type Json = Literal | { [key: string]: Json } | Json[];
export type PublicKey = z.infer<typeof PublicKeySchema>;
export type PrivateKey = z.infer<typeof PrivateKeySchema>;
export type TransactionProperties = z.infer<typeof TransactionPayload>;
export type PartiallyFormedTransactionProperties = z.infer<
typeof PartiallyFormedTransactionPayload
>;
export type TransactionBody = z.infer<typeof TransactionBodySchema>;
export type TransactionPayload = z.infer<typeof TransactionPayloadSchema>;
export type PartialTransaction = z.infer<typeof PartialTransactionSchema>;
export type ZkAppCommandProperties = z.infer<typeof ZkAppCommandPayload>;

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/utils/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const FeePayerSchema = z
})
.strict();

export const TransactionBody = z
export const TransactionBodySchema = z
.object({
from: PublicKeySchema,
to: PublicKeySchema,
Expand All @@ -49,13 +49,13 @@ export const TransactionBody = z
})
.strict();

export const TransactionPayload = z
export const TransactionPayloadSchema = z
.object({
transaction: TransactionBody,
transaction: TransactionBodySchema,
})
.strict();

export const PartiallyFormedTransactionPayload = TransactionPayload.extend({
export const PartialTransactionSchema = TransactionPayloadSchema.extend({
fee: z.coerce.string().optional(),
nonce: z.coerce.string().optional(),
});
Expand Down Expand Up @@ -112,7 +112,7 @@ export const SignedTransactionSchema = z
.object({
signature: SignatureSchema,
publicKey: PublicKeySchema,
data: TransactionBody,
data: TransactionBodySchema,
})
.strict();

Expand Down

0 comments on commit 3749b61

Please sign in to comment.