Skip to content

Commit e1ec9a1

Browse files
authored
🤖 Merge PR DefinitelyTyped#71500 Add types for opentimestamps by @despotes
1 parent 312cba1 commit e1ec9a1

22 files changed

+615
-0
lines changed

types/opentimestamps/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts

types/opentimestamps/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export * as Context from "./src/context";
2+
export { default as DetachedTimestampFile } from "./src/detached-timestamp-file";
3+
export * as Notary from "./src/notary";
4+
export * from "./src/open-timestamps";
5+
export * as Ops from "./src/ops";
6+
export { default as Timestamp } from "./src/timestamp";
7+
export * as Utils from "./src/utils";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "./test/stamp";
2+
import "./test/stamp-hash";
3+
import "./test/stamp-multiple-files";
4+
import "./test/async-usage";
5+
import "./test/info";
6+
import "./test/verify";
7+
import "./test/upgrade";

types/opentimestamps/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"private": true,
3+
"name": "@types/opentimestamps",
4+
"version": "0.4.9999",
5+
"projects": [
6+
"https://github.com/opentimestamps/javascript-opentimestamps#readme"
7+
],
8+
"dependencies": {
9+
"@types/node": "*"
10+
},
11+
"devDependencies": {
12+
"@types/opentimestamps": "workspace:."
13+
},
14+
"owners": [
15+
{
16+
"name": "Pedro Medeiros",
17+
"githubUsername": "despotes"
18+
}
19+
]
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export class BlockHeader {
2+
constructor(merkleroot: string, hash: string, time: number);
3+
getMerkleroot(): string;
4+
getHash(): string;
5+
getTime(): number;
6+
}
7+
8+
export interface BitcoinConf {
9+
rpcuser: string;
10+
rpcpassword: string;
11+
rpcconnect?: string;
12+
rpcport?: string;
13+
testnet?: boolean;
14+
}
15+
16+
export class BitcoinNode {
17+
constructor(bitcoinConf: BitcoinConf);
18+
static readBitcoinConf(): Promise<BitcoinConf>;
19+
getInfo(): Promise<any>;
20+
getBlockHeader(height: number): Promise<BlockHeader>;
21+
callRPC(params: any): Promise<any>;
22+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/// <reference types="node" />
2+
3+
import Timestamp = require("./timestamp");
4+
5+
export class RemoteCalendar {
6+
constructor(url: string);
7+
url: string;
8+
headers: { [key: string]: string };
9+
timeout: number;
10+
submit(digest: Buffer): Promise<Timestamp>;
11+
getTimestamp(commitment: Buffer): Promise<Timestamp>;
12+
}
13+
14+
export class UrlWhitelist {
15+
constructor(urls: string[]);
16+
add(url: string): void;
17+
contains(url: string): boolean;
18+
toString(): string;
19+
}
20+
21+
export const DEFAULT_CALENDAR_WHITELIST: UrlWhitelist;
22+
export const DEFAULT_AGGREGATORS: [
23+
"https://a.pool.opentimestamps.org",
24+
"https://b.pool.opentimestamps.org",
25+
"https://a.pool.eternitywall.com",
26+
"https://ots.btc.catallaxy.com",
27+
];
28+
29+
export class CommitmentNotFoundError extends Error {
30+
name: "CommitmentNotFoundError";
31+
constructor(message?: string);
32+
}
33+
34+
export class URLError extends Error {
35+
name: "URLError";
36+
constructor(message?: string);
37+
}
38+
39+
export class ExceededSizeError extends Error {
40+
name: "ExceededSizeError";
41+
constructor(message?: string);
42+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
export class StreamDeserializationContext {
2+
constructor(stream: Buffer | ArrayBuffer | Uint8Array | string | Array<number>);
3+
buffer: Uint8Array;
4+
counter: number;
5+
getOutput(): Uint8Array;
6+
getCounter(): number;
7+
readBuffer(l: number): Uint8Array | undefined;
8+
read(l: number): number[];
9+
readBool(): boolean;
10+
readVaruint(): number;
11+
readBytes(expectedLength?: number): number[];
12+
readVarbytes(maxLen: number, minLen?: number): number[];
13+
assertMagic(expectedMagic: number[]): void;
14+
assertEof(): void;
15+
toString(): string;
16+
}
17+
18+
export class StreamSerializationContext {
19+
buffer: Uint8Array;
20+
length: number;
21+
getOutput(): Uint8Array;
22+
getLenght(): number;
23+
writeBool(value: boolean): void;
24+
writeVaruint(value: number): void;
25+
writeByte(value: number): void;
26+
writeBytes(value: number[]): void;
27+
writeVarbytes(value: number[]): void;
28+
toString(): string;
29+
}
30+
31+
export class DeserializationError extends Error {
32+
constructor(message?: string);
33+
}
34+
35+
export class BadMagicError extends DeserializationError {
36+
constructor(expectedMagic?: number[], actualMagic?: number[]);
37+
}
38+
39+
export class UnsupportedMajorVersion extends Error {
40+
constructor(message?: string);
41+
}
42+
43+
export class TruncationError extends DeserializationError {
44+
constructor(message?: string);
45+
}
46+
47+
export class TrailingGarbageError extends DeserializationError {
48+
constructor(message?: string);
49+
}
50+
51+
export class RecursionLimitError extends DeserializationError {
52+
constructor(message?: string);
53+
}
54+
55+
export class SerializerTypeError extends TypeError {
56+
constructor(message?: string);
57+
}
58+
59+
export class SerializerValueError extends ValueError {
60+
constructor(message?: string);
61+
}
62+
63+
export class ValueError extends Error {
64+
constructor(message?: string);
65+
}
66+
67+
export class TypeError extends Error {
68+
constructor(message?: string);
69+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Op } from "./ops";
2+
import Timestamp = require("./timestamp");
3+
import { StreamDeserializationContext, StreamSerializationContext } from "./context";
4+
5+
declare class DetachedTimestampFile {
6+
constructor(fileHashOp: Op, timestamp: Timestamp);
7+
fileHashOp: Op;
8+
timestamp: Timestamp;
9+
fileDigest(): number[];
10+
serialize(ctx: StreamSerializationContext): void;
11+
serializeToBytes(): Uint8Array;
12+
static deserialize(
13+
buffer:
14+
| StreamDeserializationContext
15+
| number[]
16+
| Uint8Array
17+
| ArrayBuffer,
18+
): DetachedTimestampFile;
19+
static fromBytes(
20+
fileHashOp: Op,
21+
buffer:
22+
| StreamDeserializationContext
23+
| number[]
24+
| Uint8Array
25+
| ArrayBuffer,
26+
): DetachedTimestampFile;
27+
static fromHash(fileHashOp: Op, fdHash: number[] | ArrayBuffer | Uint8Array): DetachedTimestampFile;
28+
toString(): string;
29+
toJson(): any;
30+
equals(another: DetachedTimestampFile): boolean;
31+
}
32+
33+
export = DetachedTimestampFile;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const PUBLIC_ESPLORA_URL: string;
2+
3+
export interface EsploraOptions {
4+
url?: string;
5+
timeout?: number;
6+
}
7+
8+
export class Esplora {
9+
constructor(options?: EsploraOptions);
10+
url: string;
11+
timeout: number;
12+
blockhash(height: string): Promise<string>;
13+
block(hash: string): Promise<{ merkleroot: string; time: number }>;
14+
}
15+
16+
export class URLError extends Error {
17+
name: "URLError";
18+
constructor(message?: string);
19+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { BlockHeader } from "./bitcoin";
2+
import { StreamDeserializationContext, StreamSerializationContext } from "./context";
3+
4+
export class VerificationError extends Error {
5+
name: "VerificationError";
6+
constructor(message?: string);
7+
}
8+
9+
export abstract class TimeAttestation {
10+
static deserialize(ctx: StreamDeserializationContext): TimeAttestation;
11+
serialize(ctx: StreamSerializationContext): void;
12+
abstract serializePayload(ctx: StreamSerializationContext): void;
13+
abstract _TAG(): number[];
14+
compareTo(other: TimeAttestation): number;
15+
}
16+
17+
// @ts-ignore Opentimestamps library extends and change signature of deserialize method
18+
export class UnknownAttestation extends TimeAttestation {
19+
constructor(tag: number[], payload: number[]);
20+
_tag: number[];
21+
payload: number[];
22+
serializePayload(ctx: StreamSerializationContext): void;
23+
static deserialize(
24+
ctxPayload: StreamDeserializationContext,
25+
tag: number[],
26+
): UnknownAttestation;
27+
_TAG(): number[];
28+
toString(): string;
29+
equals(another: UnknownAttestation): boolean;
30+
compareTo(other: TimeAttestation): number;
31+
}
32+
33+
export class PendingAttestation extends TimeAttestation {
34+
constructor(uri_: string);
35+
uri: string;
36+
static checkUri(uri: number[]): boolean;
37+
static deserialize(ctxPayload: StreamDeserializationContext): PendingAttestation;
38+
serializePayload(ctx: StreamSerializationContext): void;
39+
_TAG(): number[];
40+
_MAX_URI_LENGTH(): number;
41+
_ALLOWED_URI_CHARS(): string;
42+
toString(): string;
43+
equals(another: PendingAttestation): boolean;
44+
compareTo(other: TimeAttestation): number;
45+
}
46+
47+
export class BitcoinBlockHeaderAttestation extends TimeAttestation {
48+
constructor(height_: number);
49+
height: number;
50+
static deserialize(ctxPayload: StreamDeserializationContext): BitcoinBlockHeaderAttestation;
51+
serializePayload(ctx: StreamSerializationContext): void;
52+
_TAG(): number[];
53+
toString(): string;
54+
equals(another: BitcoinBlockHeaderAttestation): boolean;
55+
compareTo(other: TimeAttestation): number;
56+
verifyAgainstBlockheader(digest: number[], block: BlockHeader): number;
57+
}
58+
export class LitecoinBlockHeaderAttestation extends TimeAttestation {
59+
constructor(height_: number);
60+
height: number;
61+
static deserialize(ctxPayload: StreamDeserializationContext): LitecoinBlockHeaderAttestation;
62+
serializePayload(ctx: StreamSerializationContext): void;
63+
_TAG(): number[];
64+
toString(): string;
65+
equals(another: LitecoinBlockHeaderAttestation): boolean;
66+
compareTo(other: TimeAttestation): number;
67+
verifyAgainstBlockheader(digest: number[], block: BlockHeader): number;
68+
}

0 commit comments

Comments
 (0)