@nice-code/util 0.5.5 → 0.6.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/README.md +165 -73
- package/build/index.js +779 -7
- package/build/types/core/core_valibot_schemas.d.ts +13 -0
- package/build/types/core/createDataStringConverter_stringToObject.d.ts +12 -0
- package/build/types/crypto/aes_gcm/createAesGcmKeyFromX25519Keys.d.ts +6 -0
- package/build/types/crypto/aes_gcm/decryptTextDataWithAesGcmKey.d.ts +5 -0
- package/build/types/crypto/aes_gcm/encryptTextDataWithAesGcmKey.d.ts +5 -0
- package/build/types/crypto/client_key_link/ClientCryptoKeyLink.d.ts +167 -0
- package/build/types/crypto/client_key_link/buildVerifyKeyBoundInfoString.d.ts +20 -0
- package/build/types/crypto/crypto.converters.d.ts +53 -0
- package/build/types/crypto/crypto.schema.d.ts +83 -0
- package/build/types/crypto/ed25519/generateEd25519KeyPair.d.ts +1 -0
- package/build/types/crypto/ed25519/importEd25519Key.d.ts +35 -0
- package/build/types/crypto/ed25519/serializeEd25519Key_Jwk.d.ts +2 -0
- package/build/types/crypto/ed25519/serializeEd25519Key_Raw.d.ts +2 -0
- package/build/types/crypto/ed25519/signCombinedTextDataWithKeyEd25519.d.ts +2 -0
- package/build/types/crypto/ed25519/signTextDataWithKeyEd25519.d.ts +1 -0
- package/build/types/crypto/ed25519/verifyWithKeyEd25519.d.ts +5 -0
- package/build/types/crypto/index.d.ts +18 -0
- package/build/types/crypto/x25519/createSharedBitsFromX25519.d.ts +4 -0
- package/build/types/crypto/x25519/generateX25519KeyPair.d.ts +1 -0
- package/build/types/crypto/x25519/importX25519Key.d.ts +35 -0
- package/build/types/crypto/x25519/serializeX25519Key_Jwk.d.ts +2 -0
- package/build/types/crypto/x25519/serializeX25519Key_Raw.d.ts +2 -0
- package/build/types/data_type/index.d.ts +1 -0
- package/build/types/data_type/string/nullEmpty.d.ts +3 -0
- package/build/types/index.d.ts +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
export declare const vBase64: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
|
|
3
|
+
export declare const vCreateSchema_TypePrefixedDataString: <P extends string>(typeValues: P[], typeKind: string) => v.SchemaWithPipe<readonly [v.CustomSchema<`${P}::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
4
|
+
export interface ICreateTypePrefixedDataStringResult<T extends string, F extends string> {
|
|
5
|
+
type: T;
|
|
6
|
+
format: F;
|
|
7
|
+
typeKind: string;
|
|
8
|
+
formatKind?: string;
|
|
9
|
+
transformJson?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const vCreateSchema_TypeAndFormatPrefixedDataString: <T extends string, F extends string>({ type, format, typeKind, formatKind, }: ICreateTypePrefixedDataStringResult<T, F>) => v.SchemaWithPipe<readonly [v.CustomSchema<`${T}::${F}::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
12
|
+
export declare const vCreateSchema_TypeAndId: <S extends string>(dataType: S | S[]) => v.SchemaWithPipe<readonly [v.CustomSchema<`${S}::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
13
|
+
export type TTypeAndId<S extends string = string> = `${S}::${string}`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ECryptoKeyFormat } from "../crypto/crypto.schema";
|
|
2
|
+
interface ICreateDataStringConverter_StringToObject {
|
|
3
|
+
transformJsonForFormats?: ECryptoKeyFormat[];
|
|
4
|
+
transformJson?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const createDataStringConverter_stringToObject: <T extends string, F extends ECryptoKeyFormat, D = string>({ transformJsonForFormats, transformJson, }?: ICreateDataStringConverter_StringToObject) => (inputDataString: `${T}::${F}::${string}`) => {
|
|
7
|
+
formattedString: `${T}::${F}::${string}`;
|
|
8
|
+
type: T;
|
|
9
|
+
format: F;
|
|
10
|
+
data: D;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const createAesGcmKeyFromX25519Keys: ({ externalX25519PublicKey, internalX25519PrivateKey, infoString, saltString, }: {
|
|
2
|
+
internalX25519PrivateKey: CryptoKey;
|
|
3
|
+
externalX25519PublicKey: CryptoKey;
|
|
4
|
+
saltString?: string;
|
|
5
|
+
infoString?: string;
|
|
6
|
+
}) => Promise<CryptoKey>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { TTypeAndId } from "../../core/core_valibot_schemas";
|
|
2
|
+
import type { StorageAdapter } from "../../storage_adapter/StorageAdapter";
|
|
3
|
+
import type { TEncryptedAesGcmPayload, TSerializedCryptoKeyData_Ed25519_Raw, TSerializedCryptoKeyData_X25519_Raw } from "../crypto.schema";
|
|
4
|
+
interface IClientCryptoKeyLink_Constructor {
|
|
5
|
+
storageAdapter?: StorageAdapter;
|
|
6
|
+
}
|
|
7
|
+
interface ILinkedClientPublicKeys {
|
|
8
|
+
verifyPublicKey?: TSerializedCryptoKeyData_Ed25519_Raw;
|
|
9
|
+
exchangePublicKey?: TSerializedCryptoKeyData_X25519_Raw;
|
|
10
|
+
}
|
|
11
|
+
interface ILocalPublicKeys {
|
|
12
|
+
verifyPublicKey: TSerializedCryptoKeyData_Ed25519_Raw;
|
|
13
|
+
exchangePublicKey: TSerializedCryptoKeyData_X25519_Raw;
|
|
14
|
+
}
|
|
15
|
+
interface ILinkClientKeys {
|
|
16
|
+
linkedClientId: TTypeAndId;
|
|
17
|
+
verifyPublicKey?: TSerializedCryptoKeyData_Ed25519_Raw;
|
|
18
|
+
exchangePublicKey?: TSerializedCryptoKeyData_X25519_Raw;
|
|
19
|
+
saltString?: string;
|
|
20
|
+
infoString?: string;
|
|
21
|
+
bindVerifyKeysIntoDerivation?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface IEncryptDataForLinkedClient {
|
|
24
|
+
linkedClientId: TTypeAndId;
|
|
25
|
+
dataToEncrypt: string;
|
|
26
|
+
}
|
|
27
|
+
interface IDecryptDataFromLinkedClient {
|
|
28
|
+
linkedClientId: TTypeAndId;
|
|
29
|
+
dataToDecrypt: TEncryptedAesGcmPayload;
|
|
30
|
+
}
|
|
31
|
+
interface IDecryptAndVerifyDataFromLinkedClient extends IDecryptDataFromLinkedClient {
|
|
32
|
+
signatureBase64: string;
|
|
33
|
+
}
|
|
34
|
+
interface IVerifyChallengeFromLinkedClient {
|
|
35
|
+
linkedClientId: TTypeAndId;
|
|
36
|
+
challenge: string;
|
|
37
|
+
signatureBase64: string;
|
|
38
|
+
}
|
|
39
|
+
export declare class ClientCryptoKeyLink {
|
|
40
|
+
private localExchangeKeyPair;
|
|
41
|
+
private localVerifyKeyPair;
|
|
42
|
+
private linkedClientKeys;
|
|
43
|
+
private storage;
|
|
44
|
+
private initialized;
|
|
45
|
+
private initializePromise;
|
|
46
|
+
private localExchangeKeyPairPromise;
|
|
47
|
+
private localVerifyKeyPairPromise;
|
|
48
|
+
constructor({ storageAdapter }?: IClientCryptoKeyLink_Constructor);
|
|
49
|
+
/**
|
|
50
|
+
* Loads the local key pairs and any linked client public keys from storage (when a storage
|
|
51
|
+
* adapter was provided), generating and persisting fresh local key pairs if none exist yet.
|
|
52
|
+
*
|
|
53
|
+
* Must be called (and awaited) before any sign/verify/encrypt/decrypt operation.
|
|
54
|
+
*/
|
|
55
|
+
initialize(): Promise<void>;
|
|
56
|
+
private runInitialize;
|
|
57
|
+
/**
|
|
58
|
+
* Loads the local key pairs from storage if they were previously persisted. Does NOT generate
|
|
59
|
+
* fresh keys — local identity is created lazily on first use (see {@link ensureLocalExchangeKeyPair}
|
|
60
|
+
* / {@link ensureLocalVerifyKeyPair}), so a verify-only or otherwise key-less consumer never
|
|
61
|
+
* generates or stores keys it does not need.
|
|
62
|
+
*/
|
|
63
|
+
private loadStoredLocalKeys;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the local exchange (X25519) key pair, generating and persisting it on first use.
|
|
66
|
+
* Concurrent callers share a single generation.
|
|
67
|
+
*/
|
|
68
|
+
private ensureLocalExchangeKeyPair;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the local verify (Ed25519) key pair, generating and persisting it on first use.
|
|
71
|
+
* Concurrent callers share a single generation.
|
|
72
|
+
*/
|
|
73
|
+
private ensureLocalVerifyKeyPair;
|
|
74
|
+
private loadLinkedClients;
|
|
75
|
+
private serializeExchangeKeyPair;
|
|
76
|
+
private serializeVerifyKeyPair;
|
|
77
|
+
/**
|
|
78
|
+
* The local public keys that should be shared with a linked client so that it can verify this
|
|
79
|
+
* client's signatures and derive a shared encryption key. Generates the local identity on first
|
|
80
|
+
* use.
|
|
81
|
+
*/
|
|
82
|
+
getLocalPublicKeys(): Promise<ILocalPublicKeys>;
|
|
83
|
+
/**
|
|
84
|
+
* The local exchange (X25519) public key, generating the exchange key pair on first use. Does not
|
|
85
|
+
* touch the verify key pair — useful for an exchange-only consumer (e.g. a bridge) that never
|
|
86
|
+
* signs.
|
|
87
|
+
*/
|
|
88
|
+
getLocalExchangePublicKey(): Promise<TSerializedCryptoKeyData_X25519_Raw>;
|
|
89
|
+
/**
|
|
90
|
+
* The local verify (Ed25519) public key, generating the verify key pair on first use. Does not
|
|
91
|
+
* touch the exchange key pair.
|
|
92
|
+
*/
|
|
93
|
+
getLocalVerifyPublicKey(): Promise<TSerializedCryptoKeyData_Ed25519_Raw>;
|
|
94
|
+
/**
|
|
95
|
+
* Registers (or updates) the public keys of a linked client in memory only — nothing is written
|
|
96
|
+
* to storage. Use this for ephemeral links (e.g. a per-session bridge or end-to-end peer keyed by
|
|
97
|
+
* a session salt/info), so the derived shared key never outlives the process.
|
|
98
|
+
*
|
|
99
|
+
* Re-linking with a new exchange public key, salt, or info invalidates any previously cached
|
|
100
|
+
* shared key for the link.
|
|
101
|
+
*/
|
|
102
|
+
linkClient({ linkedClientId, verifyPublicKey, exchangePublicKey, saltString, infoString, bindVerifyKeysIntoDerivation, }: ILinkClientKeys): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Like {@link linkClient}, but also persists the linked client's public keys (and salt/info) to
|
|
105
|
+
* storage so the link survives a reload.
|
|
106
|
+
*
|
|
107
|
+
* NOTE: salt/info are written in plaintext. When they are session secrets (e.g. a partner secret
|
|
108
|
+
* or bridge salt), prefer {@link linkClient} and re-establish the link per session instead.
|
|
109
|
+
*/
|
|
110
|
+
linkClientAndStore(input: ILinkClientKeys): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Whether a linked client is currently registered (in memory) under this id.
|
|
113
|
+
*/
|
|
114
|
+
hasLinkedClient(linkedClientId: TTypeAndId): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* The serialized public keys registered for a linked client, or undefined when the client is not
|
|
117
|
+
* linked. Useful when a holder needs to relay a linked client's keys onward (e.g. a backend
|
|
118
|
+
* relaying a wallet's verify key to a partner).
|
|
119
|
+
*/
|
|
120
|
+
getLinkedClientPublicKeys(linkedClientId: TTypeAndId): ILinkedClientPublicKeys | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Removes a single linked client from memory and, when storage is available, from persisted
|
|
123
|
+
* state. Any cached shared key for the link is dropped with it.
|
|
124
|
+
*/
|
|
125
|
+
unlinkClient(linkedClientId: TTypeAndId): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Removes all linked clients from memory and persisted state, while keeping the local identity
|
|
128
|
+
* key pairs intact.
|
|
129
|
+
*/
|
|
130
|
+
unlinkAllClients(): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Wipes everything this instance owns — local identity key pairs and all linked clients, in
|
|
133
|
+
* memory and in storage. After a reset, {@link initialize} must be called again before use (it
|
|
134
|
+
* will generate a fresh local identity).
|
|
135
|
+
*
|
|
136
|
+
* Only the keys owned by this util are removed, so a shared storage adapter's other data is left
|
|
137
|
+
* untouched.
|
|
138
|
+
*/
|
|
139
|
+
reset(): Promise<void>;
|
|
140
|
+
private getLinkedClient;
|
|
141
|
+
private getAesGcmKeyForLinkedClient;
|
|
142
|
+
encryptDataForLinkedClient({ dataToEncrypt, linkedClientId, }: IEncryptDataForLinkedClient): Promise<TEncryptedAesGcmPayload>;
|
|
143
|
+
decryptDataFromLinkedClient({ dataToDecrypt, linkedClientId, }: IDecryptDataFromLinkedClient): Promise<string>;
|
|
144
|
+
signAndEncryptDataForLinkedClient({ dataToEncrypt, linkedClientId, }: IEncryptDataForLinkedClient): Promise<{
|
|
145
|
+
encryptedData: TEncryptedAesGcmPayload;
|
|
146
|
+
signatureBase64: string;
|
|
147
|
+
}>;
|
|
148
|
+
/**
|
|
149
|
+
* Decrypts a payload from a linked client and verifies that the decrypted plaintext was signed
|
|
150
|
+
* by that client. Counterpart to {@link signAndEncryptDataForLinkedClient}.
|
|
151
|
+
*
|
|
152
|
+
* Returns the decrypted `data` alongside `isValid` — the caller decides how to handle an invalid
|
|
153
|
+
* signature. (A tampered ciphertext fails earlier at AES-GCM decryption.)
|
|
154
|
+
*/
|
|
155
|
+
decryptAndVerifyDataFromLinkedClient({ dataToDecrypt, linkedClientId, signatureBase64, }: IDecryptAndVerifyDataFromLinkedClient): Promise<{
|
|
156
|
+
data: string;
|
|
157
|
+
isValid: boolean;
|
|
158
|
+
}>;
|
|
159
|
+
signChallenge(challenge: [string, ...string[]]): Promise<{
|
|
160
|
+
signatureBase64: string;
|
|
161
|
+
}>;
|
|
162
|
+
/**
|
|
163
|
+
* Verifies a signature over `challenge` against the linked client's verify (Ed25519) public key.
|
|
164
|
+
*/
|
|
165
|
+
verifyChallengeFromLinkedClient({ linkedClientId, challenge, signatureBase64, }: IVerifyChallengeFromLinkedClient): Promise<boolean>;
|
|
166
|
+
}
|
|
167
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TSerializedCryptoKeyData_Ed25519_Raw } from "../crypto.schema";
|
|
2
|
+
interface IBuildVerifyKeyBoundInfoString_Input {
|
|
3
|
+
infoString?: string;
|
|
4
|
+
verifyPublicKeys: [TSerializedCryptoKeyData_Ed25519_Raw, TSerializedCryptoKeyData_Ed25519_Raw];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The canonical HKDF `info` for a client-to-client shared key that binds both sides' verify
|
|
8
|
+
* public keys into the derivation.
|
|
9
|
+
*
|
|
10
|
+
* When the two keys are relayed through an intermediary, a tampered key produces mismatched AES
|
|
11
|
+
* keys on the two sides — the very first decryption fails, so key substitution is detected without
|
|
12
|
+
* any extra signature ceremony.
|
|
13
|
+
*
|
|
14
|
+
* The keys are sorted lexicographically so the result is independent of which side is "local" —
|
|
15
|
+
* both ends of a link compute the identical string without coordinating an order. Used internally
|
|
16
|
+
* by ClientCryptoKeyLink (`bindVerifyKeysIntoDerivation`); exported for code that derives the same
|
|
17
|
+
* key outside the link.
|
|
18
|
+
*/
|
|
19
|
+
export declare const buildVerifyKeyBoundInfoString: ({ infoString, verifyPublicKeys, }: IBuildVerifyKeyBoundInfoString_Input) => string;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ECryptoKeyAlgo, ECryptoKeyFormat, type ISerializedKeyData_Ed25519_Jwk, type ISerializedKeyData_Ed25519_Raw, type ISerializedKeyData_X25519_Jwk, type ISerializedKeyData_X25519_Raw, type TSerializedCryptoKeyData_Ed25519_Jwk, type TSerializedCryptoKeyData_Ed25519_Jwk_Transformed, type TSerializedCryptoKeyData_Ed25519_Raw, type TSerializedCryptoKeyData_Ed25519_Raw_Transformed, type TSerializedCryptoKeyData_X25519_Jwk, type TSerializedCryptoKeyData_X25519_Jwk_Transformed, type TSerializedCryptoKeyData_X25519_Raw, type TSerializedCryptoKeyData_X25519_Raw_Transformed } from "./crypto.schema";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* [CRYPTO ALGO] ED25519
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export declare const convertEd25519RawDataStringToObject: (inputDataString: `ed25519::raw_base64::${string}`) => {
|
|
8
|
+
formattedString: `ed25519::raw_base64::${string}`;
|
|
9
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
10
|
+
format: ECryptoKeyFormat.raw_base64;
|
|
11
|
+
data: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const convertEd25519JwkDataStringToObject: (inputDataString: `ed25519::jwk::${string}`) => {
|
|
14
|
+
formattedString: `ed25519::jwk::${string}`;
|
|
15
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
16
|
+
format: ECryptoKeyFormat.jwk;
|
|
17
|
+
data: JsonWebKey;
|
|
18
|
+
};
|
|
19
|
+
export declare const convertEd25519FormattedStringToObject: (inputDataString: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`) => {
|
|
20
|
+
formattedString: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`;
|
|
21
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
22
|
+
format: ECryptoKeyFormat;
|
|
23
|
+
data: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const convertEd25519RawDataStringToSerializedKeyData: (input: TSerializedCryptoKeyData_Ed25519_Raw) => ISerializedKeyData_Ed25519_Raw;
|
|
26
|
+
export declare const convertEd25519JwkDataStringToSerializedKeyData: (input: TSerializedCryptoKeyData_Ed25519_Jwk) => ISerializedKeyData_Ed25519_Jwk;
|
|
27
|
+
export 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;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* [CRYPTO ALGO] X25519
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
export declare const convertX25519RawDataStringToObject: (inputDataString: `x25519::raw_base64::${string}`) => {
|
|
34
|
+
formattedString: `x25519::raw_base64::${string}`;
|
|
35
|
+
type: ECryptoKeyAlgo.x25519;
|
|
36
|
+
format: ECryptoKeyFormat.raw_base64;
|
|
37
|
+
data: string;
|
|
38
|
+
};
|
|
39
|
+
export declare const convertX25519JwkDataStringToObject: (inputDataString: `x25519::jwk::${string}`) => {
|
|
40
|
+
formattedString: `x25519::jwk::${string}`;
|
|
41
|
+
type: ECryptoKeyAlgo.x25519;
|
|
42
|
+
format: ECryptoKeyFormat.jwk;
|
|
43
|
+
data: JsonWebKey;
|
|
44
|
+
};
|
|
45
|
+
export declare const convertX25519FormattedStringToObject: (inputDataString: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`) => {
|
|
46
|
+
formattedString: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`;
|
|
47
|
+
type: ECryptoKeyAlgo.x25519;
|
|
48
|
+
format: ECryptoKeyFormat;
|
|
49
|
+
data: string;
|
|
50
|
+
};
|
|
51
|
+
export declare const convertX25519RawDataStringToSerializedKeyData: (input: TSerializedCryptoKeyData_X25519_Raw) => ISerializedKeyData_X25519_Raw;
|
|
52
|
+
export declare const convertX25519JwkDataStringToSerializedKeyData: (input: TSerializedCryptoKeyData_X25519_Jwk) => ISerializedKeyData_X25519_Jwk;
|
|
53
|
+
export 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;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
export declare enum ECryptoKeyAlgo {
|
|
3
|
+
ed25519 = "ed25519",
|
|
4
|
+
x25519 = "x25519"
|
|
5
|
+
}
|
|
6
|
+
export declare enum ECryptoKeyFormat {
|
|
7
|
+
raw_base64 = "raw_base64",
|
|
8
|
+
jwk = "jwk"
|
|
9
|
+
}
|
|
10
|
+
export declare const vSerializedCryptoKeyDataEd25519_Raw: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
11
|
+
export declare const vSerializedCryptoKeyDataEd25519_Jwk: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
12
|
+
export type TSerializedCryptoKeyData_Ed25519_Raw = v.InferInput<typeof vSerializedCryptoKeyDataEd25519_Raw>;
|
|
13
|
+
export type TSerializedCryptoKeyData_Ed25519_Raw_Transformed = {
|
|
14
|
+
formattedString: `${ECryptoKeyAlgo.ed25519}::${ECryptoKeyFormat.raw_base64}::${string}`;
|
|
15
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
16
|
+
format: ECryptoKeyFormat.raw_base64;
|
|
17
|
+
data: string;
|
|
18
|
+
};
|
|
19
|
+
export type TSerializedCryptoKeyData_Ed25519_Jwk = v.InferInput<typeof vSerializedCryptoKeyDataEd25519_Jwk>;
|
|
20
|
+
export type TSerializedCryptoKeyData_Ed25519_Jwk_Transformed = {
|
|
21
|
+
formattedString: `${ECryptoKeyAlgo.ed25519}::${ECryptoKeyFormat.jwk}::${string}`;
|
|
22
|
+
type: ECryptoKeyAlgo.ed25519;
|
|
23
|
+
format: ECryptoKeyFormat.jwk;
|
|
24
|
+
data: JsonWebKey;
|
|
25
|
+
};
|
|
26
|
+
export declare const vSerializedCryptoKeyDataX25519_Raw: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
27
|
+
export declare const vSerializedCryptoKeyDataX25519_Jwk: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
28
|
+
export declare const vCryptoKeyPairDataX25519: v.ObjectSchema<{
|
|
29
|
+
readonly publicKey: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
30
|
+
readonly privateKey: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
31
|
+
}, undefined>;
|
|
32
|
+
export type TSerializedCryptoKeyPairDataX25519 = v.InferInput<typeof vCryptoKeyPairDataX25519>;
|
|
33
|
+
export declare const vCryptoKeyPairDataEd25519: v.ObjectSchema<{
|
|
34
|
+
readonly publicKey: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
35
|
+
readonly privateKey: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
|
|
36
|
+
}, undefined>;
|
|
37
|
+
export type TSerializedCryptoKeyPairDataEd25519 = v.InferInput<typeof vCryptoKeyPairDataEd25519>;
|
|
38
|
+
export type TSerializedCryptoKeyData_X25519_Raw = v.InferInput<typeof vSerializedCryptoKeyDataX25519_Raw>;
|
|
39
|
+
export type TSerializedCryptoKeyData_X25519_Raw_Transformed = {
|
|
40
|
+
formattedString: `${ECryptoKeyAlgo.x25519}::${ECryptoKeyFormat.raw_base64}::${string}`;
|
|
41
|
+
type: ECryptoKeyAlgo.x25519;
|
|
42
|
+
format: ECryptoKeyFormat.raw_base64;
|
|
43
|
+
data: string;
|
|
44
|
+
};
|
|
45
|
+
export type TSerializedCryptoKeyData_X25519_Jwk = v.InferInput<typeof vSerializedCryptoKeyDataX25519_Jwk>;
|
|
46
|
+
export type TSerializedCryptoKeyData_X25519_Jwk_Transformed = {
|
|
47
|
+
formattedString: `${ECryptoKeyAlgo.x25519}::${ECryptoKeyFormat.jwk}::${string}`;
|
|
48
|
+
type: ECryptoKeyAlgo.x25519;
|
|
49
|
+
format: ECryptoKeyFormat.jwk;
|
|
50
|
+
data: JsonWebKey;
|
|
51
|
+
};
|
|
52
|
+
export declare const vVerifyChallengeWithSignature_Input: v.ObjectSchema<{
|
|
53
|
+
readonly challenge: v.StringSchema<undefined>;
|
|
54
|
+
readonly signatureBase64: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
|
|
55
|
+
}, undefined>;
|
|
56
|
+
export declare const vVerifyChallengeWithSignature_WithThrow_Input: v.IntersectSchema<[v.ObjectSchema<{
|
|
57
|
+
readonly challenge: v.StringSchema<undefined>;
|
|
58
|
+
readonly signatureBase64: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
|
|
59
|
+
}, undefined>, v.ObjectSchema<{
|
|
60
|
+
readonly throwOnInvalid: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
61
|
+
}, undefined>], undefined>;
|
|
62
|
+
export type TVerifyChallengeWithSignature_Input = v.InferInput<typeof vVerifyChallengeWithSignature_Input>;
|
|
63
|
+
export type TVerifyChallengeWithSignature_WithThrow_Input = v.InferInput<typeof vVerifyChallengeWithSignature_WithThrow_Input>;
|
|
64
|
+
export declare const vEncryptedAesGcmPayload: v.ObjectSchema<{
|
|
65
|
+
readonly nonce: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
|
|
66
|
+
readonly ciphertext: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
|
|
67
|
+
}, undefined>;
|
|
68
|
+
export type TEncryptedAesGcmPayload = v.InferInput<typeof vEncryptedAesGcmPayload>;
|
|
69
|
+
export type TEncryptedAesGcmPayload_Transformed = v.InferOutput<typeof vEncryptedAesGcmPayload>;
|
|
70
|
+
interface ISerializedKeyData<T, P> {
|
|
71
|
+
transformed: T;
|
|
72
|
+
prefixed: P;
|
|
73
|
+
}
|
|
74
|
+
export interface ISerializedKeyData_Ed25519_Raw extends ISerializedKeyData<TSerializedCryptoKeyData_Ed25519_Raw_Transformed, TSerializedCryptoKeyData_Ed25519_Raw> {
|
|
75
|
+
}
|
|
76
|
+
export interface ISerializedKeyData_Ed25519_Jwk extends ISerializedKeyData<TSerializedCryptoKeyData_Ed25519_Jwk_Transformed, TSerializedCryptoKeyData_Ed25519_Jwk> {
|
|
77
|
+
}
|
|
78
|
+
export interface ISerializedKeyData_X25519_Raw extends ISerializedKeyData<TSerializedCryptoKeyData_X25519_Raw_Transformed, TSerializedCryptoKeyData_X25519_Raw> {
|
|
79
|
+
}
|
|
80
|
+
export interface ISerializedKeyData_X25519_Jwk extends ISerializedKeyData<TSerializedCryptoKeyData_X25519_Jwk_Transformed, TSerializedCryptoKeyData_X25519_Jwk> {
|
|
81
|
+
}
|
|
82
|
+
export type TSerializedKeyData = ISerializedKeyData_Ed25519_Raw | ISerializedKeyData_Ed25519_Jwk | ISerializedKeyData_X25519_Raw | ISerializedKeyData_X25519_Jwk;
|
|
83
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateEd25519KeyPair: () => Promise<CryptoKeyPair>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type TSerializedCryptoKeyData_Ed25519_Jwk_Transformed, type TSerializedCryptoKeyData_Ed25519_Raw_Transformed } from "../crypto.schema";
|
|
2
|
+
export declare const importEd25519Key: {
|
|
3
|
+
private: {
|
|
4
|
+
fromFormattedString: {
|
|
5
|
+
readonly extractable: (input: `ed25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
6
|
+
readonly nonExtractable: (input: `ed25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
7
|
+
};
|
|
8
|
+
fromSerializedObject: {
|
|
9
|
+
readonly extractable: (input: TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
10
|
+
readonly nonExtractable: (input: TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
11
|
+
};
|
|
12
|
+
fromJwk: {
|
|
13
|
+
readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
14
|
+
readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
public: {
|
|
18
|
+
fromBase64: {
|
|
19
|
+
readonly extractable: (input: string) => Promise<CryptoKey>;
|
|
20
|
+
readonly nonExtractable: (input: string) => Promise<CryptoKey>;
|
|
21
|
+
};
|
|
22
|
+
fromFormattedString: {
|
|
23
|
+
readonly extractable: (input: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
24
|
+
readonly nonExtractable: (input: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
25
|
+
};
|
|
26
|
+
fromSerializedObject: {
|
|
27
|
+
readonly extractable: (input: TSerializedCryptoKeyData_Ed25519_Raw_Transformed | TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
28
|
+
readonly nonExtractable: (input: TSerializedCryptoKeyData_Ed25519_Raw_Transformed | TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
29
|
+
};
|
|
30
|
+
fromJwk: {
|
|
31
|
+
readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
32
|
+
readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const signTextDataWithKeyEd25519: (data: string, cryptoKey: CryptoKey) => Promise<Uint8Array>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from "./aes_gcm/createAesGcmKeyFromX25519Keys";
|
|
2
|
+
export * from "./aes_gcm/decryptTextDataWithAesGcmKey";
|
|
3
|
+
export * from "./aes_gcm/encryptTextDataWithAesGcmKey";
|
|
4
|
+
export * from "./client_key_link/buildVerifyKeyBoundInfoString";
|
|
5
|
+
export * from "./client_key_link/ClientCryptoKeyLink";
|
|
6
|
+
export * from "./crypto.converters";
|
|
7
|
+
export * from "./ed25519/generateEd25519KeyPair";
|
|
8
|
+
export * from "./ed25519/importEd25519Key";
|
|
9
|
+
export * from "./ed25519/serializeEd25519Key_Jwk";
|
|
10
|
+
export * from "./ed25519/serializeEd25519Key_Raw";
|
|
11
|
+
export * from "./ed25519/signCombinedTextDataWithKeyEd25519";
|
|
12
|
+
export * from "./ed25519/signTextDataWithKeyEd25519";
|
|
13
|
+
export * from "./ed25519/verifyWithKeyEd25519";
|
|
14
|
+
export * from "./x25519/createSharedBitsFromX25519";
|
|
15
|
+
export * from "./x25519/generateX25519KeyPair";
|
|
16
|
+
export * from "./x25519/importX25519Key";
|
|
17
|
+
export * from "./x25519/serializeX25519Key_Jwk";
|
|
18
|
+
export * from "./x25519/serializeX25519Key_Raw";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateX25519KeyPair: () => Promise<CryptoKeyPair>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type TSerializedCryptoKeyData_X25519_Jwk_Transformed, type TSerializedCryptoKeyData_X25519_Raw_Transformed } from "../crypto.schema";
|
|
2
|
+
export declare const importX25519Key: {
|
|
3
|
+
private: {
|
|
4
|
+
fromFormattedString: {
|
|
5
|
+
readonly extractable: (input: `x25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
6
|
+
readonly nonExtractable: (input: `x25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
7
|
+
};
|
|
8
|
+
fromSerializedObject: {
|
|
9
|
+
readonly extractable: (input: TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
10
|
+
readonly nonExtractable: (input: TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
11
|
+
};
|
|
12
|
+
fromJwk: {
|
|
13
|
+
readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
14
|
+
readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
public: {
|
|
18
|
+
fromBase64: {
|
|
19
|
+
readonly extractable: (input: string) => Promise<CryptoKey>;
|
|
20
|
+
readonly nonExtractable: (input: string) => Promise<CryptoKey>;
|
|
21
|
+
};
|
|
22
|
+
fromFormattedString: {
|
|
23
|
+
readonly extractable: (input: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
24
|
+
readonly nonExtractable: (input: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`) => Promise<CryptoKey>;
|
|
25
|
+
};
|
|
26
|
+
fromSerializedObject: {
|
|
27
|
+
readonly extractable: (input: TSerializedCryptoKeyData_X25519_Raw_Transformed | TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
28
|
+
readonly nonExtractable: (input: TSerializedCryptoKeyData_X25519_Raw_Transformed | TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
|
|
29
|
+
};
|
|
30
|
+
fromJwk: {
|
|
31
|
+
readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
32
|
+
readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./string/nullEmpty";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const notNullEmpty: (str: string | null | undefined) => str is string;
|
|
2
|
+
export declare const nullEmpty: (str: string | null | undefined) => str is null | undefined | "";
|
|
3
|
+
export declare const firstNotNullEmpty: (...strItems: (string | null | undefined)[]) => string | undefined;
|
package/build/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nice-code/util",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -35,11 +35,15 @@
|
|
|
35
35
|
"@tanstack/react-query": "^5.100.3",
|
|
36
36
|
"react": ">=19",
|
|
37
37
|
"valibot": "^1.3.1",
|
|
38
|
+
"@scure/base": "^2.2.0",
|
|
38
39
|
"wrangler": "4.94.0"
|
|
39
40
|
},
|
|
40
41
|
"peerDependenciesMeta": {
|
|
41
42
|
"wrangler": {
|
|
42
43
|
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"@scure/base": {
|
|
46
|
+
"optional": true
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
}
|