From d602cadc62d3b08c8556cc7686c9ad325d114f19 Mon Sep 17 00:00:00 2001 From: Adam McKellar Date: Thu, 27 Feb 2025 14:47:57 +0100 Subject: [PATCH] test: added test for CryptoKeyPairHandle generation This test is currently failing due to an issue in rs-crypto-node --- .../CryptoSignatureKeypairHandle.test.ts | 58 +++++++++++++++++++ test/index.ts | 2 + 2 files changed, 60 insertions(+) create mode 100644 test/crypto-layer/CryptoSignatureKeypairHandle.test.ts diff --git a/test/crypto-layer/CryptoSignatureKeypairHandle.test.ts b/test/crypto-layer/CryptoSignatureKeypairHandle.test.ts new file mode 100644 index 0000000..2954908 --- /dev/null +++ b/test/crypto-layer/CryptoSignatureKeypairHandle.test.ts @@ -0,0 +1,58 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { CryptoSignatures } from "@nmshd/crypto"; +import { KeyPairSpec } from "@nmshd/rs-crypto-types"; +import { expect } from "chai"; +import { CryptoSignatureKeypairHandle } from "src/crypto-layer/signature/CryptoSignatureKeypair"; +import { CryptoSignaturePrivateKeyHandle } from "src/crypto-layer/signature/CryptoSignaturePrivateKeyHandle"; +import { CryptoSignaturePublicKeyHandle } from "src/crypto-layer/signature/CryptoSignaturePublicKeyHandle"; + +export class CryptoSignatureKeypairHandleTest { + public static run(): void { + describe("CryptoSignatureKeypairHandle", function () { + describe("generateKeyPairHandle() SoftwareProvider", function () { + it("generateKeyPairHandle() with P256", async function () { + const spec: KeyPairSpec = { + asym_spec: "P256", + cipher: null, + signing_hash: "Sha2_512", + ephemeral: false, + non_exportable: false + }; + const cryptoKeyPairHandle = await CryptoSignatures.generateKeypairHandle( + { providerName: "SoftwareProvider" }, + spec + ); + expect(cryptoKeyPairHandle).to.exist; + expect(cryptoKeyPairHandle).to.be.instanceOf(CryptoSignatureKeypairHandle); + expect(cryptoKeyPairHandle.privateKey).to.exist; + expect(cryptoKeyPairHandle.publicKey).to.exist; + expect(cryptoKeyPairHandle.privateKey).to.be.instanceOf(CryptoSignaturePrivateKeyHandle); + expect(cryptoKeyPairHandle.publicKey).to.be.instanceOf(CryptoSignaturePublicKeyHandle); + expect(cryptoKeyPairHandle.privateKey.keyPairHandle).to.exist; + expect(cryptoKeyPairHandle.publicKey.keyPairHandle).to.exist; + expect(cryptoKeyPairHandle.privateKey.keyPairHandle).to.be.equal( + cryptoKeyPairHandle.publicKey.keyPairHandle + ); + expect(cryptoKeyPairHandle.privateKey.id).to.exist; + expect(cryptoKeyPairHandle.publicKey.id).to.exist; + expect(cryptoKeyPairHandle.privateKey.id).to.be.string(cryptoKeyPairHandle.publicKey.id); + expect(cryptoKeyPairHandle.privateKey.provider).to.exist; + expect(cryptoKeyPairHandle.publicKey.provider).to.exist; + expect(cryptoKeyPairHandle.privateKey.provider).to.equal(cryptoKeyPairHandle.publicKey.provider); + expect(cryptoKeyPairHandle.privateKey.providerName).to.exist; + expect(cryptoKeyPairHandle.publicKey.providerName).to.exist; + expect(cryptoKeyPairHandle.privateKey.providerName).to.be.string( + cryptoKeyPairHandle.publicKey.providerName + ); + expect(cryptoKeyPairHandle.privateKey.providerName).to.be.string("SoftwareProvider"); + expect(await cryptoKeyPairHandle.privateKey.keyPairHandle.id()).to.be.string( + cryptoKeyPairHandle.privateKey.id + ); + expect(await cryptoKeyPairHandle.publicKey.keyPairHandle.id()).to.be.string( + cryptoKeyPairHandle.publicKey.id + ); + }); + }); + }); + } +} diff --git a/test/index.ts b/test/index.ts index 5adc540..4008a07 100644 --- a/test/index.ts +++ b/test/index.ts @@ -7,6 +7,7 @@ import { } from "@nmshd/rs-crypto-node"; import { BufferTest } from "./BufferTest.test"; import { CryptoLayerProviderTest } from "./crypto-layer/CryptoLayerProviderTest.test"; +import { CryptoSignatureKeypairHandleTest } from "./crypto-layer/CryptoSignatureKeypairHandle.test"; import { CryptoDerivationTest } from "./crypto/CryptoDerivationTest.test"; import { CryptoEncryptionTest } from "./crypto/CryptoEncryptionTest.test"; import { CryptoExchangeTest } from "./crypto/CryptoExchangeTest.test"; @@ -35,6 +36,7 @@ import { SodiumWrapperTest } from "./crypto/SodiumWrapperTest.test"; providersToBeInitialized: [{ providerName: "SoftwareProvider" }] }); CryptoLayerProviderTest.run(); + CryptoSignatureKeypairHandleTest.run(); // === Other === await SodiumWrapper.ready();