async buildCounterKey()

in packages/sqrl/src/object/SqrlEntity.ts [80:115]


  async buildCounterKey(
    ctx: Context,
    ...featureValues: Array<any>
  ): Promise<SqrlKey | null> {
    const hasEmpty = featureValues.some((v) => {
      return v === null || v === "";
    });
    if (hasEmpty) {
      return null;
    }

    // Search through all the values for Entity/UniqueId
    let timeMs = this.uniqueId.getTimeMs();
    for (const value of featureValues) {
      if (value instanceof SqrlObject) {
        timeMs = Math.max(timeMs, value.tryGetTimeMs() || 0);
      }
    }

    const basicFeatureValues = await nice(() =>
      SqrlObject.ensureBasic(featureValues)
    );
    let featuresHash: Buffer;
    if (featureValues.length) {
      featuresHash = await murmurhashJson(basicFeatureValues);
    } else {
      featuresHash = Buffer.alloc(16);
    }
    return new SqrlKey(
      ctx.requireDatabaseSet(),
      this,
      basicFeatureValues,
      timeMs,
      featuresHash
    );
  }