@darkbio/crypto 0.1.3 → 0.1.5
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/argon2.d.ts +16 -0
- package/dist/argon2.d.ts.map +1 -0
- package/dist/cose.d.ts +117 -0
- package/dist/cose.d.ts.map +1 -0
- package/dist/hkdf.d.ts +34 -0
- package/dist/hkdf.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1174 -955
- package/dist/index.js.map +1 -1
- package/dist/rand.d.ts +8 -0
- package/dist/rand.d.ts.map +1 -0
- package/dist/x509.d.ts +18 -0
- package/dist/x509.d.ts.map +1 -0
- package/dist/xdsa.d.ts +130 -0
- package/dist/xdsa.d.ts.map +1 -0
- package/dist/xhpke.d.ts +148 -0
- package/dist/xhpke.d.ts.map +1 -0
- package/package.json +2 -1
package/dist/argon2.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a key from password, salt, and cost parameters using Argon2id.
|
|
3
|
+
*
|
|
4
|
+
* RFC 9106 Section 7.4 recommends time=1, memory=2048*1024 (2GB) as sensible
|
|
5
|
+
* defaults. If that much memory isn't available, increase time to compensate.
|
|
6
|
+
*
|
|
7
|
+
* @param password - The password to derive from
|
|
8
|
+
* @param salt - A random salt (should be at least 16 bytes)
|
|
9
|
+
* @param time - Number of passes over memory (iterations)
|
|
10
|
+
* @param memory - Memory size in KiB
|
|
11
|
+
* @param threads - Degree of parallelism
|
|
12
|
+
* @param outLen - Desired output length in bytes
|
|
13
|
+
* @returns The derived key
|
|
14
|
+
*/
|
|
15
|
+
export declare function key(password: Uint8Array, salt: Uint8Array, time: number, memory: number, threads: number, outLen: number): Promise<Uint8Array>;
|
|
16
|
+
//# sourceMappingURL=argon2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argon2.d.ts","sourceRoot":"","sources":["../src/argon2.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;GAaG;AACH,wBAAsB,GAAG,CACvB,QAAQ,EAAE,UAAU,EACpB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,CAKrB"}
|
package/dist/cose.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { SecretKey as XdsaSecretKey, PublicKey as XdsaPublicKey, Fingerprint as XdsaFingerprint } from './xdsa.js';
|
|
2
|
+
import { SecretKey as XhpkeSecretKey, PublicKey as XhpkePublicKey, Fingerprint as XhpkeFingerprint } from './xhpke.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create a COSE_Sign1 signature with an embedded payload.
|
|
5
|
+
*
|
|
6
|
+
* @param msgToEmbed - The payload to embed and sign (will be CBOR encoded)
|
|
7
|
+
* @param msgToAuth - Additional authenticated data (will be CBOR encoded)
|
|
8
|
+
* @param signer - The xDSA secret key
|
|
9
|
+
* @param domain - Application-specific domain separator
|
|
10
|
+
* @returns The serialized COSE_Sign1 structure
|
|
11
|
+
*/
|
|
12
|
+
export declare function sign<E, A>(msgToEmbed: E, msgToAuth: A, signer: XdsaSecretKey, domain: Uint8Array): Promise<Uint8Array>;
|
|
13
|
+
/**
|
|
14
|
+
* Create a COSE_Sign1 signature without an embedded payload (detached mode).
|
|
15
|
+
*
|
|
16
|
+
* @param msgToAuth - The message to authenticate (will be CBOR encoded)
|
|
17
|
+
* @param signer - The xDSA secret key
|
|
18
|
+
* @param domain - Application-specific domain separator
|
|
19
|
+
* @returns The serialized COSE_Sign1 structure (with null payload)
|
|
20
|
+
*/
|
|
21
|
+
export declare function signDetached<A>(msgToAuth: A, signer: XdsaSecretKey, domain: Uint8Array): Promise<Uint8Array>;
|
|
22
|
+
/**
|
|
23
|
+
* Verify a COSE_Sign1 signature and return the embedded payload.
|
|
24
|
+
*
|
|
25
|
+
* @param msgToCheck - The COSE_Sign1 structure to verify
|
|
26
|
+
* @param msgToAuth - Additional authenticated data (will be CBOR encoded)
|
|
27
|
+
* @param verifier - The xDSA public key
|
|
28
|
+
* @param domain - Application-specific domain separator
|
|
29
|
+
* @param maxDriftSecs - Maximum allowed clock drift (undefined for no time check)
|
|
30
|
+
* @returns The decoded embedded payload
|
|
31
|
+
*/
|
|
32
|
+
export declare function verify<T, A>(msgToCheck: Uint8Array, msgToAuth: A, verifier: XdsaPublicKey, domain: Uint8Array, maxDriftSecs?: number): Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Verify a COSE_Sign1 signature with a detached payload.
|
|
35
|
+
*
|
|
36
|
+
* @param msgToCheck - The COSE_Sign1 structure to verify
|
|
37
|
+
* @param msgToAuth - The detached message to authenticate (will be CBOR encoded)
|
|
38
|
+
* @param verifier - The xDSA public key
|
|
39
|
+
* @param domain - Application-specific domain separator
|
|
40
|
+
* @param maxDriftSecs - Maximum allowed clock drift (undefined for no time check)
|
|
41
|
+
*/
|
|
42
|
+
export declare function verifyDetached<A>(msgToCheck: Uint8Array, msgToAuth: A, verifier: XdsaPublicKey, domain: Uint8Array, maxDriftSecs?: number): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Extract the signer's fingerprint from a COSE_Sign1 without verifying.
|
|
45
|
+
*
|
|
46
|
+
* @param signature - The COSE_Sign1 structure
|
|
47
|
+
* @returns The signer fingerprint
|
|
48
|
+
*/
|
|
49
|
+
export declare function signer(signature: Uint8Array): Promise<XdsaFingerprint>;
|
|
50
|
+
/**
|
|
51
|
+
* Extract the embedded payload from a COSE_Sign1 without verifying.
|
|
52
|
+
*
|
|
53
|
+
* Warning: The returned payload is unauthenticated and should not be
|
|
54
|
+
* trusted until verified with `verify`.
|
|
55
|
+
*
|
|
56
|
+
* @param signature - The COSE_Sign1 structure
|
|
57
|
+
* @returns The decoded (but unverified) payload
|
|
58
|
+
*/
|
|
59
|
+
export declare function peek<T>(signature: Uint8Array): Promise<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Extract the recipient's fingerprint from a COSE_Encrypt0 without decrypting.
|
|
62
|
+
*
|
|
63
|
+
* @param ciphertext - The COSE_Encrypt0 structure
|
|
64
|
+
* @returns The recipient fingerprint
|
|
65
|
+
*/
|
|
66
|
+
export declare function recipient(ciphertext: Uint8Array): Promise<XhpkeFingerprint>;
|
|
67
|
+
/**
|
|
68
|
+
* Sign a message then encrypt it to a recipient (sign-then-encrypt).
|
|
69
|
+
*
|
|
70
|
+
* @param msgToSeal - The payload to sign and encrypt (will be CBOR encoded)
|
|
71
|
+
* @param msgToAuth - Additional authenticated data (will be CBOR encoded)
|
|
72
|
+
* @param signerKey - The xDSA secret key to sign with
|
|
73
|
+
* @param recipientKey - The xHPKE public key to encrypt to
|
|
74
|
+
* @param domain - Application-specific domain separator
|
|
75
|
+
* @returns The sealed COSE structure
|
|
76
|
+
*/
|
|
77
|
+
export declare function seal<S, A>(msgToSeal: S, msgToAuth: A, signerKey: XdsaSecretKey, recipientKey: XhpkePublicKey, domain: Uint8Array): Promise<Uint8Array>;
|
|
78
|
+
/**
|
|
79
|
+
* Decrypt and verify a sealed message.
|
|
80
|
+
*
|
|
81
|
+
* @param msgToOpen - The sealed COSE structure
|
|
82
|
+
* @param msgToAuth - Additional authenticated data (will be CBOR encoded)
|
|
83
|
+
* @param recipientKey - The xHPKE secret key to decrypt with
|
|
84
|
+
* @param senderKey - The xDSA public key to verify against
|
|
85
|
+
* @param domain - Application-specific domain separator
|
|
86
|
+
* @param maxDriftSecs - Maximum allowed clock drift (undefined for no time check)
|
|
87
|
+
* @returns The decoded payload
|
|
88
|
+
*/
|
|
89
|
+
export declare function open<T, A>(msgToOpen: Uint8Array, msgToAuth: A, recipientKey: XhpkeSecretKey, senderKey: XdsaPublicKey, domain: Uint8Array, maxDriftSecs?: number): Promise<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Encrypt an already-signed COSE_Sign1 to a recipient.
|
|
92
|
+
*
|
|
93
|
+
* For most use cases, prefer `seal` which signs and encrypts in one step.
|
|
94
|
+
* Use this only when re-encrypting a message to a different recipient
|
|
95
|
+
* without access to the original signer's key.
|
|
96
|
+
*
|
|
97
|
+
* @param sign1 - The COSE_Sign1 structure to encrypt
|
|
98
|
+
* @param msgToAuth - Additional authenticated data (will be CBOR encoded)
|
|
99
|
+
* @param recipientKey - The xHPKE public key to encrypt to
|
|
100
|
+
* @param domain - Application-specific domain separator
|
|
101
|
+
* @returns The COSE_Encrypt0 structure
|
|
102
|
+
*/
|
|
103
|
+
export declare function encrypt<A>(sign1: Uint8Array, msgToAuth: A, recipientKey: XhpkePublicKey, domain: Uint8Array): Promise<Uint8Array>;
|
|
104
|
+
/**
|
|
105
|
+
* Decrypt a sealed message without verifying the signature.
|
|
106
|
+
*
|
|
107
|
+
* This allows inspecting the signer before verification. Use `signer` to
|
|
108
|
+
* extract the signer's fingerprint, then verify with `verify`.
|
|
109
|
+
*
|
|
110
|
+
* @param msgToOpen - The COSE_Encrypt0 structure
|
|
111
|
+
* @param msgToAuth - Additional authenticated data (will be CBOR encoded)
|
|
112
|
+
* @param recipientKey - The xHPKE secret key to decrypt with
|
|
113
|
+
* @param domain - Application-specific domain separator
|
|
114
|
+
* @returns The decrypted COSE_Sign1 structure (not yet verified)
|
|
115
|
+
*/
|
|
116
|
+
export declare function decrypt<A>(msgToOpen: Uint8Array, msgToAuth: A, recipientKey: XhpkeSecretKey, domain: Uint8Array): Promise<Uint8Array>;
|
|
117
|
+
//# sourceMappingURL=cose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cose.d.ts","sourceRoot":"","sources":["../src/cose.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,SAAS,IAAI,aAAa,EAC1B,SAAS,IAAI,aAAa,EAC1B,WAAW,IAAI,eAAe,EAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,SAAS,IAAI,cAAc,EAC3B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AAE,CAAC,EAC7B,SAAS,EAAE,CAAC,EACZ,SAAS,EAAE,CAAC,EACZ,SAAS,EAAE,aAAa,EACxB,YAAY,EAAE,cAAc,EAC5B,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CAarB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,IAAI,CAAC,CAAC,EAAE,CAAC,EAC7B,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,CAAC,EACZ,YAAY,EAAE,cAAc,EAC5B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,UAAU,EAClB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,CAAC,CAAC,CAYZ;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,CAAC,EACZ,YAAY,EAAE,cAAc,EAC5B,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CAMrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,CAAC,EACZ,YAAY,EAAE,cAAc,EAC5B,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CAMrB"}
|
package/dist/hkdf.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a key from secret, salt, and info using HKDF-SHA256.
|
|
3
|
+
*
|
|
4
|
+
* @param secret - The input keying material
|
|
5
|
+
* @param salt - Optional salt value (can be empty)
|
|
6
|
+
* @param info - Optional context/application-specific info (can be empty)
|
|
7
|
+
* @param outLen - Desired output length in bytes (max 8160)
|
|
8
|
+
* @returns The derived key
|
|
9
|
+
*/
|
|
10
|
+
export declare function key(secret: Uint8Array, salt: Uint8Array, info: Uint8Array, outLen: number): Promise<Uint8Array>;
|
|
11
|
+
/**
|
|
12
|
+
* Extract a pseudorandom key from secret and salt using HKDF-SHA256.
|
|
13
|
+
*
|
|
14
|
+
* Only use this if you need to reuse the extracted key with multiple
|
|
15
|
+
* expand invocations. Most scenarios should use `key` instead.
|
|
16
|
+
*
|
|
17
|
+
* @param secret - The input keying material
|
|
18
|
+
* @param salt - Optional salt value (can be empty)
|
|
19
|
+
* @returns A 32-byte pseudorandom key
|
|
20
|
+
*/
|
|
21
|
+
export declare function extract(secret: Uint8Array, salt: Uint8Array): Promise<Uint8Array>;
|
|
22
|
+
/**
|
|
23
|
+
* Expand a pseudorandom key with info using HKDF-SHA256.
|
|
24
|
+
*
|
|
25
|
+
* The prk should have been generated by `extract` or be a uniformly
|
|
26
|
+
* random 32-byte key.
|
|
27
|
+
*
|
|
28
|
+
* @param prk - A 32-byte pseudorandom key
|
|
29
|
+
* @param info - Optional context/application-specific info (can be empty)
|
|
30
|
+
* @param outLen - Desired output length in bytes (max 8160)
|
|
31
|
+
* @returns The derived key
|
|
32
|
+
*/
|
|
33
|
+
export declare function expand(prk: Uint8Array, info: Uint8Array, outLen: number): Promise<Uint8Array>;
|
|
34
|
+
//# sourceMappingURL=hkdf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../src/hkdf.ts"],"names":[],"mappings":"AAqBA;;;;;;;;GAQG;AACH,wBAAsB,GAAG,CACvB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAC3B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,MAAM,CAC1B,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,CAGrB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * as rand from './rand.js';
|
|
2
|
+
export * as hkdf from './hkdf.js';
|
|
3
|
+
export * as argon2 from './argon2.js';
|
|
4
|
+
export * as x509 from './x509.js';
|
|
5
|
+
export * as xdsa from './xdsa.js';
|
|
6
|
+
export * as xhpke from './xhpke.js';
|
|
7
|
+
export * as cose from './cose.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC"}
|