Skip to content

Commit

Permalink
test: added test for CryptoKeyPairHandle generation
Browse files Browse the repository at this point in the history
This test is currently failing due to an issue in rs-crypto-node
  • Loading branch information
WyvernIXTL committed Feb 27, 2025
1 parent fba214d commit d602cad
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/crypto-layer/CryptoSignatureKeypairHandle.test.ts
Original file line number Diff line number Diff line change
@@ -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
);
});
});
});
}
}
2 changes: 2 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -35,6 +36,7 @@ import { SodiumWrapperTest } from "./crypto/SodiumWrapperTest.test";
providersToBeInitialized: [{ providerName: "SoftwareProvider" }]
});
CryptoLayerProviderTest.run();
CryptoSignatureKeypairHandleTest.run();

// === Other ===
await SodiumWrapper.ready();
Expand Down

0 comments on commit d602cad

Please sign in to comment.