From c7199c01163b190a521f654226c7bd726a47c028 Mon Sep 17 00:00:00 2001 From: dojyorin Date: Fri, 19 Apr 2024 00:50:06 +0900 Subject: [PATCH] fix method name --- src/pure/crypto.ts | 46 ++++++++++++++++++++-------------------- test/pure/crypto.test.ts | 16 +++++++------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/pure/crypto.ts b/src/pure/crypto.ts index 15debea..0bde077 100644 --- a/src/pure/crypto.ts +++ b/src/pure/crypto.ts @@ -73,11 +73,11 @@ export async function deriveHash(data:Uint8Array, sha?:`SHA-${256 | 384 | 512}`) * Curve algorithm is "NIST P-256". * @example * ```ts -* const k1 = await pkGenerateECDH(); -* const k2 = await pkGenerateECDH(); +* const k1 = await generateEncryptKey(); +* const k2 = await generateEncryptKey(); * ``` */ -export async function pkGenerateECDH():Promise{ +export async function generateEncryptKey():Promise{ return await generateKey(CURVE_ECDH, ["deriveKey"]); } @@ -86,10 +86,10 @@ export async function pkGenerateECDH():Promise{ * Curve algorithm is "NIST P-256". * @example * ```ts -* const {publicKey, privateKey} = await pkGenerateECDSA(); +* const {publicKey, privateKey} = await generateSignKey(); * ``` */ -export async function pkGenerateECDSA():Promise{ +export async function generateSignKey():Promise{ return await generateKey(CURVE_ECDSA, ["sign", "verify"]); } @@ -100,19 +100,19 @@ export async function pkGenerateECDSA():Promise{ * @example * ```ts * const bin = await Deno.readFile("./file"); -* const k1 = await pkGenerateECDH(); -* const k2 = await pkGenerateECDH(); -* const cipher = await pkEncrypt(bin, { +* const k1 = await generateEncryptKey(); +* const k2 = await generateEncryptKey(); +* const cipher = await encryptData(bin, { * publicKey: k1.publicKey, * privateKey: k2.privateKey * }); -* const decrypt = await pkDecrypt(cipher, { +* const decrypt = await decryptData(cipher, { * publicKey: k2.publicKey, * privateKey: k1.privateKey * }); * ``` */ -export async function pkEncrypt(data:Uint8Array, {publicKey, privateKey}:PortableCryptoKeyPair):Promise{ +export async function encryptData(data:Uint8Array, {publicKey, privateKey}:PortableCryptoKeyPair):Promise{ const aes = { name: AES_MODE, iv: generateRandom(12) @@ -128,19 +128,19 @@ export async function pkEncrypt(data:Uint8Array, {publicKey, privateKey}:Portabl * @example * ```ts * const bin = await Deno.readFile("./file"); -* const k1 = await pkGenerateECDH(); -* const k2 = await pkGenerateECDH(); -* const cipher = await pkEncrypt(bin, { +* const k1 = await generateEncryptKey(); +* const k2 = await generateEncryptKey(); +* const cipher = await encryptData(bin, { * publicKey: k1.publicKey, * privateKey: k2.privateKey * }); -* const decrypt = await pkDecrypt(cipher, { +* const decrypt = await decryptData(cipher, { * publicKey: k2.publicKey, * privateKey: k1.privateKey * }); * ``` */ -export async function pkDecrypt(data:Uint8Array, {publicKey, privateKey}:PortableCryptoKeyPair):Promise{ +export async function decryptData(data:Uint8Array, {publicKey, privateKey}:PortableCryptoKeyPair):Promise{ const aes = { name: AES_MODE, iv: data.subarray(0, 12) @@ -154,12 +154,12 @@ export async function pkDecrypt(data:Uint8Array, {publicKey, privateKey}:Portabl * @example * ```ts * const bin = await Deno.readFile("./file"); -* const {publicKey, privateKey} = await pkGenerateECDSA(); -* const sign = await pkSign(bin, privateKey); -* const verify = await pkVerify(bin, publicKey, sign); +* const {publicKey, privateKey} = await generateSignKey(); +* const sign = await deriveSign(bin, privateKey); +* const verify = await verifySign(bin, publicKey, sign); * ``` */ -export async function pkSign(data:Uint8Array, key:Uint8Array):Promise{ +export async function deriveSign(data:Uint8Array, key:Uint8Array):Promise{ return new Uint8Array(await crypto.subtle.sign(MAC_ECDSA, await crypto.subtle.importKey(FORMAT_PRI, key, CURVE_ECDSA, false, ["sign"]), data)); } @@ -168,11 +168,11 @@ export async function pkSign(data:Uint8Array, key:Uint8Array):Promise{ +export async function verifySign(data:Uint8Array, key:Uint8Array, sign:Uint8Array):Promise{ return await crypto.subtle.verify(MAC_ECDSA, await crypto.subtle.importKey(FORMAT_PUB, key, CURVE_ECDSA, false, ["verify"]), sign, data); } \ No newline at end of file diff --git a/test/pure/crypto.test.ts b/test/pure/crypto.test.ts index ffa2499..087c30f 100644 --- a/test/pure/crypto.test.ts +++ b/test/pure/crypto.test.ts @@ -1,5 +1,5 @@ import {assertEquals} from "../../deps.test.ts"; -import {generateRandom, deriveHash, pkGenerateECDH, pkGenerateECDSA, pkEncrypt, pkDecrypt, pkSign, pkVerify} from "../../src/pure/crypto.ts"; +import {generateRandom, deriveHash, generateEncryptKey, generateSignKey, encryptData, decryptData, deriveSign, verifySign} from "../../src/pure/crypto.ts"; const sample = new Uint8Array([0x02, 0xF2, 0x5D, 0x1F, 0x1C, 0x34, 0xB9, 0x2F]); @@ -35,15 +35,15 @@ Deno.test({ Deno.test({ name: "Crypto: Encrypt and Decrypt", async fn(){ - const key1 = await pkGenerateECDH(); - const key2 = await pkGenerateECDH(); + const key1 = await generateEncryptKey(); + const key2 = await generateEncryptKey(); - const encrypt = await pkEncrypt(sample, { + const encrypt = await encryptData(sample, { publicKey: key1.publicKey, privateKey: key2.privateKey }); - const decrypt = await pkDecrypt(encrypt, { + const decrypt = await decryptData(encrypt, { publicKey: key2.publicKey, privateKey: key1.privateKey }); @@ -55,9 +55,9 @@ Deno.test({ Deno.test({ name: "Crypto: Sign and Verify", async fn(){ - const key = await pkGenerateECDSA(); - const signature = await pkSign(sample, key.privateKey); - const verify = await pkVerify(sample, key.publicKey, signature); + const key = await generateSignKey(); + const signature = await deriveSign(sample, key.privateKey); + const verify = await verifySign(sample, key.publicKey, signature); assertEquals(verify, true); }