You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
import { fromHexToArray, toHex } from '../session/utils/String';
 | 
						|
 | 
						|
export type HexKeyPair = {
 | 
						|
  publicHex: string;
 | 
						|
  privateHex: string;
 | 
						|
};
 | 
						|
 | 
						|
export type SessionKeyPair = {
 | 
						|
  pubKey: ArrayBuffer;
 | 
						|
  privKey: ArrayBuffer;
 | 
						|
};
 | 
						|
 | 
						|
export class ECKeyPair {
 | 
						|
  public readonly publicKeyData: Uint8Array;
 | 
						|
  public readonly privateKeyData: Uint8Array;
 | 
						|
 | 
						|
  constructor(publicKeyData: Uint8Array, privateKeyData: Uint8Array) {
 | 
						|
    this.publicKeyData = publicKeyData;
 | 
						|
    this.privateKeyData = privateKeyData;
 | 
						|
  }
 | 
						|
 | 
						|
  public static fromArrayBuffer(pub: ArrayBuffer, priv: ArrayBuffer) {
 | 
						|
    return new ECKeyPair(new Uint8Array(pub), new Uint8Array(priv));
 | 
						|
  }
 | 
						|
 | 
						|
  public static fromKeyPair(pair: SessionKeyPair) {
 | 
						|
    return new ECKeyPair(new Uint8Array(pair.pubKey), new Uint8Array(pair.privKey));
 | 
						|
  }
 | 
						|
 | 
						|
  public static fromHexKeyPair(pair: HexKeyPair) {
 | 
						|
    return new ECKeyPair(fromHexToArray(pair.publicHex), fromHexToArray(pair.privateHex));
 | 
						|
  }
 | 
						|
 | 
						|
  public toString() {
 | 
						|
    const hexKeypair = this.toHexKeyPair();
 | 
						|
    return `ECKeyPair: ${hexKeypair.publicHex} ${hexKeypair.privateHex}`;
 | 
						|
  }
 | 
						|
 | 
						|
  public toHexKeyPair(): HexKeyPair {
 | 
						|
    const publicHex = toHex(this.publicKeyData);
 | 
						|
    const privateHex = toHex(this.privateKeyData);
 | 
						|
    return {
 | 
						|
      publicHex,
 | 
						|
      privateHex,
 | 
						|
    };
 | 
						|
  }
 | 
						|
}
 |