layout static method

Implementation

static Layout<BaseDkls23PublicKey> layout() =>
    ObjSeqLayout<BaseDkls23PublicKey>(
      [
        LayoutConst.u32(property: 'curve'),
        LayoutConst.fixedBlobN(33, property: 'groupPk'),
        LayoutConst.optional(
          LayoutConst.vec(LayoutConst.fixedBlobN(33), property: 'members'),
          property: 'members',
        ),
        LayoutConst.optional(LayoutConst.u32(), property: 'threshold'),
        LayoutConst.optional(LayoutConst.u32(), property: 'n'),
      ],
      build: (values) {
        final curveId = JsonParser.valueAs<int>(values.elementAtOrNull(0));
        final pk = JsonParser.valueAsBytes(values.elementAtOrNull(1));
        if (pk == null) {
          throw CoreErrors.cryptoFailed(
            'Dkls23AggregatePublicKey',
            reason: 'missing group key.',
          );
        }
        final members =
            JsonParser.valueAsList<List<List<int>>?>(
              values.elementAtOrNull(2),
            )?.map((e) => BuBytes.from(e)).toList();
        final tRaw = values.elementAtOrNull(3);
        final nRaw = values.elementAtOrNull(4);
        final threshold = tRaw is int ? tRaw : null;
        final n = nRaw is int ? nRaw : null;
        final curve = _DklsKeyRecords.curveFromId(
          curveId,
          'Dkls23AggregatePublicKey',
        );
        if (curve == Dkls23Curve.secp256k1) {
          return Dkls23Secp256k1PublicKey._(
            Secp256k1PublicKey.fromBytes(pk),
            members?.map((e) => Secp256k1PublicKey.fromBytes(e)).toList(),
            threshold: threshold,
            n: n,
          );
        }
        return Dkls23Secp256r1PublicKey._(
          Secp256r1PublicKey.fromBytes(pk),
          members?.map((e) => Secp256r1PublicKey.fromBytes(e)).toList(),
          threshold: threshold,
          n: n,
        );
      },
      unbuild:
          (value) => [
            value.curve.id,
            value.aggKey.toBytes(),
            value.members?.map((e) => e.toBytes()).toList(),
            value.threshold,
            value.n,
          ],
    );