omemo_dart/test/x3dh_test.dart

45 lines
1.1 KiB
Dart
Raw Normal View History

2022-08-01 20:08:38 +00:00
import 'package:cryptography/cryptography.dart';
import 'package:omemo_dart/omemo_dart.dart';
2022-08-02 13:10:31 +00:00
import 'package:test/test.dart';
2022-08-01 20:08:38 +00:00
2022-06-30 12:00:18 +00:00
void main() {
2022-08-02 13:10:31 +00:00
test('X3DH', () async {
// Generate keys
final ikAlice = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
final ikBob = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
final spkBob = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);
final opkBob = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);
final bundleBob = OmemoBundle(
'1',
await spkBob.pk.asBase64(),
'3',
2022-08-02 13:10:31 +00:00
// TODO(PapaTutuWawa): Do
'n/a',
await ikBob.pk.asBase64(),
{
'2': await opkBob.pk.asBase64(),
},
);
2022-08-01 20:08:38 +00:00
// Alice does X3DH
final resultAlice = await x3dhFromBundle(bundleBob, ikAlice);
2022-08-01 20:08:38 +00:00
// Alice sends the inital message to Bob
// ...
2022-08-01 20:08:38 +00:00
// Bob does X3DH
final skBob = await x3dhFromInitialMessage(
X3DHMessage(
ikAlice.pk,
resultAlice.ek.pk,
'2',
),
2022-08-01 20:08:38 +00:00
spkBob,
opkBob,
2022-08-01 20:08:38 +00:00
ikBob,
);
expect(resultAlice.sk, skBob);
2022-06-30 12:00:18 +00:00
});
}