-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPMessage.d.cts
More file actions
222 lines (222 loc) · 7.01 KB
/
SPMessage.d.cts
File metadata and controls
222 lines (222 loc) · 7.01 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import type { Key } from '@chelonia/crypto';
import { CURVE25519XSALSA20POLY1305, EDWARDS25519SHA512BATCH, XSALSA20POLY1305 } from '@chelonia/crypto';
import { serdesDeserializeSymbol, serdesSerializeSymbol, serdesTagSymbol } from '@chelonia/serdes';
import type { EncryptedData } from './encryptedData.cjs';
import type { SignedData } from './signedData.cjs';
import type { ChelContractState, JSONObject, JSONType } from './types.cjs';
export type SPKeyType = typeof EDWARDS25519SHA512BATCH | typeof CURVE25519XSALSA20POLY1305 | typeof XSALSA20POLY1305;
export type SPKeyPurpose = 'enc' | 'sig' | 'sak';
export type SPKey = {
id: string;
name: string;
purpose: SPKeyPurpose[];
ringLevel: number;
permissions: '*' | string[];
allowedActions?: '*' | string[];
permissionsContext?: '*' | string[];
meta?: {
quantity?: number;
expires?: number;
private?: {
transient?: boolean;
content?: EncryptedData<string>;
shareable?: boolean;
oldKeys?: string;
};
keyRequest?: {
contractID?: string;
reference?: string | EncryptedData<string>;
};
};
data: string;
foreignKey?: string;
_notBeforeHeight: number;
_notAfterHeight?: number;
_private?: string;
};
export type SPOpContract = {
type: string;
keys: (SPKey | EncryptedData<SPKey>)[];
parentContract?: string;
};
export type ProtoSPOpActionUnencrypted = {
action: string;
data: JSONType;
meta: JSONObject;
};
export type SPOpActionUnencrypted = ProtoSPOpActionUnencrypted | SignedData<ProtoSPOpActionUnencrypted>;
export type SPOpActionEncrypted = EncryptedData<SPOpActionUnencrypted>;
export type SPOpKeyAdd = (SPKey | EncryptedData<SPKey>)[];
export type SPOpKeyDel = (string | EncryptedData<string>)[];
export type SPOpPropSet = {
key: string;
value: JSONType;
};
export type ProtoSPOpKeyShare = {
contractID: string;
keys: SPKey[];
foreignContractID?: string;
keyRequestHash?: string;
keyRequestHeight?: number;
};
export type SPOpKeyShare = ProtoSPOpKeyShare | EncryptedData<ProtoSPOpKeyShare>;
export type ProtoSPOpKeyRequest = {
contractID: string;
height: number;
replyWith: SignedData<{
encryptionKeyId: string;
responseKey: EncryptedData<string>;
}>;
request: string;
};
export type SPOpKeyRequest = ProtoSPOpKeyRequest | EncryptedData<ProtoSPOpKeyRequest>;
export type ProtoSPOpKeyRequestSeen = {
keyRequestHash: string;
keyShareHash?: string;
success: boolean;
};
export type SPOpKeyRequestSeen = ProtoSPOpKeyRequestSeen | EncryptedData<ProtoSPOpKeyRequestSeen>;
export type SPKeyUpdate = {
name: string;
id?: string;
oldKeyId: string;
data?: string;
purpose?: string[];
permissions?: string[];
allowedActions?: '*' | string[];
permissionsContext?: '*' | string[];
meta?: {
quantity?: number;
expires?: number;
private?: {
transient?: boolean;
content?: string;
shareable?: boolean;
oldKeys?: string;
};
};
};
export type SPOpKeyUpdate = (SPKeyUpdate | EncryptedData<SPKeyUpdate>)[];
export type SPOpType = 'c' | 'a' | 'ae' | 'au' | 'ka' | 'kd' | 'ku' | 'pu' | 'ps' | 'pd' | 'ks' | 'kr' | 'krs';
type ProtoSPOpValue = SPOpContract | SPOpActionEncrypted | SPOpActionUnencrypted | SPOpKeyAdd | SPOpKeyDel | SPOpPropSet | SPOpKeyShare | SPOpKeyRequest | SPOpKeyRequestSeen | SPOpKeyUpdate;
export type ProtoSPOpMap = {
c: SPOpContract;
ae: SPOpActionEncrypted;
au: SPOpActionUnencrypted;
ka: SPOpKeyAdd;
kd: SPOpKeyDel;
ku: SPOpKeyUpdate;
pu: never;
ps: SPOpPropSet;
pd: never;
ks: SPOpKeyShare;
kr: SPOpKeyRequest;
krs: SPOpKeyRequestSeen;
};
export type SPOpAtomic = {
[K in keyof ProtoSPOpMap]: [K, ProtoSPOpMap[K]];
}[keyof ProtoSPOpMap][];
export type SPOpValue = ProtoSPOpValue | SPOpAtomic;
export type SPOpRaw = [SPOpType, SignedData<SPOpValue>];
export type SPOpMap = ProtoSPOpMap & {
a: SPOpAtomic;
};
export type SPOp = {
[K in keyof SPOpMap]: [K, SPOpMap[K]];
}[keyof SPOpMap];
export type SPMsgDirection = 'incoming' | 'outgoing';
export type SPHead = {
version: '1.0.0';
op: SPOpType;
height: number;
contractID: string | null;
previousKeyOp: string | null;
previousHEAD: string | null;
manifest: string;
};
type SPMsgParams = {
direction: SPMsgDirection;
mapping: {
key: string;
value: string;
};
head: SPHead;
signedMessageData: SignedData<SPOpValue>;
};
export declare class SPMessage {
_mapping: {
key: string;
value: string;
};
_head: SPHead;
_message: SPOpValue;
_signedMessageData: SignedData<SPOpValue>;
_direction: SPMsgDirection;
_decryptedValue?: unknown;
_innerSigningKeyId?: string;
static OP_CONTRACT: "c";
static OP_ACTION_ENCRYPTED: "ae";
static OP_ACTION_UNENCRYPTED: "au";
static OP_KEY_ADD: "ka";
static OP_KEY_DEL: "kd";
static OP_KEY_UPDATE: "ku";
static OP_PROTOCOL_UPGRADE: "pu";
static OP_PROP_SET: "ps";
static OP_PROP_DEL: "pd";
static OP_CONTRACT_AUTH: "ca";
static OP_CONTRACT_DEAUTH: "cd";
static OP_ATOMIC: "a";
static OP_KEY_SHARE: "ks";
static OP_KEY_REQUEST: "kr";
static OP_KEY_REQUEST_SEEN: "krs";
static createV1_0({ contractID, previousHEAD, previousKeyOp, height, op, manifest }: {
contractID: string | null;
previousHEAD?: string | null;
previousKeyOp?: string | null;
height?: number;
op: SPOpRaw;
manifest: string;
}): SPMessage;
static cloneWith(targetHead: SPHead, targetOp: SPOpRaw, sources: Partial<SPHead>): SPMessage;
static deserialize(value: string, additionalKeys?: Record<string, Key | string>, state?: ChelContractState, unwrapMaybeEncryptedDataFn?: (data: SPKey | EncryptedData<SPKey>) => {
encryptionKeyId: string | null;
data: SPKey;
} | undefined): SPMessage;
static deserializeHEAD(value: string): {
head: SPHead;
hash: string;
contractID: string;
isFirstMessage: boolean;
description: () => string;
};
constructor(params: SPMsgParams);
decryptedValue(): unknown | undefined;
innerSigningKeyId(): string | undefined;
head(): SPHead;
message(): SPOpValue;
op(): SPOp;
rawOp(): SPOpRaw;
opType(): SPOpType;
opValue(): SPOpValue;
signingKeyId(): string;
manifest(): string;
description(): string;
isFirstMessage(): boolean;
contractID(): string;
serialize(): string;
hash(): string;
previousKeyOp(): string | null;
height(): number;
id(): string;
direction(): 'incoming' | 'outgoing';
isKeyOp(): boolean;
static get [serdesTagSymbol](): string;
static [serdesSerializeSymbol](m: SPMessage): unknown[];
static [serdesDeserializeSymbol]([serialized, direction, decryptedValue, innerSigningKeyId]: [
string,
SPMsgDirection,
object,
string
]): SPMessage;
}
export {};