@nice-code/util 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +765 -0
- package/build/index.js +966 -1080
- package/build/index.js.map +1 -0
- package/package.json +9 -18
- package/build/types/core/core_valibot_schemas.d.ts +0 -13
- package/build/types/core/createDataStringConverter_stringToObject.d.ts +0 -12
- package/build/types/crypto/aes_gcm/createAesGcmKeyFromX25519Keys.d.ts +0 -6
- package/build/types/crypto/aes_gcm/decryptBytesWithAesGcmKey.d.ts +0 -9
- package/build/types/crypto/aes_gcm/decryptTextDataWithAesGcmKey.d.ts +0 -5
- package/build/types/crypto/aes_gcm/encryptBytesWithAesGcmKey.d.ts +0 -10
- package/build/types/crypto/aes_gcm/encryptTextDataWithAesGcmKey.d.ts +0 -5
- package/build/types/crypto/client_key_link/ClientCryptoKeyLink.d.ts +0 -181
- package/build/types/crypto/client_key_link/buildVerifyKeyBoundInfoString.d.ts +0 -20
- package/build/types/crypto/crypto.converters.d.ts +0 -53
- package/build/types/crypto/crypto.schema.d.ts +0 -92
- package/build/types/crypto/ed25519/generateEd25519KeyPair.d.ts +0 -1
- package/build/types/crypto/ed25519/importEd25519Key.d.ts +0 -35
- package/build/types/crypto/ed25519/serializeEd25519Key_Jwk.d.ts +0 -2
- package/build/types/crypto/ed25519/serializeEd25519Key_Raw.d.ts +0 -2
- package/build/types/crypto/ed25519/signCombinedTextDataWithKeyEd25519.d.ts +0 -2
- package/build/types/crypto/ed25519/signTextDataWithKeyEd25519.d.ts +0 -1
- package/build/types/crypto/ed25519/verifyWithKeyEd25519.d.ts +0 -5
- package/build/types/crypto/index.d.ts +0 -21
- package/build/types/crypto/x25519/createSharedBitsFromX25519.d.ts +0 -4
- package/build/types/crypto/x25519/generateX25519KeyPair.d.ts +0 -1
- package/build/types/crypto/x25519/importX25519Key.d.ts +0 -35
- package/build/types/crypto/x25519/serializeX25519Key_Jwk.d.ts +0 -2
- package/build/types/crypto/x25519/serializeX25519Key_Raw.d.ts +0 -2
- package/build/types/data_type/index.d.ts +0 -1
- package/build/types/data_type/string/nullEmpty.d.ts +0 -3
- package/build/types/index.d.ts +0 -10
- package/build/types/storage_adapter/StorageAdapter.d.ts +0 -23
- package/build/types/storage_adapter/specific/browser/browser_storage.d.ts +0 -26
- package/build/types/storage_adapter/specific/cloudflare/durable_object/durable_object_storage.d.ts +0 -14
- package/build/types/storage_adapter/specific/cloudflare/durable_object/durable_object_storage.types.d.ts +0 -18
- package/build/types/storage_adapter/specific/cloudflare/kv/kv_storage.d.ts +0 -18
- package/build/types/storage_adapter/specific/cloudflare/kv/kv_storage.types.d.ts +0 -22
- package/build/types/storage_adapter/specific/memory/memory_storage.d.ts +0 -28
- package/build/types/storage_adapter/storage_adapter.types.d.ts +0 -21
- package/build/types/storage_adapter/typed_storage/createTypedStorage.d.ts +0 -16
- package/build/types/typescript/special_typescript_types.d.ts +0 -1
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
//#region src/core/core_valibot_schemas.d.ts
|
|
4
|
+
type TTypeAndId<S extends string = string> = `${S}::${string}`;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/crypto/aes_gcm/createAesGcmKeyFromX25519Keys.d.ts
|
|
7
|
+
declare const createAesGcmKeyFromX25519Keys: ({
|
|
8
|
+
externalX25519PublicKey,
|
|
9
|
+
internalX25519PrivateKey,
|
|
10
|
+
infoString,
|
|
11
|
+
saltString
|
|
12
|
+
}: {
|
|
13
|
+
internalX25519PrivateKey: CryptoKey;
|
|
14
|
+
externalX25519PublicKey: CryptoKey;
|
|
15
|
+
saltString?: string;
|
|
16
|
+
infoString?: string;
|
|
17
|
+
}) => Promise<CryptoKey>;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/crypto/crypto.schema.d.ts
|
|
20
|
+
declare enum ECryptoKeyAlgo {
|
|
21
|
+
ed25519 = "ed25519",
|
|
22
|
+
x25519 = "x25519"
|
|
23
|
+
}
|
|
24
|
+
declare enum ECryptoKeyFormat {
|
|
25
|
+
raw_base64 = "raw_base64",
|
|
26
|
+
jwk = "jwk"
|
|
27
|
+
}
|
|
28
|
+
declare const vSerializedCryptoKeyDataEd25519_Raw: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
29
|
+
declare const vSerializedCryptoKeyDataEd25519_Jwk: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
30
|
+
type TSerializedCryptoKeyData_Ed25519_Raw = v.InferInput<typeof vSerializedCryptoKeyDataEd25519_Raw>;
|
|
31
|
+
type TSerializedCryptoKeyData_Ed25519_Raw_Transformed = {
|
|
32
|
+
formattedString: `${ECryptoKeyAlgo.ed25519}::${ECryptoKeyFormat.raw_base64}::${string}`;
|
|
33
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
34
|
+
format: ECryptoKeyFormat.raw_base64;
|
|
35
|
+
data: string;
|
|
36
|
+
};
|
|
37
|
+
type TSerializedCryptoKeyData_Ed25519_Jwk = v.InferInput<typeof vSerializedCryptoKeyDataEd25519_Jwk>;
|
|
38
|
+
type TSerializedCryptoKeyData_Ed25519_Jwk_Transformed = {
|
|
39
|
+
formattedString: `${ECryptoKeyAlgo.ed25519}::${ECryptoKeyFormat.jwk}::${string}`;
|
|
40
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
41
|
+
format: ECryptoKeyFormat.jwk;
|
|
42
|
+
data: JsonWebKey;
|
|
43
|
+
};
|
|
44
|
+
declare const vSerializedCryptoKeyDataX25519_Raw: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
45
|
+
declare const vSerializedCryptoKeyDataX25519_Jwk: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
46
|
+
declare const vCryptoKeyPairDataX25519: v.ObjectSchema<{
|
|
47
|
+
readonly publicKey: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
48
|
+
readonly privateKey: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
49
|
+
}, undefined>;
|
|
50
|
+
type TSerializedCryptoKeyPairDataX25519 = v.InferInput<typeof vCryptoKeyPairDataX25519>;
|
|
51
|
+
declare const vCryptoKeyPairDataEd25519: v.ObjectSchema<{
|
|
52
|
+
readonly publicKey: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
53
|
+
readonly privateKey: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
54
|
+
}, undefined>;
|
|
55
|
+
type TSerializedCryptoKeyPairDataEd25519 = v.InferInput<typeof vCryptoKeyPairDataEd25519>;
|
|
56
|
+
type TSerializedCryptoKeyData_X25519_Raw = v.InferInput<typeof vSerializedCryptoKeyDataX25519_Raw>;
|
|
57
|
+
type TSerializedCryptoKeyData_X25519_Raw_Transformed = {
|
|
58
|
+
formattedString: `${ECryptoKeyAlgo.x25519}::${ECryptoKeyFormat.raw_base64}::${string}`;
|
|
59
|
+
type: ECryptoKeyAlgo.x25519;
|
|
60
|
+
format: ECryptoKeyFormat.raw_base64;
|
|
61
|
+
data: string;
|
|
62
|
+
};
|
|
63
|
+
type TSerializedCryptoKeyData_X25519_Jwk = v.InferInput<typeof vSerializedCryptoKeyDataX25519_Jwk>;
|
|
64
|
+
type TSerializedCryptoKeyData_X25519_Jwk_Transformed = {
|
|
65
|
+
formattedString: `${ECryptoKeyAlgo.x25519}::${ECryptoKeyFormat.jwk}::${string}`;
|
|
66
|
+
type: ECryptoKeyAlgo.x25519;
|
|
67
|
+
format: ECryptoKeyFormat.jwk;
|
|
68
|
+
data: JsonWebKey;
|
|
69
|
+
};
|
|
70
|
+
declare const vVerifyChallengeWithSignature_Input: v.ObjectSchema<{
|
|
71
|
+
readonly challenge: v.StringSchema<undefined>;
|
|
72
|
+
readonly signatureBase64: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
|
|
73
|
+
}, undefined>;
|
|
74
|
+
declare const vVerifyChallengeWithSignature_WithThrow_Input: v.IntersectSchema<[v.ObjectSchema<{
|
|
75
|
+
readonly challenge: v.StringSchema<undefined>;
|
|
76
|
+
readonly signatureBase64: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
|
|
77
|
+
}, undefined>, v.ObjectSchema<{
|
|
78
|
+
readonly throwOnInvalid: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
79
|
+
}, undefined>], undefined>;
|
|
80
|
+
type TVerifyChallengeWithSignature_Input = v.InferInput<typeof vVerifyChallengeWithSignature_Input>;
|
|
81
|
+
type TVerifyChallengeWithSignature_WithThrow_Input = v.InferInput<typeof vVerifyChallengeWithSignature_WithThrow_Input>;
|
|
82
|
+
declare const vEncryptedAesGcmPayload: v.ObjectSchema<{
|
|
83
|
+
readonly nonce: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
|
|
84
|
+
readonly ciphertext: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
|
|
85
|
+
}, undefined>;
|
|
86
|
+
type TEncryptedAesGcmPayload = v.InferInput<typeof vEncryptedAesGcmPayload>;
|
|
87
|
+
type TEncryptedAesGcmPayload_Transformed = v.InferOutput<typeof vEncryptedAesGcmPayload>;
|
|
88
|
+
/**
|
|
89
|
+
* Raw-bytes counterpart of {@link TEncryptedAesGcmPayload} — keeps `nonce`/`ciphertext` as binary
|
|
90
|
+
* instead of base64 strings. For binary channels (e.g. msgpack WebSocket frames) this avoids the
|
|
91
|
+
* ~33% base64 inflation the text payload incurs.
|
|
92
|
+
*/
|
|
93
|
+
type TEncryptedAesGcmBytes = {
|
|
94
|
+
nonce: Uint8Array;
|
|
95
|
+
ciphertext: Uint8Array;
|
|
96
|
+
};
|
|
97
|
+
interface ISerializedKeyData<T, P> {
|
|
98
|
+
transformed: T;
|
|
99
|
+
prefixed: P;
|
|
100
|
+
}
|
|
101
|
+
interface ISerializedKeyData_Ed25519_Raw extends ISerializedKeyData<TSerializedCryptoKeyData_Ed25519_Raw_Transformed, TSerializedCryptoKeyData_Ed25519_Raw> {}
|
|
102
|
+
interface ISerializedKeyData_Ed25519_Jwk extends ISerializedKeyData<TSerializedCryptoKeyData_Ed25519_Jwk_Transformed, TSerializedCryptoKeyData_Ed25519_Jwk> {}
|
|
103
|
+
interface ISerializedKeyData_X25519_Raw extends ISerializedKeyData<TSerializedCryptoKeyData_X25519_Raw_Transformed, TSerializedCryptoKeyData_X25519_Raw> {}
|
|
104
|
+
interface ISerializedKeyData_X25519_Jwk extends ISerializedKeyData<TSerializedCryptoKeyData_X25519_Jwk_Transformed, TSerializedCryptoKeyData_X25519_Jwk> {}
|
|
105
|
+
type TSerializedKeyData = ISerializedKeyData_Ed25519_Raw | ISerializedKeyData_Ed25519_Jwk | ISerializedKeyData_X25519_Raw | ISerializedKeyData_X25519_Jwk;
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/crypto/aes_gcm/decryptBytesWithAesGcmKey.d.ts
|
|
108
|
+
/**
|
|
109
|
+
* Decrypts a raw-bytes AES-GCM payload (binary nonce + ciphertext) back to bytes. The counterpart of
|
|
110
|
+
* {@link decryptTextDataWithAesGcmKey}. AES-GCM verifies integrity, so a tampered ciphertext throws.
|
|
111
|
+
*/
|
|
112
|
+
declare const decryptBytesWithAesGcmKey: ({
|
|
113
|
+
aesGcmKey,
|
|
114
|
+
dataToDecrypt
|
|
115
|
+
}: {
|
|
116
|
+
aesGcmKey: CryptoKey;
|
|
117
|
+
dataToDecrypt: TEncryptedAesGcmBytes;
|
|
118
|
+
}) => Promise<Uint8Array>;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/crypto/aes_gcm/decryptTextDataWithAesGcmKey.d.ts
|
|
121
|
+
declare const decryptTextDataWithAesGcmKey: ({
|
|
122
|
+
aesGcmKey,
|
|
123
|
+
dataToDecrypt
|
|
124
|
+
}: {
|
|
125
|
+
aesGcmKey: CryptoKey;
|
|
126
|
+
dataToDecrypt: TEncryptedAesGcmPayload;
|
|
127
|
+
}) => Promise<string>;
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/crypto/aes_gcm/encryptBytesWithAesGcmKey.d.ts
|
|
130
|
+
/**
|
|
131
|
+
* Encrypts raw bytes with an AES-GCM key, returning the binary nonce + ciphertext. The bytes
|
|
132
|
+
* counterpart of {@link encryptTextDataWithAesGcmKey} — use it for binary channels (msgpack frames)
|
|
133
|
+
* to avoid base64 inflation. A fresh 12-byte nonce is generated per call (never reuse a nonce).
|
|
134
|
+
*/
|
|
135
|
+
declare const encryptBytesWithAesGcmKey: ({
|
|
136
|
+
aesGcmKey,
|
|
137
|
+
dataToEncrypt
|
|
138
|
+
}: {
|
|
139
|
+
aesGcmKey: CryptoKey;
|
|
140
|
+
dataToEncrypt: Uint8Array;
|
|
141
|
+
}) => Promise<TEncryptedAesGcmBytes>;
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/crypto/aes_gcm/encryptTextDataWithAesGcmKey.d.ts
|
|
144
|
+
declare const encryptTextDataWithAesGcmKey: ({
|
|
145
|
+
aesGcmKey,
|
|
146
|
+
dataToEncrypt
|
|
147
|
+
}: {
|
|
148
|
+
aesGcmKey: CryptoKey;
|
|
149
|
+
dataToEncrypt: string;
|
|
150
|
+
}) => Promise<TEncryptedAesGcmPayload>;
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/crypto/client_key_link/buildVerifyKeyBoundInfoString.d.ts
|
|
153
|
+
interface IBuildVerifyKeyBoundInfoString_Input {
|
|
154
|
+
infoString?: string;
|
|
155
|
+
verifyPublicKeys: [TSerializedCryptoKeyData_Ed25519_Raw, TSerializedCryptoKeyData_Ed25519_Raw];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The canonical HKDF `info` for a client-to-client shared key that binds both sides' verify
|
|
159
|
+
* public keys into the derivation.
|
|
160
|
+
*
|
|
161
|
+
* When the two keys are relayed through an intermediary, a tampered key produces mismatched AES
|
|
162
|
+
* keys on the two sides — the very first decryption fails, so key substitution is detected without
|
|
163
|
+
* any extra signature ceremony.
|
|
164
|
+
*
|
|
165
|
+
* The keys are sorted lexicographically so the result is independent of which side is "local" —
|
|
166
|
+
* both ends of a link compute the identical string without coordinating an order. Used internally
|
|
167
|
+
* by ClientCryptoKeyLink (`bindVerifyKeysIntoDerivation`); exported for code that derives the same
|
|
168
|
+
* key outside the link.
|
|
169
|
+
*/
|
|
170
|
+
declare const buildVerifyKeyBoundInfoString: ({
|
|
171
|
+
infoString,
|
|
172
|
+
verifyPublicKeys
|
|
173
|
+
}: IBuildVerifyKeyBoundInfoString_Input) => string;
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/storage_adapter/storage_adapter.types.d.ts
|
|
176
|
+
declare enum EStorageAdapterType {
|
|
177
|
+
string = "string",
|
|
178
|
+
json = "json"
|
|
179
|
+
}
|
|
180
|
+
interface IStorageAdapterMethods_String {
|
|
181
|
+
type: EStorageAdapterType.string;
|
|
182
|
+
setItem: (key: string, value: string) => Promise<void>;
|
|
183
|
+
getItem: (key: string) => Promise<string | null | undefined>;
|
|
184
|
+
removeItem: (key: string) => Promise<void>;
|
|
185
|
+
}
|
|
186
|
+
interface IStorageAdapterMethods_Json {
|
|
187
|
+
type: EStorageAdapterType.json;
|
|
188
|
+
setItem: <T>(key: string, value: T) => Promise<void>;
|
|
189
|
+
getItem: <T>(key: string) => Promise<T | null | undefined>;
|
|
190
|
+
removeItem: (key: string) => Promise<void>;
|
|
191
|
+
}
|
|
192
|
+
type TStorageAdapterMethods = IStorageAdapterMethods_String | IStorageAdapterMethods_Json;
|
|
193
|
+
interface IStorageKeyGetterAndSetter<T> {
|
|
194
|
+
get: () => Promise<T | undefined>;
|
|
195
|
+
set: (value: T) => Promise<void>;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/storage_adapter/StorageAdapter.d.ts
|
|
199
|
+
interface IStorageAdapterConstructor {
|
|
200
|
+
methods: TStorageAdapterMethods;
|
|
201
|
+
trackKeysForClearing?: boolean;
|
|
202
|
+
keyPrefix?: string;
|
|
203
|
+
}
|
|
204
|
+
declare class StorageAdapter {
|
|
205
|
+
private implementation;
|
|
206
|
+
readonly keyPrefix: string;
|
|
207
|
+
private readonly adapterStorage?;
|
|
208
|
+
constructor({
|
|
209
|
+
methods,
|
|
210
|
+
keyPrefix,
|
|
211
|
+
trackKeysForClearing: trackKeys
|
|
212
|
+
}: IStorageAdapterConstructor);
|
|
213
|
+
private getPrefixedKey;
|
|
214
|
+
private trackUsedKey;
|
|
215
|
+
private untrackUsedKey;
|
|
216
|
+
clearAll(): Promise<void>;
|
|
217
|
+
removeItem(rawKey: string): Promise<void>;
|
|
218
|
+
setJson(rawKey: string, value: any): Promise<void>;
|
|
219
|
+
getJson<T>(rawKey: string): Promise<T | undefined>;
|
|
220
|
+
getJsonOrDef<T>(rawKey: string, defVal: T): Promise<T>;
|
|
221
|
+
updateJson<T>(rawKey: string, updater: (currentVal: T | undefined) => T): Promise<T>;
|
|
222
|
+
updateJsonOrDef<T>(rawKey: string, defVal: T, updater: (currentVal: T) => T): Promise<T>;
|
|
223
|
+
createJsonGetterSetter<T>(rawKey: string): IStorageKeyGetterAndSetter<T>;
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/crypto/client_key_link/ClientCryptoKeyLink.d.ts
|
|
227
|
+
interface IClientCryptoKeyLink_Constructor {
|
|
228
|
+
storageAdapter?: StorageAdapter;
|
|
229
|
+
}
|
|
230
|
+
interface ILinkedClientPublicKeys {
|
|
231
|
+
verifyPublicKey?: TSerializedCryptoKeyData_Ed25519_Raw;
|
|
232
|
+
exchangePublicKey?: TSerializedCryptoKeyData_X25519_Raw;
|
|
233
|
+
}
|
|
234
|
+
interface ILocalPublicKeys {
|
|
235
|
+
verifyPublicKey: TSerializedCryptoKeyData_Ed25519_Raw;
|
|
236
|
+
exchangePublicKey: TSerializedCryptoKeyData_X25519_Raw;
|
|
237
|
+
}
|
|
238
|
+
interface ILinkClientKeys {
|
|
239
|
+
linkedClientId: TTypeAndId;
|
|
240
|
+
verifyPublicKey?: TSerializedCryptoKeyData_Ed25519_Raw;
|
|
241
|
+
exchangePublicKey?: TSerializedCryptoKeyData_X25519_Raw;
|
|
242
|
+
saltString?: string;
|
|
243
|
+
infoString?: string;
|
|
244
|
+
bindVerifyKeysIntoDerivation?: boolean;
|
|
245
|
+
}
|
|
246
|
+
interface IEncryptDataForLinkedClient {
|
|
247
|
+
linkedClientId: TTypeAndId;
|
|
248
|
+
dataToEncrypt: string;
|
|
249
|
+
}
|
|
250
|
+
interface IDecryptDataFromLinkedClient {
|
|
251
|
+
linkedClientId: TTypeAndId;
|
|
252
|
+
dataToDecrypt: TEncryptedAesGcmPayload;
|
|
253
|
+
}
|
|
254
|
+
interface IDecryptAndVerifyDataFromLinkedClient extends IDecryptDataFromLinkedClient {
|
|
255
|
+
signatureBase64: string;
|
|
256
|
+
}
|
|
257
|
+
interface IVerifyChallengeFromLinkedClient {
|
|
258
|
+
linkedClientId: TTypeAndId;
|
|
259
|
+
challenge: string;
|
|
260
|
+
signatureBase64: string;
|
|
261
|
+
}
|
|
262
|
+
declare class ClientCryptoKeyLink {
|
|
263
|
+
private localExchangeKeyPair;
|
|
264
|
+
private localVerifyKeyPair;
|
|
265
|
+
private linkedClientKeys;
|
|
266
|
+
private storage;
|
|
267
|
+
private initialized;
|
|
268
|
+
private initializePromise;
|
|
269
|
+
private localExchangeKeyPairPromise;
|
|
270
|
+
private localVerifyKeyPairPromise;
|
|
271
|
+
constructor({
|
|
272
|
+
storageAdapter
|
|
273
|
+
}?: IClientCryptoKeyLink_Constructor);
|
|
274
|
+
/**
|
|
275
|
+
* Loads the local key pairs and any linked client public keys from storage (when a storage
|
|
276
|
+
* adapter was provided), generating and persisting fresh local key pairs if none exist yet.
|
|
277
|
+
*
|
|
278
|
+
* Must be called (and awaited) before any sign/verify/encrypt/decrypt operation.
|
|
279
|
+
*/
|
|
280
|
+
initialize(): Promise<void>;
|
|
281
|
+
private runInitialize;
|
|
282
|
+
/**
|
|
283
|
+
* Loads the local key pairs from storage if they were previously persisted. Does NOT generate
|
|
284
|
+
* fresh keys — local identity is created lazily on first use (see {@link ensureLocalExchangeKeyPair}
|
|
285
|
+
* / {@link ensureLocalVerifyKeyPair}), so a verify-only or otherwise key-less consumer never
|
|
286
|
+
* generates or stores keys it does not need.
|
|
287
|
+
*/
|
|
288
|
+
private loadStoredLocalKeys;
|
|
289
|
+
/**
|
|
290
|
+
* Returns the local exchange (X25519) key pair, generating and persisting it on first use.
|
|
291
|
+
* Concurrent callers share a single generation.
|
|
292
|
+
*/
|
|
293
|
+
private ensureLocalExchangeKeyPair;
|
|
294
|
+
/**
|
|
295
|
+
* Returns the local verify (Ed25519) key pair, generating and persisting it on first use.
|
|
296
|
+
* Concurrent callers share a single generation.
|
|
297
|
+
*/
|
|
298
|
+
private ensureLocalVerifyKeyPair;
|
|
299
|
+
private loadLinkedClients;
|
|
300
|
+
private serializeExchangeKeyPair;
|
|
301
|
+
private serializeVerifyKeyPair;
|
|
302
|
+
/**
|
|
303
|
+
* The local public keys that should be shared with a linked client so that it can verify this
|
|
304
|
+
* client's signatures and derive a shared encryption key. Generates the local identity on first
|
|
305
|
+
* use.
|
|
306
|
+
*/
|
|
307
|
+
getLocalPublicKeys(): Promise<ILocalPublicKeys>;
|
|
308
|
+
/**
|
|
309
|
+
* The local exchange (X25519) public key, generating the exchange key pair on first use. Does not
|
|
310
|
+
* touch the verify key pair — useful for an exchange-only consumer (e.g. a bridge) that never
|
|
311
|
+
* signs.
|
|
312
|
+
*/
|
|
313
|
+
getLocalExchangePublicKey(): Promise<TSerializedCryptoKeyData_X25519_Raw>;
|
|
314
|
+
/**
|
|
315
|
+
* The local verify (Ed25519) public key, generating the verify key pair on first use. Does not
|
|
316
|
+
* touch the exchange key pair.
|
|
317
|
+
*/
|
|
318
|
+
getLocalVerifyPublicKey(): Promise<TSerializedCryptoKeyData_Ed25519_Raw>;
|
|
319
|
+
/**
|
|
320
|
+
* Registers (or updates) the public keys of a linked client in memory only — nothing is written
|
|
321
|
+
* to storage. Use this for ephemeral links (e.g. a per-session bridge or end-to-end peer keyed by
|
|
322
|
+
* a session salt/info), so the derived shared key never outlives the process.
|
|
323
|
+
*
|
|
324
|
+
* Re-linking with a new exchange public key, salt, or info invalidates any previously cached
|
|
325
|
+
* shared key for the link.
|
|
326
|
+
*/
|
|
327
|
+
linkClient({
|
|
328
|
+
linkedClientId,
|
|
329
|
+
verifyPublicKey,
|
|
330
|
+
exchangePublicKey,
|
|
331
|
+
saltString,
|
|
332
|
+
infoString,
|
|
333
|
+
bindVerifyKeysIntoDerivation
|
|
334
|
+
}: ILinkClientKeys): Promise<void>;
|
|
335
|
+
/**
|
|
336
|
+
* Like {@link linkClient}, but also persists the linked client's public keys (and salt/info) to
|
|
337
|
+
* storage so the link survives a reload.
|
|
338
|
+
*
|
|
339
|
+
* NOTE: salt/info are written in plaintext. When they are session secrets (e.g. a partner secret
|
|
340
|
+
* or bridge salt), prefer {@link linkClient} and re-establish the link per session instead.
|
|
341
|
+
*/
|
|
342
|
+
linkClientAndStore(input: ILinkClientKeys): Promise<void>;
|
|
343
|
+
/**
|
|
344
|
+
* Whether a linked client is currently registered (in memory) under this id.
|
|
345
|
+
*/
|
|
346
|
+
hasLinkedClient(linkedClientId: TTypeAndId): boolean;
|
|
347
|
+
/**
|
|
348
|
+
* The serialized public keys registered for a linked client, or undefined when the client is not
|
|
349
|
+
* linked. Useful when a holder needs to relay a linked client's keys onward (e.g. a backend
|
|
350
|
+
* relaying a wallet's verify key to a partner).
|
|
351
|
+
*/
|
|
352
|
+
getLinkedClientPublicKeys(linkedClientId: TTypeAndId): ILinkedClientPublicKeys | undefined;
|
|
353
|
+
/**
|
|
354
|
+
* Removes a single linked client from memory and, when storage is available, from persisted
|
|
355
|
+
* state. Any cached shared key for the link is dropped with it.
|
|
356
|
+
*/
|
|
357
|
+
unlinkClient(linkedClientId: TTypeAndId): Promise<void>;
|
|
358
|
+
/**
|
|
359
|
+
* Removes all linked clients from memory and persisted state, while keeping the local identity
|
|
360
|
+
* key pairs intact.
|
|
361
|
+
*/
|
|
362
|
+
unlinkAllClients(): Promise<void>;
|
|
363
|
+
/**
|
|
364
|
+
* Wipes everything this instance owns — local identity key pairs and all linked clients, in
|
|
365
|
+
* memory and in storage. After a reset, {@link initialize} must be called again before use (it
|
|
366
|
+
* will generate a fresh local identity).
|
|
367
|
+
*
|
|
368
|
+
* Only the keys owned by this util are removed, so a shared storage adapter's other data is left
|
|
369
|
+
* untouched.
|
|
370
|
+
*/
|
|
371
|
+
reset(): Promise<void>;
|
|
372
|
+
private getLinkedClient;
|
|
373
|
+
private getAesGcmKeyForLinkedClient;
|
|
374
|
+
encryptDataForLinkedClient({
|
|
375
|
+
dataToEncrypt,
|
|
376
|
+
linkedClientId
|
|
377
|
+
}: IEncryptDataForLinkedClient): Promise<TEncryptedAesGcmPayload>;
|
|
378
|
+
decryptDataFromLinkedClient({
|
|
379
|
+
dataToDecrypt,
|
|
380
|
+
linkedClientId
|
|
381
|
+
}: IDecryptDataFromLinkedClient): Promise<string>;
|
|
382
|
+
/**
|
|
383
|
+
* Bytes counterpart of {@link encryptDataForLinkedClient} — encrypts raw bytes with the shared
|
|
384
|
+
* AES-GCM key, returning a binary nonce + ciphertext. Use it for binary channels (e.g. msgpack
|
|
385
|
+
* WebSocket frames) to avoid base64 inflation.
|
|
386
|
+
*/
|
|
387
|
+
encryptBytesForLinkedClient({
|
|
388
|
+
dataToEncrypt,
|
|
389
|
+
linkedClientId
|
|
390
|
+
}: {
|
|
391
|
+
dataToEncrypt: Uint8Array;
|
|
392
|
+
linkedClientId: TTypeAndId;
|
|
393
|
+
}): Promise<TEncryptedAesGcmBytes>;
|
|
394
|
+
/** Bytes counterpart of {@link decryptDataFromLinkedClient}. */
|
|
395
|
+
decryptBytesFromLinkedClient({
|
|
396
|
+
dataToDecrypt,
|
|
397
|
+
linkedClientId
|
|
398
|
+
}: {
|
|
399
|
+
dataToDecrypt: TEncryptedAesGcmBytes;
|
|
400
|
+
linkedClientId: TTypeAndId;
|
|
401
|
+
}): Promise<Uint8Array>;
|
|
402
|
+
signAndEncryptDataForLinkedClient({
|
|
403
|
+
dataToEncrypt,
|
|
404
|
+
linkedClientId
|
|
405
|
+
}: IEncryptDataForLinkedClient): Promise<{
|
|
406
|
+
encryptedData: TEncryptedAesGcmPayload;
|
|
407
|
+
signatureBase64: string;
|
|
408
|
+
}>;
|
|
409
|
+
/**
|
|
410
|
+
* Decrypts a payload from a linked client and verifies that the decrypted plaintext was signed
|
|
411
|
+
* by that client. Counterpart to {@link signAndEncryptDataForLinkedClient}.
|
|
412
|
+
*
|
|
413
|
+
* Returns the decrypted `data` alongside `isValid` — the caller decides how to handle an invalid
|
|
414
|
+
* signature. (A tampered ciphertext fails earlier at AES-GCM decryption.)
|
|
415
|
+
*/
|
|
416
|
+
decryptAndVerifyDataFromLinkedClient({
|
|
417
|
+
dataToDecrypt,
|
|
418
|
+
linkedClientId,
|
|
419
|
+
signatureBase64
|
|
420
|
+
}: IDecryptAndVerifyDataFromLinkedClient): Promise<{
|
|
421
|
+
data: string;
|
|
422
|
+
isValid: boolean;
|
|
423
|
+
}>;
|
|
424
|
+
signChallenge(challenge: [string, ...string[]]): Promise<{
|
|
425
|
+
signatureBase64: string;
|
|
426
|
+
}>;
|
|
427
|
+
/**
|
|
428
|
+
* Verifies a signature over `challenge` against the linked client's verify (Ed25519) public key.
|
|
429
|
+
*/
|
|
430
|
+
verifyChallengeFromLinkedClient({
|
|
431
|
+
linkedClientId,
|
|
432
|
+
challenge,
|
|
433
|
+
signatureBase64
|
|
434
|
+
}: IVerifyChallengeFromLinkedClient): Promise<boolean>;
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/crypto/crypto.converters.d.ts
|
|
438
|
+
/**
|
|
439
|
+
*
|
|
440
|
+
* [CRYPTO ALGO] ED25519
|
|
441
|
+
*
|
|
442
|
+
*/
|
|
443
|
+
declare const convertEd25519RawDataStringToObject: (inputDataString: `ed25519::raw_base64::${string}`) => {
|
|
444
|
+
formattedString: `ed25519::raw_base64::${string}`;
|
|
445
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
446
|
+
format: ECryptoKeyFormat.raw_base64;
|
|
447
|
+
data: string;
|
|
448
|
+
};
|
|
449
|
+
declare const convertEd25519JwkDataStringToObject: (inputDataString: `ed25519::jwk::${string}`) => {
|
|
450
|
+
formattedString: `ed25519::jwk::${string}`;
|
|
451
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
452
|
+
format: ECryptoKeyFormat.jwk;
|
|
453
|
+
data: JsonWebKey;
|
|
454
|
+
};
|
|
455
|
+
declare const convertEd25519FormattedStringToObject: (inputDataString: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`) => {
|
|
456
|
+
formattedString: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`;
|
|
457
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
458
|
+
format: ECryptoKeyFormat;
|
|
459
|
+
data: string;
|
|
460
|
+
};
|
|
461
|
+
declare const convertEd25519RawDataStringToSerializedKeyData: (input: TSerializedCryptoKeyData_Ed25519_Raw) => ISerializedKeyData_Ed25519_Raw;
|
|
462
|
+
declare const convertEd25519JwkDataStringToSerializedKeyData: (input: TSerializedCryptoKeyData_Ed25519_Jwk) => ISerializedKeyData_Ed25519_Jwk;
|
|
463
|
+
declare const convertEd25519FormattedStringToSerializedKeyData: <I extends TSerializedCryptoKeyData_Ed25519_Raw | TSerializedCryptoKeyData_Ed25519_Jwk, O extends (I extends TSerializedCryptoKeyData_Ed25519_Raw ? TSerializedCryptoKeyData_Ed25519_Raw_Transformed : TSerializedCryptoKeyData_Ed25519_Jwk_Transformed)>(input: I) => O;
|
|
464
|
+
/**
|
|
465
|
+
*
|
|
466
|
+
* [CRYPTO ALGO] X25519
|
|
467
|
+
*
|
|
468
|
+
*/
|
|
469
|
+
declare const convertX25519RawDataStringToObject: (inputDataString: `x25519::raw_base64::${string}`) => {
|
|
470
|
+
formattedString: `x25519::raw_base64::${string}`;
|
|
471
|
+
type: ECryptoKeyAlgo.x25519;
|
|
472
|
+
format: ECryptoKeyFormat.raw_base64;
|
|
473
|
+
data: string;
|
|
474
|
+
};
|
|
475
|
+
declare const convertX25519JwkDataStringToObject: (inputDataString: `x25519::jwk::${string}`) => {
|
|
476
|
+
formattedString: `x25519::jwk::${string}`;
|
|
477
|
+
type: ECryptoKeyAlgo.x25519;
|
|
478
|
+
format: ECryptoKeyFormat.jwk;
|
|
479
|
+
data: JsonWebKey;
|
|
480
|
+
};
|
|
481
|
+
declare const convertX25519FormattedStringToObject: (inputDataString: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`) => {
|
|
482
|
+
formattedString: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`;
|
|
483
|
+
type: ECryptoKeyAlgo.x25519;
|
|
484
|
+
format: ECryptoKeyFormat;
|
|
485
|
+
data: string;
|
|
486
|
+
};
|
|
487
|
+
declare const convertX25519RawDataStringToSerializedKeyData: (input: TSerializedCryptoKeyData_X25519_Raw) => ISerializedKeyData_X25519_Raw;
|
|
488
|
+
declare const convertX25519JwkDataStringToSerializedKeyData: (input: TSerializedCryptoKeyData_X25519_Jwk) => ISerializedKeyData_X25519_Jwk;
|
|
489
|
+
declare const convertX25519FormattedStringToSerializedKeyData: <I extends TSerializedCryptoKeyData_X25519_Raw | TSerializedCryptoKeyData_X25519_Jwk, O extends (I extends TSerializedCryptoKeyData_X25519_Raw ? TSerializedCryptoKeyData_X25519_Raw_Transformed : TSerializedCryptoKeyData_X25519_Jwk_Transformed)>(input: I) => O;
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/crypto/ed25519/generateEd25519KeyPair.d.ts
|
|
492
|
+
declare const generateEd25519KeyPair: () => Promise<CryptoKeyPair>;
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/crypto/ed25519/importEd25519Key.d.ts
|
|
495
|
+
declare const importEd25519Key: {
|
|
496
|
+
private: {
|
|
497
|
+
fromFormattedString: {
|
|
498
|
+
readonly extractable: (input: `ed25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
499
|
+
readonly nonExtractable: (input: `ed25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
500
|
+
};
|
|
501
|
+
fromSerializedObject: {
|
|
502
|
+
readonly extractable: (input: TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
503
|
+
readonly nonExtractable: (input: TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
504
|
+
};
|
|
505
|
+
fromJwk: {
|
|
506
|
+
readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
507
|
+
readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
public: {
|
|
511
|
+
fromBase64: {
|
|
512
|
+
readonly extractable: (input: string) => Promise<CryptoKey>;
|
|
513
|
+
readonly nonExtractable: (input: string) => Promise<CryptoKey>;
|
|
514
|
+
};
|
|
515
|
+
fromFormattedString: {
|
|
516
|
+
readonly extractable: (input: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
517
|
+
readonly nonExtractable: (input: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
518
|
+
};
|
|
519
|
+
fromSerializedObject: {
|
|
520
|
+
readonly extractable: (input: TSerializedCryptoKeyData_Ed25519_Raw_Transformed | TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
521
|
+
readonly nonExtractable: (input: TSerializedCryptoKeyData_Ed25519_Raw_Transformed | TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
522
|
+
};
|
|
523
|
+
fromJwk: {
|
|
524
|
+
readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
525
|
+
readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
//#endregion
|
|
530
|
+
//#region src/crypto/ed25519/serializeEd25519Key_Jwk.d.ts
|
|
531
|
+
declare const serializeEd25519Key_Jwk: (key: CryptoKey) => Promise<ISerializedKeyData_Ed25519_Jwk>;
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region src/crypto/ed25519/serializeEd25519Key_Raw.d.ts
|
|
534
|
+
declare const serializeEd25519Key_Raw: (publicKey: CryptoKey) => Promise<ISerializedKeyData_Ed25519_Raw>;
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/crypto/ed25519/signCombinedTextDataWithKeyEd25519.d.ts
|
|
537
|
+
declare const DEFAULT_COMBINED_TEXT_DATA_SEPARATOR = "::";
|
|
538
|
+
declare const signCombinedTextDataWithKeyEd25519: (data: string[], cryptoKey: CryptoKey, separator?: string) => Promise<Uint8Array>;
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/crypto/ed25519/signTextDataWithKeyEd25519.d.ts
|
|
541
|
+
declare const signTextDataWithKeyEd25519: (data: string, cryptoKey: CryptoKey) => Promise<Uint8Array>;
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region src/crypto/ed25519/verifyWithKeyEd25519.d.ts
|
|
544
|
+
declare const verifyWithKeyEd25519: ({
|
|
545
|
+
challenge,
|
|
546
|
+
signatureBase64,
|
|
547
|
+
publicKey
|
|
548
|
+
}: {
|
|
549
|
+
challenge: string;
|
|
550
|
+
signatureBase64: string;
|
|
551
|
+
publicKey: CryptoKey;
|
|
552
|
+
}) => Promise<boolean>;
|
|
553
|
+
//#endregion
|
|
554
|
+
//#region src/crypto/x25519/createSharedBitsFromX25519.d.ts
|
|
555
|
+
declare const createSharedBitsFromX25519: ({
|
|
556
|
+
privateKey,
|
|
557
|
+
publicKey
|
|
558
|
+
}: {
|
|
559
|
+
privateKey: CryptoKey;
|
|
560
|
+
publicKey: CryptoKey;
|
|
561
|
+
}) => Promise<Uint8Array>;
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region src/crypto/x25519/generateX25519KeyPair.d.ts
|
|
564
|
+
declare const generateX25519KeyPair: () => Promise<CryptoKeyPair>;
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region src/crypto/x25519/importX25519Key.d.ts
|
|
567
|
+
declare const importX25519Key: {
|
|
568
|
+
private: {
|
|
569
|
+
fromFormattedString: {
|
|
570
|
+
readonly extractable: (input: `x25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
571
|
+
readonly nonExtractable: (input: `x25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
572
|
+
};
|
|
573
|
+
fromSerializedObject: {
|
|
574
|
+
readonly extractable: (input: TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
575
|
+
readonly nonExtractable: (input: TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
576
|
+
};
|
|
577
|
+
fromJwk: {
|
|
578
|
+
readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
579
|
+
readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
580
|
+
};
|
|
581
|
+
};
|
|
582
|
+
public: {
|
|
583
|
+
fromBase64: {
|
|
584
|
+
readonly extractable: (input: string) => Promise<CryptoKey>;
|
|
585
|
+
readonly nonExtractable: (input: string) => Promise<CryptoKey>;
|
|
586
|
+
};
|
|
587
|
+
fromFormattedString: {
|
|
588
|
+
readonly extractable: (input: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
589
|
+
readonly nonExtractable: (input: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
590
|
+
};
|
|
591
|
+
fromSerializedObject: {
|
|
592
|
+
readonly extractable: (input: TSerializedCryptoKeyData_X25519_Raw_Transformed | TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
593
|
+
readonly nonExtractable: (input: TSerializedCryptoKeyData_X25519_Raw_Transformed | TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
594
|
+
};
|
|
595
|
+
fromJwk: {
|
|
596
|
+
readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
597
|
+
readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
};
|
|
601
|
+
//#endregion
|
|
602
|
+
//#region src/crypto/x25519/serializeX25519Key_Jwk.d.ts
|
|
603
|
+
declare const serializeX25519Key_Jwk: (key: CryptoKey) => Promise<ISerializedKeyData_X25519_Jwk>;
|
|
604
|
+
//#endregion
|
|
605
|
+
//#region src/crypto/x25519/serializeX25519Key_Raw.d.ts
|
|
606
|
+
declare const serializeX25519Key_Raw: (key: CryptoKey) => Promise<ISerializedKeyData_X25519_Raw>;
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/typescript/special_typescript_types.d.ts
|
|
609
|
+
type StringKeys<T> = keyof T & string;
|
|
610
|
+
//#endregion
|
|
611
|
+
//#region src/storage_adapter/typed_storage/createTypedStorage.d.ts
|
|
612
|
+
interface ITypedStorage<T extends Record<string, any>> {
|
|
613
|
+
getJson<K extends StringKeys<T>>(key: K): Promise<T[K] | undefined>;
|
|
614
|
+
getJsonOrDef<K extends StringKeys<T>>(key: K, defVal: T[K]): Promise<T[K]>;
|
|
615
|
+
setJson<K extends StringKeys<T>>(key: K, val: T[K]): Promise<void>;
|
|
616
|
+
removeItem<K extends StringKeys<T>>(key: K): Promise<void>;
|
|
617
|
+
updateJson<K extends StringKeys<T>>(key: K, updater: (currentVal: T[K] | undefined) => T[K]): Promise<void>;
|
|
618
|
+
updateJsonWithDef<K extends StringKeys<T>>(key: K, defaultVal: T[K], updater: (currentVal: T[K]) => T[K]): Promise<void>;
|
|
619
|
+
clearAll(): Promise<void>;
|
|
620
|
+
}
|
|
621
|
+
interface ITypedStorage_Create_Input {
|
|
622
|
+
storageAdapter: StorageAdapter;
|
|
623
|
+
}
|
|
624
|
+
declare function createTypedStorage<T extends Record<string, any>>({
|
|
625
|
+
storageAdapter
|
|
626
|
+
}: ITypedStorage_Create_Input): ITypedStorage<T>;
|
|
627
|
+
//#endregion
|
|
628
|
+
//#region src/storage_adapter/specific/browser/browser_storage.d.ts
|
|
629
|
+
/**
|
|
630
|
+
*
|
|
631
|
+
* Web Storage [LOCAL STORAGE]
|
|
632
|
+
*
|
|
633
|
+
*/
|
|
634
|
+
type TCreateWebLocalStorageOptions = Omit<IStorageAdapterConstructor, "methods"> & {
|
|
635
|
+
localStorage: typeof localStorage;
|
|
636
|
+
};
|
|
637
|
+
declare function createWebLocalStorageMethods(_localStorage: typeof localStorage): IStorageAdapterMethods_String;
|
|
638
|
+
declare const createWebLocalStorageAdapter: ({
|
|
639
|
+
localStorage: _localStorage,
|
|
640
|
+
...options
|
|
641
|
+
}: TCreateWebLocalStorageOptions) => StorageAdapter;
|
|
642
|
+
declare function createTypedWebLocalStorage<T extends Record<string, any>>(options: TCreateWebLocalStorageOptions): ITypedStorage<T>;
|
|
643
|
+
/**
|
|
644
|
+
*
|
|
645
|
+
* Web Storage [SESSION STORAGE]
|
|
646
|
+
*
|
|
647
|
+
*/
|
|
648
|
+
type TCreateWebSessionStorageOptions = Omit<IStorageAdapterConstructor, "methods"> & {
|
|
649
|
+
sessionStorage: typeof sessionStorage;
|
|
650
|
+
};
|
|
651
|
+
declare function createWebSessionStorageMethods(_sessionStorage: typeof sessionStorage): IStorageAdapterMethods_String;
|
|
652
|
+
declare const createWebSessionStorageAdapter: ({
|
|
653
|
+
sessionStorage: _sessionStorage,
|
|
654
|
+
...options
|
|
655
|
+
}: TCreateWebSessionStorageOptions) => StorageAdapter;
|
|
656
|
+
declare function createTypedWebSessionStorage<T extends Record<string, any>>(options: TCreateWebSessionStorageOptions): ITypedStorage<T>;
|
|
657
|
+
//#endregion
|
|
658
|
+
//#region src/storage_adapter/specific/cloudflare/durable_object/durable_object_storage.types.d.ts
|
|
659
|
+
interface DurableObjectGetOptions {
|
|
660
|
+
allowConcurrency?: boolean;
|
|
661
|
+
noCache?: boolean;
|
|
662
|
+
}
|
|
663
|
+
interface DurableObjectPutOptions {
|
|
664
|
+
allowConcurrency?: boolean;
|
|
665
|
+
allowUnconfirmed?: boolean;
|
|
666
|
+
noCache?: boolean;
|
|
667
|
+
}
|
|
668
|
+
interface IDurableObjectStorage {
|
|
669
|
+
get<T = unknown>(key: string, options?: DurableObjectGetOptions): Promise<T | undefined>;
|
|
670
|
+
get<T = unknown>(keys: string[], options?: DurableObjectGetOptions): Promise<Map<string, T>>;
|
|
671
|
+
put<T>(key: string, value: T, options?: DurableObjectPutOptions): Promise<void>;
|
|
672
|
+
put<T>(entries: Record<string, T>, options?: DurableObjectPutOptions): Promise<void>;
|
|
673
|
+
delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>;
|
|
674
|
+
delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>;
|
|
675
|
+
}
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region src/storage_adapter/specific/cloudflare/durable_object/durable_object_storage.d.ts
|
|
678
|
+
declare function createDurableObjectStorageMethods(durableObjectStorage: IDurableObjectStorage): IStorageAdapterMethods_Json;
|
|
679
|
+
type TCreateDurableObjectStorageOptions = Omit<IStorageAdapterConstructor, "methods"> & {
|
|
680
|
+
durableObjectStorage: IDurableObjectStorage;
|
|
681
|
+
};
|
|
682
|
+
/**
|
|
683
|
+
* Wraps a Durable Object's storage in the generic StorageAdapter interface, e.g. for handing to a
|
|
684
|
+
* ClientCryptoKeyLink so it can persist its keys inside the DO's own storage.
|
|
685
|
+
*/
|
|
686
|
+
declare const createDurableObjectStorageAdapter: ({
|
|
687
|
+
durableObjectStorage,
|
|
688
|
+
...options
|
|
689
|
+
}: TCreateDurableObjectStorageOptions) => StorageAdapter;
|
|
690
|
+
declare function createDurableObjectTypedStorage<T extends Record<string, any>>(options: TCreateDurableObjectStorageOptions): ITypedStorage<T>;
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region src/storage_adapter/specific/cloudflare/kv/kv_storage.types.d.ts
|
|
693
|
+
interface IKVNamespaceGetOptions {
|
|
694
|
+
cacheTtl?: number;
|
|
695
|
+
}
|
|
696
|
+
interface IKVNamespacePutOptions {
|
|
697
|
+
/** Absolute time (seconds since epoch) at which the key should expire. */
|
|
698
|
+
expiration?: number;
|
|
699
|
+
/** Relative TTL (in seconds) from now, after which the key should expire. */
|
|
700
|
+
expirationTtl?: number;
|
|
701
|
+
metadata?: unknown;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Minimal subset of Cloudflare's `KVNamespace` binding that our storage adapter relies on. Values
|
|
705
|
+
* are always written/read as strings (KV's `put` only accepts string/stream/buffer values), so the
|
|
706
|
+
* adapter is a {@link EStorageAdapterType.string} adapter and JSON (de)serialization happens in the
|
|
707
|
+
* generic `StorageAdapter`.
|
|
708
|
+
*/
|
|
709
|
+
interface IKVNamespace {
|
|
710
|
+
get(key: string, options?: IKVNamespaceGetOptions): Promise<string | null>;
|
|
711
|
+
put(key: string, value: string, options?: IKVNamespacePutOptions): Promise<void>;
|
|
712
|
+
delete(key: string): Promise<void>;
|
|
713
|
+
}
|
|
714
|
+
//#endregion
|
|
715
|
+
//#region src/storage_adapter/specific/cloudflare/kv/kv_storage.d.ts
|
|
716
|
+
interface ICreateKVStorageMethodsOptions {
|
|
717
|
+
/** The `KVNamespace` binding, e.g. accessed off `env.MY_KV` inside a worker. */
|
|
718
|
+
kvNamespace: IKVNamespace;
|
|
719
|
+
/** Default options applied to every `put`, e.g. `{ expirationTtl }` for TTL-based eviction. */
|
|
720
|
+
defaultPutOptions?: IKVNamespacePutOptions;
|
|
721
|
+
}
|
|
722
|
+
declare function createKVStorageMethods({
|
|
723
|
+
kvNamespace,
|
|
724
|
+
defaultPutOptions
|
|
725
|
+
}: ICreateKVStorageMethodsOptions): IStorageAdapterMethods_String;
|
|
726
|
+
type TCreateKVStorageOptions = Omit<IStorageAdapterConstructor, "methods"> & ICreateKVStorageMethodsOptions;
|
|
727
|
+
/**
|
|
728
|
+
* Wraps a Cloudflare KV namespace binding in the generic StorageAdapter interface, e.g. for handing
|
|
729
|
+
* to a ClientCryptoKeyLink so it can persist its keys inside KV.
|
|
730
|
+
*/
|
|
731
|
+
declare const createKVStorageAdapter: ({
|
|
732
|
+
kvNamespace,
|
|
733
|
+
defaultPutOptions,
|
|
734
|
+
...options
|
|
735
|
+
}: TCreateKVStorageOptions) => StorageAdapter;
|
|
736
|
+
declare function createKVTypedStorage<T extends Record<string, any>>(options: TCreateKVStorageOptions): ITypedStorage<T>;
|
|
737
|
+
//#endregion
|
|
738
|
+
//#region src/storage_adapter/specific/memory/memory_storage.d.ts
|
|
739
|
+
type TMemoryStorage_string = Map<string, string>;
|
|
740
|
+
type TMemoryStorage_json = Map<string, any>;
|
|
741
|
+
/**
|
|
742
|
+
*
|
|
743
|
+
* Memory Storage [STRING]
|
|
744
|
+
*
|
|
745
|
+
*/
|
|
746
|
+
type TCreateMemoryStorageOptions_string = Omit<IStorageAdapterConstructor, "methods"> & {
|
|
747
|
+
memoryStorageMap?: TMemoryStorage_string;
|
|
748
|
+
};
|
|
749
|
+
declare function createMemoryStorageMethods_string(memoryStorageMap?: TMemoryStorage_string): IStorageAdapterMethods_String;
|
|
750
|
+
declare const createMemoryStorageAdapter_string: (options?: TCreateMemoryStorageOptions_string) => StorageAdapter;
|
|
751
|
+
declare function createTypedMemoryStorage_string<T extends Record<string, any>>(options?: TCreateMemoryStorageOptions_string): ITypedStorage<T>;
|
|
752
|
+
/**
|
|
753
|
+
*
|
|
754
|
+
* Memory Storage [JSON]
|
|
755
|
+
*
|
|
756
|
+
*/
|
|
757
|
+
type TCreateMemoryStorageOptions_json = Omit<IStorageAdapterConstructor, "methods"> & {
|
|
758
|
+
memoryStorageMap?: TMemoryStorage_json;
|
|
759
|
+
};
|
|
760
|
+
declare function createMemoryStorageMethods_json(memoryStorageMap?: TMemoryStorage_json): IStorageAdapterMethods_Json;
|
|
761
|
+
declare const createMemoryStorageAdapter_json: (options?: TCreateMemoryStorageOptions_json) => StorageAdapter;
|
|
762
|
+
declare function createTypedMemoryStorage_json<T extends Record<string, any>>(options?: TCreateMemoryStorageOptions_json): ITypedStorage<T>;
|
|
763
|
+
//#endregion
|
|
764
|
+
export { ClientCryptoKeyLink, DEFAULT_COMBINED_TEXT_DATA_SEPARATOR, ECryptoKeyAlgo, ECryptoKeyFormat, EStorageAdapterType, ICreateKVStorageMethodsOptions, ISerializedKeyData_Ed25519_Jwk, ISerializedKeyData_Ed25519_Raw, ISerializedKeyData_X25519_Jwk, ISerializedKeyData_X25519_Raw, IStorageAdapterConstructor, IStorageAdapterMethods_Json, IStorageAdapterMethods_String, IStorageKeyGetterAndSetter, ITypedStorage, StorageAdapter, StringKeys, TCreateDurableObjectStorageOptions, TCreateKVStorageOptions, TEncryptedAesGcmBytes, TEncryptedAesGcmPayload, TEncryptedAesGcmPayload_Transformed, TMemoryStorage_json, TMemoryStorage_string, TSerializedCryptoKeyData_Ed25519_Jwk, TSerializedCryptoKeyData_Ed25519_Jwk_Transformed, TSerializedCryptoKeyData_Ed25519_Raw, TSerializedCryptoKeyData_Ed25519_Raw_Transformed, TSerializedCryptoKeyData_X25519_Jwk, TSerializedCryptoKeyData_X25519_Jwk_Transformed, TSerializedCryptoKeyData_X25519_Raw, TSerializedCryptoKeyData_X25519_Raw_Transformed, TSerializedCryptoKeyPairDataEd25519, TSerializedCryptoKeyPairDataX25519, TSerializedKeyData, TStorageAdapterMethods, type TTypeAndId, TVerifyChallengeWithSignature_Input, TVerifyChallengeWithSignature_WithThrow_Input, buildVerifyKeyBoundInfoString, convertEd25519FormattedStringToObject, convertEd25519FormattedStringToSerializedKeyData, convertEd25519JwkDataStringToObject, convertEd25519JwkDataStringToSerializedKeyData, convertEd25519RawDataStringToObject, convertEd25519RawDataStringToSerializedKeyData, convertX25519FormattedStringToObject, convertX25519FormattedStringToSerializedKeyData, convertX25519JwkDataStringToObject, convertX25519JwkDataStringToSerializedKeyData, convertX25519RawDataStringToObject, convertX25519RawDataStringToSerializedKeyData, createAesGcmKeyFromX25519Keys, createDurableObjectStorageAdapter, createDurableObjectStorageMethods, createDurableObjectTypedStorage, createKVStorageAdapter, createKVStorageMethods, createKVTypedStorage, createMemoryStorageAdapter_json, createMemoryStorageAdapter_string, createMemoryStorageMethods_json, createMemoryStorageMethods_string, createSharedBitsFromX25519, createTypedMemoryStorage_json, createTypedMemoryStorage_string, createTypedStorage, createTypedWebLocalStorage, createTypedWebSessionStorage, createWebLocalStorageAdapter, createWebLocalStorageMethods, createWebSessionStorageAdapter, createWebSessionStorageMethods, decryptBytesWithAesGcmKey, decryptTextDataWithAesGcmKey, encryptBytesWithAesGcmKey, encryptTextDataWithAesGcmKey, generateEd25519KeyPair, generateX25519KeyPair, importEd25519Key, importX25519Key, serializeEd25519Key_Jwk, serializeEd25519Key_Raw, serializeX25519Key_Jwk, serializeX25519Key_Raw, signCombinedTextDataWithKeyEd25519, signTextDataWithKeyEd25519, vCryptoKeyPairDataEd25519, vCryptoKeyPairDataX25519, vEncryptedAesGcmPayload, vSerializedCryptoKeyDataEd25519_Jwk, vSerializedCryptoKeyDataEd25519_Raw, vSerializedCryptoKeyDataX25519_Jwk, vSerializedCryptoKeyDataX25519_Raw, vVerifyChallengeWithSignature_Input, vVerifyChallengeWithSignature_WithThrow_Input, verifyWithKeyEd25519 };
|
|
765
|
+
//# sourceMappingURL=index.d.ts.map
|