@k9o/react-native-matrix-crypto 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/RNMatrixCryptoModule.kt +20 -0
- package/android/build.gradle +62 -0
- package/android/proguard-rules.pro +16 -0
- package/ios/RNMatrixCryptoModule.swift +20 -0
- package/lib/CryptoAPI.d.ts +83 -0
- package/lib/CryptoAPI.js +220 -0
- package/lib/NativeMatrixCrypto.d.ts +87 -0
- package/lib/NativeMatrixCrypto.js +38 -0
- package/lib/index.d.ts +116 -0
- package/lib/index.js +267 -0
- package/package.json +74 -0
- package/react-native-matrix-crypto.podspec +25 -0
- package/src/CryptoAPI.ts +256 -0
- package/src/NativeMatrixCrypto.ts +157 -0
- package/src/index.ts +369 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.matrix.crypto
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* React Native package for Matrix crypto (Android)
|
|
10
|
+
* This is the entry point for the React Native module on Android
|
|
11
|
+
*/
|
|
12
|
+
class RNMatrixCryptoPackage : ReactPackage {
|
|
13
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
14
|
+
return listOf(RNMatrixCrypto(reactContext))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
18
|
+
return emptyList()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.safeExtGet = {prop, fallback ->
|
|
3
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
4
|
+
}
|
|
5
|
+
repositories {
|
|
6
|
+
google()
|
|
7
|
+
mavenCentral()
|
|
8
|
+
}
|
|
9
|
+
dependencies {
|
|
10
|
+
classpath("com.android.tools.build:gradle:${safeExtGet("androidBuildToolsVersion", "7.3.1")}")
|
|
11
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet("kotlinVersion", "1.9.20")}")
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
apply plugin: 'com.android.library'
|
|
16
|
+
apply plugin: 'kotlin-android'
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
compileSdk safeExtGet("compileSdkVersion", 34)
|
|
20
|
+
|
|
21
|
+
defaultConfig {
|
|
22
|
+
minSdk safeExtGet("minSdkVersion", 21)
|
|
23
|
+
targetSdk safeExtGet("targetSdkVersion", 34)
|
|
24
|
+
versionCode 1
|
|
25
|
+
versionName "0.1.0"
|
|
26
|
+
|
|
27
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
compileOptions {
|
|
38
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
39
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
kotlinOptions {
|
|
43
|
+
jvmTarget = '11'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
namespace 'com.matrix.crypto'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
repositories {
|
|
50
|
+
mavenCentral()
|
|
51
|
+
google()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
dependencies {
|
|
55
|
+
implementation "com.facebook.react:react-native:${safeExtGet("reactNativeVersion", "0.73.0")}"
|
|
56
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:${safeExtGet("kotlinVersion", "1.9.20")}"
|
|
57
|
+
implementation 'androidx.core:core:1.12.0'
|
|
58
|
+
|
|
59
|
+
testImplementation 'junit:junit:4.13.2'
|
|
60
|
+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
|
61
|
+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
|
62
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Matrix Crypto Bridge
|
|
2
|
+
-keep class com.matrix.crypto.** { *; }
|
|
3
|
+
-keepclassmembers class com.matrix.crypto.** { *; }
|
|
4
|
+
|
|
5
|
+
# React Native
|
|
6
|
+
-keep class com.facebook.react.** { *; }
|
|
7
|
+
-keepclassmembers class com.facebook.react.** { *; }
|
|
8
|
+
|
|
9
|
+
# Kotlin
|
|
10
|
+
-keep class kotlin.** { *; }
|
|
11
|
+
-keepclassmembers class kotlin.** { *; }
|
|
12
|
+
|
|
13
|
+
# Native methods
|
|
14
|
+
-keepclasseswithmembernames class * {
|
|
15
|
+
native <methods>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* React Native module for Matrix crypto (iOS)
|
|
6
|
+
* This is the entry point for the React Native module on iOS
|
|
7
|
+
*/
|
|
8
|
+
@objc(RNMatrixCryptoModule)
|
|
9
|
+
class RNMatrixCryptoModule: NSObject {
|
|
10
|
+
|
|
11
|
+
@objc
|
|
12
|
+
static func moduleName() -> String! {
|
|
13
|
+
return "RNMatrixCrypto"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@objc
|
|
17
|
+
static func requiresMainQueueSetup() -> Bool {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DeviceInfo, EmojiSASPair, VerificationState, RoomEncryptionState } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* High-level API for Matrix crypto operations
|
|
4
|
+
* Provides a clean, easy-to-use interface for encryption, device verification, and key management
|
|
5
|
+
*/
|
|
6
|
+
export declare class CryptoAPI {
|
|
7
|
+
private initialized;
|
|
8
|
+
private userId;
|
|
9
|
+
private deviceId;
|
|
10
|
+
/**
|
|
11
|
+
* Initialize the crypto API
|
|
12
|
+
*/
|
|
13
|
+
initialize(userId: string, deviceId: string, pickleKey: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Check if crypto is initialized
|
|
16
|
+
*/
|
|
17
|
+
isInitialized(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Get device information
|
|
20
|
+
*/
|
|
21
|
+
getDeviceInfo(): Promise<{
|
|
22
|
+
fingerprint: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
deviceId: string;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Get all devices for a user
|
|
28
|
+
*/
|
|
29
|
+
getUserDevices(userId: string): Promise<DeviceInfo[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Add a device to the device store
|
|
32
|
+
*/
|
|
33
|
+
addDevice(device: DeviceInfo): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Start device verification with another device
|
|
36
|
+
*/
|
|
37
|
+
startVerification(otherUserId: string, otherDeviceId: string): Promise<VerificationState>;
|
|
38
|
+
/**
|
|
39
|
+
* Get SAS emoji pairs for verification
|
|
40
|
+
*/
|
|
41
|
+
getSASEmojis(verificationId: string): Promise<EmojiSASPair[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Confirm SAS verification
|
|
44
|
+
*/
|
|
45
|
+
confirmSAS(verificationId: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Complete device verification
|
|
48
|
+
*/
|
|
49
|
+
completeVerification(verificationId: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Cancel device verification
|
|
52
|
+
*/
|
|
53
|
+
cancelVerification(verificationId: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Get the current state of a verification
|
|
56
|
+
*/
|
|
57
|
+
getVerificationState(verificationId: string): Promise<VerificationState>;
|
|
58
|
+
/**
|
|
59
|
+
* Enable encryption for a room
|
|
60
|
+
*/
|
|
61
|
+
enableRoomEncryption(roomId: string, algorithm?: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Get encryption state for a room
|
|
64
|
+
*/
|
|
65
|
+
getRoomEncryptionState(roomId: string): Promise<RoomEncryptionState>;
|
|
66
|
+
/**
|
|
67
|
+
* Encrypt an event
|
|
68
|
+
*/
|
|
69
|
+
encryptEvent(roomId: string, eventType: string, content: string): Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Decrypt an event
|
|
72
|
+
*/
|
|
73
|
+
decryptEvent(roomId: string, encryptedContent: string): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Cleanup and destroy the crypto instance
|
|
76
|
+
*/
|
|
77
|
+
destroy(): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Helper method to ensure crypto is initialized
|
|
80
|
+
*/
|
|
81
|
+
private assertInitialized;
|
|
82
|
+
}
|
|
83
|
+
export default CryptoAPI;
|
package/lib/CryptoAPI.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CryptoAPI = void 0;
|
|
4
|
+
const NativeMatrixCrypto_1 = require("./NativeMatrixCrypto");
|
|
5
|
+
/**
|
|
6
|
+
* High-level API for Matrix crypto operations
|
|
7
|
+
* Provides a clean, easy-to-use interface for encryption, device verification, and key management
|
|
8
|
+
*/
|
|
9
|
+
class CryptoAPI {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.initialized = false;
|
|
12
|
+
this.userId = '';
|
|
13
|
+
this.deviceId = '';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the crypto API
|
|
17
|
+
*/
|
|
18
|
+
async initialize(userId, deviceId, pickleKey) {
|
|
19
|
+
try {
|
|
20
|
+
await NativeMatrixCrypto_1.NativeMatrixCrypto.initialize(userId, deviceId, pickleKey);
|
|
21
|
+
this.initialized = true;
|
|
22
|
+
this.userId = userId;
|
|
23
|
+
this.deviceId = deviceId;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new Error(`Failed to initialize crypto: ${error}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if crypto is initialized
|
|
31
|
+
*/
|
|
32
|
+
isInitialized() {
|
|
33
|
+
return this.initialized;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get device information
|
|
37
|
+
*/
|
|
38
|
+
async getDeviceInfo() {
|
|
39
|
+
this.assertInitialized();
|
|
40
|
+
try {
|
|
41
|
+
const [fingerprint, userId, deviceId] = await Promise.all([
|
|
42
|
+
NativeMatrixCrypto_1.NativeMatrixCrypto.getDeviceFingerprint(),
|
|
43
|
+
NativeMatrixCrypto_1.NativeMatrixCrypto.getUserId(),
|
|
44
|
+
NativeMatrixCrypto_1.NativeMatrixCrypto.getDeviceId(),
|
|
45
|
+
]);
|
|
46
|
+
return { fingerprint, userId, deviceId };
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new Error(`Failed to get device info: ${error}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get all devices for a user
|
|
54
|
+
*/
|
|
55
|
+
async getUserDevices(userId) {
|
|
56
|
+
this.assertInitialized();
|
|
57
|
+
try {
|
|
58
|
+
return await NativeMatrixCrypto_1.NativeMatrixCrypto.getUserDevices(userId);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error(`Failed to get user devices: ${error}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Add a device to the device store
|
|
66
|
+
*/
|
|
67
|
+
async addDevice(device) {
|
|
68
|
+
this.assertInitialized();
|
|
69
|
+
try {
|
|
70
|
+
await NativeMatrixCrypto_1.NativeMatrixCrypto.addDevice(device);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new Error(`Failed to add device: ${error}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Start device verification with another device
|
|
78
|
+
*/
|
|
79
|
+
async startVerification(otherUserId, otherDeviceId) {
|
|
80
|
+
this.assertInitialized();
|
|
81
|
+
try {
|
|
82
|
+
const result = await NativeMatrixCrypto_1.NativeMatrixCrypto.startVerification(otherUserId, otherDeviceId);
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new Error(`Failed to start verification: ${error}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get SAS emoji pairs for verification
|
|
91
|
+
*/
|
|
92
|
+
async getSASEmojis(verificationId) {
|
|
93
|
+
this.assertInitialized();
|
|
94
|
+
try {
|
|
95
|
+
return await NativeMatrixCrypto_1.NativeMatrixCrypto.getSASEmojis(verificationId);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw new Error(`Failed to get SAS emojis: ${error}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Confirm SAS verification
|
|
103
|
+
*/
|
|
104
|
+
async confirmSAS(verificationId) {
|
|
105
|
+
this.assertInitialized();
|
|
106
|
+
try {
|
|
107
|
+
await NativeMatrixCrypto_1.NativeMatrixCrypto.confirmSAS(verificationId);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw new Error(`Failed to confirm SAS: ${error}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Complete device verification
|
|
115
|
+
*/
|
|
116
|
+
async completeVerification(verificationId) {
|
|
117
|
+
this.assertInitialized();
|
|
118
|
+
try {
|
|
119
|
+
await NativeMatrixCrypto_1.NativeMatrixCrypto.completeVerification(verificationId);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
throw new Error(`Failed to complete verification: ${error}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Cancel device verification
|
|
127
|
+
*/
|
|
128
|
+
async cancelVerification(verificationId) {
|
|
129
|
+
this.assertInitialized();
|
|
130
|
+
try {
|
|
131
|
+
await NativeMatrixCrypto_1.NativeMatrixCrypto.cancelVerification(verificationId);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
throw new Error(`Failed to cancel verification: ${error}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get the current state of a verification
|
|
139
|
+
*/
|
|
140
|
+
async getVerificationState(verificationId) {
|
|
141
|
+
this.assertInitialized();
|
|
142
|
+
try {
|
|
143
|
+
const result = await NativeMatrixCrypto_1.NativeMatrixCrypto.getVerificationState(verificationId);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw new Error(`Failed to get verification state: ${error}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Enable encryption for a room
|
|
152
|
+
*/
|
|
153
|
+
async enableRoomEncryption(roomId, algorithm = 'm.megolm.v1.aes-sha2') {
|
|
154
|
+
this.assertInitialized();
|
|
155
|
+
try {
|
|
156
|
+
await NativeMatrixCrypto_1.NativeMatrixCrypto.enableRoomEncryption(roomId, algorithm);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw new Error(`Failed to enable room encryption: ${error}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get encryption state for a room
|
|
164
|
+
*/
|
|
165
|
+
async getRoomEncryptionState(roomId) {
|
|
166
|
+
this.assertInitialized();
|
|
167
|
+
try {
|
|
168
|
+
return await NativeMatrixCrypto_1.NativeMatrixCrypto.getRoomEncryptionState(roomId);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
throw new Error(`Failed to get room encryption state: ${error}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Encrypt an event
|
|
176
|
+
*/
|
|
177
|
+
async encryptEvent(roomId, eventType, content) {
|
|
178
|
+
this.assertInitialized();
|
|
179
|
+
try {
|
|
180
|
+
return await NativeMatrixCrypto_1.NativeMatrixCrypto.encryptEvent(roomId, eventType, content);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw new Error(`Failed to encrypt event: ${error}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Decrypt an event
|
|
188
|
+
*/
|
|
189
|
+
async decryptEvent(roomId, encryptedContent) {
|
|
190
|
+
this.assertInitialized();
|
|
191
|
+
try {
|
|
192
|
+
return await NativeMatrixCrypto_1.NativeMatrixCrypto.decryptEvent(roomId, encryptedContent);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
throw new Error(`Failed to decrypt event: ${error}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Cleanup and destroy the crypto instance
|
|
200
|
+
*/
|
|
201
|
+
async destroy() {
|
|
202
|
+
try {
|
|
203
|
+
await NativeMatrixCrypto_1.NativeMatrixCrypto.destroy();
|
|
204
|
+
this.initialized = false;
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
throw new Error(`Failed to destroy crypto: ${error}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Helper method to ensure crypto is initialized
|
|
212
|
+
*/
|
|
213
|
+
assertInitialized() {
|
|
214
|
+
if (!this.initialized) {
|
|
215
|
+
throw new Error('Crypto not initialized. Call initialize() first.');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.CryptoAPI = CryptoAPI;
|
|
220
|
+
exports.default = CryptoAPI;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native module interface for Matrix crypto
|
|
3
|
+
* This is the low-level binding to the native iOS/Android modules
|
|
4
|
+
*/
|
|
5
|
+
export interface NativeMatrixCryptoInterface {
|
|
6
|
+
initialize(userId: string, deviceId: string, pickleKey: string): Promise<{
|
|
7
|
+
success: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
getDeviceFingerprint(): Promise<string>;
|
|
10
|
+
getUserId(): Promise<string>;
|
|
11
|
+
getDeviceId(): Promise<string>;
|
|
12
|
+
getUserDevices(userId: string): Promise<Array<{
|
|
13
|
+
deviceId: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
displayName?: string;
|
|
16
|
+
fingerprint: string;
|
|
17
|
+
isVerified: boolean;
|
|
18
|
+
isBlocked: boolean;
|
|
19
|
+
algorithm: string;
|
|
20
|
+
}>>;
|
|
21
|
+
addDevice(device: {
|
|
22
|
+
deviceId: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
displayName?: string;
|
|
25
|
+
fingerprint: string;
|
|
26
|
+
isVerified: boolean;
|
|
27
|
+
isBlocked: boolean;
|
|
28
|
+
algorithm: string;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
success: boolean;
|
|
31
|
+
}>;
|
|
32
|
+
startVerification(otherUserId: string, otherDeviceId: string): Promise<{
|
|
33
|
+
verificationId: string;
|
|
34
|
+
state: string;
|
|
35
|
+
otherUserId: string;
|
|
36
|
+
otherDeviceId: string;
|
|
37
|
+
emojis: Array<{
|
|
38
|
+
emoji: string;
|
|
39
|
+
name: string;
|
|
40
|
+
}>;
|
|
41
|
+
decimals: number[];
|
|
42
|
+
}>;
|
|
43
|
+
getSASEmojis(verificationId: string): Promise<Array<{
|
|
44
|
+
emoji: string;
|
|
45
|
+
name: string;
|
|
46
|
+
}>>;
|
|
47
|
+
confirmSAS(verificationId: string): Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
completeVerification(verificationId: string): Promise<{
|
|
51
|
+
success: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
cancelVerification(verificationId: string): Promise<{
|
|
54
|
+
success: boolean;
|
|
55
|
+
}>;
|
|
56
|
+
getVerificationState(verificationId: string): Promise<{
|
|
57
|
+
verificationId: string;
|
|
58
|
+
state: string;
|
|
59
|
+
otherUserId: string;
|
|
60
|
+
otherDeviceId: string;
|
|
61
|
+
emojis: Array<{
|
|
62
|
+
emoji: string;
|
|
63
|
+
name: string;
|
|
64
|
+
}>;
|
|
65
|
+
decimals: number[];
|
|
66
|
+
}>;
|
|
67
|
+
enableRoomEncryption(roomId: string, algorithm: string): Promise<{
|
|
68
|
+
success: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
getRoomEncryptionState(roomId: string): Promise<{
|
|
71
|
+
roomId: string;
|
|
72
|
+
isEncrypted: boolean;
|
|
73
|
+
algorithm?: string;
|
|
74
|
+
trustedDevices: string[];
|
|
75
|
+
untrustedDevices: string[];
|
|
76
|
+
}>;
|
|
77
|
+
encryptEvent(roomId: string, eventType: string, content: string): Promise<string>;
|
|
78
|
+
decryptEvent(roomId: string, encryptedContent: string): Promise<string>;
|
|
79
|
+
destroy(): Promise<{
|
|
80
|
+
success: boolean;
|
|
81
|
+
}>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Native module proxy that delegates to the platform-specific implementation
|
|
85
|
+
*/
|
|
86
|
+
export declare const NativeMatrixCrypto: NativeMatrixCryptoInterface;
|
|
87
|
+
export default NativeMatrixCrypto;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeMatrixCrypto = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
const LINKING_ERROR = `The package 'react-native-matrix-crypto' doesn't seem to be linked. Make sure: \n\n` +
|
|
6
|
+
react_native_1.Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
7
|
+
'- You rebuilt the app after installing the package\n' +
|
|
8
|
+
'- You are not using Expo Go\n';
|
|
9
|
+
const NativeMatrixCryptoModule = react_native_1.NativeModules.RNMatrixCrypto
|
|
10
|
+
? react_native_1.NativeModules.RNMatrixCrypto
|
|
11
|
+
: new Proxy({}, {
|
|
12
|
+
get() {
|
|
13
|
+
throw new Error(LINKING_ERROR);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Native module proxy that delegates to the platform-specific implementation
|
|
18
|
+
*/
|
|
19
|
+
exports.NativeMatrixCrypto = {
|
|
20
|
+
initialize: (userId, deviceId, pickleKey) => NativeMatrixCryptoModule.initialize(userId, deviceId, pickleKey),
|
|
21
|
+
getDeviceFingerprint: () => NativeMatrixCryptoModule.getDeviceFingerprint(),
|
|
22
|
+
getUserId: () => NativeMatrixCryptoModule.getUserId(),
|
|
23
|
+
getDeviceId: () => NativeMatrixCryptoModule.getDeviceId(),
|
|
24
|
+
getUserDevices: (userId) => NativeMatrixCryptoModule.getUserDevices(userId),
|
|
25
|
+
addDevice: (device) => NativeMatrixCryptoModule.addDevice(device),
|
|
26
|
+
startVerification: (otherUserId, otherDeviceId) => NativeMatrixCryptoModule.startVerification(otherUserId, otherDeviceId),
|
|
27
|
+
getSASEmojis: (verificationId) => NativeMatrixCryptoModule.getSASEmojis(verificationId),
|
|
28
|
+
confirmSAS: (verificationId) => NativeMatrixCryptoModule.confirmSAS(verificationId),
|
|
29
|
+
completeVerification: (verificationId) => NativeMatrixCryptoModule.completeVerification(verificationId),
|
|
30
|
+
cancelVerification: (verificationId) => NativeMatrixCryptoModule.cancelVerification(verificationId),
|
|
31
|
+
getVerificationState: (verificationId) => NativeMatrixCryptoModule.getVerificationState(verificationId),
|
|
32
|
+
enableRoomEncryption: (roomId, algorithm) => NativeMatrixCryptoModule.enableRoomEncryption(roomId, algorithm),
|
|
33
|
+
getRoomEncryptionState: (roomId) => NativeMatrixCryptoModule.getRoomEncryptionState(roomId),
|
|
34
|
+
encryptEvent: (roomId, eventType, content) => NativeMatrixCryptoModule.encryptEvent(roomId, eventType, content),
|
|
35
|
+
decryptEvent: (roomId, encryptedContent) => NativeMatrixCryptoModule.decryptEvent(roomId, encryptedContent),
|
|
36
|
+
destroy: () => NativeMatrixCryptoModule.destroy(),
|
|
37
|
+
};
|
|
38
|
+
exports.default = exports.NativeMatrixCrypto;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export interface DeviceInfo {
|
|
2
|
+
deviceId: string;
|
|
3
|
+
userId: string;
|
|
4
|
+
displayName?: string;
|
|
5
|
+
fingerprint: string;
|
|
6
|
+
isVerified: boolean;
|
|
7
|
+
isBlocked: boolean;
|
|
8
|
+
algorithm: string;
|
|
9
|
+
}
|
|
10
|
+
export interface EmojiSASPair {
|
|
11
|
+
emoji: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
export interface VerificationState {
|
|
15
|
+
verificationId: string;
|
|
16
|
+
state: 'pending' | 'sas_ready' | 'confirmed' | 'completed' | 'cancelled';
|
|
17
|
+
otherUserId: string;
|
|
18
|
+
otherDeviceId: string;
|
|
19
|
+
emojis: EmojiSASPair[];
|
|
20
|
+
decimals: number[];
|
|
21
|
+
}
|
|
22
|
+
export interface RoomEncryptionState {
|
|
23
|
+
roomId: string;
|
|
24
|
+
isEncrypted: boolean;
|
|
25
|
+
algorithm?: string;
|
|
26
|
+
trustedDevices: string[];
|
|
27
|
+
untrustedDevices: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface EncryptionAlgorithm {
|
|
30
|
+
algorithm: string;
|
|
31
|
+
rotationPeriodMs: number;
|
|
32
|
+
rotationPeriodMsgs: number;
|
|
33
|
+
}
|
|
34
|
+
export interface UserDevices {
|
|
35
|
+
userId: string;
|
|
36
|
+
devices: DeviceInfo[];
|
|
37
|
+
}
|
|
38
|
+
export declare class MatrixCrypto {
|
|
39
|
+
private static instance;
|
|
40
|
+
private handle;
|
|
41
|
+
private constructor();
|
|
42
|
+
/**
|
|
43
|
+
* Get or create singleton instance
|
|
44
|
+
*/
|
|
45
|
+
static getInstance(): MatrixCrypto;
|
|
46
|
+
/**
|
|
47
|
+
* Initialize the crypto machine
|
|
48
|
+
*/
|
|
49
|
+
initialize(userId: string, deviceId: string, pickleKey: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Get the device fingerprint
|
|
52
|
+
*/
|
|
53
|
+
getDeviceFingerprint(): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Get the user ID
|
|
56
|
+
*/
|
|
57
|
+
getUserId(): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Get the device ID
|
|
60
|
+
*/
|
|
61
|
+
getDeviceId(): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Get devices for a user
|
|
64
|
+
*/
|
|
65
|
+
getUserDevices(userId: string): Promise<DeviceInfo[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Add a device
|
|
68
|
+
*/
|
|
69
|
+
addDevice(device: DeviceInfo): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Start device verification
|
|
72
|
+
*/
|
|
73
|
+
startVerification(otherUserId: string, otherDeviceId: string): Promise<VerificationState>;
|
|
74
|
+
/**
|
|
75
|
+
* Get SAS emojis
|
|
76
|
+
*/
|
|
77
|
+
getSASEmojis(verificationId: string): Promise<EmojiSASPair[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Confirm SAS
|
|
80
|
+
*/
|
|
81
|
+
confirmSAS(verificationId: string): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Complete verification
|
|
84
|
+
*/
|
|
85
|
+
completeVerification(verificationId: string): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Cancel verification
|
|
88
|
+
*/
|
|
89
|
+
cancelVerification(verificationId: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Get verification state
|
|
92
|
+
*/
|
|
93
|
+
getVerificationState(verificationId: string): Promise<VerificationState>;
|
|
94
|
+
/**
|
|
95
|
+
* Enable room encryption
|
|
96
|
+
*/
|
|
97
|
+
enableRoomEncryption(roomId: string, algorithm: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Get room encryption state
|
|
100
|
+
*/
|
|
101
|
+
getRoomEncryptionState(roomId: string): Promise<RoomEncryptionState>;
|
|
102
|
+
/**
|
|
103
|
+
* Encrypt event
|
|
104
|
+
*/
|
|
105
|
+
encryptEvent(roomId: string, eventType: string, content: string): Promise<string>;
|
|
106
|
+
/**
|
|
107
|
+
* Decrypt event
|
|
108
|
+
*/
|
|
109
|
+
decryptEvent(roomId: string, encryptedContent: string): Promise<string>;
|
|
110
|
+
/**
|
|
111
|
+
* Cleanup
|
|
112
|
+
*/
|
|
113
|
+
destroy(): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
declare const _default: MatrixCrypto;
|
|
116
|
+
export default _default;
|