-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathtypes.ts
166 lines (148 loc) · 4.49 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { NodeAlgorithmSuite } from './node_algorithms'
import { WebCryptoAlgorithmSuite } from './web_crypto_algorithms'
import { EncryptedDataKey } from './encrypted_data_key'
import {
NodeBranchKeyMaterial,
NodeDecryptionMaterial,
NodeEncryptionMaterial,
WebCryptoDecryptionMaterial,
WebCryptoEncryptionMaterial,
} from './cryptographic_material'
import { CommitmentPolicy } from './algorithm_suites'
export type EncryptionContext = { [index: string]: string }
/* need to copy some things from DOM */
export interface AwsEsdkJsKeyAlgorithm {
name: string
}
export type AwsEsdkJsKeyType = 'public' | 'private' | 'secret'
export type AwsEsdkJsKeyUsage =
| 'encrypt'
| 'decrypt'
| 'sign'
| 'verify'
| 'deriveKey'
| 'deriveBits'
| 'wrapKey'
| 'unwrapKey'
export interface AwsEsdkJsCryptoKey {
readonly algorithm: AwsEsdkJsKeyAlgorithm
readonly extractable: boolean
readonly type: AwsEsdkJsKeyType
readonly usages: AwsEsdkJsKeyUsage[]
}
export interface AwsEsdkJsCryptoKeyPair {
readonly publicKey: AwsEsdkJsCryptoKey
readonly privateKey: AwsEsdkJsCryptoKey
}
export type MixedBackendCryptoKey = {
nonZeroByteCryptoKey: AwsEsdkJsCryptoKey
zeroByteCryptoKey: AwsEsdkJsCryptoKey
}
export interface EncryptionRequest<
S extends NodeAlgorithmSuite | WebCryptoAlgorithmSuite
> {
readonly suite?: S
readonly encryptionContext: EncryptionContext
readonly commitmentPolicy: CommitmentPolicy
readonly plaintextLength?: number
}
export interface DecryptionRequest<
S extends NodeAlgorithmSuite | WebCryptoAlgorithmSuite
> {
readonly suite: S
readonly encryptionContext: EncryptionContext
readonly encryptedDataKeys: ReadonlyArray<EncryptedDataKey>
}
export type SupportedAlgorithmSuites =
| NodeAlgorithmSuite
| WebCryptoAlgorithmSuite
export type EncryptionMaterial<Suite> = Suite extends NodeAlgorithmSuite
? NodeEncryptionMaterial
: Suite extends WebCryptoAlgorithmSuite
? WebCryptoEncryptionMaterial
: never
export type DecryptionMaterial<Suite> = Suite extends NodeAlgorithmSuite
? NodeDecryptionMaterial
: Suite extends WebCryptoAlgorithmSuite
? WebCryptoDecryptionMaterial
: never
export type BranchKeyMaterial = NodeBranchKeyMaterial
/* These are copies of the v12 Node.js types.
* I copied them here to avoid exporting v12 types
* and forcing consumers to install/use v12 in their projects.
*/
export type AwsEsdkKeyObjectType = 'secret' | 'public' | 'private'
export type AwsEsdkKeyFormat = 'pem' | 'der'
export type AwsEsdkKeyType = 'rsa' | 'dsa' | 'ec'
export interface AwsEsdkKeyExportOptions<T extends AwsEsdkKeyFormat> {
type: 'pkcs1' | 'spki' | 'pkcs8' | 'sec1'
format: T
cipher?: string
passphrase?: string | Buffer
}
export interface AwsEsdkKeyObject {
asymmetricKeyType?: AwsEsdkKeyType
/**
* For asymmetric keys, this property represents the size of the embedded key in
* bytes. This property is `undefined` for symmetric keys.
*/
asymmetricKeySize?: number
/**
* This property exists only on asymmetric keys. Depending on the type of the key,
* this object contains information about the key. None of the information obtained
* through this property can be used to uniquely identify a key or to compromise the
* security of the key.
*/
asymmetricKeyDetails?: AwsEsdkAsymmetricKeyDetails
export(options: AwsEsdkKeyExportOptions<'pem'>): string | Buffer
export(options?: AwsEsdkKeyExportOptions<'der'>): Buffer
export(options?: { format: 'jwk' }): AwsEsdkJsonWebKey
symmetricSize?: number
type: AwsEsdkKeyObjectType
equals(otherKeyObject: AwsEsdkKeyObject): boolean
}
export type AwsEsdkCreateSecretKey = (key: Uint8Array) => AwsEsdkKeyObject
export interface ClientOptions {
commitmentPolicy: CommitmentPolicy
maxEncryptedDataKeys: number | false
}
export type Newable<T> = { new (...args: any[]): T }
export interface AwsEsdkJsonWebKey {
crv?: string
d?: string
dp?: string
dq?: string
e?: string
k?: string
kty?: string
n?: string
p?: string
q?: string
qi?: string
x?: string
y?: string
[key: string]: unknown
}
export interface AwsEsdkAsymmetricKeyDetails {
/**
* Key size in bits (RSA, DSA).
*/
modulusLength?: number
/**
* Public exponent (RSA).
*/
publicExponent?: bigint
/**
* Size of q in bits (DSA).
*/
divisorLength?: number
/**
* Name of the curve (EC).
*/
namedCurve?: string
}
export interface Catchable {
errPlus?: Error | string | any
}