createForTesting static method

  1. @visibleForTesting
Future<NoiseXXPattern> createForTesting(
  1. bool isInitiator,
  2. SimpleKeyPair staticKeys,
  3. SimpleKeyPair ephemeralKeys
)

Implementation

@visibleForTesting
static Future<NoiseXXPattern> createForTesting(
  bool isInitiator,
  SimpleKeyPair staticKeys,
  SimpleKeyPair ephemeralKeys,
) async {
  final protocolName = utf8.encode(PROTOCOL_NAME);
  _validateProtocolName(protocolName);

  Uint8List initialH;
  if (protocolName.length <= 32) {
    initialH = Uint8List(32);
    initialH.setAll(0, protocolName);
  } else {
    final hash = await Sha256().hash(protocolName);
    initialH = Uint8List.fromList(hash.bytes);
  }
  final ck = Uint8List.fromList(initialH);
  final hAfterPrologue = await Sha256().hash(initialH);

  final state = HandshakeState(
    chainKey: ck,
    handshakeHash: Uint8List.fromList(hAfterPrologue.bytes),
    state: XXHandshakeState.initial,
  );

  return NoiseXXPattern._(isInitiator, staticKeys, ephemeralKeys, state);
}