UNPKG

@microsoft/useragent-sdk

Version:

SDK for building decentralized identity wallets and enterprise agents.

61 lines (60 loc) 2.19 kB
/// <reference types="node" /> /// <reference types="pouchdb-core" /> import CryptoFactory from "../../plugin/CryptoFactory"; import PrivateKey from "../PrivateKey"; /** * Class to model RSA pairwise keys */ export default class RsaPairwiseKey { /** * Statistics on the number of prime tests */ static numberOfPrimeTests: number; /** * Generate a pairwise key for the specified algorithms * @param cryptoFactory defining the key store and the used crypto api * @param personaMasterKey Master key for the current selected persona * @param algorithm for the key * @param peerId Id for the peer */ static generate(cryptoFactory: CryptoFactory, personaMasterKey: Buffer, algorithm: RsaHashedKeyGenParams, peerId: string): Promise<PrivateKey>; /** * Uses primeBase as reference and generate the closest prime number */ private static getPrime; /** * Generate a deterministic number that can be used as prime * @param cryptoFactory The crypto factory. * @param keySize Desired key size * @param personaMasterKey The persona master key * @param peerId The peer id */ static generateDeterministicNumberForPrime(cryptoFactory: CryptoFactory, primeSize: number, personaMasterKey: Buffer, peerId: Buffer): Promise<Buffer>; /** * Generate a hash used as component for prime number * @param crypto The crypto object. * @param inx Round number * @param key Signature key * @param data Data to sign */ private static generateHashForPrime; /** * Execute all rounds * @param rounds Array of functions to execute * @param inx Current step * @param key Key to sign * @param data Data to sign */ private static executeRounds; /** * Generate a prime number from the seed. * isProbablyPrime is based on the Miller-Rabin prime test. * @param primeSeed seed for prime generator */ private static generatePrime; /** * Convert big number to base64 url. * @param bigNumber Number to convert */ private static toBase; }