@dwn-protocol/id-sdk
Version:
SDK for accessing the features and capabilities
30 lines (22 loc) • 1.18 kB
text/typescript
import type { IDCrypto } from '../../types/iddwn-crypto.js';
import { InvalidAccessError } from '../errors.js';
import { BaseEllipticCurveAlgorithm } from './base.js';
export abstract class BaseEdDsaAlgorithm extends BaseEllipticCurveAlgorithm {
public readonly name: string = 'EdDSA';
public readonly keyUsages: IDCrypto.KeyPairUsage = {
privateKey : ['sign'],
publicKey : ['verify'],
};
public checkAlgorithmOptions(options: {
algorithm: IDCrypto.EdDsaOptions
}): void {
const { algorithm } = options;
// Algorithm specified in the operation must match the algorithm implementation processing the operation.
this.checkAlgorithmName({ algorithmName: algorithm.name });
}
public override async deriveBits(): Promise<Uint8Array> {
throw new InvalidAccessError(`Requested operation 'deriveBits' is not valid for ${this.name} keys.`);
}
public abstract sign(options: { algorithm: IDCrypto.EdDsaOptions; key: IDCrypto.CryptoKey; data: Uint8Array; }): Promise<Uint8Array>;
public abstract verify(options: { algorithm: IDCrypto.EdDsaOptions; key: IDCrypto.CryptoKey; signature: Uint8Array; data: Uint8Array; }): Promise<boolean>;
}