-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
9 changed files
with
181 additions
and
23 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,15 @@ | ||
name: Run tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
my-job: | ||
name: my-job | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: oven-sh/setup-bun@v2 | ||
- run: bun install | ||
- run: bun run build | ||
- run: bun run test |
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,32 @@ | ||
// import MinaSigner from "mina-signer"; | ||
|
||
// /** | ||
// * @description Creates an Account from a private key. | ||
// * | ||
// * @returns A Private Key Account. | ||
// */ | ||
// export function privateKeyToAccount(privateKey: string): PrivateKeyAccount { | ||
// const client = new MinaSigner({ network: "mainnet" }); | ||
// const publicKey = client.derivePublicKey(privateKey); | ||
// const account = toAccount({ | ||
// publicKey, | ||
// async sign({ hash }) { | ||
// return sign({ hash, privateKey, to: "hex" }); | ||
// }, | ||
// async signMessage({ message }) { | ||
// return signMessage({ message, privateKey }); | ||
// }, | ||
// async signTransaction(transaction, { serializer } = {}) { | ||
// return signTransaction({ privateKey, transaction, serializer }); | ||
// }, | ||
// async signTypedData(typedData) { | ||
// return signTypedData({ ...typedData, privateKey }); | ||
// }, | ||
// }); | ||
|
||
// return { | ||
// ...account, | ||
// publicKey, | ||
// source: "privateKey", | ||
// } as PrivateKeyAccount; | ||
// } |
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 @@ | ||
export type CustomSource = { | ||
publicKey: string; | ||
}; | ||
|
||
export type LocalAccount<source extends string = string> = CustomSource & { | ||
publicKey: string; | ||
source: source; | ||
type: "local"; | ||
}; | ||
|
||
// export type PrivateKeyAccount = Prettify< | ||
// LocalAccount<'privateKey'> & { | ||
// // TODO(v3): This will be redundant. | ||
// sign: NonNullable<CustomSource['sign']> | ||
// } |
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,24 @@ | ||
{ | ||
"name": "@mina-js/shared", | ||
"version": "0.0.1", | ||
"type": "module", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.cjs", | ||
"import": "./dist/index.js" | ||
} | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"test": "bun test" | ||
}, | ||
"dependencies": { | ||
"zod": "3.23.8" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
} | ||
} |
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,17 @@ | ||
export type { | ||
SignedMessage, | ||
SignedFields, | ||
Nullifier, | ||
PublicKey, | ||
TransactionReceipt, | ||
} from "./types"; | ||
export type { | ||
SignatureSchema, | ||
SignedMessageSchema, | ||
FieldSchema, | ||
GroupSchema, | ||
NullifierSchema, | ||
PublicKeySchema, | ||
SignedFieldsSchema, | ||
TransactionReceiptSchema, | ||
} from "./validation"; |
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,18 @@ | ||
import type { z } from "zod"; | ||
import type { | ||
NullifierSchema, | ||
PublicKeySchema, | ||
SignedFieldsSchema, | ||
SignedMessageSchema, | ||
TransactionReceiptSchema, | ||
} from "./validation"; | ||
|
||
export type PublicKey = z.infer<typeof PublicKeySchema>; | ||
|
||
export type SignedMessage = z.infer<typeof SignedMessageSchema>; | ||
|
||
export type SignedFields = z.infer<typeof SignedFieldsSchema>; | ||
|
||
export type Nullifier = z.infer<typeof NullifierSchema>; | ||
|
||
export type TransactionReceipt = z.infer<typeof TransactionReceiptSchema>; |
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,48 @@ | ||
import { z } from "zod"; | ||
|
||
export const FieldSchema = z.coerce.bigint(); | ||
|
||
export const GroupSchema = z.object({ | ||
x: FieldSchema, | ||
y: FieldSchema, | ||
}); | ||
|
||
export const PublicKeySchema = z.string().length(55).startsWith("B62"); | ||
|
||
export const SignatureSchema = z | ||
.object({ | ||
field: z.string(), | ||
scalar: z.string(), | ||
}) | ||
.strict(); | ||
|
||
export const SignedMessageSchema = z | ||
.object({ | ||
publicKey: PublicKeySchema, | ||
data: z.string(), | ||
signature: SignatureSchema, | ||
}) | ||
.strict(); | ||
|
||
export const SignedFieldsSchema = z.object({ | ||
data: z.array(z.number()), | ||
publicKey: PublicKeySchema, | ||
signature: z.string(), | ||
}); | ||
|
||
export const NullifierSchema = z.object({ | ||
publicKey: GroupSchema, | ||
public: z.object({ | ||
nullifier: GroupSchema, | ||
s: FieldSchema, | ||
}), | ||
private: z.object({ | ||
c: FieldSchema, | ||
g_r: GroupSchema, | ||
h_m_pk_r: GroupSchema, | ||
}), | ||
}); | ||
|
||
export const TransactionReceiptSchema = z.object({ | ||
hash: z.string(), | ||
}); |