Skip to content

computor-tools/qubic-crypto

Repository files navigation

qubic-crypto

build

Cryptographic functions used by Qubic protocol in WASM.

Caution

Do not run in production yet, more testing is needed.

License

Come-from-Beyond's Anti-Military License.

Usage

To install dependencies and build:

Build command should pull and run emsdk from https://github.com/emscripten-core/emsdk

Tested on arch linux and ubuntu only, check CI. You'll need GNU Make.

bun run build

Run test:

bun run test

Instal with Bun from Github:

  1. Add qubic-crypto to trustedDependencies. This allows to execute postinstall script.
   "name": "test",
   "module": "index.js",
   "type": "module",
+  "trustedDependencies": ["qubic-crypto"],
   "dependencies": {
  1. Postinstall fetches dependencies (FourQlib, K12 & emsdk) from Github, executes GNU Make and emsdk scripts. Requires GNU Make to be already installed, check CI for more info.
bun add --verbose github:computor-tools/qubic-crypto
  1. Import
import crypto from 'qubic-crypto';

Function list

createPrivateKey

const privateKey = await crypto.createPrivateKey(seed, index);

generatePublicKey

const publicKey = await crypto.generatePublicKey(privateKey);

K12

const digest = new Uint8Array(crypto.DIGEST_LENGTH);
await crypto.K12(message, digest, crypto.DIGEST_LENGTH);

sign

const signature = await crypto.sign(privateKey, publicKey, digest);

verify

await crypto.verify(publicKey, digest, signature);

generateCompressedPublicKey

const compressedPublicKey = await crypto.generateCompressedPublicKey(privateKey);

compressedSecretAgreement

const sharedSecret = await crypto.compressedSecretAgreement(privateKey, compressedPublicKey);

merkleRoot

await crypto.merkleRoot(depth, index, data, siblings, root);

Constants

  • crypto.SEED_LENGTH = 55
  • crypto.PRIVATE_KEY_LENGTH = 32
  • crypto.PUBLIC_KEY_LENGTH = 32
  • crypto.SIGNATURE_LENGTH = 64
  • crypto.SHARED_SECRET_LENGTH = 32
  • crypto.DIGEST_LENGTH = 32
  • crypto.NONCE_LENGTH = 32

This project was created using bun init in bun v1.0.20. Bun is a fast all-in-one JavaScript runtime.

About

Crypto functions used by Qubic protocol compiled into Wasm with Emscripten (KangarooTwelve, FourQ, merkle root, solution verification)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published