/** * @license * @preserve * * KeeeX SAS Public code * https://keeex.me * Copyright 2013-2023 KeeeX All Rights Reserved. * * These computer program listings and specifications, herein, * are and remain the property of KeeeX SAS. The intellectual * and technical concepts herein are proprietary to KeeeX SAS * and may be covered by EU and foreign patents, * patents in process, trade secrets and copyright law. * * These listings are published as a way to provide third party * with the ability to process KeeeX data. * As such, support for public inquiries is limited. * They are provided "as-is", without warrany of any kind. * * They shall not be reproduced or copied or used in whole or * in part as the basis for manufacture or sale of items unless * prior written permission is obtained from KeeeX SAS. * * For a license agreement, please contact: * * */ import * as recovery from "../utils/recovery.js"; import * as io from "./io.js"; import * as localData from "./localdata.js"; import * as types from "./types.js"; import type * as typesUtils from "@keeex/utils/types/types.js"; /** * Base interface for all keypair types * * It is advised to use the basic implementation below instead of reimplementing everything. */ export interface IKeypair { getRecovery(recoveryMethod: recovery.RecoveryMethod): typesUtils.Awaitable; /** Return the private key as a string representation depending on the key type */ getPrivate(): typesUtils.Awaitable; /** Return the raw private key bytes */ getPrivateRaw(): typesUtils.Awaitable; /** Return the public key as a string representation depending on the key type */ getPublic(): typesUtils.Awaitable; /** Return the raw public key bytes */ getPublicRaw(): typesUtils.Awaitable; /** * Return an address for this key. * * A keypair address is a way to publicly identify a key specific to the keytype. */ getAddress(): string; /** * Return a "friendly" address. * * These are KeeeX-only, and can be converted from/to regular address for bitcoin/ethereum. * Non-compatible key types will return the regular address. */ getFriendlyAddress(): string; /** * A label suitable for displaying to users. * * This is not a technical information, and the content vary from implementation to * implementation. * The sole purpose of this label is to display a name in a friendly manner. */ getLabel(): string; /** * Return the key type * * This is the same key type as used in importKey()/generateKey() */ getType(): types.KeyType; /** * This is used to determine if an object is an instance of Keys when instanceof is not reliable. * (for example, if multiple copy of the library are used in a project). * * The string returned will always be the same for the same interface base. */ getClassType(): string; /** * Return a full type descriptor string * * Used to check compatibility between keys. * * Implementation must not override this, but instead override * getLocalType(). */ getFullType(): string; /** * Return a sub-type for this key * * This should be used to create compatible keys using * generateCompatibleKey(). * This should be derived from getLocalTypeRaw(), so override the other method instead. */ getLocalType(): string; /** * Return a sub-type for this key * * This should be used to create compatible keys using * generateCompatibleKey(). * The return value is an array of string/number/boolean that will be converted to a string. */ getLocalTypeRaw(): localData.LocalTypeData; /** Derive a key. * * This will compute a shared secret between this key and the second party * key. * The second party needs only to have a public key available, while this key * needs the private part to be available. */ deriveKey(secondParty: IKeypair): typesUtils.Awaitable; /** * Convert this key into another key type if possible. * * This will throw if the conversion is not supported. * * Usually one should override the convertToRaw() method instead. * * @param extra - Depending on the keytype, some extra data can be provided, matching the format * of getLocalType(). */ convertTo(keyType: types.KeyType, localType?: string): typesUtils.Awaitable; /** Actual conversion for convertTo(), to be overriden */ convertToRaw(keyType: types.KeyType, localType?: localData.LocalTypeData): typesUtils.Awaitable; /** Export the keypair (if possible) */ exportKey(publicOnly: boolean, options?: unknown): typesUtils.Awaitable; /** * Return a signature placeholder that is guaranteed to be long enough to hold a signature for the * associated public key. */ getSignaturePlaceholder(encoding: io.SignatureFormat.raw): typesUtils.Awaitable; /** * Return a signature placeholder that is guaranteed to be long enough to hold a signature for the * associated public key. */ getSignaturePlaceholder(encoding: io.SignatureFormat.utf8): typesUtils.Awaitable; isSignaturePlaceholder(signature: string | Uint8Array): typesUtils.Awaitable; /** Indicate that a keypair instance can perform digital signature */ canSign(): typesUtils.Awaitable; /** Sign input, return raw signature bytes as an Uint8Array */ sign(data: string | Uint8Array, encoding: io.SignatureFormat.raw | types.SignatureSettingsBuf8): typesUtils.Awaitable; /** Sign input, return a string representing the signature */ sign(data: string | Uint8Array, encoding?: io.SignatureFormat.utf8 | types.SignatureSettingsUtf8): typesUtils.Awaitable; /** Verify that a signature is valid and match the keypair */ verify(data: string | Uint8Array, signature: string | Uint8Array, messageFormat?: MessageFormat): typesUtils.Awaitable; /** Perform a signature and return raw signature bytes */ signRaw(data: Uint8Array): typesUtils.Awaitable; /** Perform a verification on raw signature bytes */ verifyRaw(data: Uint8Array, signature: Uint8Array): typesUtils.Awaitable; } /** @public */ export declare const isIKeypair: typesUtils.TypePredicate>; /** * Base implementation for all keypair. * * Provides some shared behavior. * * All keypair type should inherit from this instead of the interface. */ export declare abstract class Keypair, ExportOptions, MessageFormat, PrivateMetadata = undefined, PublicMetadata = undefined, PrivateParams = undefined> implements IKeypair { #private; protected dataFormatter: DataFormatter; protected constructor(type: types.KeyType, address: string, friendlyAddress: string | undefined, dataFormatter: DataFormatter, defaultMessageType: MessageFormat, messageFormatPredicate: typesUtils.TypePredicate, genRecoveryInfo?: recovery.UserGenerationRecoveryInfo); getRecovery: (recoveryMethod: recovery.RecoveryMethod) => typesUtils.Awaitable; getPrivate: () => Promise; getPublic: () => Promise; getAddress: () => string; getFriendlyAddress: () => string; /** Default implementation that returns the keytype and the address */ getLabel: () => string; getType: () => types.KeyType; getClassType: () => string; getFullType: () => string; getLocalType: () => string; convertTo: (keyType: types.KeyType, localType?: string) => Promise; getSignaturePlaceholder(encoding: io.SignatureFormat.raw): Promise; getSignaturePlaceholder(encoding: io.SignatureFormat.utf8): Promise; isSignaturePlaceholder: (signature: string | Uint8Array) => Promise; sign(data: string | Uint8Array, encoding?: io.SignatureFormat.raw | types.SignatureSettingsBuf8): Promise; sign(data: string | Uint8Array, encoding?: io.SignatureFormat.utf8 | types.SignatureSettingsUtf8): Promise; verify: (data: string | Uint8Array, signature: string | Uint8Array, messageFormat?: MessageFormat) => Promise; /** Can be overriden to provide a different content in the default `getLabel()` implementation */ protected getLabelRaw: () => string; /** Compute the signature placeholder based on the expected length */ protected getSignaturePlaceholderRaw: () => Promise; /** Convert signature data input to signable */ private readonly signatureDataInput; /** Cache the return value of getPrivateRaw() */ private readonly getPrivateRawCache; /** Cache the return value of getPrivateRaw() */ private readonly getPublicRawCache; abstract getPrivateRaw(): typesUtils.Awaitable; abstract getPublicRaw(): typesUtils.Awaitable; abstract getLocalTypeRaw(): localData.LocalTypeData; abstract deriveKey(secondParty: IKeypair): typesUtils.Awaitable; abstract convertToRaw(keyType: types.KeyType, localType?: localData.LocalTypeData): typesUtils.Awaitable; abstract exportKey(publicOnly: boolean, options: ExportOptions): typesUtils.Awaitable; abstract canSign(): typesUtils.Awaitable; abstract signRaw(data: Uint8Array): typesUtils.Awaitable; abstract verifyRaw(data: Uint8Array, signature: Uint8Array): typesUtils.Awaitable; /** * Return the length of the signature placeholder. * * This is used by the default getSignaturePlaceholderRaw() implementation. */ protected abstract getSignaturePlaceholderLength(): typesUtils.Awaitable; }