TypeScript
Class method vs. Static method

by Benny Neugebauer

class CryptoboxSession {
  public id: string;
  public session: ProteusSession.Session;

  constructor(id: string, session: ProteusSession.Session) {
    this.id = id || CryptoboxSession.generateSessionId(session);
    this.session = session;
    Object.freeze(this);
  }

  public static generateSessionId(session: ProteusSession.Session): string {
    const from = session.local_identity.public_key.fingerprint();
    const to = session.remote_identity.fingerprint();
    return `${from}@${to}`;
  }
}

class CryptoboxSession {
  public id: string;
  public session: ProteusSession.Session;

  constructor(id: string | undefined, session: ProteusSession.Session) {
    this.session = session;
    this.id = id || this.generateSessionId();
    Object.freeze(this);
  }

  public generateSessionId(): string {
    const from = this.session.local_identity.public_key.fingerprint();
    const to = this.session.remote_identity.fingerprint();
    return `${from}@${to}`;
  }
}