encodeBls12381PrivateKeyPkcs8 static method

SecretBytes encodeBls12381PrivateKeyPkcs8(
  1. List<int> privateKey
)

OPTIONAL, NON-STANDARD: wraps a raw BLS12-381 private key scalar in a PKCS8-shaped PrivateKeyInfo, reusing the real IC algorithm OID pair so it at least round-trips against decodeBls12381PrivateKeyPkcs8 and carries a meaningful algorithm identifier. No implementation of ours or anyone else's (including DFINITY) produces or expects this for private keys — use encodeBls12381PrivateKeyRaw unless you specifically need an ASN.1 container for internal storage/interop.

Implementation

static SecretBytes encodeBls12381PrivateKeyPkcs8(List<int> privateKey) {
  if (privateKey.length != 32) {
    throw CoreErrors.cryptoFailed(
      "encodeBls12381PrivateKeyPkcs8",
      reason: 'BLS12-381 private key must be 32 bytes',
    );
  }
  final algId = DerUtils.derSequence([
    ...DerUtils.derOid(Oids.icBls12381),
    ...DerUtils.derOid(Oids.icBls12381G2),
  ]);
  return SecretBytes.take(
    DerUtils.derSequence([
      ...DerUtils.derSmallInt(0),
      ...algId,
      ...DerUtils.derOctetString(privateKey),
    ]),
  );
}