@mshindi-labs/google 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +90 -2
- package/dist/chunk-JVP7HHFU.js +76 -0
- package/dist/chunk-JVP7HHFU.js.map +1 -0
- package/dist/chunk-KJPQ3DMR.cjs +76 -0
- package/dist/chunk-KJPQ3DMR.cjs.map +1 -0
- package/dist/chunk-RWT25QHA.js +190 -0
- package/dist/chunk-RWT25QHA.js.map +1 -0
- package/dist/chunk-SHDP4A3A.cjs +190 -0
- package/dist/chunk-SHDP4A3A.cjs.map +1 -0
- package/dist/chunk-SIDO26T7.js +949 -0
- package/dist/chunk-SIDO26T7.js.map +1 -0
- package/dist/chunk-V22QP2AM.cjs +49 -0
- package/dist/chunk-V22QP2AM.cjs.map +1 -0
- package/dist/chunk-VN5VWVCT.cjs +949 -0
- package/dist/chunk-VN5VWVCT.cjs.map +1 -0
- package/dist/chunk-Z7O6GO3C.js +49 -0
- package/dist/chunk-Z7O6GO3C.js.map +1 -0
- package/dist/core.cjs +289 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +173 -0
- package/dist/core.d.ts +173 -0
- package/dist/core.js +289 -0
- package/dist/core.js.map +1 -0
- package/dist/create-google-CPGcK-3G.d.cts +107 -0
- package/dist/create-google-nP9f9jd9.d.ts +107 -0
- package/dist/events-BsWOMtza.d.cts +160 -0
- package/dist/events-BsWOMtza.d.ts +160 -0
- package/dist/gmail.cjs +489 -0
- package/dist/gmail.cjs.map +1 -0
- package/dist/gmail.d.cts +53 -0
- package/dist/gmail.d.ts +53 -0
- package/dist/gmail.js +489 -0
- package/dist/gmail.js.map +1 -0
- package/dist/key-provider-Cq_14Bh6.d.cts +53 -0
- package/dist/key-provider-Cq_14Bh6.d.ts +53 -0
- package/dist/postgres.cjs +455 -0
- package/dist/postgres.cjs.map +1 -0
- package/dist/postgres.d.cts +22 -0
- package/dist/postgres.d.ts +22 -0
- package/dist/postgres.js +455 -0
- package/dist/postgres.js.map +1 -0
- package/dist/static-key-provider-BhyRhY6-.d.ts +18 -0
- package/dist/static-key-provider-CPNt4YvF.d.cts +18 -0
- package/dist/testing.cjs +829 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +147 -0
- package/dist/testing.d.ts +147 -0
- package/dist/testing.js +829 -0
- package/dist/testing.js.map +1 -0
- package/dist/transport-CVOgr9XP.d.cts +20 -0
- package/dist/transport-CVOgr9XP.d.ts +20 -0
- package/package.json +143 -4
package/dist/core.d.cts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
export { B as BASE_SCOPES, C as ClientsApi, a as ConnectionsApi, b as CreateGoogleOptions, G as GoogleCore, c as GoogleService, O as OAuthApi, S as SERVICE_SCOPES, d as createGoogle, s as scopesFor } from './create-google-CPGcK-3G.cjs';
|
|
2
|
+
export { S as StaticKeyProvider } from './static-key-provider-CPNt4YvF.cjs';
|
|
3
|
+
import { K as KeyProvider } from './key-provider-Cq_14Bh6.cjs';
|
|
4
|
+
export { I as InvalidGrantError, O as OAuthGateway } from './key-provider-Cq_14Bh6.cjs';
|
|
5
|
+
import { C as CredentialStore } from './events-BsWOMtza.cjs';
|
|
6
|
+
export { A as AadRecord, a as ConnectionRecord, b as ConnectionStatus, c as ConnectionView, E as EncryptedValue, d as EncryptedValueRef, G as GoogleEvent, L as Logger, O as OAuthClientRecord, e as OAuthStateRecord } from './events-BsWOMtza.cjs';
|
|
7
|
+
|
|
8
|
+
interface GoogleErrorOptions {
|
|
9
|
+
tenantId?: string;
|
|
10
|
+
connectionId?: string;
|
|
11
|
+
cause?: unknown;
|
|
12
|
+
}
|
|
13
|
+
declare class GoogleLibError extends Error {
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly tenantId?: string;
|
|
16
|
+
readonly connectionId?: string;
|
|
17
|
+
constructor(code: string, message: string, opts?: GoogleErrorOptions);
|
|
18
|
+
}
|
|
19
|
+
declare class OAuthClientNotConfiguredError extends GoogleLibError {
|
|
20
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
21
|
+
}
|
|
22
|
+
declare class InvalidOAuthStateError extends GoogleLibError {
|
|
23
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
24
|
+
}
|
|
25
|
+
declare class OAuthConsentDeniedError extends GoogleLibError {
|
|
26
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
27
|
+
}
|
|
28
|
+
declare class UnexpectedAccountError extends GoogleLibError {
|
|
29
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
30
|
+
}
|
|
31
|
+
declare class NoRefreshTokenError extends GoogleLibError {
|
|
32
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
33
|
+
}
|
|
34
|
+
declare class MissingScopeError extends GoogleLibError {
|
|
35
|
+
readonly required: string[];
|
|
36
|
+
constructor(required: string[], message?: string, opts?: GoogleErrorOptions);
|
|
37
|
+
}
|
|
38
|
+
declare class ConnectionNotFoundError extends GoogleLibError {
|
|
39
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
40
|
+
}
|
|
41
|
+
declare class ConnectionRevokedError extends GoogleLibError {
|
|
42
|
+
readonly reason: string;
|
|
43
|
+
constructor(reason: string, opts?: GoogleErrorOptions);
|
|
44
|
+
}
|
|
45
|
+
declare class CredentialIntegrityError extends GoogleLibError {
|
|
46
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
47
|
+
}
|
|
48
|
+
declare class KeyProviderUnavailableError extends GoogleLibError {
|
|
49
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
50
|
+
}
|
|
51
|
+
declare class InvalidMessageError extends GoogleLibError {
|
|
52
|
+
readonly field: string;
|
|
53
|
+
constructor(field: string, message?: string, opts?: GoogleErrorOptions);
|
|
54
|
+
}
|
|
55
|
+
declare class MessageTooLargeError extends GoogleLibError {
|
|
56
|
+
readonly bytes: number;
|
|
57
|
+
readonly limit: number;
|
|
58
|
+
constructor(bytes: number, limit: number, opts?: GoogleErrorOptions);
|
|
59
|
+
}
|
|
60
|
+
declare class RateLimitedError extends GoogleLibError {
|
|
61
|
+
readonly retryAfterMs: number | null;
|
|
62
|
+
constructor(retryAfterMs: number | null, opts?: GoogleErrorOptions);
|
|
63
|
+
}
|
|
64
|
+
declare class DailyQuotaExceededError extends GoogleLibError {
|
|
65
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
66
|
+
}
|
|
67
|
+
declare class SendOutcomeUnknownError extends GoogleLibError {
|
|
68
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
69
|
+
}
|
|
70
|
+
declare class GoogleApiError extends GoogleLibError {
|
|
71
|
+
readonly status: number;
|
|
72
|
+
readonly reason: string | null;
|
|
73
|
+
constructor(status: number, reason: string | null, opts?: GoogleErrorOptions);
|
|
74
|
+
}
|
|
75
|
+
declare class MissingPeerDependencyError extends GoogleLibError {
|
|
76
|
+
readonly peer: string;
|
|
77
|
+
constructor(peer: string, opts?: GoogleErrorOptions);
|
|
78
|
+
}
|
|
79
|
+
declare class InvalidConfigError extends GoogleLibError {
|
|
80
|
+
constructor(message: string, opts?: GoogleErrorOptions);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
type GcpKmsClientLike = {
|
|
84
|
+
encrypt(req: {
|
|
85
|
+
name: string;
|
|
86
|
+
plaintext: Uint8Array;
|
|
87
|
+
additionalAuthenticatedData: Uint8Array;
|
|
88
|
+
}): Promise<[{
|
|
89
|
+
ciphertext?: Uint8Array | string | null;
|
|
90
|
+
}]>;
|
|
91
|
+
decrypt(req: {
|
|
92
|
+
name: string;
|
|
93
|
+
ciphertext: Uint8Array;
|
|
94
|
+
additionalAuthenticatedData: Uint8Array;
|
|
95
|
+
}): Promise<[{
|
|
96
|
+
plaintext?: Uint8Array | string | null;
|
|
97
|
+
}]>;
|
|
98
|
+
};
|
|
99
|
+
/** Wraps DEKs with a Cloud KMS symmetric key. kid is `gcp-kms:<keyName>`. */
|
|
100
|
+
declare class GcpKmsKeyProvider implements KeyProvider {
|
|
101
|
+
#private;
|
|
102
|
+
readonly currentKeyId: string;
|
|
103
|
+
constructor(opts: {
|
|
104
|
+
keyName: string;
|
|
105
|
+
client?: GcpKmsClientLike;
|
|
106
|
+
});
|
|
107
|
+
wrap(dek: Uint8Array, aad: string): Promise<{
|
|
108
|
+
kid: string;
|
|
109
|
+
wdek: Uint8Array;
|
|
110
|
+
}>;
|
|
111
|
+
unwrap(kid: string, wdek: Uint8Array, aad: string): Promise<Uint8Array>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type AwsKmsClientLike = {
|
|
115
|
+
send(cmd: unknown): Promise<{
|
|
116
|
+
CiphertextBlob?: Uint8Array;
|
|
117
|
+
Plaintext?: Uint8Array;
|
|
118
|
+
}>;
|
|
119
|
+
};
|
|
120
|
+
type AwsKmsCommands = {
|
|
121
|
+
EncryptCommand: new (input: any) => unknown;
|
|
122
|
+
DecryptCommand: new (input: any) => unknown;
|
|
123
|
+
};
|
|
124
|
+
/** Wraps DEKs with an AWS KMS symmetric key. kid is `aws-kms:<keyId>`. */
|
|
125
|
+
declare class AwsKmsKeyProvider implements KeyProvider {
|
|
126
|
+
#private;
|
|
127
|
+
readonly currentKeyId: string;
|
|
128
|
+
/**
|
|
129
|
+
* AWS SDK v3 `send` needs real Command instances, so the SDK is loaded
|
|
130
|
+
* lazily via loadPeer only when `client` or `commands` is not injected.
|
|
131
|
+
* Inject both (e.g. in tests) to avoid loading it at all.
|
|
132
|
+
*/
|
|
133
|
+
constructor(opts: {
|
|
134
|
+
keyId: string;
|
|
135
|
+
client?: AwsKmsClientLike;
|
|
136
|
+
commands?: AwsKmsCommands;
|
|
137
|
+
});
|
|
138
|
+
wrap(dek: Uint8Array, aad: string): Promise<{
|
|
139
|
+
kid: string;
|
|
140
|
+
wdek: Uint8Array;
|
|
141
|
+
}>;
|
|
142
|
+
unwrap(kid: string, wdek: Uint8Array, aad: string): Promise<Uint8Array>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
type OpsFailure = {
|
|
146
|
+
record: string;
|
|
147
|
+
error: string;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Re-wraps every stored DEK under the provider's current key. Idempotent and
|
|
151
|
+
* resumable: values already on the current key (or outside `fromKeyId`) are skipped.
|
|
152
|
+
*/
|
|
153
|
+
declare function rewrapAll(opts: {
|
|
154
|
+
store: CredentialStore;
|
|
155
|
+
keyProvider: KeyProvider;
|
|
156
|
+
fromKeyId?: string;
|
|
157
|
+
batchSize?: number;
|
|
158
|
+
}): Promise<{
|
|
159
|
+
rewrapped: number;
|
|
160
|
+
skipped: number;
|
|
161
|
+
failed: OpsFailure[];
|
|
162
|
+
}>;
|
|
163
|
+
/** Fully decrypts every stored value (plaintext discarded immediately) to prove integrity. */
|
|
164
|
+
declare function verifyAll(opts: {
|
|
165
|
+
store: CredentialStore;
|
|
166
|
+
keyProvider: KeyProvider;
|
|
167
|
+
batchSize?: number;
|
|
168
|
+
}): Promise<{
|
|
169
|
+
ok: number;
|
|
170
|
+
failed: OpsFailure[];
|
|
171
|
+
}>;
|
|
172
|
+
|
|
173
|
+
export { type AwsKmsClientLike, type AwsKmsCommands, AwsKmsKeyProvider, ConnectionNotFoundError, ConnectionRevokedError, CredentialIntegrityError, CredentialStore, DailyQuotaExceededError, type GcpKmsClientLike, GcpKmsKeyProvider, GoogleApiError, type GoogleErrorOptions, GoogleLibError, InvalidConfigError, InvalidMessageError, InvalidOAuthStateError, KeyProvider, KeyProviderUnavailableError, MessageTooLargeError, MissingPeerDependencyError, MissingScopeError, NoRefreshTokenError, OAuthClientNotConfiguredError, OAuthConsentDeniedError, type OpsFailure, RateLimitedError, SendOutcomeUnknownError, UnexpectedAccountError, rewrapAll, verifyAll };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
export { B as BASE_SCOPES, C as ClientsApi, a as ConnectionsApi, b as CreateGoogleOptions, G as GoogleCore, c as GoogleService, O as OAuthApi, S as SERVICE_SCOPES, d as createGoogle, s as scopesFor } from './create-google-nP9f9jd9.js';
|
|
2
|
+
export { S as StaticKeyProvider } from './static-key-provider-BhyRhY6-.js';
|
|
3
|
+
import { K as KeyProvider } from './key-provider-Cq_14Bh6.js';
|
|
4
|
+
export { I as InvalidGrantError, O as OAuthGateway } from './key-provider-Cq_14Bh6.js';
|
|
5
|
+
import { C as CredentialStore } from './events-BsWOMtza.js';
|
|
6
|
+
export { A as AadRecord, a as ConnectionRecord, b as ConnectionStatus, c as ConnectionView, E as EncryptedValue, d as EncryptedValueRef, G as GoogleEvent, L as Logger, O as OAuthClientRecord, e as OAuthStateRecord } from './events-BsWOMtza.js';
|
|
7
|
+
|
|
8
|
+
interface GoogleErrorOptions {
|
|
9
|
+
tenantId?: string;
|
|
10
|
+
connectionId?: string;
|
|
11
|
+
cause?: unknown;
|
|
12
|
+
}
|
|
13
|
+
declare class GoogleLibError extends Error {
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly tenantId?: string;
|
|
16
|
+
readonly connectionId?: string;
|
|
17
|
+
constructor(code: string, message: string, opts?: GoogleErrorOptions);
|
|
18
|
+
}
|
|
19
|
+
declare class OAuthClientNotConfiguredError extends GoogleLibError {
|
|
20
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
21
|
+
}
|
|
22
|
+
declare class InvalidOAuthStateError extends GoogleLibError {
|
|
23
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
24
|
+
}
|
|
25
|
+
declare class OAuthConsentDeniedError extends GoogleLibError {
|
|
26
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
27
|
+
}
|
|
28
|
+
declare class UnexpectedAccountError extends GoogleLibError {
|
|
29
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
30
|
+
}
|
|
31
|
+
declare class NoRefreshTokenError extends GoogleLibError {
|
|
32
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
33
|
+
}
|
|
34
|
+
declare class MissingScopeError extends GoogleLibError {
|
|
35
|
+
readonly required: string[];
|
|
36
|
+
constructor(required: string[], message?: string, opts?: GoogleErrorOptions);
|
|
37
|
+
}
|
|
38
|
+
declare class ConnectionNotFoundError extends GoogleLibError {
|
|
39
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
40
|
+
}
|
|
41
|
+
declare class ConnectionRevokedError extends GoogleLibError {
|
|
42
|
+
readonly reason: string;
|
|
43
|
+
constructor(reason: string, opts?: GoogleErrorOptions);
|
|
44
|
+
}
|
|
45
|
+
declare class CredentialIntegrityError extends GoogleLibError {
|
|
46
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
47
|
+
}
|
|
48
|
+
declare class KeyProviderUnavailableError extends GoogleLibError {
|
|
49
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
50
|
+
}
|
|
51
|
+
declare class InvalidMessageError extends GoogleLibError {
|
|
52
|
+
readonly field: string;
|
|
53
|
+
constructor(field: string, message?: string, opts?: GoogleErrorOptions);
|
|
54
|
+
}
|
|
55
|
+
declare class MessageTooLargeError extends GoogleLibError {
|
|
56
|
+
readonly bytes: number;
|
|
57
|
+
readonly limit: number;
|
|
58
|
+
constructor(bytes: number, limit: number, opts?: GoogleErrorOptions);
|
|
59
|
+
}
|
|
60
|
+
declare class RateLimitedError extends GoogleLibError {
|
|
61
|
+
readonly retryAfterMs: number | null;
|
|
62
|
+
constructor(retryAfterMs: number | null, opts?: GoogleErrorOptions);
|
|
63
|
+
}
|
|
64
|
+
declare class DailyQuotaExceededError extends GoogleLibError {
|
|
65
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
66
|
+
}
|
|
67
|
+
declare class SendOutcomeUnknownError extends GoogleLibError {
|
|
68
|
+
constructor(message?: string, opts?: GoogleErrorOptions);
|
|
69
|
+
}
|
|
70
|
+
declare class GoogleApiError extends GoogleLibError {
|
|
71
|
+
readonly status: number;
|
|
72
|
+
readonly reason: string | null;
|
|
73
|
+
constructor(status: number, reason: string | null, opts?: GoogleErrorOptions);
|
|
74
|
+
}
|
|
75
|
+
declare class MissingPeerDependencyError extends GoogleLibError {
|
|
76
|
+
readonly peer: string;
|
|
77
|
+
constructor(peer: string, opts?: GoogleErrorOptions);
|
|
78
|
+
}
|
|
79
|
+
declare class InvalidConfigError extends GoogleLibError {
|
|
80
|
+
constructor(message: string, opts?: GoogleErrorOptions);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
type GcpKmsClientLike = {
|
|
84
|
+
encrypt(req: {
|
|
85
|
+
name: string;
|
|
86
|
+
plaintext: Uint8Array;
|
|
87
|
+
additionalAuthenticatedData: Uint8Array;
|
|
88
|
+
}): Promise<[{
|
|
89
|
+
ciphertext?: Uint8Array | string | null;
|
|
90
|
+
}]>;
|
|
91
|
+
decrypt(req: {
|
|
92
|
+
name: string;
|
|
93
|
+
ciphertext: Uint8Array;
|
|
94
|
+
additionalAuthenticatedData: Uint8Array;
|
|
95
|
+
}): Promise<[{
|
|
96
|
+
plaintext?: Uint8Array | string | null;
|
|
97
|
+
}]>;
|
|
98
|
+
};
|
|
99
|
+
/** Wraps DEKs with a Cloud KMS symmetric key. kid is `gcp-kms:<keyName>`. */
|
|
100
|
+
declare class GcpKmsKeyProvider implements KeyProvider {
|
|
101
|
+
#private;
|
|
102
|
+
readonly currentKeyId: string;
|
|
103
|
+
constructor(opts: {
|
|
104
|
+
keyName: string;
|
|
105
|
+
client?: GcpKmsClientLike;
|
|
106
|
+
});
|
|
107
|
+
wrap(dek: Uint8Array, aad: string): Promise<{
|
|
108
|
+
kid: string;
|
|
109
|
+
wdek: Uint8Array;
|
|
110
|
+
}>;
|
|
111
|
+
unwrap(kid: string, wdek: Uint8Array, aad: string): Promise<Uint8Array>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type AwsKmsClientLike = {
|
|
115
|
+
send(cmd: unknown): Promise<{
|
|
116
|
+
CiphertextBlob?: Uint8Array;
|
|
117
|
+
Plaintext?: Uint8Array;
|
|
118
|
+
}>;
|
|
119
|
+
};
|
|
120
|
+
type AwsKmsCommands = {
|
|
121
|
+
EncryptCommand: new (input: any) => unknown;
|
|
122
|
+
DecryptCommand: new (input: any) => unknown;
|
|
123
|
+
};
|
|
124
|
+
/** Wraps DEKs with an AWS KMS symmetric key. kid is `aws-kms:<keyId>`. */
|
|
125
|
+
declare class AwsKmsKeyProvider implements KeyProvider {
|
|
126
|
+
#private;
|
|
127
|
+
readonly currentKeyId: string;
|
|
128
|
+
/**
|
|
129
|
+
* AWS SDK v3 `send` needs real Command instances, so the SDK is loaded
|
|
130
|
+
* lazily via loadPeer only when `client` or `commands` is not injected.
|
|
131
|
+
* Inject both (e.g. in tests) to avoid loading it at all.
|
|
132
|
+
*/
|
|
133
|
+
constructor(opts: {
|
|
134
|
+
keyId: string;
|
|
135
|
+
client?: AwsKmsClientLike;
|
|
136
|
+
commands?: AwsKmsCommands;
|
|
137
|
+
});
|
|
138
|
+
wrap(dek: Uint8Array, aad: string): Promise<{
|
|
139
|
+
kid: string;
|
|
140
|
+
wdek: Uint8Array;
|
|
141
|
+
}>;
|
|
142
|
+
unwrap(kid: string, wdek: Uint8Array, aad: string): Promise<Uint8Array>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
type OpsFailure = {
|
|
146
|
+
record: string;
|
|
147
|
+
error: string;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Re-wraps every stored DEK under the provider's current key. Idempotent and
|
|
151
|
+
* resumable: values already on the current key (or outside `fromKeyId`) are skipped.
|
|
152
|
+
*/
|
|
153
|
+
declare function rewrapAll(opts: {
|
|
154
|
+
store: CredentialStore;
|
|
155
|
+
keyProvider: KeyProvider;
|
|
156
|
+
fromKeyId?: string;
|
|
157
|
+
batchSize?: number;
|
|
158
|
+
}): Promise<{
|
|
159
|
+
rewrapped: number;
|
|
160
|
+
skipped: number;
|
|
161
|
+
failed: OpsFailure[];
|
|
162
|
+
}>;
|
|
163
|
+
/** Fully decrypts every stored value (plaintext discarded immediately) to prove integrity. */
|
|
164
|
+
declare function verifyAll(opts: {
|
|
165
|
+
store: CredentialStore;
|
|
166
|
+
keyProvider: KeyProvider;
|
|
167
|
+
batchSize?: number;
|
|
168
|
+
}): Promise<{
|
|
169
|
+
ok: number;
|
|
170
|
+
failed: OpsFailure[];
|
|
171
|
+
}>;
|
|
172
|
+
|
|
173
|
+
export { type AwsKmsClientLike, type AwsKmsCommands, AwsKmsKeyProvider, ConnectionNotFoundError, ConnectionRevokedError, CredentialIntegrityError, CredentialStore, DailyQuotaExceededError, type GcpKmsClientLike, GcpKmsKeyProvider, GoogleApiError, type GoogleErrorOptions, GoogleLibError, InvalidConfigError, InvalidMessageError, InvalidOAuthStateError, KeyProvider, KeyProviderUnavailableError, MessageTooLargeError, MissingPeerDependencyError, MissingScopeError, NoRefreshTokenError, OAuthClientNotConfiguredError, OAuthConsentDeniedError, type OpsFailure, RateLimitedError, SendOutcomeUnknownError, UnexpectedAccountError, rewrapAll, verifyAll };
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BASE_SCOPES,
|
|
3
|
+
SERVICE_SCOPES,
|
|
4
|
+
buildAad,
|
|
5
|
+
createGoogle,
|
|
6
|
+
decryptValue,
|
|
7
|
+
rewrapValue,
|
|
8
|
+
scopesFor
|
|
9
|
+
} from "./chunk-SIDO26T7.js";
|
|
10
|
+
import {
|
|
11
|
+
StaticKeyProvider
|
|
12
|
+
} from "./chunk-JVP7HHFU.js";
|
|
13
|
+
import {
|
|
14
|
+
InvalidGrantError,
|
|
15
|
+
loadPeer
|
|
16
|
+
} from "./chunk-Z7O6GO3C.js";
|
|
17
|
+
import {
|
|
18
|
+
ConnectionNotFoundError,
|
|
19
|
+
ConnectionRevokedError,
|
|
20
|
+
CredentialIntegrityError,
|
|
21
|
+
DailyQuotaExceededError,
|
|
22
|
+
GoogleApiError,
|
|
23
|
+
GoogleLibError,
|
|
24
|
+
InvalidConfigError,
|
|
25
|
+
InvalidMessageError,
|
|
26
|
+
InvalidOAuthStateError,
|
|
27
|
+
KeyProviderUnavailableError,
|
|
28
|
+
MessageTooLargeError,
|
|
29
|
+
MissingPeerDependencyError,
|
|
30
|
+
MissingScopeError,
|
|
31
|
+
NoRefreshTokenError,
|
|
32
|
+
OAuthClientNotConfiguredError,
|
|
33
|
+
OAuthConsentDeniedError,
|
|
34
|
+
RateLimitedError,
|
|
35
|
+
SendOutcomeUnknownError,
|
|
36
|
+
UnexpectedAccountError
|
|
37
|
+
} from "./chunk-RWT25QHA.js";
|
|
38
|
+
|
|
39
|
+
// src/core/crypto/kms-errors.ts
|
|
40
|
+
var NET_CODES = /* @__PURE__ */ new Set([
|
|
41
|
+
"ECONNREFUSED",
|
|
42
|
+
"ECONNRESET",
|
|
43
|
+
"ETIMEDOUT",
|
|
44
|
+
"ENOTFOUND",
|
|
45
|
+
"EAI_AGAIN"
|
|
46
|
+
]);
|
|
47
|
+
var GRPC_CODES = /* @__PURE__ */ new Set([4, 8, 14]);
|
|
48
|
+
function isKmsAvailabilityError(err) {
|
|
49
|
+
if (typeof err !== "object" || err === null) return false;
|
|
50
|
+
const e = err;
|
|
51
|
+
if (typeof e.code === "string" && NET_CODES.has(e.code)) return true;
|
|
52
|
+
if (typeof e.code === "number" && GRPC_CODES.has(e.code)) return true;
|
|
53
|
+
if (e.name === "ThrottlingException" || e.name === "TimeoutError") {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
const status = e.$metadata?.httpStatusCode;
|
|
57
|
+
return typeof status === "number" && status >= 500;
|
|
58
|
+
}
|
|
59
|
+
function mapKmsError(err) {
|
|
60
|
+
return isKmsAvailabilityError(err) ? new KeyProviderUnavailableError(void 0, { cause: err }) : new CredentialIntegrityError(void 0, { cause: err });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/core/crypto/gcp-kms.ts
|
|
64
|
+
var PREFIX = "gcp-kms:";
|
|
65
|
+
var GcpKmsKeyProvider = class {
|
|
66
|
+
currentKeyId;
|
|
67
|
+
#keyName;
|
|
68
|
+
#client;
|
|
69
|
+
#loading;
|
|
70
|
+
constructor(opts) {
|
|
71
|
+
this.#keyName = opts.keyName;
|
|
72
|
+
this.currentKeyId = PREFIX + opts.keyName;
|
|
73
|
+
this.#client = opts.client;
|
|
74
|
+
}
|
|
75
|
+
async #getClient() {
|
|
76
|
+
if (this.#client) return this.#client;
|
|
77
|
+
this.#loading ??= loadPeer("@google-cloud/kms", "@google-cloud/kms").then(
|
|
78
|
+
(m) => this.#client = new m.KeyManagementServiceClient(),
|
|
79
|
+
(err) => {
|
|
80
|
+
this.#loading = void 0;
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
return this.#loading;
|
|
85
|
+
}
|
|
86
|
+
async wrap(dek, aad) {
|
|
87
|
+
const client = await this.#getClient();
|
|
88
|
+
let res;
|
|
89
|
+
try {
|
|
90
|
+
res = await client.encrypt({
|
|
91
|
+
name: this.#keyName,
|
|
92
|
+
plaintext: dek,
|
|
93
|
+
additionalAuthenticatedData: Buffer.from(aad, "utf8")
|
|
94
|
+
});
|
|
95
|
+
} catch (err) {
|
|
96
|
+
throw mapKmsError(err);
|
|
97
|
+
}
|
|
98
|
+
const ciphertext = res?.[0]?.ciphertext;
|
|
99
|
+
if (ciphertext == null || ciphertext.length === 0) {
|
|
100
|
+
throw new CredentialIntegrityError();
|
|
101
|
+
}
|
|
102
|
+
return { kid: this.currentKeyId, wdek: toBytes(ciphertext) };
|
|
103
|
+
}
|
|
104
|
+
async unwrap(kid, wdek, aad) {
|
|
105
|
+
if (!kid.startsWith(PREFIX) || kid.length === PREFIX.length) {
|
|
106
|
+
throw new CredentialIntegrityError();
|
|
107
|
+
}
|
|
108
|
+
const client = await this.#getClient();
|
|
109
|
+
let res;
|
|
110
|
+
try {
|
|
111
|
+
res = await client.decrypt({
|
|
112
|
+
name: kid.slice(PREFIX.length),
|
|
113
|
+
ciphertext: wdek,
|
|
114
|
+
additionalAuthenticatedData: Buffer.from(aad, "utf8")
|
|
115
|
+
});
|
|
116
|
+
} catch (err) {
|
|
117
|
+
throw mapKmsError(err);
|
|
118
|
+
}
|
|
119
|
+
const plaintext = res?.[0]?.plaintext;
|
|
120
|
+
if (plaintext == null || plaintext.length === 0) {
|
|
121
|
+
throw new CredentialIntegrityError();
|
|
122
|
+
}
|
|
123
|
+
return toBytes(plaintext);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
function toBytes(v) {
|
|
127
|
+
return typeof v === "string" ? Buffer.from(v, "base64") : v;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/core/crypto/aws-kms.ts
|
|
131
|
+
var PREFIX2 = "aws-kms:";
|
|
132
|
+
var CONTEXT_KEY = "mshindi-google";
|
|
133
|
+
var AwsKmsKeyProvider = class {
|
|
134
|
+
currentKeyId;
|
|
135
|
+
#keyId;
|
|
136
|
+
#client;
|
|
137
|
+
#commands;
|
|
138
|
+
#sdk;
|
|
139
|
+
/**
|
|
140
|
+
* AWS SDK v3 `send` needs real Command instances, so the SDK is loaded
|
|
141
|
+
* lazily via loadPeer only when `client` or `commands` is not injected.
|
|
142
|
+
* Inject both (e.g. in tests) to avoid loading it at all.
|
|
143
|
+
*/
|
|
144
|
+
constructor(opts) {
|
|
145
|
+
this.#keyId = opts.keyId;
|
|
146
|
+
this.currentKeyId = PREFIX2 + opts.keyId;
|
|
147
|
+
this.#client = opts.client;
|
|
148
|
+
this.#commands = opts.commands;
|
|
149
|
+
}
|
|
150
|
+
async #load() {
|
|
151
|
+
if (this.#client && this.#commands) {
|
|
152
|
+
return { sdk: this.#commands, client: this.#client };
|
|
153
|
+
}
|
|
154
|
+
this.#sdk ??= loadPeer(
|
|
155
|
+
"@aws-sdk/client-kms",
|
|
156
|
+
"@aws-sdk/client-kms"
|
|
157
|
+
).catch((err) => {
|
|
158
|
+
this.#sdk = void 0;
|
|
159
|
+
throw err;
|
|
160
|
+
});
|
|
161
|
+
const sdk = await this.#sdk;
|
|
162
|
+
this.#commands ??= sdk;
|
|
163
|
+
this.#client ??= new sdk.KMSClient();
|
|
164
|
+
return { sdk: this.#commands, client: this.#client };
|
|
165
|
+
}
|
|
166
|
+
async wrap(dek, aad) {
|
|
167
|
+
const { sdk, client } = await this.#load();
|
|
168
|
+
let res;
|
|
169
|
+
try {
|
|
170
|
+
res = await client.send(
|
|
171
|
+
new sdk.EncryptCommand({
|
|
172
|
+
KeyId: this.#keyId,
|
|
173
|
+
Plaintext: dek,
|
|
174
|
+
EncryptionContext: { [CONTEXT_KEY]: aad }
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
throw mapKmsError(err);
|
|
179
|
+
}
|
|
180
|
+
if (!res?.CiphertextBlob || res.CiphertextBlob.length === 0) {
|
|
181
|
+
throw new CredentialIntegrityError();
|
|
182
|
+
}
|
|
183
|
+
return { kid: this.currentKeyId, wdek: res.CiphertextBlob };
|
|
184
|
+
}
|
|
185
|
+
async unwrap(kid, wdek, aad) {
|
|
186
|
+
if (!kid.startsWith(PREFIX2) || kid.length === PREFIX2.length) {
|
|
187
|
+
throw new CredentialIntegrityError();
|
|
188
|
+
}
|
|
189
|
+
const { sdk, client } = await this.#load();
|
|
190
|
+
let res;
|
|
191
|
+
try {
|
|
192
|
+
res = await client.send(
|
|
193
|
+
new sdk.DecryptCommand({
|
|
194
|
+
// KeyId makes a wrong-key ciphertext fail closed.
|
|
195
|
+
KeyId: kid.slice(PREFIX2.length),
|
|
196
|
+
CiphertextBlob: wdek,
|
|
197
|
+
EncryptionContext: { [CONTEXT_KEY]: aad }
|
|
198
|
+
})
|
|
199
|
+
);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
throw mapKmsError(err);
|
|
202
|
+
}
|
|
203
|
+
if (!res?.Plaintext || res.Plaintext.length === 0) {
|
|
204
|
+
throw new CredentialIntegrityError();
|
|
205
|
+
}
|
|
206
|
+
return res.Plaintext;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// src/core/ops.ts
|
|
211
|
+
var DEFAULT_BATCH_SIZE = 100;
|
|
212
|
+
var label = (ref) => `${ref.record}:${ref.recordId}.${ref.field}`;
|
|
213
|
+
var aadOf = (ref) => buildAad({
|
|
214
|
+
tenantId: ref.tenantId,
|
|
215
|
+
record: ref.record,
|
|
216
|
+
recordId: ref.recordId,
|
|
217
|
+
field: ref.field
|
|
218
|
+
});
|
|
219
|
+
var codeOf = (err) => err instanceof GoogleLibError ? err.code : "unknown";
|
|
220
|
+
async function rewrapAll(opts) {
|
|
221
|
+
const { store, keyProvider, fromKeyId } = opts;
|
|
222
|
+
const result = {
|
|
223
|
+
rewrapped: 0,
|
|
224
|
+
skipped: 0,
|
|
225
|
+
failed: []
|
|
226
|
+
};
|
|
227
|
+
for await (const ref of store.iterateEncryptedValues(
|
|
228
|
+
opts.batchSize ?? DEFAULT_BATCH_SIZE
|
|
229
|
+
)) {
|
|
230
|
+
if (ref.value.kid === keyProvider.currentKeyId || fromKeyId !== void 0 && ref.value.kid !== fromKeyId) {
|
|
231
|
+
result.skipped++;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const next = await rewrapValue(ref.value, aadOf(ref), keyProvider);
|
|
236
|
+
if (await store.replaceEncryptedValue(ref, next)) result.rewrapped++;
|
|
237
|
+
else result.skipped++;
|
|
238
|
+
} catch (err) {
|
|
239
|
+
result.failed.push({ record: label(ref), error: codeOf(err) });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
async function verifyAll(opts) {
|
|
245
|
+
const result = { ok: 0, failed: [] };
|
|
246
|
+
for await (const ref of opts.store.iterateEncryptedValues(
|
|
247
|
+
opts.batchSize ?? DEFAULT_BATCH_SIZE
|
|
248
|
+
)) {
|
|
249
|
+
try {
|
|
250
|
+
await decryptValue(ref.value, aadOf(ref), opts.keyProvider);
|
|
251
|
+
result.ok++;
|
|
252
|
+
} catch (err) {
|
|
253
|
+
result.failed.push({ record: label(ref), error: codeOf(err) });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
export {
|
|
259
|
+
AwsKmsKeyProvider,
|
|
260
|
+
BASE_SCOPES,
|
|
261
|
+
ConnectionNotFoundError,
|
|
262
|
+
ConnectionRevokedError,
|
|
263
|
+
CredentialIntegrityError,
|
|
264
|
+
DailyQuotaExceededError,
|
|
265
|
+
GcpKmsKeyProvider,
|
|
266
|
+
GoogleApiError,
|
|
267
|
+
GoogleLibError,
|
|
268
|
+
InvalidConfigError,
|
|
269
|
+
InvalidGrantError,
|
|
270
|
+
InvalidMessageError,
|
|
271
|
+
InvalidOAuthStateError,
|
|
272
|
+
KeyProviderUnavailableError,
|
|
273
|
+
MessageTooLargeError,
|
|
274
|
+
MissingPeerDependencyError,
|
|
275
|
+
MissingScopeError,
|
|
276
|
+
NoRefreshTokenError,
|
|
277
|
+
OAuthClientNotConfiguredError,
|
|
278
|
+
OAuthConsentDeniedError,
|
|
279
|
+
RateLimitedError,
|
|
280
|
+
SERVICE_SCOPES,
|
|
281
|
+
SendOutcomeUnknownError,
|
|
282
|
+
StaticKeyProvider,
|
|
283
|
+
UnexpectedAccountError,
|
|
284
|
+
createGoogle,
|
|
285
|
+
rewrapAll,
|
|
286
|
+
scopesFor,
|
|
287
|
+
verifyAll
|
|
288
|
+
};
|
|
289
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/crypto/kms-errors.ts","../src/core/crypto/gcp-kms.ts","../src/core/crypto/aws-kms.ts","../src/core/ops.ts"],"sourcesContent":["import {\n CredentialIntegrityError,\n KeyProviderUnavailableError,\n} from \"../errors.js\";\n\nconst NET_CODES = new Set([\n \"ECONNREFUSED\",\n \"ECONNRESET\",\n \"ETIMEDOUT\",\n \"ENOTFOUND\",\n \"EAI_AGAIN\",\n]);\n// gRPC: DEADLINE_EXCEEDED, RESOURCE_EXHAUSTED, UNAVAILABLE.\nconst GRPC_CODES = new Set([4, 8, 14]);\n\n/** True for transport/availability failures (retryable), false otherwise. */\nexport function isKmsAvailabilityError(err: unknown): boolean {\n if (typeof err !== \"object\" || err === null) return false;\n const e = err as {\n code?: unknown;\n name?: unknown;\n $metadata?: { httpStatusCode?: unknown };\n };\n if (typeof e.code === \"string\" && NET_CODES.has(e.code)) return true;\n if (typeof e.code === \"number\" && GRPC_CODES.has(e.code)) return true;\n if (e.name === \"ThrottlingException\" || e.name === \"TimeoutError\") {\n return true;\n }\n const status = e.$metadata?.httpStatusCode;\n return typeof status === \"number\" && status >= 500;\n}\n\n/** Maps a KMS client failure to the library error; the cause is redacted. */\nexport function mapKmsError(err: unknown): Error {\n return isKmsAvailabilityError(err)\n ? new KeyProviderUnavailableError(undefined, { cause: err })\n : new CredentialIntegrityError(undefined, { cause: err });\n}\n","import { CredentialIntegrityError } from \"../errors.js\";\nimport { loadPeer } from \"../peer.js\";\nimport { mapKmsError } from \"./kms-errors.js\";\nimport type { KeyProvider } from \"./key-provider.js\";\n\nconst PREFIX = \"gcp-kms:\";\n\nexport type GcpKmsClientLike = {\n encrypt(req: {\n name: string;\n plaintext: Uint8Array;\n additionalAuthenticatedData: Uint8Array;\n }): Promise<[{ ciphertext?: Uint8Array | string | null }]>;\n decrypt(req: {\n name: string;\n ciphertext: Uint8Array;\n additionalAuthenticatedData: Uint8Array;\n }): Promise<[{ plaintext?: Uint8Array | string | null }]>;\n};\n\n/** Wraps DEKs with a Cloud KMS symmetric key. kid is `gcp-kms:<keyName>`. */\nexport class GcpKmsKeyProvider implements KeyProvider {\n readonly currentKeyId: string;\n readonly #keyName: string;\n #client: GcpKmsClientLike | undefined;\n #loading: Promise<GcpKmsClientLike> | undefined;\n\n constructor(opts: { keyName: string; client?: GcpKmsClientLike }) {\n this.#keyName = opts.keyName;\n this.currentKeyId = PREFIX + opts.keyName;\n this.#client = opts.client;\n }\n\n async #getClient(): Promise<GcpKmsClientLike> {\n if (this.#client) return this.#client;\n this.#loading ??= loadPeer<{\n KeyManagementServiceClient: new () => GcpKmsClientLike;\n }>(\"@google-cloud/kms\", \"@google-cloud/kms\").then(\n (m) => (this.#client = new m.KeyManagementServiceClient()),\n (err) => {\n this.#loading = undefined;\n throw err;\n },\n );\n return this.#loading;\n }\n\n async wrap(\n dek: Uint8Array,\n aad: string,\n ): Promise<{ kid: string; wdek: Uint8Array }> {\n const client = await this.#getClient();\n let res: [{ ciphertext?: Uint8Array | string | null }];\n try {\n res = await client.encrypt({\n name: this.#keyName,\n plaintext: dek,\n additionalAuthenticatedData: Buffer.from(aad, \"utf8\"),\n });\n } catch (err) {\n throw mapKmsError(err);\n }\n const ciphertext = res?.[0]?.ciphertext;\n if (ciphertext == null || ciphertext.length === 0) {\n throw new CredentialIntegrityError();\n }\n return { kid: this.currentKeyId, wdek: toBytes(ciphertext) };\n }\n\n async unwrap(\n kid: string,\n wdek: Uint8Array,\n aad: string,\n ): Promise<Uint8Array> {\n if (!kid.startsWith(PREFIX) || kid.length === PREFIX.length) {\n throw new CredentialIntegrityError();\n }\n const client = await this.#getClient();\n let res: [{ plaintext?: Uint8Array | string | null }];\n try {\n res = await client.decrypt({\n name: kid.slice(PREFIX.length),\n ciphertext: wdek,\n additionalAuthenticatedData: Buffer.from(aad, \"utf8\"),\n });\n } catch (err) {\n throw mapKmsError(err);\n }\n const plaintext = res?.[0]?.plaintext;\n if (plaintext == null || plaintext.length === 0) {\n throw new CredentialIntegrityError();\n }\n // Return the response buffer itself: the caller zeroes what it receives.\n return toBytes(plaintext);\n }\n}\n\nfunction toBytes(v: Uint8Array | string): Uint8Array {\n return typeof v === \"string\" ? Buffer.from(v, \"base64\") : v;\n}\n","import { CredentialIntegrityError } from \"../errors.js\";\nimport { loadPeer } from \"../peer.js\";\nimport { mapKmsError } from \"./kms-errors.js\";\nimport type { KeyProvider } from \"./key-provider.js\";\n\nconst PREFIX = \"aws-kms:\";\nconst CONTEXT_KEY = \"mshindi-google\";\n\nexport type AwsKmsClientLike = {\n send(\n cmd: unknown,\n ): Promise<{ CiphertextBlob?: Uint8Array; Plaintext?: Uint8Array }>;\n};\n\nexport type AwsKmsCommands = {\n EncryptCommand: new (input: any) => unknown;\n DecryptCommand: new (input: any) => unknown;\n};\n\ntype AwsKmsModule = AwsKmsCommands & { KMSClient: new () => AwsKmsClientLike };\n\n/** Wraps DEKs with an AWS KMS symmetric key. kid is `aws-kms:<keyId>`. */\nexport class AwsKmsKeyProvider implements KeyProvider {\n readonly currentKeyId: string;\n readonly #keyId: string;\n #client: AwsKmsClientLike | undefined;\n #commands: AwsKmsCommands | undefined;\n #sdk: Promise<AwsKmsModule> | undefined;\n\n /**\n * AWS SDK v3 `send` needs real Command instances, so the SDK is loaded\n * lazily via loadPeer only when `client` or `commands` is not injected.\n * Inject both (e.g. in tests) to avoid loading it at all.\n */\n constructor(opts: {\n keyId: string;\n client?: AwsKmsClientLike;\n commands?: AwsKmsCommands;\n }) {\n this.#keyId = opts.keyId;\n this.currentKeyId = PREFIX + opts.keyId;\n this.#client = opts.client;\n this.#commands = opts.commands;\n }\n\n async #load(): Promise<{\n sdk: AwsKmsCommands;\n client: AwsKmsClientLike;\n }> {\n if (this.#client && this.#commands) {\n return { sdk: this.#commands, client: this.#client };\n }\n this.#sdk ??= loadPeer<AwsKmsModule>(\n \"@aws-sdk/client-kms\",\n \"@aws-sdk/client-kms\",\n ).catch((err) => {\n this.#sdk = undefined;\n throw err;\n });\n const sdk = await this.#sdk;\n this.#commands ??= sdk;\n this.#client ??= new sdk.KMSClient();\n return { sdk: this.#commands, client: this.#client };\n }\n\n async wrap(\n dek: Uint8Array,\n aad: string,\n ): Promise<{ kid: string; wdek: Uint8Array }> {\n const { sdk, client } = await this.#load();\n let res: { CiphertextBlob?: Uint8Array };\n try {\n res = await client.send(\n new sdk.EncryptCommand({\n KeyId: this.#keyId,\n Plaintext: dek,\n EncryptionContext: { [CONTEXT_KEY]: aad },\n }),\n );\n } catch (err) {\n throw mapKmsError(err);\n }\n if (!res?.CiphertextBlob || res.CiphertextBlob.length === 0) {\n throw new CredentialIntegrityError();\n }\n return { kid: this.currentKeyId, wdek: res.CiphertextBlob };\n }\n\n async unwrap(\n kid: string,\n wdek: Uint8Array,\n aad: string,\n ): Promise<Uint8Array> {\n if (!kid.startsWith(PREFIX) || kid.length === PREFIX.length) {\n throw new CredentialIntegrityError();\n }\n const { sdk, client } = await this.#load();\n let res: { Plaintext?: Uint8Array };\n try {\n res = await client.send(\n new sdk.DecryptCommand({\n // KeyId makes a wrong-key ciphertext fail closed.\n KeyId: kid.slice(PREFIX.length),\n CiphertextBlob: wdek,\n EncryptionContext: { [CONTEXT_KEY]: aad },\n }),\n );\n } catch (err) {\n throw mapKmsError(err);\n }\n if (!res?.Plaintext || res.Plaintext.length === 0) {\n throw new CredentialIntegrityError();\n }\n // Return the response buffer itself: the caller zeroes what it receives.\n return res.Plaintext;\n }\n}\n","import { buildAad, decryptValue, rewrapValue } from \"./crypto/envelope.js\";\nimport type { KeyProvider } from \"./crypto/key-provider.js\";\nimport { GoogleLibError } from \"./errors.js\";\nimport type { CredentialStore } from \"./store.js\";\nimport type { EncryptedValueRef } from \"./types.js\";\n\nconst DEFAULT_BATCH_SIZE = 100;\n\nexport type OpsFailure = { record: string; error: string };\n\nconst label = (ref: EncryptedValueRef): string =>\n `${ref.record}:${ref.recordId}.${ref.field}`;\n\nconst aadOf = (ref: EncryptedValueRef): string =>\n buildAad({\n tenantId: ref.tenantId,\n record: ref.record,\n recordId: ref.recordId,\n field: ref.field,\n });\n\n/** Error code only: never a message, cause, or plaintext. */\nconst codeOf = (err: unknown): string =>\n err instanceof GoogleLibError ? err.code : \"unknown\";\n\n/**\n * Re-wraps every stored DEK under the provider's current key. Idempotent and\n * resumable: values already on the current key (or outside `fromKeyId`) are skipped.\n */\nexport async function rewrapAll(opts: {\n store: CredentialStore;\n keyProvider: KeyProvider;\n fromKeyId?: string;\n batchSize?: number;\n}): Promise<{ rewrapped: number; skipped: number; failed: OpsFailure[] }> {\n const { store, keyProvider, fromKeyId } = opts;\n const result = {\n rewrapped: 0,\n skipped: 0,\n failed: [] as OpsFailure[],\n };\n for await (const ref of store.iterateEncryptedValues(\n opts.batchSize ?? DEFAULT_BATCH_SIZE,\n )) {\n if (\n ref.value.kid === keyProvider.currentKeyId ||\n (fromKeyId !== undefined && ref.value.kid !== fromKeyId)\n ) {\n result.skipped++;\n continue;\n }\n try {\n const next = await rewrapValue(ref.value, aadOf(ref), keyProvider);\n // A CAS miss means a concurrent writer changed it; a rerun will pick it up.\n if (await store.replaceEncryptedValue(ref, next)) result.rewrapped++;\n else result.skipped++;\n } catch (err) {\n result.failed.push({ record: label(ref), error: codeOf(err) });\n }\n }\n return result;\n}\n\n/** Fully decrypts every stored value (plaintext discarded immediately) to prove integrity. */\nexport async function verifyAll(opts: {\n store: CredentialStore;\n keyProvider: KeyProvider;\n batchSize?: number;\n}): Promise<{ ok: number; failed: OpsFailure[] }> {\n const result = { ok: 0, failed: [] as OpsFailure[] };\n for await (const ref of opts.store.iterateEncryptedValues(\n opts.batchSize ?? DEFAULT_BATCH_SIZE,\n )) {\n try {\n await decryptValue(ref.value, aadOf(ref), opts.keyProvider);\n result.ok++;\n } catch (err) {\n result.failed.push({ record: label(ref), error: codeOf(err) });\n }\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAM,YAAY,oBAAI,IAAI;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,aAAa,oBAAI,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;AAG9B,SAAS,uBAAuB,KAAuB;AAC5D,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AACpD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