|
| 1 | +@@warning("-30") |
| 2 | + |
| 3 | +open Prelude |
| 4 | + |
| 5 | +type keyType = |
| 6 | + | @as("private") Private |
| 7 | + | @as("public") Public |
| 8 | + | @as("secret") Secret |
| 9 | + |
| 10 | +type keyUsage = |
| 11 | + | @as("decrypt") Decrypt |
| 12 | + | @as("deriveBits") DeriveBits |
| 13 | + | @as("deriveKey") DeriveKey |
| 14 | + | @as("encrypt") Encrypt |
| 15 | + | @as("sign") Sign |
| 16 | + | @as("unwrapKey") UnwrapKey |
| 17 | + | @as("verify") Verify |
| 18 | + | @as("wrapKey") WrapKey |
| 19 | + |
| 20 | +type keyFormat = |
| 21 | + | @as("jwk") Jwk |
| 22 | + | @as("pkcs8") Pkcs8 |
| 23 | + | @as("raw") Raw |
| 24 | + | @as("spki") Spki |
| 25 | + |
| 26 | +type keyAlgorithm = {mutable name: string} |
| 27 | + |
| 28 | +/** |
| 29 | +This Web Crypto API interface provides a number of low-level cryptographic functions. It is accessed via the Crypto.subtle properties available in a window context (via Window.crypto). |
| 30 | +[See SubtleCrypto on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto) |
| 31 | +*/ |
| 32 | +type subtleCrypto = {} |
| 33 | + |
| 34 | +/** |
| 35 | +Basic cryptography features available in the current context. It allows access to a cryptographically strong random number generator and to cryptographic primitives. |
| 36 | +[See Crypto on MDN](https://developer.mozilla.org/docs/Web/API/Crypto) |
| 37 | +*/ |
| 38 | +type crypto = { |
| 39 | + /** |
| 40 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Crypto/subtle) |
| 41 | + */ |
| 42 | + subtle: subtleCrypto, |
| 43 | +} |
| 44 | + |
| 45 | +/** |
| 46 | +The CryptoKey dictionary of the Web Crypto API represents a cryptographic key. |
| 47 | +[See CryptoKey on MDN](https://developer.mozilla.org/docs/Web/API/CryptoKey) |
| 48 | +*/ |
| 49 | +type cryptoKey = { |
| 50 | + /** |
| 51 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/CryptoKey/type) |
| 52 | + */ |
| 53 | + @as("type") |
| 54 | + type_: keyType, |
| 55 | + /** |
| 56 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/CryptoKey/extractable) |
| 57 | + */ |
| 58 | + extractable: bool, |
| 59 | + /** |
| 60 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/CryptoKey/algorithm) |
| 61 | + */ |
| 62 | + algorithm: keyAlgorithm, |
| 63 | + /** |
| 64 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/CryptoKey/usages) |
| 65 | + */ |
| 66 | + usages: array<keyUsage>, |
| 67 | +} |
| 68 | + |
| 69 | +type algorithmIdentifier = any |
| 70 | + |
| 71 | +module SubtleCrypto = { |
| 72 | + /** |
| 73 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/encrypt) |
| 74 | + */ |
| 75 | + @send |
| 76 | + external encrypt: ( |
| 77 | + subtleCrypto, |
| 78 | + algorithmIdentifier, |
| 79 | + cryptoKey, |
| 80 | + bufferSource, |
| 81 | + ) => Promise.t<ArrayBuffer.t> = "encrypt" |
| 82 | + |
| 83 | + /** |
| 84 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/decrypt) |
| 85 | + */ |
| 86 | + @send |
| 87 | + external decrypt: ( |
| 88 | + subtleCrypto, |
| 89 | + algorithmIdentifier, |
| 90 | + cryptoKey, |
| 91 | + bufferSource, |
| 92 | + ) => Promise.t<ArrayBuffer.t> = "decrypt" |
| 93 | + |
| 94 | + /** |
| 95 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/sign) |
| 96 | + */ |
| 97 | + @send |
| 98 | + external sign: (subtleCrypto, algorithmIdentifier, cryptoKey, bufferSource) => Promise.t<any> = |
| 99 | + "sign" |
| 100 | + |
| 101 | + /** |
| 102 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/verify) |
| 103 | + */ |
| 104 | + @send |
| 105 | + external verify: ( |
| 106 | + subtleCrypto, |
| 107 | + algorithmIdentifier, |
| 108 | + cryptoKey, |
| 109 | + bufferSource, |
| 110 | + bufferSource, |
| 111 | + ) => Promise.t<any> = "verify" |
| 112 | + |
| 113 | + /** |
| 114 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/digest) |
| 115 | + */ |
| 116 | + @send |
| 117 | + external digest: (subtleCrypto, algorithmIdentifier, bufferSource) => Promise.t<any> = "digest" |
| 118 | + |
| 119 | + /** |
| 120 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/generateKey) |
| 121 | + */ |
| 122 | + @send |
| 123 | + external generateKey: ( |
| 124 | + subtleCrypto, |
| 125 | + algorithmIdentifier, |
| 126 | + bool, |
| 127 | + array<keyUsage>, |
| 128 | + ) => Promise.t<any> = "generateKey" |
| 129 | + |
| 130 | + /** |
| 131 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/deriveKey) |
| 132 | + */ |
| 133 | + @send |
| 134 | + external deriveKey: ( |
| 135 | + subtleCrypto, |
| 136 | + algorithmIdentifier, |
| 137 | + cryptoKey, |
| 138 | + algorithmIdentifier, |
| 139 | + bool, |
| 140 | + array<keyUsage>, |
| 141 | + ) => Promise.t<any> = "deriveKey" |
| 142 | + |
| 143 | + /** |
| 144 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/deriveBits) |
| 145 | + */ |
| 146 | + @send |
| 147 | + external deriveBits: ( |
| 148 | + subtleCrypto, |
| 149 | + algorithmIdentifier, |
| 150 | + cryptoKey, |
| 151 | + int, |
| 152 | + ) => Promise.t<ArrayBuffer.t> = "deriveBits" |
| 153 | + |
| 154 | + /** |
| 155 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/importKey) |
| 156 | + */ |
| 157 | + @send |
| 158 | + external importKey: ( |
| 159 | + subtleCrypto, |
| 160 | + any, |
| 161 | + bufferSource, |
| 162 | + algorithmIdentifier, |
| 163 | + bool, |
| 164 | + array<keyUsage>, |
| 165 | + ) => Promise.t<cryptoKey> = "importKey" |
| 166 | + |
| 167 | + /** |
| 168 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/exportKey) |
| 169 | + */ |
| 170 | + @send |
| 171 | + external exportKey: (subtleCrypto, keyFormat, cryptoKey) => Promise.t<any> = "exportKey" |
| 172 | + |
| 173 | + /** |
| 174 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/wrapKey) |
| 175 | + */ |
| 176 | + @send |
| 177 | + external wrapKey: ( |
| 178 | + subtleCrypto, |
| 179 | + keyFormat, |
| 180 | + cryptoKey, |
| 181 | + cryptoKey, |
| 182 | + algorithmIdentifier, |
| 183 | + ) => Promise.t<any> = "wrapKey" |
| 184 | + |
| 185 | + /** |
| 186 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/unwrapKey) |
| 187 | + */ |
| 188 | + @send |
| 189 | + external unwrapKey: ( |
| 190 | + subtleCrypto, |
| 191 | + keyFormat, |
| 192 | + bufferSource, |
| 193 | + cryptoKey, |
| 194 | + algorithmIdentifier, |
| 195 | + algorithmIdentifier, |
| 196 | + bool, |
| 197 | + array<keyUsage>, |
| 198 | + ) => Promise.t<cryptoKey> = "unwrapKey" |
| 199 | +} |
| 200 | + |
| 201 | +module Crypto = { |
| 202 | + /** |
| 203 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Crypto/getRandomValues) |
| 204 | + */ |
| 205 | + @send |
| 206 | + external getRandomValues: (crypto, 't) => 't = "getRandomValues" |
| 207 | + |
| 208 | + /** |
| 209 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Crypto/randomUUID) |
| 210 | + */ |
| 211 | + @send |
| 212 | + external randomUUID: crypto => string = "randomUUID" |
| 213 | +} |
0 commit comments