@cardanowall/crypto-core 0.2.0 → 0.4.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/dist/hash.cjs +10 -1
- package/dist/hash.cjs.map +1 -1
- package/dist/hash.d.cts +8 -1
- package/dist/hash.d.ts +8 -1
- package/dist/hash.js +10 -2
- package/dist/hash.js.map +1 -1
- package/dist/index.cjs +2247 -363
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2211 -361
- package/dist/index.js.map +1 -1
- package/dist/kem.cjs.map +1 -1
- package/dist/kem.js.map +1 -1
- package/dist/sealed-poe.cjs +2097 -289
- package/dist/sealed-poe.cjs.map +1 -1
- package/dist/sealed-poe.d.cts +147 -16
- package/dist/sealed-poe.d.ts +147 -16
- package/dist/sealed-poe.js +2067 -288
- package/dist/sealed-poe.js.map +1 -1
- package/dist/seed-derive.cjs +195 -0
- package/dist/seed-derive.cjs.map +1 -1
- package/dist/seed-derive.d.cts +12 -1
- package/dist/seed-derive.d.ts +12 -1
- package/dist/seed-derive.js +192 -1
- package/dist/seed-derive.js.map +1 -1
- package/package.json +1 -1
package/dist/sealed-poe.d.cts
CHANGED
|
@@ -1,29 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
3
|
-
declare
|
|
4
|
-
declare
|
|
1
|
+
declare const CARDANO_POE_ITEM_HASHES_PREFIX: Uint8Array;
|
|
2
|
+
declare const CARDANO_POE_SLOTS_TRANSCRIPT_PREFIX: Uint8Array;
|
|
3
|
+
declare const CARDANO_POE_PASSPHRASE_TRANSCRIPT_PREFIX: Uint8Array;
|
|
4
|
+
declare const CARDANO_POE_HKDF_INFO_SLOTS_MAC: Uint8Array;
|
|
5
|
+
declare const CARDANO_POE_HKDF_INFO_PASSPHRASE_MAC: Uint8Array;
|
|
6
|
+
declare const CARDANO_POE_HKDF_INFO_PAYLOAD: Uint8Array;
|
|
7
|
+
declare const CARDANO_POE_HKDF_INFO_PAYLOAD_PASSPHRASE: Uint8Array;
|
|
8
|
+
declare const CARDANO_POE_X25519_KEK_SALT_PREFIX: Uint8Array;
|
|
9
|
+
declare const CARDANO_POE_XWING_KEK_SALT_PREFIX: Uint8Array;
|
|
10
|
+
declare const CARDANO_POE_PW_NORM_PROFILE: "cardano-poe-pw-norm-v1";
|
|
11
|
+
declare const MAX_SLOTS = 1024;
|
|
12
|
+
declare const MAX_DECODED_ENVELOPE_BYTES = 65536;
|
|
13
|
+
type ItemHashes = Readonly<Record<string, Uint8Array>>;
|
|
14
|
+
declare function itemHashesHash(hashes: ItemHashes): Uint8Array;
|
|
15
|
+
declare function computeSlotsHash(args: {
|
|
16
|
+
aead: string;
|
|
17
|
+
kem: SealedKem;
|
|
18
|
+
nonce: Uint8Array;
|
|
19
|
+
slots: ReadonlyArray<X25519Slot | Mlkem768X25519Slot>;
|
|
20
|
+
hashesHash: Uint8Array;
|
|
21
|
+
}): Uint8Array;
|
|
22
|
+
declare function computePassphraseHash(args: {
|
|
23
|
+
aead: string;
|
|
24
|
+
nonce: Uint8Array;
|
|
25
|
+
hashesHash: Uint8Array;
|
|
26
|
+
salt: Uint8Array;
|
|
27
|
+
params: {
|
|
28
|
+
m: number;
|
|
29
|
+
t: number;
|
|
30
|
+
p: number;
|
|
31
|
+
};
|
|
32
|
+
}): Uint8Array;
|
|
33
|
+
declare function computeSlotsMac(args: {
|
|
34
|
+
cek: Uint8Array;
|
|
35
|
+
slotsHash: Uint8Array;
|
|
36
|
+
}): Uint8Array;
|
|
37
|
+
declare function computePassphraseCommitment(args: {
|
|
38
|
+
cek: Uint8Array;
|
|
39
|
+
pwHash: Uint8Array;
|
|
40
|
+
}): Uint8Array;
|
|
41
|
+
declare function slotsPayloadKey(args: {
|
|
42
|
+
cek: Uint8Array;
|
|
43
|
+
nonce: Uint8Array;
|
|
44
|
+
}): Uint8Array;
|
|
45
|
+
declare function passphrasePayloadKey(args: {
|
|
46
|
+
cek: Uint8Array;
|
|
47
|
+
nonce: Uint8Array;
|
|
48
|
+
}): Uint8Array;
|
|
49
|
+
declare function x25519KekSalt(args: {
|
|
50
|
+
nonce: Uint8Array;
|
|
51
|
+
epk: Uint8Array;
|
|
52
|
+
pubR: Uint8Array;
|
|
53
|
+
}): Uint8Array;
|
|
54
|
+
declare function xwingKekSalt(args: {
|
|
55
|
+
nonce: Uint8Array;
|
|
56
|
+
kemCt: Uint8Array;
|
|
57
|
+
pubR: Uint8Array;
|
|
58
|
+
}): Uint8Array;
|
|
5
59
|
|
|
60
|
+
type SealedKem = 'x25519' | 'mlkem768x25519';
|
|
61
|
+
declare const SEALED_POE_AEAD: "chacha20-poly1305-stream64k";
|
|
6
62
|
declare const CARDANO_POE_HKDF_INFO_KEK: Uint8Array;
|
|
7
63
|
declare const CARDANO_POE_HKDF_INFO_KEK_MLKEM768X25519: Uint8Array;
|
|
8
|
-
declare const CARDANO_POE_HKDF_INFO_SLOTS_MAC: Uint8Array;
|
|
9
64
|
interface X25519Slot {
|
|
10
65
|
readonly epk: Uint8Array;
|
|
11
66
|
readonly wrap: Uint8Array;
|
|
12
67
|
}
|
|
13
68
|
interface Mlkem768X25519Slot {
|
|
14
|
-
readonly kem_ct:
|
|
69
|
+
readonly kem_ct: Uint8Array;
|
|
15
70
|
readonly wrap: Uint8Array;
|
|
16
71
|
}
|
|
17
72
|
type SealedEnvelope = {
|
|
18
73
|
readonly scheme: 1;
|
|
19
|
-
readonly aead:
|
|
74
|
+
readonly aead: typeof SEALED_POE_AEAD;
|
|
20
75
|
readonly kem: 'x25519';
|
|
21
76
|
readonly nonce: Uint8Array;
|
|
22
77
|
readonly slots: ReadonlyArray<X25519Slot>;
|
|
23
78
|
readonly slots_mac: Uint8Array;
|
|
24
79
|
} | {
|
|
25
80
|
readonly scheme: 1;
|
|
26
|
-
readonly aead:
|
|
81
|
+
readonly aead: typeof SEALED_POE_AEAD;
|
|
27
82
|
readonly kem: 'mlkem768x25519';
|
|
28
83
|
readonly nonce: Uint8Array;
|
|
29
84
|
readonly slots: ReadonlyArray<Mlkem768X25519Slot>;
|
|
@@ -35,6 +90,7 @@ interface SealedPoeOutput {
|
|
|
35
90
|
}
|
|
36
91
|
interface WrapArgs {
|
|
37
92
|
readonly plaintext: Uint8Array;
|
|
93
|
+
readonly hashes: ItemHashes;
|
|
38
94
|
readonly recipientPublicKeys: ReadonlyArray<Uint8Array>;
|
|
39
95
|
readonly kem?: SealedKem;
|
|
40
96
|
readonly cek?: Uint8Array;
|
|
@@ -61,7 +117,7 @@ interface RecipientKeyBundle {
|
|
|
61
117
|
interface UnwrapArgsCommon {
|
|
62
118
|
readonly envelope: SealedEnvelope;
|
|
63
119
|
readonly ciphertext: Uint8Array;
|
|
64
|
-
readonly
|
|
120
|
+
readonly hashes: ItemHashes;
|
|
65
121
|
readonly _slotsAttemptedOut?: {
|
|
66
122
|
count: number;
|
|
67
123
|
perPrivCounts?: number[];
|
|
@@ -82,7 +138,7 @@ interface UnwrapArgsBundle extends UnwrapArgsCommon {
|
|
|
82
138
|
type UnwrapArgs = UnwrapArgsSinglePriv | UnwrapArgsMultiPriv | UnwrapArgsBundle;
|
|
83
139
|
interface TrialDecryptOnlyArgsCommon {
|
|
84
140
|
readonly envelope: SealedEnvelope;
|
|
85
|
-
readonly
|
|
141
|
+
readonly hashes: ItemHashes;
|
|
86
142
|
readonly _slotsAttemptedOut?: {
|
|
87
143
|
count: number;
|
|
88
144
|
perPrivCounts?: number[];
|
|
@@ -101,14 +157,12 @@ type TrialDecryptOnlyResult = {
|
|
|
101
157
|
readonly slotIdx: number;
|
|
102
158
|
readonly cek: Uint8Array;
|
|
103
159
|
} | {
|
|
104
|
-
readonly kind: '
|
|
105
|
-
} | {
|
|
106
|
-
readonly kind: 'aead_pass_no_mac_match';
|
|
160
|
+
readonly kind: 'no_match';
|
|
107
161
|
};
|
|
108
162
|
declare function eciesSealedPoeUnwrap(args: UnwrapArgs): UnwrapResult;
|
|
109
163
|
declare function eciesSealedPoeTrialDecrypt(args: TrialDecryptOnlyArgs): TrialDecryptOnlyResult;
|
|
110
164
|
|
|
111
|
-
type EciesSealedPoeErrorCode = 'ENC_SLOTS_EMPTY' | '
|
|
165
|
+
type EciesSealedPoeErrorCode = 'ENC_SLOTS_EMPTY' | 'ENC_SLOTS_MAC_INVALID_LENGTH' | 'ENC_SLOTS_DUPLICATE_KEM_MATERIAL' | 'ENC_SLOTS_TOO_MANY' | 'ENC_ENVELOPE_TOO_LARGE' | 'ENC_REQUIRES_CONTENT_HASH' | 'ENC_PASSPHRASE_EMPTY' | 'ENC_PASSPHRASE_UNNORMALIZABLE' | 'ENC_PASSPHRASE_ALG_UNSUPPORTED' | 'ENC_PASSPHRASE_SALT_TOO_SHORT' | 'ENC_PASSPHRASE_SALT_TOO_LONG' | 'ENC_PASSPHRASE_ARGON2_PARAMS_TOO_LOW' | 'KEM_EPK_LENGTH_MISMATCH' | 'KEM_CT_LENGTH_MISMATCH' | 'NONCE_LENGTH_MISMATCH' | 'WRAP_LENGTH_MISMATCH' | 'UNSUPPORTED_ENVELOPE_SCHEME' | 'UNSUPPORTED_AEAD_ALG' | 'UNSUPPORTED_KEM_ALG' | 'KDF_DERIVATION_FAILED' | 'INVALID_CEK_LENGTH' | 'INVALID_EPHEMERAL_SECRET_LENGTH' | 'EPHEMERAL_SECRETS_COUNT_MISMATCH' | 'INVALID_RECIPIENT_KEY' | 'INVALID_PASSPHRASE_PARAMS' | 'PASSPHRASE_INPUT_TOO_LONG';
|
|
112
166
|
declare class EciesSealedPoeError extends Error {
|
|
113
167
|
readonly code: EciesSealedPoeErrorCode;
|
|
114
168
|
constructor(code: EciesSealedPoeErrorCode, message: string, options?: {
|
|
@@ -116,9 +170,86 @@ declare class EciesSealedPoeError extends Error {
|
|
|
116
170
|
});
|
|
117
171
|
}
|
|
118
172
|
|
|
173
|
+
declare const CHUNK_SIZE = 65536;
|
|
174
|
+
declare const TAG_SIZE = 16;
|
|
175
|
+
declare class StreamTamperedError extends Error {
|
|
176
|
+
readonly code: "TAMPERED_CIPHERTEXT";
|
|
177
|
+
constructor(message: string, options?: {
|
|
178
|
+
cause?: unknown;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
declare class StreamSealer {
|
|
182
|
+
private readonly payloadKey;
|
|
183
|
+
private readonly nonce;
|
|
184
|
+
private chunkIndex;
|
|
185
|
+
constructor(payloadKey: Uint8Array);
|
|
186
|
+
sealChunk(plaintext: Uint8Array, final: boolean): Uint8Array;
|
|
187
|
+
}
|
|
188
|
+
declare class StreamOpener {
|
|
189
|
+
private readonly payloadKey;
|
|
190
|
+
private readonly nonce;
|
|
191
|
+
private chunkIndex;
|
|
192
|
+
constructor(payloadKey: Uint8Array);
|
|
193
|
+
openChunk(sealedChunk: Uint8Array, final: boolean): Uint8Array;
|
|
194
|
+
}
|
|
195
|
+
declare function streamSeal(args: {
|
|
196
|
+
payloadKey: Uint8Array;
|
|
197
|
+
plaintext: Uint8Array;
|
|
198
|
+
}): Uint8Array;
|
|
199
|
+
declare function streamOpen(args: {
|
|
200
|
+
payloadKey: Uint8Array;
|
|
201
|
+
ciphertext: Uint8Array;
|
|
202
|
+
}): Uint8Array;
|
|
203
|
+
|
|
204
|
+
interface PassphraseParams {
|
|
205
|
+
readonly m: number;
|
|
206
|
+
readonly t: number;
|
|
207
|
+
readonly p: number;
|
|
208
|
+
}
|
|
209
|
+
interface PassphraseSealedEnvelope {
|
|
210
|
+
readonly scheme: 1;
|
|
211
|
+
readonly aead: typeof SEALED_POE_AEAD;
|
|
212
|
+
readonly nonce: Uint8Array;
|
|
213
|
+
readonly passphrase: {
|
|
214
|
+
readonly alg: 'argon2id';
|
|
215
|
+
readonly salt: Uint8Array;
|
|
216
|
+
readonly params: PassphraseParams;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
interface PassphraseSealArgs {
|
|
220
|
+
readonly plaintext: Uint8Array;
|
|
221
|
+
readonly hashes: ItemHashes;
|
|
222
|
+
readonly passphrase: string;
|
|
223
|
+
readonly salt?: Uint8Array;
|
|
224
|
+
readonly params?: PassphraseParams;
|
|
225
|
+
readonly nonce?: Uint8Array;
|
|
226
|
+
}
|
|
227
|
+
interface PassphraseSealedPoeOutput {
|
|
228
|
+
readonly envelope: PassphraseSealedEnvelope;
|
|
229
|
+
readonly blob: Uint8Array;
|
|
230
|
+
}
|
|
231
|
+
interface PassphraseOpenArgs {
|
|
232
|
+
readonly envelope: PassphraseSealedEnvelope;
|
|
233
|
+
readonly blob: Uint8Array;
|
|
234
|
+
readonly passphrase: string;
|
|
235
|
+
readonly hashes: ItemHashes;
|
|
236
|
+
}
|
|
237
|
+
type PassphraseOpenResult = {
|
|
238
|
+
readonly matched: true;
|
|
239
|
+
readonly plaintext: Uint8Array;
|
|
240
|
+
} | {
|
|
241
|
+
readonly matched: false;
|
|
242
|
+
readonly reason: 'TAMPERED_CIPHERTEXT';
|
|
243
|
+
};
|
|
244
|
+
declare function passphraseSealedPoeSeal(args: PassphraseSealArgs): Promise<PassphraseSealedPoeOutput>;
|
|
245
|
+
declare function passphraseSealedPoeOpen(args: PassphraseOpenArgs): Promise<PassphraseOpenResult>;
|
|
246
|
+
|
|
247
|
+
declare const MAX_PASSPHRASE_INPUT_BYTES = 4096;
|
|
248
|
+
declare function normalizePassphrase(passphrase: string): Uint8Array;
|
|
249
|
+
|
|
119
250
|
interface ParsedSlotShape {
|
|
120
251
|
readonly epk?: Uint8Array | undefined;
|
|
121
|
-
readonly kem_ct?:
|
|
252
|
+
readonly kem_ct?: Uint8Array | undefined;
|
|
122
253
|
readonly wrap?: Uint8Array | undefined;
|
|
123
254
|
}
|
|
124
255
|
interface ParsedEnvelopeShape {
|
|
@@ -131,4 +262,4 @@ interface ParsedEnvelopeShape {
|
|
|
131
262
|
}
|
|
132
263
|
declare function sealedEnvelopeFromParsed(enc: ParsedEnvelopeShape): SealedEnvelope | null;
|
|
133
264
|
|
|
134
|
-
export { CARDANO_POE_HKDF_INFO_KEK, CARDANO_POE_HKDF_INFO_KEK_MLKEM768X25519, CARDANO_POE_HKDF_INFO_SLOTS_MAC, EciesSealedPoeError, type EciesSealedPoeErrorCode, type Mlkem768X25519Slot, type ParsedEnvelopeShape, type ParsedSlotShape, type RecipientKeyBundle, type SealedEnvelope, type SealedKem, type SealedPoeOutput, type TrialDecryptOnlyArgs, type TrialDecryptOnlyResult, type UnwrapArgs, type UnwrapArgsBundle, type UnwrapArgsMultiPriv, type UnwrapArgsSinglePriv, type UnwrapFailureReason, type UnwrapResult, type WrapArgs, type X25519Slot,
|
|
265
|
+
export { CARDANO_POE_HKDF_INFO_KEK, CARDANO_POE_HKDF_INFO_KEK_MLKEM768X25519, CARDANO_POE_HKDF_INFO_PASSPHRASE_MAC, CARDANO_POE_HKDF_INFO_PAYLOAD, CARDANO_POE_HKDF_INFO_PAYLOAD_PASSPHRASE, CARDANO_POE_HKDF_INFO_SLOTS_MAC, CARDANO_POE_ITEM_HASHES_PREFIX, CARDANO_POE_PASSPHRASE_TRANSCRIPT_PREFIX, CARDANO_POE_PW_NORM_PROFILE, CARDANO_POE_SLOTS_TRANSCRIPT_PREFIX, CARDANO_POE_X25519_KEK_SALT_PREFIX, CARDANO_POE_XWING_KEK_SALT_PREFIX, CHUNK_SIZE, EciesSealedPoeError, type EciesSealedPoeErrorCode, type ItemHashes, MAX_DECODED_ENVELOPE_BYTES, MAX_PASSPHRASE_INPUT_BYTES, MAX_SLOTS, type Mlkem768X25519Slot, type ParsedEnvelopeShape, type ParsedSlotShape, type PassphraseOpenArgs, type PassphraseOpenResult, type PassphraseParams, type PassphraseSealArgs, type PassphraseSealedEnvelope, type PassphraseSealedPoeOutput, type RecipientKeyBundle, SEALED_POE_AEAD, type SealedEnvelope, type SealedKem, type SealedPoeOutput, StreamOpener, StreamSealer, StreamTamperedError, TAG_SIZE, type TrialDecryptOnlyArgs, type TrialDecryptOnlyResult, type UnwrapArgs, type UnwrapArgsBundle, type UnwrapArgsMultiPriv, type UnwrapArgsSinglePriv, type UnwrapFailureReason, type UnwrapResult, type WrapArgs, type X25519Slot, computePassphraseCommitment, computePassphraseHash, computeSlotsHash, computeSlotsMac, eciesSealedPoeTrialDecrypt, eciesSealedPoeUnwrap, eciesSealedPoeWrap, itemHashesHash, normalizePassphrase, passphrasePayloadKey, passphraseSealedPoeOpen, passphraseSealedPoeSeal, sealedEnvelopeFromParsed, slotsPayloadKey, streamOpen, streamSeal, uniformIndexBelow, x25519KekSalt, xwingKekSalt };
|
package/dist/sealed-poe.d.ts
CHANGED
|
@@ -1,29 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
3
|
-
declare
|
|
4
|
-
declare
|
|
1
|
+
declare const CARDANO_POE_ITEM_HASHES_PREFIX: Uint8Array;
|
|
2
|
+
declare const CARDANO_POE_SLOTS_TRANSCRIPT_PREFIX: Uint8Array;
|
|
3
|
+
declare const CARDANO_POE_PASSPHRASE_TRANSCRIPT_PREFIX: Uint8Array;
|
|
4
|
+
declare const CARDANO_POE_HKDF_INFO_SLOTS_MAC: Uint8Array;
|
|
5
|
+
declare const CARDANO_POE_HKDF_INFO_PASSPHRASE_MAC: Uint8Array;
|
|
6
|
+
declare const CARDANO_POE_HKDF_INFO_PAYLOAD: Uint8Array;
|
|
7
|
+
declare const CARDANO_POE_HKDF_INFO_PAYLOAD_PASSPHRASE: Uint8Array;
|
|
8
|
+
declare const CARDANO_POE_X25519_KEK_SALT_PREFIX: Uint8Array;
|
|
9
|
+
declare const CARDANO_POE_XWING_KEK_SALT_PREFIX: Uint8Array;
|
|
10
|
+
declare const CARDANO_POE_PW_NORM_PROFILE: "cardano-poe-pw-norm-v1";
|
|
11
|
+
declare const MAX_SLOTS = 1024;
|
|
12
|
+
declare const MAX_DECODED_ENVELOPE_BYTES = 65536;
|
|
13
|
+
type ItemHashes = Readonly<Record<string, Uint8Array>>;
|
|
14
|
+
declare function itemHashesHash(hashes: ItemHashes): Uint8Array;
|
|
15
|
+
declare function computeSlotsHash(args: {
|
|
16
|
+
aead: string;
|
|
17
|
+
kem: SealedKem;
|
|
18
|
+
nonce: Uint8Array;
|
|
19
|
+
slots: ReadonlyArray<X25519Slot | Mlkem768X25519Slot>;
|
|
20
|
+
hashesHash: Uint8Array;
|
|
21
|
+
}): Uint8Array;
|
|
22
|
+
declare function computePassphraseHash(args: {
|
|
23
|
+
aead: string;
|
|
24
|
+
nonce: Uint8Array;
|
|
25
|
+
hashesHash: Uint8Array;
|
|
26
|
+
salt: Uint8Array;
|
|
27
|
+
params: {
|
|
28
|
+
m: number;
|
|
29
|
+
t: number;
|
|
30
|
+
p: number;
|
|
31
|
+
};
|
|
32
|
+
}): Uint8Array;
|
|
33
|
+
declare function computeSlotsMac(args: {
|
|
34
|
+
cek: Uint8Array;
|
|
35
|
+
slotsHash: Uint8Array;
|
|
36
|
+
}): Uint8Array;
|
|
37
|
+
declare function computePassphraseCommitment(args: {
|
|
38
|
+
cek: Uint8Array;
|
|
39
|
+
pwHash: Uint8Array;
|
|
40
|
+
}): Uint8Array;
|
|
41
|
+
declare function slotsPayloadKey(args: {
|
|
42
|
+
cek: Uint8Array;
|
|
43
|
+
nonce: Uint8Array;
|
|
44
|
+
}): Uint8Array;
|
|
45
|
+
declare function passphrasePayloadKey(args: {
|
|
46
|
+
cek: Uint8Array;
|
|
47
|
+
nonce: Uint8Array;
|
|
48
|
+
}): Uint8Array;
|
|
49
|
+
declare function x25519KekSalt(args: {
|
|
50
|
+
nonce: Uint8Array;
|
|
51
|
+
epk: Uint8Array;
|
|
52
|
+
pubR: Uint8Array;
|
|
53
|
+
}): Uint8Array;
|
|
54
|
+
declare function xwingKekSalt(args: {
|
|
55
|
+
nonce: Uint8Array;
|
|
56
|
+
kemCt: Uint8Array;
|
|
57
|
+
pubR: Uint8Array;
|
|
58
|
+
}): Uint8Array;
|
|
5
59
|
|
|
60
|
+
type SealedKem = 'x25519' | 'mlkem768x25519';
|
|
61
|
+
declare const SEALED_POE_AEAD: "chacha20-poly1305-stream64k";
|
|
6
62
|
declare const CARDANO_POE_HKDF_INFO_KEK: Uint8Array;
|
|
7
63
|
declare const CARDANO_POE_HKDF_INFO_KEK_MLKEM768X25519: Uint8Array;
|
|
8
|
-
declare const CARDANO_POE_HKDF_INFO_SLOTS_MAC: Uint8Array;
|
|
9
64
|
interface X25519Slot {
|
|
10
65
|
readonly epk: Uint8Array;
|
|
11
66
|
readonly wrap: Uint8Array;
|
|
12
67
|
}
|
|
13
68
|
interface Mlkem768X25519Slot {
|
|
14
|
-
readonly kem_ct:
|
|
69
|
+
readonly kem_ct: Uint8Array;
|
|
15
70
|
readonly wrap: Uint8Array;
|
|
16
71
|
}
|
|
17
72
|
type SealedEnvelope = {
|
|
18
73
|
readonly scheme: 1;
|
|
19
|
-
readonly aead:
|
|
74
|
+
readonly aead: typeof SEALED_POE_AEAD;
|
|
20
75
|
readonly kem: 'x25519';
|
|
21
76
|
readonly nonce: Uint8Array;
|
|
22
77
|
readonly slots: ReadonlyArray<X25519Slot>;
|
|
23
78
|
readonly slots_mac: Uint8Array;
|
|
24
79
|
} | {
|
|
25
80
|
readonly scheme: 1;
|
|
26
|
-
readonly aead:
|
|
81
|
+
readonly aead: typeof SEALED_POE_AEAD;
|
|
27
82
|
readonly kem: 'mlkem768x25519';
|
|
28
83
|
readonly nonce: Uint8Array;
|
|
29
84
|
readonly slots: ReadonlyArray<Mlkem768X25519Slot>;
|
|
@@ -35,6 +90,7 @@ interface SealedPoeOutput {
|
|
|
35
90
|
}
|
|
36
91
|
interface WrapArgs {
|
|
37
92
|
readonly plaintext: Uint8Array;
|
|
93
|
+
readonly hashes: ItemHashes;
|
|
38
94
|
readonly recipientPublicKeys: ReadonlyArray<Uint8Array>;
|
|
39
95
|
readonly kem?: SealedKem;
|
|
40
96
|
readonly cek?: Uint8Array;
|
|
@@ -61,7 +117,7 @@ interface RecipientKeyBundle {
|
|
|
61
117
|
interface UnwrapArgsCommon {
|
|
62
118
|
readonly envelope: SealedEnvelope;
|
|
63
119
|
readonly ciphertext: Uint8Array;
|
|
64
|
-
readonly
|
|
120
|
+
readonly hashes: ItemHashes;
|
|
65
121
|
readonly _slotsAttemptedOut?: {
|
|
66
122
|
count: number;
|
|
67
123
|
perPrivCounts?: number[];
|
|
@@ -82,7 +138,7 @@ interface UnwrapArgsBundle extends UnwrapArgsCommon {
|
|
|
82
138
|
type UnwrapArgs = UnwrapArgsSinglePriv | UnwrapArgsMultiPriv | UnwrapArgsBundle;
|
|
83
139
|
interface TrialDecryptOnlyArgsCommon {
|
|
84
140
|
readonly envelope: SealedEnvelope;
|
|
85
|
-
readonly
|
|
141
|
+
readonly hashes: ItemHashes;
|
|
86
142
|
readonly _slotsAttemptedOut?: {
|
|
87
143
|
count: number;
|
|
88
144
|
perPrivCounts?: number[];
|
|
@@ -101,14 +157,12 @@ type TrialDecryptOnlyResult = {
|
|
|
101
157
|
readonly slotIdx: number;
|
|
102
158
|
readonly cek: Uint8Array;
|
|
103
159
|
} | {
|
|
104
|
-
readonly kind: '
|
|
105
|
-
} | {
|
|
106
|
-
readonly kind: 'aead_pass_no_mac_match';
|
|
160
|
+
readonly kind: 'no_match';
|
|
107
161
|
};
|
|
108
162
|
declare function eciesSealedPoeUnwrap(args: UnwrapArgs): UnwrapResult;
|
|
109
163
|
declare function eciesSealedPoeTrialDecrypt(args: TrialDecryptOnlyArgs): TrialDecryptOnlyResult;
|
|
110
164
|
|
|
111
|
-
type EciesSealedPoeErrorCode = 'ENC_SLOTS_EMPTY' | '
|
|
165
|
+
type EciesSealedPoeErrorCode = 'ENC_SLOTS_EMPTY' | 'ENC_SLOTS_MAC_INVALID_LENGTH' | 'ENC_SLOTS_DUPLICATE_KEM_MATERIAL' | 'ENC_SLOTS_TOO_MANY' | 'ENC_ENVELOPE_TOO_LARGE' | 'ENC_REQUIRES_CONTENT_HASH' | 'ENC_PASSPHRASE_EMPTY' | 'ENC_PASSPHRASE_UNNORMALIZABLE' | 'ENC_PASSPHRASE_ALG_UNSUPPORTED' | 'ENC_PASSPHRASE_SALT_TOO_SHORT' | 'ENC_PASSPHRASE_SALT_TOO_LONG' | 'ENC_PASSPHRASE_ARGON2_PARAMS_TOO_LOW' | 'KEM_EPK_LENGTH_MISMATCH' | 'KEM_CT_LENGTH_MISMATCH' | 'NONCE_LENGTH_MISMATCH' | 'WRAP_LENGTH_MISMATCH' | 'UNSUPPORTED_ENVELOPE_SCHEME' | 'UNSUPPORTED_AEAD_ALG' | 'UNSUPPORTED_KEM_ALG' | 'KDF_DERIVATION_FAILED' | 'INVALID_CEK_LENGTH' | 'INVALID_EPHEMERAL_SECRET_LENGTH' | 'EPHEMERAL_SECRETS_COUNT_MISMATCH' | 'INVALID_RECIPIENT_KEY' | 'INVALID_PASSPHRASE_PARAMS' | 'PASSPHRASE_INPUT_TOO_LONG';
|
|
112
166
|
declare class EciesSealedPoeError extends Error {
|
|
113
167
|
readonly code: EciesSealedPoeErrorCode;
|
|
114
168
|
constructor(code: EciesSealedPoeErrorCode, message: string, options?: {
|
|
@@ -116,9 +170,86 @@ declare class EciesSealedPoeError extends Error {
|
|
|
116
170
|
});
|
|
117
171
|
}
|
|
118
172
|
|
|
173
|
+
declare const CHUNK_SIZE = 65536;
|
|
174
|
+
declare const TAG_SIZE = 16;
|
|
175
|
+
declare class StreamTamperedError extends Error {
|
|
176
|
+
readonly code: "TAMPERED_CIPHERTEXT";
|
|
177
|
+
constructor(message: string, options?: {
|
|
178
|
+
cause?: unknown;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
declare class StreamSealer {
|
|
182
|
+
private readonly payloadKey;
|
|
183
|
+
private readonly nonce;
|
|
184
|
+
private chunkIndex;
|
|
185
|
+
constructor(payloadKey: Uint8Array);
|
|
186
|
+
sealChunk(plaintext: Uint8Array, final: boolean): Uint8Array;
|
|
187
|
+
}
|
|
188
|
+
declare class StreamOpener {
|
|
189
|
+
private readonly payloadKey;
|
|
190
|
+
private readonly nonce;
|
|
191
|
+
private chunkIndex;
|
|
192
|
+
constructor(payloadKey: Uint8Array);
|
|
193
|
+
openChunk(sealedChunk: Uint8Array, final: boolean): Uint8Array;
|
|
194
|
+
}
|
|
195
|
+
declare function streamSeal(args: {
|
|
196
|
+
payloadKey: Uint8Array;
|
|
197
|
+
plaintext: Uint8Array;
|
|
198
|
+
}): Uint8Array;
|
|
199
|
+
declare function streamOpen(args: {
|
|
200
|
+
payloadKey: Uint8Array;
|
|
201
|
+
ciphertext: Uint8Array;
|
|
202
|
+
}): Uint8Array;
|
|
203
|
+
|
|
204
|
+
interface PassphraseParams {
|
|
205
|
+
readonly m: number;
|
|
206
|
+
readonly t: number;
|
|
207
|
+
readonly p: number;
|
|
208
|
+
}
|
|
209
|
+
interface PassphraseSealedEnvelope {
|
|
210
|
+
readonly scheme: 1;
|
|
211
|
+
readonly aead: typeof SEALED_POE_AEAD;
|
|
212
|
+
readonly nonce: Uint8Array;
|
|
213
|
+
readonly passphrase: {
|
|
214
|
+
readonly alg: 'argon2id';
|
|
215
|
+
readonly salt: Uint8Array;
|
|
216
|
+
readonly params: PassphraseParams;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
interface PassphraseSealArgs {
|
|
220
|
+
readonly plaintext: Uint8Array;
|
|
221
|
+
readonly hashes: ItemHashes;
|
|
222
|
+
readonly passphrase: string;
|
|
223
|
+
readonly salt?: Uint8Array;
|
|
224
|
+
readonly params?: PassphraseParams;
|
|
225
|
+
readonly nonce?: Uint8Array;
|
|
226
|
+
}
|
|
227
|
+
interface PassphraseSealedPoeOutput {
|
|
228
|
+
readonly envelope: PassphraseSealedEnvelope;
|
|
229
|
+
readonly blob: Uint8Array;
|
|
230
|
+
}
|
|
231
|
+
interface PassphraseOpenArgs {
|
|
232
|
+
readonly envelope: PassphraseSealedEnvelope;
|
|
233
|
+
readonly blob: Uint8Array;
|
|
234
|
+
readonly passphrase: string;
|
|
235
|
+
readonly hashes: ItemHashes;
|
|
236
|
+
}
|
|
237
|
+
type PassphraseOpenResult = {
|
|
238
|
+
readonly matched: true;
|
|
239
|
+
readonly plaintext: Uint8Array;
|
|
240
|
+
} | {
|
|
241
|
+
readonly matched: false;
|
|
242
|
+
readonly reason: 'TAMPERED_CIPHERTEXT';
|
|
243
|
+
};
|
|
244
|
+
declare function passphraseSealedPoeSeal(args: PassphraseSealArgs): Promise<PassphraseSealedPoeOutput>;
|
|
245
|
+
declare function passphraseSealedPoeOpen(args: PassphraseOpenArgs): Promise<PassphraseOpenResult>;
|
|
246
|
+
|
|
247
|
+
declare const MAX_PASSPHRASE_INPUT_BYTES = 4096;
|
|
248
|
+
declare function normalizePassphrase(passphrase: string): Uint8Array;
|
|
249
|
+
|
|
119
250
|
interface ParsedSlotShape {
|
|
120
251
|
readonly epk?: Uint8Array | undefined;
|
|
121
|
-
readonly kem_ct?:
|
|
252
|
+
readonly kem_ct?: Uint8Array | undefined;
|
|
122
253
|
readonly wrap?: Uint8Array | undefined;
|
|
123
254
|
}
|
|
124
255
|
interface ParsedEnvelopeShape {
|
|
@@ -131,4 +262,4 @@ interface ParsedEnvelopeShape {
|
|
|
131
262
|
}
|
|
132
263
|
declare function sealedEnvelopeFromParsed(enc: ParsedEnvelopeShape): SealedEnvelope | null;
|
|
133
264
|
|
|
134
|
-
export { CARDANO_POE_HKDF_INFO_KEK, CARDANO_POE_HKDF_INFO_KEK_MLKEM768X25519, CARDANO_POE_HKDF_INFO_SLOTS_MAC, EciesSealedPoeError, type EciesSealedPoeErrorCode, type Mlkem768X25519Slot, type ParsedEnvelopeShape, type ParsedSlotShape, type RecipientKeyBundle, type SealedEnvelope, type SealedKem, type SealedPoeOutput, type TrialDecryptOnlyArgs, type TrialDecryptOnlyResult, type UnwrapArgs, type UnwrapArgsBundle, type UnwrapArgsMultiPriv, type UnwrapArgsSinglePriv, type UnwrapFailureReason, type UnwrapResult, type WrapArgs, type X25519Slot,
|
|
265
|
+
export { CARDANO_POE_HKDF_INFO_KEK, CARDANO_POE_HKDF_INFO_KEK_MLKEM768X25519, CARDANO_POE_HKDF_INFO_PASSPHRASE_MAC, CARDANO_POE_HKDF_INFO_PAYLOAD, CARDANO_POE_HKDF_INFO_PAYLOAD_PASSPHRASE, CARDANO_POE_HKDF_INFO_SLOTS_MAC, CARDANO_POE_ITEM_HASHES_PREFIX, CARDANO_POE_PASSPHRASE_TRANSCRIPT_PREFIX, CARDANO_POE_PW_NORM_PROFILE, CARDANO_POE_SLOTS_TRANSCRIPT_PREFIX, CARDANO_POE_X25519_KEK_SALT_PREFIX, CARDANO_POE_XWING_KEK_SALT_PREFIX, CHUNK_SIZE, EciesSealedPoeError, type EciesSealedPoeErrorCode, type ItemHashes, MAX_DECODED_ENVELOPE_BYTES, MAX_PASSPHRASE_INPUT_BYTES, MAX_SLOTS, type Mlkem768X25519Slot, type ParsedEnvelopeShape, type ParsedSlotShape, type PassphraseOpenArgs, type PassphraseOpenResult, type PassphraseParams, type PassphraseSealArgs, type PassphraseSealedEnvelope, type PassphraseSealedPoeOutput, type RecipientKeyBundle, SEALED_POE_AEAD, type SealedEnvelope, type SealedKem, type SealedPoeOutput, StreamOpener, StreamSealer, StreamTamperedError, TAG_SIZE, type TrialDecryptOnlyArgs, type TrialDecryptOnlyResult, type UnwrapArgs, type UnwrapArgsBundle, type UnwrapArgsMultiPriv, type UnwrapArgsSinglePriv, type UnwrapFailureReason, type UnwrapResult, type WrapArgs, type X25519Slot, computePassphraseCommitment, computePassphraseHash, computeSlotsHash, computeSlotsMac, eciesSealedPoeTrialDecrypt, eciesSealedPoeUnwrap, eciesSealedPoeWrap, itemHashesHash, normalizePassphrase, passphrasePayloadKey, passphraseSealedPoeOpen, passphraseSealedPoeSeal, sealedEnvelopeFromParsed, slotsPayloadKey, streamOpen, streamSeal, uniformIndexBelow, x25519KekSalt, xwingKekSalt };
|