-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
823253c
commit c524f3f
Showing
85 changed files
with
2,739 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { API } from '../../../../API' | ||
import { APINotSupportedError } from '../../../../exception/APINotImplementedError' | ||
import { BootOpt } from '../../../../system' | ||
|
||
export function webCrypto(window: Window, opt: BootOpt): API['crypto'] { | ||
const crypto: API['crypto'] = { | ||
generateKey: function ( | ||
algorithm: AlgorithmIdentifier, | ||
extractable: boolean, | ||
keyUsages: KeyUsage[] | ||
): Promise<CryptoKey | CryptoKeyPair> { | ||
if (window.crypto) { | ||
return window.crypto.subtle.generateKey( | ||
algorithm, | ||
extractable, | ||
keyUsages | ||
) | ||
} | ||
|
||
throw new APINotSupportedError('Crypto') | ||
}, | ||
exportKey: function ( | ||
format: KeyFormat, | ||
key: CryptoKey | ||
): Promise<ArrayBuffer | JsonWebKey> { | ||
if (window.crypto) { | ||
return window.crypto.subtle.exportKey(format, key) | ||
} | ||
|
||
throw new APINotSupportedError('Crypto') | ||
}, | ||
importKey: function < | ||
F extends KeyFormat, | ||
K extends F extends 'jwk' ? JsonWebKey : BufferSource, | ||
>( | ||
format: F, | ||
key: K, | ||
algorithm: AlgorithmIdentifier, | ||
extractable: boolean, | ||
keyUsages: KeyUsage[] | ||
): Promise<CryptoKey> { | ||
if (window.crypto) { | ||
return window.crypto.subtle.importKey( | ||
format as any, | ||
key as any, | ||
algorithm, | ||
extractable, | ||
keyUsages | ||
) | ||
} | ||
|
||
throw new APINotSupportedError('Crypto') | ||
}, | ||
encrypt: function ( | ||
algorithm: AlgorithmIdentifier, | ||
key: CryptoKey, | ||
data: BufferSource | ||
): Promise<ArrayBuffer> { | ||
if (window.crypto) { | ||
return window.crypto.subtle.encrypt(algorithm, key, data) | ||
} | ||
|
||
throw new APINotSupportedError('Crypto') | ||
}, | ||
decrypt: function ( | ||
algorithm: AlgorithmIdentifier, | ||
key: CryptoKey, | ||
data: BufferSource | ||
): Promise<ArrayBuffer> { | ||
if (window.crypto) { | ||
return window.crypto.subtle.decrypt(algorithm, key, data) | ||
} | ||
|
||
throw new APINotSupportedError('Crypto') | ||
}, | ||
sign: function ( | ||
algorithm: AlgorithmIdentifier, | ||
key: CryptoKey, | ||
data: ArrayBuffer | ||
): Promise<ArrayBuffer> { | ||
if (window.crypto) { | ||
return window.crypto.subtle.sign(algorithm, key, data) | ||
} | ||
|
||
throw new APINotSupportedError('Crypto') | ||
}, | ||
verify: function ( | ||
algorithm: AlgorithmIdentifier, | ||
key: CryptoKey, | ||
signature: BufferSource, | ||
data: BufferSource | ||
): Promise<boolean> { | ||
if (window.crypto) { | ||
return window.crypto.subtle.verify(algorithm, key, signature, data) | ||
} | ||
|
||
throw new APINotSupportedError('Crypto') | ||
}, | ||
} | ||
|
||
return crypto | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.