Cryptographic functions used by Qubic protocol in WASM.
Caution
Do not run in production yet, more testing is needed.
Come-from-Beyond's Anti-Military License.
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
- Add
qubic-crypto
totrustedDependencies
. This allows to execute postinstall script.
"name": "test",
"module": "index.js",
"type": "module",
+ "trustedDependencies": ["qubic-crypto"],
"dependencies": {
- 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
- Import
import crypto from 'qubic-crypto';
const privateKey = await crypto.createPrivateKey(seed, index);
const publicKey = await crypto.generatePublicKey(privateKey);
const digest = new Uint8Array(crypto.DIGEST_LENGTH);
await crypto.K12(message, digest, crypto.DIGEST_LENGTH);
const signature = await crypto.sign(privateKey, publicKey, digest);
await crypto.verify(publicKey, digest, signature);
const compressedPublicKey = await crypto.generateCompressedPublicKey(privateKey);
const sharedSecret = await crypto.compressedSecretAgreement(privateKey, compressedPublicKey);
await crypto.merkleRoot(depth, index, data, siblings, root);
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.