@origincloud/kms 0.0.0-stage → 0.27.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,25 @@
1
- # Temporary Holding Version
1
+ # @origincloud/kms
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The client of Origin Cloud's KMS service: grants: permission for one platform
4
+ host to use one key for one operation and one encryption context, for at most an
5
+ hour at a time. Part of the [Origin Cloud SDK for
6
+ TypeScript](https://github.com/origincloudhq/sdk-typescript), generated from the
7
+ API definitions in [origincloudhq/api](https://github.com/origincloudhq/api).
8
+
9
+ ```ts
10
+ import { Client } from "@origincloud/core";
11
+ import { GrantClient } from "@origincloud/kms/v1beta1";
12
+
13
+ const grants = new GrantClient(new Client());
14
+ ```
15
+
16
+ | Import | API |
17
+ |---|---|
18
+ | `@origincloud/kms/v1beta1` | Grants: permission for one platform host to use one key for one operation and one encryption context, for at most an hour at a time |
19
+
20
+ `v1beta1` is a preview version and may change in incompatible ways, like the API
21
+ itself. See the [repository's
22
+ README](https://github.com/origincloudhq/sdk-typescript#readme) for credentials
23
+ and behaviour.
24
+
25
+ Apache License 2.0.
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@origincloud/kms",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.27.0",
4
+ "description": "Origin Cloud's KMS service: grants: permission for one platform host to use one key for one operation and one encryption context, for at most an hour at a time.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://github.com/origincloudhq/sdk-typescript#readme",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/origincloudhq/sdk-typescript.git",
10
+ "directory": "packages/kms"
11
+ },
12
+ "bugs": "https://github.com/origincloudhq/sdk-typescript/issues",
13
+ "keywords": [
14
+ "origincloud",
15
+ "origin-cloud",
16
+ "sdk",
17
+ "kms"
18
+ ],
19
+ "type": "module",
20
+ "sideEffects": false,
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "exports": {
25
+ "./*": {
26
+ "types": "./dist/*/index.d.ts",
27
+ "default": "./dist/*/index.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "src",
34
+ "!dist/**/*.tsbuildinfo"
35
+ ],
36
+ "peerDependencies": {
37
+ "@origincloud/core": "^0.27.0"
38
+ },
39
+ "devDependencies": {
40
+ "@origincloud/core": "^0.27.0"
41
+ }
42
+ }
@@ -0,0 +1,240 @@
1
+ // Code generated by the SDK's generator (generator/). DO NOT EDIT.
2
+ // source: origincloud/kms/v1beta1/grant.proto
3
+
4
+ import {
5
+ type CallOptions,
6
+ type Client,
7
+ type Empty,
8
+ type Service,
9
+ newRequestId,
10
+ pathValue,
11
+ query,
12
+ } from "@origincloud/core";
13
+
14
+ /**
15
+ * Calls GrantService.
16
+ *
17
+ * A key's grants.
18
+ *
19
+ * Making, renewing and deleting a grant needs `kms.grant.create`,
20
+ * `kms.grant.update` and `kms.grant.delete` on the key's project, which the
21
+ * platform's own services hold where you let them use your keys; none of
22
+ * them lets the holder use the key itself. Reading and listing need
23
+ * `kms.grant.get` and `kms.grant.list`.
24
+ */
25
+ export class GrantClient {
26
+ /**
27
+ * The endpoint the client sends its calls to, which also serves the
28
+ * operations its methods answer with.
29
+ */
30
+ readonly service: Service;
31
+
32
+ /** A client of GrantService that sends its calls through `client`. */
33
+ constructor(client: Client) {
34
+ this.service = client.service("kms", true);
35
+ }
36
+
37
+ /**
38
+ * Returns a grant that hasn't expired; an expired one is `NOT_FOUND`. A
39
+ * grant made moments ago may be refused with `SERVICE_UNAVAILABLE`,
40
+ * retryable, until its zone's change arrives. Needs `kms.grant.get` on
41
+ * the project.
42
+ */
43
+ async getGrant(request: GetGrantRequest, options?: CallOptions): Promise<Grant> {
44
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*/grants/*");
45
+ return this.service.call<Grant>(
46
+ {
47
+ method: "GET",
48
+ path: `/v1beta1/${p0}`,
49
+ query: query(request, ["name"]),
50
+ idempotent: true,
51
+ },
52
+ options,
53
+ );
54
+ }
55
+
56
+ /**
57
+ * Lists a key's grants that haven't expired, in every zone, ordered by
58
+ * name. A grant made moments ago may be missing from the list until its
59
+ * zone's change arrives. Needs `kms.grant.list` on the project.
60
+ */
61
+ async listGrants(request: ListGrantsRequest, options?: CallOptions): Promise<ListGrantsResponse> {
62
+ const p0 = pathValue("parent", request.parent, "projects/*/regions/*/keys/*");
63
+ return this.service.call<ListGrantsResponse>(
64
+ {
65
+ method: "GET",
66
+ path: `/v1beta1/${p0}/grants`,
67
+ query: query(request, ["parent"]),
68
+ idempotent: true,
69
+ },
70
+ options,
71
+ );
72
+ }
73
+
74
+ /**
75
+ * Iterates over everything listGrants lists from the request's page on,
76
+ * fetching the next page as the loop reaches it. A page that fails ends
77
+ * the iteration with its error.
78
+ */
79
+ async *allGrants(request: ListGrantsRequest, options?: CallOptions): AsyncGenerator<Grant, void, undefined> {
80
+ for (let page = request; ; ) {
81
+ const response = await this.listGrants(page, options);
82
+ yield* response.grants ?? [];
83
+ if (!response.nextPageToken) return;
84
+ page = { ...page, pageToken: response.nextPageToken };
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Makes a grant on an `ENCRYPT_DECRYPT` key for one host, refused with
90
+ * `BAD_REQUEST` for a key of another purpose, a host that isn't one of
91
+ * the region's, an empty encryption context, or a `ttl` outside 1 to 60
92
+ * minutes, and with `CONFLICT` for a key that isn't enabled. Needs
93
+ * `kms.grant.create` on the project.
94
+ */
95
+ async createGrant(request: CreateGrantRequest, options?: CallOptions): Promise<Grant> {
96
+ if (!request.requestId) request = { ...request, requestId: newRequestId() };
97
+ const p0 = pathValue("parent", request.parent, "projects/*/regions/*/keys/*");
98
+ return this.service.call<Grant>(
99
+ {
100
+ method: "POST",
101
+ path: `/v1beta1/${p0}/grants`,
102
+ body: request.grant,
103
+ query: query(request, ["parent", "grant"]),
104
+ idempotent: true,
105
+ },
106
+ options,
107
+ );
108
+ }
109
+
110
+ /**
111
+ * Extends a grant that hasn't expired to `ttl` from now. An expired
112
+ * grant isn't renewed: `CONFLICT`, and a new one is made instead. Needs
113
+ * `kms.grant.update` on the project.
114
+ */
115
+ async renewGrant(request: RenewGrantRequest, options?: CallOptions): Promise<Grant> {
116
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*/grants/*");
117
+ return this.service.call<Grant>(
118
+ {
119
+ method: "POST",
120
+ path: `/v1beta1/${p0}:renew`,
121
+ body: request,
122
+ },
123
+ options,
124
+ );
125
+ }
126
+
127
+ /**
128
+ * Ends a grant before it expires: from then on it opens nothing. Needs
129
+ * `kms.grant.delete` on the project.
130
+ */
131
+ async deleteGrant(request: DeleteGrantRequest, options?: CallOptions): Promise<Empty> {
132
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*/grants/*");
133
+ return this.service.call<Empty>(
134
+ {
135
+ method: "DELETE",
136
+ path: `/v1beta1/${p0}`,
137
+ query: query(request, ["name"]),
138
+ },
139
+ options,
140
+ );
141
+ }
142
+ }
143
+
144
+ /**
145
+ * A grant: one host may use one key for one operation, with exactly one
146
+ * encryption context, until `expireTime`.
147
+ */
148
+ export interface Grant {
149
+ /** The grant's resource name. */
150
+ name?: string;
151
+ /** What the host may do with the key. */
152
+ operation?: Grant_Operation;
153
+ /**
154
+ * The platform host the grant is for, by the SPIFFE ID its certificate
155
+ * names, which ends in `/zones/{zone}/hosts/{host}`.
156
+ */
157
+ grantee?: string;
158
+ /** The encryption context a use must carry, exactly; never empty. */
159
+ encryptionContext?: Record<string, string>;
160
+ /** How long the grant lives from now: 1 to 60 minutes. */
161
+ ttl?: string;
162
+ /** The zone that keeps the grant: its host's. */
163
+ zone?: string;
164
+ /** Who made the grant. */
165
+ delegate?: string;
166
+ /** When the grant was made. */
167
+ createTime?: string;
168
+ /** When the grant was last renewed, or made. */
169
+ renewTime?: string;
170
+ /** When the grant stops opening anything unless renewed before. */
171
+ expireTime?: string;
172
+ }
173
+
174
+ /** What a grant lets its host do. */
175
+ export const Grant_Operation = {
176
+ /** Not set. */
177
+ OPERATION_UNSPECIFIED: "OPERATION_UNSPECIFIED",
178
+ /**
179
+ * Decrypt ciphertexts made under the key with the grant's encryption
180
+ * context.
181
+ */
182
+ DECRYPT: "DECRYPT",
183
+ } as const;
184
+
185
+ /** What a grant lets its host do. */
186
+ export type Grant_Operation = (typeof Grant_Operation)[keyof typeof Grant_Operation];
187
+
188
+ /** The request for GetGrant. */
189
+ export interface GetGrantRequest {
190
+ /** The grant to return. */
191
+ name?: string;
192
+ }
193
+
194
+ /** The request for ListGrants. */
195
+ export interface ListGrantsRequest {
196
+ /** The key whose grants to list. */
197
+ parent?: string;
198
+ /**
199
+ * The most grants to return; the server clamps it, and 0 means its
200
+ * default.
201
+ */
202
+ pageSize?: number;
203
+ /** A previous response's `nextPageToken`, for the page after it. */
204
+ pageToken?: string;
205
+ }
206
+
207
+ /** The response for ListGrants. */
208
+ export interface ListGrantsResponse {
209
+ /** The grants on this page. */
210
+ grants?: Grant[];
211
+ /** The token for the next page; empty on the last one. */
212
+ nextPageToken?: string;
213
+ }
214
+
215
+ /** The request for CreateGrant. */
216
+ export interface CreateGrantRequest {
217
+ /** The key to grant. */
218
+ parent?: string;
219
+ /** The grant to make: its operation, host, encryption context and `ttl`. */
220
+ grant?: Grant;
221
+ /**
222
+ * A UUID; a repeat with the same id within a day returns the grant the
223
+ * first request made, instead of making a second.
224
+ */
225
+ requestId?: string;
226
+ }
227
+
228
+ /** The request for RenewGrant. */
229
+ export interface RenewGrantRequest {
230
+ /** The grant to renew. */
231
+ name?: string;
232
+ /** How long the grant lives from now: 1 to 60 minutes. */
233
+ ttl?: string;
234
+ }
235
+
236
+ /** The request for DeleteGrant. */
237
+ export interface DeleteGrantRequest {
238
+ /** The grant to end. */
239
+ name?: string;
240
+ }
@@ -0,0 +1,4 @@
1
+ // Code generated by the SDK's generator (generator/). DO NOT EDIT.
2
+
3
+ export * from "./grant.js";
4
+ export * from "./key.js";
@@ -0,0 +1,590 @@
1
+ // Code generated by the SDK's generator (generator/). DO NOT EDIT.
2
+ // source: origincloud/kms/v1beta1/key.proto
3
+
4
+ import {
5
+ type CallOptions,
6
+ type Client,
7
+ type Service,
8
+ newRequestId,
9
+ pathValue,
10
+ query,
11
+ } from "@origincloud/core";
12
+
13
+ /**
14
+ * Calls KeyService.
15
+ *
16
+ * Keys and the operations made with them.
17
+ *
18
+ * An `ENCRYPT_DECRYPT` key encrypts with AES-256-GCM-SIV. Its ciphertext
19
+ * names the key version that made it but not the key: Decrypt names the
20
+ * key, and a ciphertext decrypts only under the key and the encryption
21
+ * context it was made with. A signing key signs with ECDSA over P-256 and
22
+ * SHA-256 (ASN.1 DER signatures) or with Ed25519; its public keys are read
23
+ * with GetPublicKey.
24
+ */
25
+ export class KeyClient {
26
+ /**
27
+ * The endpoint the client sends its calls to, which also serves the
28
+ * operations its methods answer with.
29
+ */
30
+ readonly service: Service;
31
+
32
+ /** A client of KeyService that sends its calls through `client`. */
33
+ constructor(client: Client) {
34
+ this.service = client.service("kms", true);
35
+ }
36
+
37
+ /** Returns a key, deleted or not. Needs `kms.key.get` on the project. */
38
+ async getKey(request: GetKeyRequest, options?: CallOptions): Promise<Key> {
39
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*");
40
+ return this.service.call<Key>(
41
+ {
42
+ method: "GET",
43
+ path: `/v1beta1/${p0}`,
44
+ query: query(request, ["name"]),
45
+ idempotent: true,
46
+ },
47
+ options,
48
+ );
49
+ }
50
+
51
+ /**
52
+ * Lists a project's keys in a region, ordered by name. Deleted ones are
53
+ * listed only when `showDeleted` is set, so a page may hold fewer keys
54
+ * than `pageSize` and still be followed by another. Needs `kms.key.list`
55
+ * on the project.
56
+ */
57
+ async listKeys(request: ListKeysRequest, options?: CallOptions): Promise<ListKeysResponse> {
58
+ const p0 = pathValue("parent", request.parent, "projects/*/regions/*");
59
+ return this.service.call<ListKeysResponse>(
60
+ {
61
+ method: "GET",
62
+ path: `/v1beta1/${p0}/keys`,
63
+ query: query(request, ["parent"]),
64
+ idempotent: true,
65
+ },
66
+ options,
67
+ );
68
+ }
69
+
70
+ /**
71
+ * Iterates over everything listKeys lists from the request's page on,
72
+ * fetching the next page as the loop reaches it. A page that fails ends
73
+ * the iteration with its error.
74
+ */
75
+ async *allKeys(request: ListKeysRequest, options?: CallOptions): AsyncGenerator<Key, void, undefined> {
76
+ for (let page = request; ; ) {
77
+ const response = await this.listKeys(page, options);
78
+ yield* response.keys ?? [];
79
+ if (!response.nextPageToken) return;
80
+ page = { ...page, pageToken: response.nextPageToken };
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Creates a key, `ENABLED`, with its first version as the primary. The
86
+ * platform assigns its id, which its `name` returns; an id is never used
87
+ * again. Needs `kms.key.create` on the project.
88
+ */
89
+ async createKey(request: CreateKeyRequest, options?: CallOptions): Promise<Key> {
90
+ if (!request.requestId) request = { ...request, requestId: newRequestId() };
91
+ const p0 = pathValue("parent", request.parent, "projects/*/regions/*");
92
+ return this.service.call<Key>(
93
+ {
94
+ method: "POST",
95
+ path: `/v1beta1/${p0}/keys`,
96
+ body: request.key,
97
+ query: query(request, ["parent", "key"]),
98
+ idempotent: true,
99
+ },
100
+ options,
101
+ );
102
+ }
103
+
104
+ /**
105
+ * Enables or disables a key, or changes its tags: `state` and `tags` are
106
+ * the fields it changes. A disabled key refuses every operation but
107
+ * GetPublicKey with `CONFLICT` until it is enabled again. Setting the
108
+ * state or the tags the key has already succeeds and changes nothing. A
109
+ * deleted key can't be changed: undelete it first. A key the platform
110
+ * manages (`platformManaged`) is refused with `FORBIDDEN`, even when the
111
+ * request would change nothing. Needs
112
+ * `kms.key.update` on the project.
113
+ */
114
+ async updateKey(request: UpdateKeyRequest, options?: CallOptions): Promise<Key> {
115
+ if (!request.requestId) request = { ...request, requestId: newRequestId() };
116
+ const p0 = pathValue("key.name", request.key?.name, "projects/*/regions/*/keys/*");
117
+ return this.service.call<Key>(
118
+ {
119
+ method: "PATCH",
120
+ path: `/v1beta1/${p0}`,
121
+ body: request.key,
122
+ query: query(request, ["key.name", "key"]),
123
+ idempotent: true,
124
+ },
125
+ options,
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Deletes a key: it becomes `DELETED` at once, refuses every operation
131
+ * but GetPublicKey, and its material is destroyed at `purgeTime`, after
132
+ * `destroyDelay`. Until then UndeleteKey restores it, disabled. After it,
133
+ * nothing it encrypted can ever be decrypted again. Deleting a deleted key
134
+ * succeeds and changes nothing. A key the platform manages is refused with
135
+ * `FORBIDDEN`, deleted or not. Needs `kms.key.delete` on the project.
136
+ */
137
+ async deleteKey(request: DeleteKeyRequest, options?: CallOptions): Promise<Key> {
138
+ if (!request.requestId) request = { ...request, requestId: newRequestId() };
139
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*");
140
+ return this.service.call<Key>(
141
+ {
142
+ method: "DELETE",
143
+ path: `/v1beta1/${p0}`,
144
+ query: query(request, ["name"]),
145
+ idempotent: true,
146
+ },
147
+ options,
148
+ );
149
+ }
150
+
151
+ /**
152
+ * Restores a deleted key whose material isn't destroyed yet: it becomes
153
+ * `DISABLED`, to be enabled with UpdateKey. Refused with `CONFLICT` for a
154
+ * key that isn't deleted, or whose `purgeTime` has passed, and with
155
+ * `FORBIDDEN` for a key the platform manages. Needs `kms.key.delete` on
156
+ * the project.
157
+ */
158
+ async undeleteKey(request: UndeleteKeyRequest, options?: CallOptions): Promise<Key> {
159
+ if (!request.requestId) request = { ...request, requestId: newRequestId() };
160
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*");
161
+ return this.service.call<Key>(
162
+ {
163
+ method: "POST",
164
+ path: `/v1beta1/${p0}:undelete`,
165
+ body: request,
166
+ idempotent: true,
167
+ },
168
+ options,
169
+ );
170
+ }
171
+
172
+ /**
173
+ * Adds a new version to a key and makes it the primary: new ciphertexts
174
+ * and signatures use it, and every earlier version still decrypts and
175
+ * its public key stays readable. Refused with `CONFLICT` for a key that
176
+ * isn't enabled, and with `FORBIDDEN` for a key the platform manages.
177
+ * Needs `kms.key.rotate` on the project.
178
+ */
179
+ async rotateKey(request: RotateKeyRequest, options?: CallOptions): Promise<Key> {
180
+ if (!request.requestId) request = { ...request, requestId: newRequestId() };
181
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*");
182
+ return this.service.call<Key>(
183
+ {
184
+ method: "POST",
185
+ path: `/v1beta1/${p0}:rotate`,
186
+ body: request,
187
+ idempotent: true,
188
+ },
189
+ options,
190
+ );
191
+ }
192
+
193
+ /**
194
+ * Encrypts up to 64 KiB with an `ENCRYPT_DECRYPT` key's primary version,
195
+ * bound to the encryption context. For more data, encrypt it yourself
196
+ * with a data key from GenerateDataKey. Refused with `CONFLICT` for a key
197
+ * that isn't enabled, and with `BAD_REQUEST` for a signing key. Needs
198
+ * `kms.key.encrypt` on the project.
199
+ */
200
+ async encrypt(request: EncryptRequest, options?: CallOptions): Promise<EncryptResponse> {
201
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*");
202
+ return this.service.call<EncryptResponse>(
203
+ {
204
+ method: "POST",
205
+ path: `/v1beta1/${p0}:encrypt`,
206
+ body: request,
207
+ },
208
+ options,
209
+ );
210
+ }
211
+
212
+ /**
213
+ * Decrypts a ciphertext Encrypt or GenerateDataKey made with this key,
214
+ * given the same encryption context. Refused with `BAD_REQUEST` for a
215
+ * ciphertext that doesn't decrypt under this key and context, and with
216
+ * `CONFLICT` for a key that isn't enabled. Needs `kms.key.decrypt` on the
217
+ * project.
218
+ */
219
+ async decrypt(request: DecryptRequest, options?: CallOptions): Promise<DecryptResponse> {
220
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*");
221
+ return this.service.call<DecryptResponse>(
222
+ {
223
+ method: "POST",
224
+ path: `/v1beta1/${p0}:decrypt`,
225
+ body: request,
226
+ },
227
+ options,
228
+ );
229
+ }
230
+
231
+ /**
232
+ * Returns a new random 256-bit data key, in plaintext and encrypted under
233
+ * an `ENCRYPT_DECRYPT` key's primary version with the encryption context.
234
+ * Encrypt your data with the plaintext, keep only the ciphertext beside
235
+ * it, and recover the data key with Decrypt when you need it. Needs
236
+ * `kms.key.generate_data_key` on the project.
237
+ */
238
+ async generateDataKey(request: GenerateDataKeyRequest, options?: CallOptions): Promise<GenerateDataKeyResponse> {
239
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*");
240
+ return this.service.call<GenerateDataKeyResponse>(
241
+ {
242
+ method: "POST",
243
+ path: `/v1beta1/${p0}:generateDataKey`,
244
+ body: request,
245
+ },
246
+ options,
247
+ );
248
+ }
249
+
250
+ /**
251
+ * Signs up to 64 KiB with a signing key's primary version, or the
252
+ * version `keyVersion` names. ECDSA hashes
253
+ * the data with SHA-256 itself: send the data, not a digest. Refused with
254
+ * `CONFLICT` for a key that isn't enabled, and with `BAD_REQUEST` for an
255
+ * `ENCRYPT_DECRYPT` key. Needs `kms.key.sign` on the project.
256
+ */
257
+ async sign(request: SignRequest, options?: CallOptions): Promise<SignResponse> {
258
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*");
259
+ return this.service.call<SignResponse>(
260
+ {
261
+ method: "POST",
262
+ path: `/v1beta1/${p0}:sign`,
263
+ body: request,
264
+ },
265
+ options,
266
+ );
267
+ }
268
+
269
+ /**
270
+ * Returns a signing key version's public key, to verify its signatures
271
+ * with. Answered for a disabled or deleted key too, until its material is
272
+ * destroyed. Refused with `BAD_REQUEST` for an `ENCRYPT_DECRYPT` key.
273
+ * Needs `kms.key.get_public_key` on the project.
274
+ */
275
+ async getPublicKey(request: GetPublicKeyRequest, options?: CallOptions): Promise<PublicKey> {
276
+ const p0 = pathValue("name", request.name, "projects/*/regions/*/keys/*/versions/*/publicKey");
277
+ return this.service.call<PublicKey>(
278
+ {
279
+ method: "GET",
280
+ path: `/v1beta1/${p0}`,
281
+ query: query(request, ["name"]),
282
+ idempotent: true,
283
+ },
284
+ options,
285
+ );
286
+ }
287
+ }
288
+
289
+ /**
290
+ * A key: its versions' material is kept by the platform and never leaves
291
+ * it.
292
+ */
293
+ export interface Key {
294
+ /** The key's resource name. */
295
+ name?: string;
296
+ /** What the key is for. */
297
+ purpose?: Key_Purpose;
298
+ /**
299
+ * Whether the key can be used. A new key is `ENABLED`; UpdateKey sets it
300
+ * to `ENABLED` or `DISABLED`, and DeleteKey makes it `DELETED`.
301
+ */
302
+ state?: Key_State;
303
+ /** The version new ciphertexts and signatures use. */
304
+ primaryVersion?: string;
305
+ /** Every version, oldest first. RotateKey adds one. */
306
+ versions?: Key_Version[];
307
+ /** When the key was created. */
308
+ createTime?: string;
309
+ /** When the key last changed. */
310
+ updateTime?: string;
311
+ /**
312
+ * When a deleted key's material is destroyed, or was; unset unless the
313
+ * key is `DELETED`.
314
+ */
315
+ purgeTime?: string;
316
+ /**
317
+ * Labels of your own, at most 50. The `origin:name` tag is the name the
318
+ * console shows.
319
+ */
320
+ tags?: Record<string, string>;
321
+ /**
322
+ * Whether the platform manages the key: it made the key in your project
323
+ * for its own use of the project's data, such as the key, tagged
324
+ * `origin:name=volumes`, that protects your volumes' data keys. You see it,
325
+ * its grants and its audit log entries like any key of yours, but
326
+ * UpdateKey, DeleteKey, UndeleteKey and RotateKey refuse it with
327
+ * `FORBIDDEN`, whatever roles you hold.
328
+ */
329
+ platformManaged?: boolean;
330
+ }
331
+
332
+ /** What a key is for, and the algorithm it uses. */
333
+ export const Key_Purpose = {
334
+ /** Not set. */
335
+ PURPOSE_UNSPECIFIED: "PURPOSE_UNSPECIFIED",
336
+ /** Encrypt, Decrypt and GenerateDataKey, with AES-256-GCM-SIV. */
337
+ ENCRYPT_DECRYPT: "ENCRYPT_DECRYPT",
338
+ /** Sign with ECDSA over P-256 and SHA-256; signatures are ASN.1 DER. */
339
+ SIGN_ECDSA_P256_SHA256: "SIGN_ECDSA_P256_SHA256",
340
+ /** Sign with Ed25519; signatures are 64 bytes. */
341
+ SIGN_ED25519: "SIGN_ED25519",
342
+ } as const;
343
+
344
+ /** What a key is for, and the algorithm it uses. */
345
+ export type Key_Purpose = (typeof Key_Purpose)[keyof typeof Key_Purpose];
346
+
347
+ /** Whether a key can be used. */
348
+ export const Key_State = {
349
+ /** Not set. */
350
+ STATE_UNSPECIFIED: "STATE_UNSPECIFIED",
351
+ /** Serves every operation of its purpose. */
352
+ ENABLED: "ENABLED",
353
+ /** Refuses every operation but GetPublicKey until enabled again. */
354
+ DISABLED: "DISABLED",
355
+ /**
356
+ * Deleted: refuses every operation but GetPublicKey. Until
357
+ * `purgeTime` UndeleteKey restores it; after it, its material is
358
+ * destroyed.
359
+ */
360
+ DELETED: "DELETED",
361
+ } as const;
362
+
363
+ /** Whether a key can be used. */
364
+ export type Key_State = (typeof Key_State)[keyof typeof Key_State];
365
+
366
+ /** A version of the key: one generation of its material. */
367
+ export interface Key_Version {
368
+ /**
369
+ * The version's resource name,
370
+ * `projects/{project}/regions/{region}/keys/{key}/versions/{version}`,
371
+ * numbered from 1.
372
+ */
373
+ keyVersion?: string;
374
+ /** When the version was created. */
375
+ createTime?: string;
376
+ }
377
+
378
+ /** A signing key version's public key. */
379
+ export interface PublicKey {
380
+ /**
381
+ * The public key's resource name: its version's, followed by
382
+ * `/publicKey`.
383
+ */
384
+ name?: string;
385
+ /** The algorithm the key version signs with. */
386
+ algorithm?: Key_Purpose;
387
+ /**
388
+ * The public key as a PEM-encoded SubjectPublicKeyInfo, which OpenSSL and
389
+ * most libraries read.
390
+ */
391
+ pem?: string;
392
+ }
393
+
394
+ /** The request for GetKey. */
395
+ export interface GetKeyRequest {
396
+ /** The key to return. */
397
+ name?: string;
398
+ }
399
+
400
+ /** The request for ListKeys. */
401
+ export interface ListKeysRequest {
402
+ /**
403
+ * The project and region whose keys to list,
404
+ * `projects/{project}/regions/{region}`.
405
+ */
406
+ parent?: string;
407
+ /**
408
+ * The most keys to return; the server clamps it, and 0 means its
409
+ * default.
410
+ */
411
+ pageSize?: number;
412
+ /** A previous response's `nextPageToken`, for the page after it. */
413
+ pageToken?: string;
414
+ /** Whether deleted keys are listed too. */
415
+ showDeleted?: boolean;
416
+ }
417
+
418
+ /** The response for ListKeys. */
419
+ export interface ListKeysResponse {
420
+ /** The keys on this page. */
421
+ keys?: Key[];
422
+ /** The token for the next page; empty on the last one. */
423
+ nextPageToken?: string;
424
+ }
425
+
426
+ /** The request for CreateKey. */
427
+ export interface CreateKeyRequest {
428
+ /**
429
+ * The project and region to create the key in,
430
+ * `projects/{project}/regions/{region}`.
431
+ */
432
+ parent?: string;
433
+ /** The key to create: its `purpose`, and optionally its tags. */
434
+ key?: Key;
435
+ /**
436
+ * A UUID; a repeat with the same id within a day returns the key the
437
+ * first request created, as it was then, instead of creating a second
438
+ * one.
439
+ */
440
+ requestId?: string;
441
+ }
442
+
443
+ /** The request for UpdateKey. */
444
+ export interface UpdateKeyRequest {
445
+ /**
446
+ * The key, by its name, with the state to set (`ENABLED` or `DISABLED`)
447
+ * or the tags to replace its tags with.
448
+ */
449
+ key?: Key;
450
+ /** The fields to change: `state`, `tags`, or both. `*` is both. */
451
+ updateMask?: string;
452
+ /**
453
+ * A UUID; a repeat with the same id within a day returns the key as the
454
+ * first request left it, instead of changing it again.
455
+ */
456
+ requestId?: string;
457
+ }
458
+
459
+ /** The request for DeleteKey. */
460
+ export interface DeleteKeyRequest {
461
+ /** The key to delete. */
462
+ name?: string;
463
+ /**
464
+ * How long until the key's material is destroyed: whole days, from 1 to
465
+ * 90; 30 days when unset.
466
+ */
467
+ destroyDelay?: string;
468
+ /**
469
+ * A UUID; a repeat with the same id within a day returns the key as the
470
+ * first request left it.
471
+ */
472
+ requestId?: string;
473
+ }
474
+
475
+ /** The request for UndeleteKey. */
476
+ export interface UndeleteKeyRequest {
477
+ /** The deleted key to restore. */
478
+ name?: string;
479
+ /**
480
+ * A UUID; a repeat with the same id within a day returns the key as the
481
+ * first request left it, instead of answering `CONFLICT`.
482
+ */
483
+ requestId?: string;
484
+ }
485
+
486
+ /** The request for RotateKey. */
487
+ export interface RotateKeyRequest {
488
+ /** The key to rotate. */
489
+ name?: string;
490
+ /**
491
+ * A UUID; a repeat with the same id within a day returns the key as the
492
+ * first request left it, instead of adding another version.
493
+ */
494
+ requestId?: string;
495
+ }
496
+
497
+ /** The request for Encrypt. */
498
+ export interface EncryptRequest {
499
+ /** The `ENCRYPT_DECRYPT` key to encrypt with. */
500
+ name?: string;
501
+ /** The data to encrypt, at most 64 KiB. */
502
+ plaintext?: string;
503
+ /**
504
+ * Pairs bound into the ciphertext, which Decrypt must be given again,
505
+ * exactly. They aren't secret: the audit log records them. At most 16
506
+ * pairs, each key and value 1 to 256 bytes.
507
+ */
508
+ encryptionContext?: Record<string, string>;
509
+ }
510
+
511
+ /** The response for Encrypt. */
512
+ export interface EncryptResponse {
513
+ /** The ciphertext, to store and pass to Decrypt. */
514
+ ciphertext?: string;
515
+ /** The key version that encrypted it. */
516
+ keyVersion?: string;
517
+ }
518
+
519
+ /** The request for Decrypt. */
520
+ export interface DecryptRequest {
521
+ /** The key the ciphertext was made with. */
522
+ name?: string;
523
+ /** What Encrypt or GenerateDataKey returned as `ciphertext`. */
524
+ ciphertext?: string;
525
+ /** The encryption context the ciphertext was made with. */
526
+ encryptionContext?: Record<string, string>;
527
+ }
528
+
529
+ /** The response for Decrypt. */
530
+ export interface DecryptResponse {
531
+ /** The decrypted data. */
532
+ plaintext?: string;
533
+ /** The key version that decrypted it. */
534
+ keyVersion?: string;
535
+ }
536
+
537
+ /** The request for GenerateDataKey. */
538
+ export interface GenerateDataKeyRequest {
539
+ /** The `ENCRYPT_DECRYPT` key to encrypt the data key with. */
540
+ name?: string;
541
+ /** Pairs bound into the data key's ciphertext, as Encrypt's. */
542
+ encryptionContext?: Record<string, string>;
543
+ }
544
+
545
+ /** The response for GenerateDataKey. */
546
+ export interface GenerateDataKeyResponse {
547
+ /** The 32-byte data key. Use it, then discard it: never store it. */
548
+ plaintext?: string;
549
+ /**
550
+ * The data key encrypted under the key, to store beside your data and
551
+ * pass to Decrypt.
552
+ */
553
+ ciphertext?: string;
554
+ /** The key version that encrypted it. */
555
+ keyVersion?: string;
556
+ }
557
+
558
+ /** The request for Sign. */
559
+ export interface SignRequest {
560
+ /** The signing key to sign with. */
561
+ name?: string;
562
+ /** The data to sign, at most 64 KiB. */
563
+ data?: string;
564
+ /**
565
+ * The version of `name` to sign with, `{name}/versions/{version}`.
566
+ * Without it, the key's primary version signs. Name it when the
567
+ * signature's verifiers must know the version before the signature
568
+ * exists, for example a token whose header names its key: the primary
569
+ * can change between reading it and signing. Refused with `BAD_REQUEST`
570
+ * for a version of another key or a destroyed version.
571
+ */
572
+ keyVersion?: string;
573
+ }
574
+
575
+ /** The response for Sign. */
576
+ export interface SignResponse {
577
+ /** The signature: ASN.1 DER for ECDSA, 64 bytes for Ed25519. */
578
+ signature?: string;
579
+ /** The key version that signed, whose public key verifies it. */
580
+ keyVersion?: string;
581
+ }
582
+
583
+ /** The request for GetPublicKey. */
584
+ export interface GetPublicKeyRequest {
585
+ /**
586
+ * The public key to return: a key version's name followed by
587
+ * `/publicKey`.
588
+ */
589
+ name?: string;
590
+ }