Skip to content

Commit 02fed52

Browse files
committed
feat(lib): add testing ci workflow
1 parent 9618882 commit 02fed52

File tree

9 files changed

+181
-23
lines changed

9 files changed

+181
-23
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Run tests
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
my-job:
8+
name: my-job
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: oven-sh/setup-bun@v2
13+
- run: bun install
14+
- run: bun run build
15+
- run: bun run test

bun.lockb

448 Bytes
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// import MinaSigner from "mina-signer";
2+
3+
// /**
4+
// * @description Creates an Account from a private key.
5+
// *
6+
// * @returns A Private Key Account.
7+
// */
8+
// export function privateKeyToAccount(privateKey: string): PrivateKeyAccount {
9+
// const client = new MinaSigner({ network: "mainnet" });
10+
// const publicKey = client.derivePublicKey(privateKey);
11+
// const account = toAccount({
12+
// publicKey,
13+
// async sign({ hash }) {
14+
// return sign({ hash, privateKey, to: "hex" });
15+
// },
16+
// async signMessage({ message }) {
17+
// return signMessage({ message, privateKey });
18+
// },
19+
// async signTransaction(transaction, { serializer } = {}) {
20+
// return signTransaction({ privateKey, transaction, serializer });
21+
// },
22+
// async signTypedData(typedData) {
23+
// return signTypedData({ ...typedData, privateKey });
24+
// },
25+
// });
26+
27+
// return {
28+
// ...account,
29+
// publicKey,
30+
// source: "privateKey",
31+
// } as PrivateKeyAccount;
32+
// }

packages/accounts/src/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export type CustomSource = {
2+
publicKey: string;
3+
};
4+
5+
export type LocalAccount<source extends string = string> = CustomSource & {
6+
publicKey: string;
7+
source: source;
8+
type: "local";
9+
};
10+
11+
// export type PrivateKeyAccount = Prettify<
12+
// LocalAccount<'privateKey'> & {
13+
// // TODO(v3): This will be redundant.
14+
// sign: NonNullable<CustomSource['sign']>
15+
// }

packages/providers/src/types.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import type {
2+
Nullifier,
3+
PublicKey,
4+
SignedFields,
5+
SignedMessage,
6+
TransactionReceipt,
7+
} from "@mina-js/shared";
18
import type {
29
AddChainData,
310
CreateNullifierData,
@@ -11,8 +18,6 @@ import type {
1118
// biome-ignore lint/suspicious/noExplicitAny: Deal with it.
1219
type TODO = any;
1320

14-
export type Address = `b62${string}`;
15-
1621
export type MinaProviderDetail = {
1722
info: MinaProviderInfo;
1823
provider: MinaProviderClient;
@@ -50,26 +55,10 @@ export type ProviderRpcEvent =
5055
| "accountsChanged"
5156
| "mina_message";
5257

53-
// Return types
54-
type SignedMessage = {
55-
publicKey: string;
56-
data: string;
57-
signature: {
58-
field: string;
59-
scalar: string;
60-
};
61-
};
62-
63-
type SignedFieldsData = {
64-
data: (string | number)[];
65-
publicKey: string;
66-
signature: string;
67-
};
68-
6958
// Request variants
7059
export type AccountsRequest = (args: {
7160
method: "mina_accounts";
72-
}) => Promise<Address[]>;
61+
}) => Promise<PublicKey[]>;
7362

7463
export type ChainIdRequest = (args: {
7564
method: "mina_chainId";
@@ -91,7 +80,7 @@ export type SignRequest = (args: {
9180
export type SignFieldsRequest = (args: {
9281
method: "mina_signFields";
9382
params: SignFieldsData;
94-
}) => Promise<SignedFieldsData>;
83+
}) => Promise<SignedFields>;
9584

9685
export type SignTransactionRequest = (args: {
9786
method: "mina_signTransaction";
@@ -101,12 +90,12 @@ export type SignTransactionRequest = (args: {
10190
export type SendTransactionRequest = (args: {
10291
method: "mina_sendTransaction";
10392
params: SendTransactionData;
104-
}) => Promise<TODO>;
93+
}) => Promise<TransactionReceipt>;
10594

10695
export type CreateNullifierRequest = (args: {
10796
method: "mina_createNullifier";
10897
params: CreateNullifierData;
109-
}) => Promise<TODO>;
98+
}) => Promise<Nullifier>;
11099

111100
export type SwitchChainRequest = (args: {
112101
method: "mina_switchChain";
@@ -148,7 +137,7 @@ export type ChainChangedListener = (
148137

149138
export type AccountsChangedListener = (
150139
event: "accountsChanged",
151-
callback: (params: { accounts: Address[] }) => void,
140+
callback: (params: { accounts: PublicKey[] }) => void,
152141
) => void;
153142

154143
export type MessageListener = (

packages/shared/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@mina-js/shared",
3+
"version": "0.0.1",
4+
"type": "module",
5+
"module": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"exports": {
8+
".": {
9+
"types": "./dist/index.d.ts",
10+
"default": "./dist/index.cjs",
11+
"import": "./dist/index.js"
12+
}
13+
},
14+
"scripts": {
15+
"build": "tsup",
16+
"test": "bun test"
17+
},
18+
"dependencies": {
19+
"zod": "3.23.8"
20+
},
21+
"peerDependencies": {
22+
"typescript": "^5.0.0"
23+
}
24+
}

packages/shared/src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export type {
2+
SignedMessage,
3+
SignedFields,
4+
Nullifier,
5+
PublicKey,
6+
TransactionReceipt,
7+
} from "./types";
8+
export type {
9+
SignatureSchema,
10+
SignedMessageSchema,
11+
FieldSchema,
12+
GroupSchema,
13+
NullifierSchema,
14+
PublicKeySchema,
15+
SignedFieldsSchema,
16+
TransactionReceiptSchema,
17+
} from "./validation";

packages/shared/src/types.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { z } from "zod";
2+
import type {
3+
NullifierSchema,
4+
PublicKeySchema,
5+
SignedFieldsSchema,
6+
SignedMessageSchema,
7+
TransactionReceiptSchema,
8+
} from "./validation";
9+
10+
export type PublicKey = z.infer<typeof PublicKeySchema>;
11+
12+
export type SignedMessage = z.infer<typeof SignedMessageSchema>;
13+
14+
export type SignedFields = z.infer<typeof SignedFieldsSchema>;
15+
16+
export type Nullifier = z.infer<typeof NullifierSchema>;
17+
18+
export type TransactionReceipt = z.infer<typeof TransactionReceiptSchema>;

packages/shared/src/validation.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { z } from "zod";
2+
3+
export const FieldSchema = z.coerce.bigint();
4+
5+
export const GroupSchema = z.object({
6+
x: FieldSchema,
7+
y: FieldSchema,
8+
});
9+
10+
export const PublicKeySchema = z.string().length(55).startsWith("B62");
11+
12+
export const SignatureSchema = z
13+
.object({
14+
field: z.string(),
15+
scalar: z.string(),
16+
})
17+
.strict();
18+
19+
export const SignedMessageSchema = z
20+
.object({
21+
publicKey: PublicKeySchema,
22+
data: z.string(),
23+
signature: SignatureSchema,
24+
})
25+
.strict();
26+
27+
export const SignedFieldsSchema = z.object({
28+
data: z.array(z.number()),
29+
publicKey: PublicKeySchema,
30+
signature: z.string(),
31+
});
32+
33+
export const NullifierSchema = z.object({
34+
publicKey: GroupSchema,
35+
public: z.object({
36+
nullifier: GroupSchema,
37+
s: FieldSchema,
38+
}),
39+
private: z.object({
40+
c: FieldSchema,
41+
g_r: GroupSchema,
42+
h_m_pk_r: GroupSchema,
43+
}),
44+
});
45+
46+
export const TransactionReceiptSchema = z.object({
47+
hash: z.string(),
48+
});

0 commit comments

Comments
 (0)