@@ -15,7 +15,7 @@ const CURVE_DSA = Object.freeze<EcKeyAlgorithm & EcdsaParams>({
15
15
hash : "SHA-256"
16
16
} ) ;
17
17
18
- async function generateKey ( alg :EcKeyAlgorithm , usage :KeyUsage [ ] ) :Promise < PubKey > {
18
+ async function generateKey ( alg : EcKeyAlgorithm , usage : KeyUsage [ ] ) : Promise < PubKey > {
19
19
const { publicKey, privateKey} = await crypto . subtle . generateKey ( alg , true , usage ) ;
20
20
21
21
return {
@@ -24,7 +24,7 @@ async function generateKey(alg:EcKeyAlgorithm, usage:KeyUsage[]):Promise<PubKey>
24
24
} ;
25
25
}
26
26
27
- async function deriveKey ( pub :Uint8Array , key :Uint8Array ) :Promise < CryptoKey > {
27
+ async function deriveKey ( pub : Uint8Array , key : Uint8Array ) : Promise < CryptoKey > {
28
28
return await crypto . subtle . deriveKey ( {
29
29
name : CURVE_KEX . name ,
30
30
public : await crypto . subtle . importKey ( "spki" , pub , CURVE_KEX , false , [ ] )
@@ -41,7 +41,7 @@ async function deriveKey(pub:Uint8Array, key:Uint8Array):Promise<CryptoKey> {
41
41
* const random = cryptoRandom(16);
42
42
* ```
43
43
*/
44
- export function cryptoRandom ( n :number ) :Uint8Array {
44
+ export function cryptoRandom ( n : number ) : Uint8Array {
45
45
return crypto . getRandomValues ( new Uint8Array ( n ) ) ;
46
46
}
47
47
@@ -54,7 +54,7 @@ export function cryptoRandom(n:number):Uint8Array {
54
54
* const hash = await cryptoHash(bin);
55
55
* ```
56
56
*/
57
- export async function cryptoHash ( data :Uint8Array , alg ?:string ) :Promise < Uint8Array > {
57
+ export async function cryptoHash ( data : Uint8Array , alg ?: string ) : Promise < Uint8Array > {
58
58
return new Uint8Array ( await crypto . subtle . digest ( alg ?? "SHA-256" , data ) ) ;
59
59
}
60
60
@@ -68,7 +68,7 @@ export async function cryptoHash(data:Uint8Array, alg?:string):Promise<Uint8Arra
68
68
* const key2 = await cryptoGenerateEncryptKey();
69
69
* ```
70
70
*/
71
- export async function cryptoGenerateEncryptKey ( ) :Promise < PubKey > {
71
+ export async function cryptoGenerateEncryptKey ( ) : Promise < PubKey > {
72
72
return await generateKey ( CURVE_KEX , [ "deriveKey" ] ) ;
73
73
}
74
74
@@ -81,7 +81,7 @@ export async function cryptoGenerateEncryptKey():Promise<PubKey> {
81
81
* const {pub, key} = await cryptoGenerateSignKey();
82
82
* ```
83
83
*/
84
- export async function cryptoGenerateSignKey ( ) :Promise < PubKey > {
84
+ export async function cryptoGenerateSignKey ( ) : Promise < PubKey > {
85
85
return await generateKey ( CURVE_DSA , [ "sign" , "verify" ] ) ;
86
86
}
87
87
@@ -98,8 +98,8 @@ export async function cryptoGenerateSignKey():Promise<PubKey> {
98
98
* const decrypt = await cryptoDecrypt(encrypt, key2.pub, key1.key);
99
99
* ```
100
100
*/
101
- export async function cryptoEncrypt ( data :Uint8Array , pub :Uint8Array , key :Uint8Array ) :Promise < Uint8Array > {
102
- const aes :AesGcmParams = {
101
+ export async function cryptoEncrypt ( data : Uint8Array , pub : Uint8Array , key : Uint8Array ) : Promise < Uint8Array > {
102
+ const aes : AesGcmParams = {
103
103
name : AES_MODE ,
104
104
iv : cryptoRandom ( 12 )
105
105
} ;
@@ -120,8 +120,8 @@ export async function cryptoEncrypt(data:Uint8Array, pub:Uint8Array, key:Uint8Ar
120
120
* const decrypt = await cryptoDecrypt(encrypt, key2.pub, key1.key);
121
121
* ```
122
122
*/
123
- export async function cryptoDecrypt ( data :Uint8Array , pub :Uint8Array , key :Uint8Array ) :Promise < Uint8Array > {
124
- const aes :AesGcmParams = {
123
+ export async function cryptoDecrypt ( data : Uint8Array , pub : Uint8Array , key : Uint8Array ) : Promise < Uint8Array > {
124
+ const aes : AesGcmParams = {
125
125
name : AES_MODE ,
126
126
iv : data . subarray ( 0 , 12 )
127
127
} ;
@@ -139,7 +139,7 @@ export async function cryptoDecrypt(data:Uint8Array, pub:Uint8Array, key:Uint8Ar
139
139
* const verify = await cryptoVerify(bin, pub, sign);
140
140
* ```
141
141
*/
142
- export async function cryptoSign ( data :Uint8Array , key :Uint8Array ) :Promise < Uint8Array > {
142
+ export async function cryptoSign ( data : Uint8Array , key : Uint8Array ) : Promise < Uint8Array > {
143
143
return new Uint8Array ( await crypto . subtle . sign ( CURVE_DSA , await crypto . subtle . importKey ( "pkcs8" , key , CURVE_DSA , false , [ "sign" ] ) , data ) ) ;
144
144
}
145
145
@@ -153,6 +153,6 @@ export async function cryptoSign(data:Uint8Array, key:Uint8Array):Promise<Uint8A
153
153
* const verify = await cryptoVerify(bin, pub, sign);
154
154
* ```
155
155
*/
156
- export async function cryptoVerify ( data :Uint8Array , pub :Uint8Array , sign :Uint8Array ) :Promise < boolean > {
156
+ export async function cryptoVerify ( data : Uint8Array , pub : Uint8Array , sign : Uint8Array ) : Promise < boolean > {
157
157
return await crypto . subtle . verify ( CURVE_DSA , await crypto . subtle . importKey ( "spki" , pub , CURVE_DSA , false , [ "verify" ] ) , sign , data ) ;
158
158
}
0 commit comments