@scure/starknet
Version:
Audited & minimal implementation of Starknet cryptography including Pedersen and Stark Curve
52 lines • 3 kB
TypeScript
/*! scure-starknet - MIT License (c) 2022 Paul Miller (paulmillr.com) */
import { type IField } from '@noble/curves/abstract/modular.js';
import { poseidon } from '@noble/curves/abstract/poseidon.js';
import { type ECDSASignature, type ECDSASignatureCons, type WeierstrassPoint, type WeierstrassPointCons } from '@noble/curves/abstract/weierstrass.js';
type Hex = Uint8Array | string;
type PrivKey = Hex | bigint;
type Point = WeierstrassPoint<bigint>;
export declare const MAX_VALUE: bigint;
declare const Point: WeierstrassPointCons<bigint>;
export declare function normalizePrivateKey(privKey: Hex): string;
export declare function getPublicKey(privKey: Hex, isCompressed?: boolean): Uint8Array;
export declare function getSharedSecret(privKeyA: Hex, pubKeyB: Hex): Uint8Array;
export declare function sign(msgHash: Hex, privKey: Hex, opts?: any): ECDSASignature;
export declare function verify(signature: ECDSASignature | Hex, msgHash: Hex, pubKey: Hex): boolean;
declare const Signature: ECDSASignatureCons;
declare const utils: {
normPrivateKeyToScalar: (key: PrivKey) => bigint;
isValidPrivateKey(privateKey: PrivKey): boolean;
randomPrivateKey: () => Uint8Array;
precompute: (windowSize?: number, point?: WeierstrassPoint<bigint>) => WeierstrassPoint<bigint>;
};
export { Point, Signature, utils };
export declare function grindKey(seed: Hex): string;
export declare function getStarkKey(privateKey: Hex): string;
export declare function ethSigToPrivate(signature: string): string;
export declare function getAccountPath(layer: string, application: string, ethereumAddress: string, index: number): string;
type PedersenArg = Hex | bigint | number;
export declare function pedersen(x: PedersenArg, y: PedersenArg): string;
export declare const computeHashOnElements: (data: PedersenArg[], fn?: typeof pedersen) => PedersenArg;
export declare const keccak: (data: Uint8Array) => bigint;
export declare const Fp251: Readonly<IField<bigint> & Required<Pick<IField<bigint>, 'isOdd'>>>;
export declare function _poseidonMDS(Fp: IField<bigint>, name: string, m: number, attempt?: number): bigint[][];
export type PoseidonOpts = {
Fp: IField<bigint>;
rate: number;
capacity: number;
roundsFull: number;
roundsPartial: number;
};
export type PoseidonFn = ReturnType<typeof poseidon> & {
m: number;
rate: number;
capacity: number;
};
export declare function poseidonBasic(opts: PoseidonOpts, mds: bigint[][]): PoseidonFn;
export declare function poseidonCreate(opts: PoseidonOpts, mdsAttempt?: number): PoseidonFn;
export declare const poseidonSmall: PoseidonFn;
export declare function poseidonHash(x: bigint, y: bigint, fn?: PoseidonFn): bigint;
export declare function poseidonHashFunc(x: Uint8Array, y: Uint8Array, fn?: PoseidonFn): Uint8Array;
export declare function poseidonHashSingle(x: bigint, fn?: PoseidonFn): bigint;
export declare function poseidonHashMany(values: bigint[], fn?: PoseidonFn): bigint;
//# sourceMappingURL=index.d.ts.map