Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Aug 1, 2024
0 parents commit 8100402
Show file tree
Hide file tree
Showing 16 changed files with 555 additions and 0 deletions.
177 changes: 177 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

dist

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# mina-js

The TypeScript interface for Mina Protocol.

## Features

- Interact with Mina Wallets such as [Pallad](https://pallad.co/).
- Browser native BigInt.
- TypeScript ready.

## Acknowledgements

- This is not a library to write provable programs. In that case head over to [o1js](https://github.com/o1-labs/o1js).
- Inspired heavily by [viem](https://github.com/wevm/viem).
- Great part of the code is based our work and code of [Pallad](https://pallad.co).

## Authors

- [@mrcnk](https://github.com/mrcnk) ([X.com](https://x.com/schoolboytom))
15 changes: 15 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"ignore": ["dist/**/*"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}
Binary file added bun.lockb
Binary file not shown.
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "mina-js",
"scripts": {
"build": "tsup",
"test": "bun test",
"lint": "bunx biome check .",
"format": "bunx biome check . --write",
"format:unsafe": "bunx biome check . --write --unsafe"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@tsconfig/bun": "1.0.7",
"@types/bun": "1.1.6",
"tsup": "8.2.3"
},
"dependencies": {
"@noble/curves": "1.4.2",
"@noble/hashes": "1.4.0",
"@scure/bip32": "1.4.0",
"@scure/bip39": "1.3.0",
"mina-signer": "3.0.7",
"zod": "3.23.8"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
8 changes: 8 additions & 0 deletions src/accounts/generate-mnemonic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, it } from "bun:test";
import { english } from ".";
import { generateMnemonic } from "./generate-mnemonic";

it("generates 12 word mnemonic", () => {
const mnemonic = generateMnemonic(english);
expect(mnemonic.split(" ").length).toBe(12);
});
16 changes: 16 additions & 0 deletions src/accounts/generate-mnemonic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { generateMnemonic as generateMnemonic_ } from "@scure/bip39";

/**
* @description Generates a random mnemonic phrase with a given wordlist.
*
* @param wordlist The wordlist to use for generating the mnemonic phrase.
* @param strength mnemonic strength 128-256 bits
*
* @returns A randomly generated mnemonic phrase.
*/
export function generateMnemonic(
wordlist: string[],
strength?: number | undefined,
): string {
return generateMnemonic_(wordlist, strength);
}
12 changes: 12 additions & 0 deletions src/accounts/generate-private-key.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect, it } from "bun:test";
import { generatePrivateKey } from "./generate-private-key";

it("returns a string", () => {
const privateKey = generatePrivateKey();
expect(typeof privateKey).toBe("string");
});

it("has a length of 64 characters", () => {
const privateKey = generatePrivateKey();
expect(privateKey.length).toBe(52);
});
11 changes: 11 additions & 0 deletions src/accounts/generate-private-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Client from "mina-signer";

/**
* @description Generates a random private key.
*
* @returns A randomly generated private key.
*/
export function generatePrivateKey(): string {
const client = new Client({ network: "mainnet" });
return client.genKeys().privateKey;
}
4 changes: 4 additions & 0 deletions src/accounts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { wordlist as english } from "@scure/bip39/wordlists/english";

export { generateMnemonic } from "./generate-mnemonic";
export { generatePrivateKey } from "./generate-private-key";
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./accounts";
2 changes: 2 additions & 0 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./types";
export * from "./validation";
Loading

0 comments on commit 8100402

Please sign in to comment.