forked from reseau-constellation/orbit-db-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
188 lines (172 loc) · 4.91 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
declare module "@orbitdb/core" {
import EventEmitter from "events";
import type { HeliaLibp2p } from "helia";
export function Database(args: {
ipfs: HeliaLibp2p;
identity?: Identity;
address: string;
name?: string;
access?: AccessController;
directory?: string;
meta?: object;
headsStorage?: Storage;
entryStorage?: Storage;
indexStorage?: Storage;
referencesCount?: number;
syncAutomatically?: boolean;
onUpdate?: () => void;
}): Promise<{
type: string;
addOperation: (args: {
op: string;
key: string | null;
value: unknown;
}) => Promise<string>;
address: string;
close(): Promise<void>;
drop(): Promise<void>;
events: EventEmitter;
access: AccessController;
log: Log;
}>;
export type Identity = {
id: string;
publicKey: string;
signatures: {
id: string;
publicKey: string;
};
type: string;
sign: (identity: Identity, data: string) => Promise<string>;
verify: (
signature: string,
publicKey: string,
data: string
) => Promise<boolean>;
};
export type OrbitDB = {
id: string;
open: (
address: string,
OrbitDBDatabaseOptions?
) => ReturnType<typeof Database>;
stop;
ipfs;
directory;
keystore;
identity: Identity;
peerId;
};
export function createOrbitDB(args: {
ipfs: HeliaLibp2p;
directory: string;
id?: string;
}): Promise<OrbitDB>;
export function useAccessController(accessController: { type: string }): void;
export function isValidAddress(address: unknown): boolean;
export type Log = {
id;
clock: Clock;
heads: () => Promise<LogEntry[]>;
traverse: () => AsyncGenerator<LogEntry, void, unknown>;
};
export function AccessControllerGenerator({
orbitdb,
identities,
address,
}: {
orbitdb: OrbitDB;
identities: IdentitiesType;
address?: string;
}): Promise<AccessController>;
export class AccessController {
type: string;
address: string;
canAppend: (entry: LogEntry) => Promise<boolean>;
}
export function useDatabaseType(type: { type: string }): void;
export function IPFSAccessController(args: {
write: string[];
storage: Storage;
}): (args: {
orbitdb: OrbitDB;
identities: IdentitiesType;
address: string;
}) => Promise<{
type: "ipfs";
address: string;
write: string[];
canAppend: (entry: LogEntry) => Promise<boolean>;
}>;
export function Identities(args: {keystore?: KeyStoreType, path?: string, storage?: Storage, ipfs?: HeliaLibp2p}): Promise<IdentitiesType>;
export class IdentitiesType {
createIdentity;
getIdentity;
verifyIdentity: (identity) => boolean;
sign;
verify;
keystore;
}
export const Entry: {
create: (identity: Identity, id: string, payload: unknown, clock?: Clock, next?: string[], refs?: string[]) => Promise<LogEntry>;
verify: (identities: IdentitiesType, entry: LogEntry) => Promise<boolean>;
decode: (bytes: Uint8Array) => Promise<LogEntry>;
isEntry: (obj: object) => boolean;
isEqual: (a: LogEntry, b: LogEntry) => boolean;
};
export class Storage {
put;
get;
}
export function IPFSBlockStorage({
ipfs: IPFS,
pin: boolean,
}): Promise<Storage>;
export function LRUStorage({ size: number }): Promise<Storage>;
export function ComposedStorage(...args: Storage[]): Promise<Storage>;
export type OrbitDBDatabaseOptions = {
type: string;
AccessController?: typeof AccessControllerGenerator;
syncAutomatically?: boolean;
};
export type Clock = {
id: string;
time: number;
};
export type LogEntry<T = unknown> = {
id: string;
payload: { op: string; key: string | null; value?: T };
next: string[];
refs: string[];
clock: Clock;
v: Number;
key: string;
identity: string;
sig: string;
hash: string;
};
export type KeyValue = {
type: "keyvalue";
address: string;
put(key: string, value: unknown): Promise<string>;
set: KeyValue["put"];
del(key: string): Promise<string>;
get(key: string): Promise<unknown | undefined>;
all(): Promise<{ key: string; value: unknown; hash: string }[]>;
close(): Promise<void>;
drop(): Promise<void>;
events: EventEmitter;
access: AccessController;
log: Log;
};
export function KeyStore (args: {storage?: Storage, path?: string}): Promise<KeyStoreType>;
export type KeyStoreType = {
clear,
close,
hasKey,
addKey,
createKey,
getKey,
getPublic
}
}