-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
crypto-types.ts
70 lines (65 loc) · 1.93 KB
/
crypto-types.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
import {
AuthorAddress,
Base32String,
ShareAddress,
} from "../util/doc-types.ts";
import { ValidationError } from "../util/errors.ts";
import { UpdatableHash } from "./updatable_hash.ts";
export interface KeypairBytes {
pubkey: Uint8Array;
secret: Uint8Array;
}
/** A keypair used by individual entities to sign documents. */
export interface AuthorKeypair {
address: AuthorAddress;
secret: string;
}
/** A keypair used to write to a specific share */
export type ShareKeypair = {
shareAddress: ShareAddress;
secret: string;
};
/** Higher-level crypto functions. Not used directly for the most part, but useful for generating new keypairs. */
// These all handle base32-encoded strings.
export interface ICrypto {
sha256base32(
input: string | Uint8Array,
): Promise<Base32String>;
updatableSha256(): UpdatableHash<any>;
generateAuthorKeypair(
name: string,
): Promise<AuthorKeypair | ValidationError>;
generateShareKeypair(
name: string,
): Promise<ShareKeypair | ValidationError>;
sign(
keypair: AuthorKeypair | ShareKeypair,
msg: string | Uint8Array,
): Promise<Base32String | ValidationError>;
verify(
address: AuthorAddress | ShareAddress,
sig: Base32String,
msg: string | Uint8Array,
): Promise<boolean>;
checkKeypairIsValid(
keypair: AuthorKeypair | ShareKeypair,
): Promise<true | ValidationError>;
}
/** A crypto driver provides low-level access to an implementation providing ed25519 cryptography, e.g. Chloride, noble/ed25519, Node crypto. */
// These all handle Uint8Arrays (bytes)
export interface ICryptoDriver {
sha256(
input: string | Uint8Array,
): Promise<Uint8Array>;
updatableSha256(): UpdatableHash<any>;
generateKeypairBytes(): Promise<KeypairBytes>;
sign(
keypairBytes: KeypairBytes,
msg: string | Uint8Array,
): Promise<Uint8Array>;
verify(
publicKey: Uint8Array,
sig: Uint8Array,
msg: string | Uint8Array,
): Promise<boolean>;
}