mina-attestations
Version:
Private Attestations on Mina
48 lines (47 loc) • 1.56 kB
TypeScript
/**
* Minimal version of a DER parsing library (in parser-combinator style),
* sufficient to parse a RSA public key in SubjectPublicKeyInfo format.
*/
import type { Tuple } from '../types.ts';
export { parse, Sequence, ObjectIdentifier, Null, BitString, Integer };
export { parseRSASubjectPublicKeyInfo };
/**
* An Offset is a number that can be increased
*/
declare class Offset {
i: number;
constructor(i?: number);
incr(): number;
incrBy(n: number): number;
copy(): Offset;
}
/**
* A Parser is a function that takes a byte array and an offset,
* and either returns the parsed value and increments the offset,
* or throws an error.
*/
type Parser<T = any> = (bytes: Uint8Array, offset: Offset) => T;
/**
* Parse a byte array using a parser.
*
* Asserts that the parser consumes all bytes.
*/
declare function parse<T>(parser: Parser<T>, bytes: Uint8Array): T;
declare function Sequence<T extends Tuple<Parser>>(parsers: T): Parser<{
[K in keyof T]: ReturnType<T[K]>;
}>;
declare function ObjectIdentifier(bytes: Uint8Array, offset: Offset): number[];
declare function Null(bytes: Uint8Array, offset: Offset): null;
declare function BitString(bytes: Uint8Array, offset: Offset): {
content: Uint8Array<ArrayBuffer>;
unusedBits: number;
};
declare function Integer(bytes: Uint8Array, offset: Offset): bigint;
/**
* Parse a RSA public key in SubjectPublicKeyInfo format,
* returning the modulus `n` as a bigint.
*/
declare function parseRSASubjectPublicKeyInfo(bytes: Uint8Array): {
n: bigint;
e: bigint;
};