package
Audited & minimal implementation of Starknet cryptography including Pedersen and Stark Curve
npm install @scure/starknetGitHub-flavored package documentation.
Across all versions, last 30 days.
1,579,612 in 30 days
Runtime metadata.
Tagged topics.
Audited & minimal JS implementation of Starknet cryptography.
scure — audited micro-libraries.
npm install @scure/starknet
jsr add jsr:@scure/starknet
import * as starknet from '@scure/starknet';We support all major platforms and runtimes.
Note: the examples use the 'deepStrictEqual' function from the 'assert' built-in NodeJS module to compare values.
In Typescript, you must first install the '@types/node' npm package and then import like this: import { deepStrictEqual } from 'assert';.
In vanilla Javascript, just do this: const { deepStrictEqual } = require("assert");
import { deepStrictEqual } from 'node:assert';
import * as starknet from '@scure/starknet';
// Signing and verification
const privateKey = '2dccce1da22003777062ee0870e9881b460a8b7eca276870f57c601f182136c';
const publicKey = starknet.getPublicKey(privateKey);
const messageHash = 'c465dd6b1bbffdb05442eb17f5ca38ad1aa78a6f56bf4415bdee219114a47';
const sig = starknet.sign(messageHash, privateKey);
const { r, s } = sig;
deepStrictEqual(r.toString(16), '5f496f6f210b5810b2711c74c15c05244dad43d18ecbbdbe6ed55584bc3b0a2');
deepStrictEqual(s.toString(16), '4e8657b153787f741a67c0666bad6426c3741b478c8eaa3155196fc571416f3'
npm install @scure/bip32 @scure/bip39
import { deepStrictEqual } from 'node:assert';
import * as bip32 from '@scure/bip32';
import * as bip39 from '@scure/bip39';
import * as starknet from '@scure/starknet';
const layer = 'starkex';
const application = 'starkdeployement';
const mnemonic =
'range mountain blast problem vibrant void vivid doctor cluster enough melody ' +
'salt layer language laptop boat major space monkey unit glimpse pause change vibrant';
const ethAddress = '0xa4864d977b944315389d1765ffa7e66F74ee8cd7';
const hdKey = bip32.HDKey.fromMasterSeed(bip39.
Poseidon hash can be used in the following way:
type PoseidonFn = ReturnType<typeof poseidon> & {
m: number;
rate: number;
capacity: number;
};
function poseidonHash(x: bigint, y: bigint, fn?: PoseidonFn): bigint;
function poseidonHashFunc(x: Uint8Array, y: Uint8Array, fn?: PoseidonFn): Uint8Array;
function poseidonHashSingle(x: bigint, fn?: PoseidonFn): bigint
import { deepStrictEqual } from 'node:assert';
import * as starknet from '@scure/starknet';
// Hash list of elements (same as hashChain, but includes single values and preserves order)
deepStrictEqual(
starknet.computeHashOnElements([1, 2, 3]),
'0xf9d95fbf356fbeda26538c92f7040abe51bf142350f73c9ee5ba7c660bae71'
);
// Key grinding
deepStrictEqual(
starknet.grindKey('86F3E7293141F20A8BAFF320E8EE4ACCB9D4A4BF2B4D295E8CEE784DB46E0519'),
'5c8c8683596c732541a59e03007b2d30dbbbb873556fe65b5fb63c16688f941'
);
// Starknet keccak
deepStrictEqual(
starknet.keccak(new TextEncoder().encode(
The library has been audited:
npm run benchmark
Benchmark results on Apple M4:
pedersen x 1,131 ops/sec @ 883μs/op
poseidon x 10,916 ops/sec @ 91μs/op
verify x 820 ops/sec @ 1ms/opThe MIT License (MIT)
Copyright (c) 2022 Paul Miller (https://paulmillr.com)
See LICENSE file.
curve, modular, poseidon, weierstrassEstimated unpacked size across 3 packages.
2.3 MB
Includes dependencies.