Skip to content
Snippets Groups Projects
Commit 435852dc authored by Matt Burton's avatar Matt Burton
Browse files

Fix the typings then struggle with mjs/cjs/whatamievendoingjs

parent 8d532ad1
No related branches found
No related tags found
No related merge requests found
......@@ -8,11 +8,11 @@
"elixxir",
"cmix"
],
"module": "dist/xxdk.mjs",
"type": "module",
"typings": "dist/xxdk.d.ts",
"prepare": "yarn build",
"main": "./dist/xxdk.js",
"main": "dist/xxdk.js",
"module": "dist/xxdk.esm.js",
"homepage": "https://xx.network/developers-mixnet/",
"license": "BSD-2-Clause",
"author": "Elixxir Team",
......
......@@ -15,11 +15,6 @@ export default [
bundle({
plugins: [wasm(), esbuild()],
output: [
{
file: `${name}.js`,
format: 'cjs',
sourcemap: true,
},
{
file: `${name}.mjs`,
format: 'es',
......
import type { XXDKUtils } from './types';
import type { XXDKUtils } from './types/index';
declare global {
interface Window extends XXDKUtils {}
interface Window extends XXDKUtils {
onWasmInitialized: () => void;
}
}
import './wasm_exec';
// @ts-ignore
import makeWasm from './xxdk.wasm';
import makeWasm from './wasm-assets/xxdk.wasm';
export const loadUtils = () => new Promise<XXDKUtils>(async (res) => {
const go = new (window as any).Go();
go.argv = [
'--logLevel=1',
'--fileLogLevel=1',
// '--workerScriptURL=integrations/assets/logFileWorker.js',
]
const isReady = new Promise<void>((resolve) => {
window.onWasmInitialized = resolve;
});
const result = await makeWasm(go.importObject);
go.run(result.instance);
await isReady;
const {
Base64ToUint8Array,
Crash,
ConstructIdentity,
DecodePrivateURL,
DecodePublicURL,
......@@ -24,7 +37,6 @@ export const loadUtils = () => new Promise<XXDKUtils>(async (res) => {
GetChannelInfo,
GetChannelJSON,
GetClientVersion,
getCrashedLogFile,
GetDefaultCMixParams,
GetLogger,
GetOrInitPassword,
......@@ -36,21 +48,22 @@ export const loadUtils = () => new Promise<XXDKUtils>(async (res) => {
IsNicknameValid,
LoadChannelsManagerWithIndexedDb,
LoadCmix,
LogLevel,
NewChannelsDatabaseCipher,
LoadNotifications,
LoadNotificationsDummy,
LoadSynchronizedCmix,
NewChannelsManagerWithIndexedDb,
NewCmix,
NewDMClientWithIndexedDb,
NewDMsDatabaseCipher,
NewDatabaseCipher,
NewDummyTrafficManager,
NewSynchronizedCmix,
Purge,
ValidForever,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} = (window) || {};
} = window;
res({
return {
Base64ToUint8Array,
Crash,
ConstructIdentity,
DecodePrivateURL,
DecodePublicURL,
......@@ -58,7 +71,6 @@ export const loadUtils = () => new Promise<XXDKUtils>(async (res) => {
GetChannelInfo,
GetChannelJSON,
GetClientVersion,
getCrashedLogFile,
GetDefaultCMixParams,
GetLogger,
GetOrInitPassword,
......@@ -70,16 +82,17 @@ export const loadUtils = () => new Promise<XXDKUtils>(async (res) => {
IsNicknameValid,
LoadChannelsManagerWithIndexedDb,
LoadCmix,
LogLevel,
NewChannelsDatabaseCipher,
LoadNotifications,
LoadNotificationsDummy,
LoadSynchronizedCmix,
NewChannelsManagerWithIndexedDb,
NewCmix,
NewDMClientWithIndexedDb,
NewDMsDatabaseCipher,
NewDatabaseCipher,
NewDummyTrafficManager,
NewSynchronizedCmix,
Purge,
ValidForever,
})
})
ValidForever
};
export * from './types';
\ No newline at end of file
});
\ No newline at end of file
export enum LogLevel {
TRACE = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4,
CRITICAL = 5,
FATAL = 6
}
export enum PrivacyLevel {
Public = 0,
Private = 1,
Secret = 2
}
export type Cipher = {
GetID: () => number;
Decrypt: (plaintext: Uint8Array) => Uint8Array;
}
export type ChannelManager = {
GetID: () => number;
AreDMsEnabled: (channelId: Uint8Array) => boolean;
DisableDirectMessages: (channelId: Uint8Array) => void;
EnableDirectMessages: (channelId: Uint8Array) => void;
JoinChannel: (channelId: string) => Promise<Uint8Array>;
LeaveChannel: (channelId: Uint8Array) => Promise<void>;
GetMutedUsers: (channelId: Uint8Array) => Uint8Array;
Muted: (channelId: Uint8Array) => boolean;
MuteUser: (
channelId: Uint8Array,
publicKey: Uint8Array,
mute: boolean,
messageValidityTimeoutMilliseconds: number,
cmixParams?: Uint8Array
) => Promise<void>;
SendMessage: (
channelId: Uint8Array,
message: string,
messageValidityTimeoutMilliseconds: number,
cmixParams: Uint8Array
) => Promise<Uint8Array>;
PinMessage: (
channelId: Uint8Array,
messageId: Uint8Array,
unpin: boolean,
pinDurationInMilliseconds: number,
cmixParams: Uint8Array,
) => Promise<Uint8Array>;
DeleteMessage: (
channelId: Uint8Array,
messageId: Uint8Array,
cmixParams: Uint8Array
) => Promise<void>;
SendReaction: (
channelId: Uint8Array,
reaction: string,
messageToReactTo: Uint8Array,
messageValidityTimeoutMilliseconds: number,
cmixParams: Uint8Array
) => Promise<Uint8Array>;
SendReply: (
channelId: Uint8Array,
message: string,
messageToReactTo: Uint8Array,
messageValidityTimeoutMilliseconds: number,
cmixParams: Uint8Array
) => Promise<Uint8Array>;
IsChannelAdmin: (channelId: Uint8Array) => boolean;
GenerateChannel: (channelname: string, description: string, privacyLevel: PrivacyLevel) => Promise<string>;
GetStorageTag: () => string | undefined;
SetNickname: (newNickname: string, channel: Uint8Array) => void;
GetNickname: (channelId: Uint8Array) => string;
GetIdentity: () => Uint8Array;
GetShareURL: (cmixId: number, host: string, maxUses: number, channelId: Uint8Array) => Uint8Array;
JoinChannelFromURL: (url: string, password: string) => Uint8Array;
ExportPrivateIdentity: (password: string) => Uint8Array;
ExportChannelAdminKey: (channelId: Uint8Array, encryptionPassword: string) => Uint8Array;
ImportChannelAdminKey: (channelId: Uint8Array, encryptionPassword: string, privateKey: Uint8Array) => void;
}
type HealthCallback = { Callback: (healthy: boolean) => void }
export type CMix = {
AddHealthCallback: (callback: HealthCallback) => number;
GetID: () => number;
IsReady: (threshold: number) => Uint8Array;
ReadyToSend: () => boolean;
StartNetworkFollower: (timeoutMilliseconds: number) => void;
StopNetworkFollower: () => void;
WaitForNetwork: (timeoutMilliseconds: number) => Promise<void>;
}
export type DMClient = {
SendText: (pubkey: Uint8Array, dmToken: number, message: string, leaseTimeMs: number, cmixParams: Uint8Array) => Promise<void>;
SendReply: (pubkey: Uint8Array, dmToken: number, message: string, replyToId: Uint8Array, leaseTimeMs: number, cmixParams: Uint8Array) => Promise<void>;
SendReaction: (pubkey: Uint8Array, dmToken: number, message: string, reactToId: Uint8Array, cmixParams: Uint8Array) => Promise<void>;
GetIdentity: () => Uint8Array;
SetNickname: (nickname: string) => void;
GetNickname: () => string;
GetDatabaseName: () => string;
}
export type DummyTraffic = {
GetStatus: () => boolean;
Pause: () => void;
Start: () => void;
}
export type MessageReceivedCallback = (uuid: string, channelId: Uint8Array, update: boolean) => void;
export type MessageDeletedCallback = (uuid: Uint8Array) => void;
export type UserMutedCallback = (channelId: Uint8Array, pubkey: string, unmute: boolean) => void;
export type DMReceivedCallback = (uuid: string, pubkey: Uint8Array, update: boolean, updateConversation: boolean) => void;
export type XXDKUtils = {
logger?: Logger;
Crash: () => void;
GetLogger: () => Logger;
LogLevel: (level: LogLevel) => void;
getCrashedLogFile: () => Promise<string>;
NewCmix: (
ndf: string,
storageDir: string,
password: Uint8Array,
registrationCode: string
) => Promise<void>;
LoadCmix: (
storageDirectory: string,
password: Uint8Array,
cmixParams: Uint8Array
) => Promise<CMix>;
GetDefaultCMixParams: () => Uint8Array;GetChannelInfo: (prettyPrint: string) => Uint8Array;
Base64ToUint8Array: (base64: string) => Uint8Array;
GenerateChannelIdentity: (cmixId: number) => Uint8Array;
NewChannelsManagerWithIndexedDb: (
cmixId: number,
wasmJsPath: string,
privateIdentity: Uint8Array,
onMessage: MessageReceivedCallback,
onDelete: MessageDeletedCallback,
onMuted: UserMutedCallback,
channelDbCipher: number
) => Promise<ChannelManager>;
NewDMClientWithIndexedDb: (
cmixId: number,
wasmJsPath: string,
privateIdentity: Uint8Array,
messageCallback: DMReceivedCallback,
cipherId: number
) => Promise<DMClient>;
NewDMsDatabaseCipher: (cmixId: number, storagePassword: Uint8Array, payloadMaximumSize: number) => Cipher
LoadChannelsManagerWithIndexedDb: (
cmixId: number,
wasmJsPath: string,
storageTag: string,
onMessage: MessageReceivedCallback,
onDelete: MessageDeletedCallback,
onMuted: UserMutedCallback,
channelDbCipher: number
) => Promise<ChannelManager>;
GetPublicChannelIdentityFromPrivate: (privateKey: Uint8Array) => Uint8Array;
IsNicknameValid: (nickname: string) => null;
GetShareUrlType: (url: string) => PrivacyLevel;
GetVersion: () => string;
GetClientVersion: () => string;
GetOrInitPassword: (password: string) => Uint8Array;
ImportPrivateIdentity: (password: string, privateIdentity: Uint8Array) => Uint8Array;
ConstructIdentity: (publicKey: Uint8Array, codesetVersion: number) => Uint8Array;
DecodePrivateURL: (url: string, password: string) => string;
DecodePublicURL: (url: string) => string;
GetChannelJSON: (prettyPrint: string) => Uint8Array;
NewDummyTrafficManager: (
cmixId: number,
maximumOfMessagesPerCycle: number,
durationToWaitBetweenSendsMilliseconds: number,
upperBoundIntervalBetweenCyclesMilliseconds: number
) => DummyTraffic;
GetWasmSemanticVersion: () => Uint8Array;
NewChannelsDatabaseCipher: (cmixId: number, storagePassword: Uint8Array, payloadMaximumSize: number) => Cipher;
Purge: (storageDirectory: string, userPassword: string) => void;
ValidForever: () => number;
}
export type Logger = {
LogToFile: (level: number, maxLogFileSizeBytes: number) => void,
LogToFileWorker: (
level: number,
maxLogFileSizeBytes: number,
wasmJsPath: string,
workerName: string
) => Promise<void>,
StopLogging: () => void,
GetFile: () => Promise<string>,
Threshold: () => number,
MaxSize: () => number,
Size: () => Promise<number>,
Worker: () => Worker,
};
\ No newline at end of file
export enum PrivacyLevel {
Public = 0,
Private = 1,
Secret = 2
}
export type ChannelManager = {
GetID: () => number;
AreDMsEnabled: (channelId: Uint8Array) => boolean;
DisableDirectMessages: (channelId: Uint8Array) => void;
EnableDirectMessages: (channelId: Uint8Array) => void;
JoinChannel: (channelId: string) => Promise<Uint8Array>;
LeaveChannel: (channelId: Uint8Array) => Promise<void>;
GetMutedUsers: (channelId: Uint8Array) => Uint8Array;
Muted: (channelId: Uint8Array) => boolean;
MuteUser: (channelId: Uint8Array, publicKey: Uint8Array, mute: boolean, messageValidityTimeoutMilliseconds: number, cmixParams?: Uint8Array) => Promise<void>;
SendMessage: (channelId: Uint8Array, message: string, messageValidityTimeoutMilliseconds: number, cmixParams: Uint8Array) => Promise<Uint8Array>;
PinMessage: (channelId: Uint8Array, messageId: Uint8Array, unpin: boolean, pinDurationInMilliseconds: number, cmixParams: Uint8Array) => Promise<Uint8Array>;
DeleteMessage: (channelId: Uint8Array, messageId: Uint8Array, cmixParams: Uint8Array) => Promise<void>;
SendReaction: (channelId: Uint8Array, reaction: string, messageToReactTo: Uint8Array, messageValidityTimeoutMilliseconds: number, cmixParams: Uint8Array) => Promise<Uint8Array>;
SendReply: (channelId: Uint8Array, message: string, messageToReactTo: Uint8Array, messageValidityTimeoutMilliseconds: number, cmixParams: Uint8Array) => Promise<Uint8Array>;
IsChannelAdmin: (channelId: Uint8Array) => boolean;
GenerateChannel: (channelname: string, description: string, privacyLevel: PrivacyLevel) => Promise<string>;
GetStorageTag: () => string | undefined;
SetNickname: (newNickname: string, channel: Uint8Array) => void;
GetNickname: (channelId: Uint8Array) => string;
GetIdentity: () => Uint8Array;
GetShareURL: (cmixId: number, host: string, maxUses: number, channelId: Uint8Array) => Uint8Array;
JoinChannelFromURL: (url: string, password: string) => Uint8Array;
ExportPrivateIdentity: (password: string) => Uint8Array;
ExportChannelAdminKey: (channelId: Uint8Array, encryptionPassword: string) => Uint8Array;
ImportChannelAdminKey: (channelId: Uint8Array, encryptionPassword: string, privateKey: Uint8Array) => void;
};
\ No newline at end of file
import { RemoteKV } from "./store";
type HealthCallback = { Callback: (healthy: boolean) => void }
export type CMix = {
AddHealthCallback: (callback: HealthCallback) => number;
GetID: () => number;
IsReady: (threshold: number) => Uint8Array;
ReadyToSend: () => boolean;
StartNetworkFollower: (timeoutMilliseconds: number) => void;
StopNetworkFollower: () => void;
WaitForNetwork: (timeoutMilliseconds: number) => Promise<void>;
SetTrackNetworkPeriod: (periodMs: number) => void;
GetRemoteKV: () => Promise<RemoteKV>;
}
export type DMClient = {
SendText: (pubkey: Uint8Array, dmToken: number, message: string, leaseTimeMs: number, cmixParams: Uint8Array) => Promise<void>;
SendReply: (pubkey: Uint8Array, dmToken: number, message: string, replyToId: Uint8Array, leaseTimeMs: number, cmixParams: Uint8Array) => Promise<void>;
SendReaction: (pubkey: Uint8Array, dmToken: number, message: string, reactToId: Uint8Array, cmixParams: Uint8Array) => Promise<void>;
GetIdentity: () => Uint8Array;
SetNickname: (nickname: string) => void;
GetNickname: () => string;
GetDatabaseName: () => string;
};
\ No newline at end of file
export enum ChannelEvents {
NICKNAME_UPDATE = 1000,
NOTIFICATION_UPDATE = 2000,
MESSAGE_RECEIVED = 3000,
USER_MUTED = 4000,
MESSAGE_DELETED = 5000,
ADMIN_KEY_UPDATE = 6000,
DM_TOKEN_UPDATE = 7000,
CHANNEL_UPDATE = 8000
}
export type ChannelEventHandler = (eventType: ChannelEvents, data: unknown) => void;
export enum DMEvents {
DM_NOTIFICATION_UPDATE = 1000,
DM_BLOCKED_USER = 2000,
DM_MESSAGE_RECEIVED = 3000
}
export type DMEventHandler = (eventType: DMEvents, data: unknown) => void;
export * from './utils';
\ No newline at end of file
export enum OperationType {
Created = 0,
Updated = 1,
Deleted = 2
}
export type KVEntry = {
version: number;
timestamp: string;
data: string;
}
type KeyChangedByRemoteCallback = {
Callback: (
key: string,
oldEntry: Uint8Array,
newEntry: Uint8Array,
operationType: OperationType
) => void;
}
export type RemoteKV = {
Get: (key: string, version: number) => Promise<Uint8Array>;
Delete: (key: string, version: number) => Promise<void>;
Set: (key: string, encodedKVMapEntry: Uint8Array) => Promise<void>;
ListenOnRemoteKey: (key: string, version: number, onChange: KeyChangedByRemoteCallback) => number;
DeleteRemoteKeyListener: (key: string, id: number) => void;
}
export interface RemoteStore {
Read: (path: string) => Promise<Uint8Array | null>;
Write: (path: string, data: Uint8Array) => Promise<void>;
GetLastModified: (path: string) => Promise<string | null>;
ReadDir: (path: string) => Promise<string[]>;
DeleteAll: () => Promise<void>;
}
\ No newline at end of file
import type { RemoteStore } from "./store";
import type { CMix } from "./cmix";
import type { DMEventHandler, ChannelEventHandler } from "./events";
import type { ChannelManager, PrivacyLevel } from "./channels";
import type { DMClient } from './dm';
export type DBCipher = {
GetID: () => number;
Decrypt: (plaintext: string) => Uint8Array;
}
type DummyTrafficController = {
GetStatus: () => boolean;
Pause: () => void;
Start: () => void;
};
type Logger = {
StopLogging: () => void,
GetFile: () => Promise<string>,
Threshold: () => number,
MaxSize: () => number,
Size: () => Promise<number>,
Worker: () => Worker,
};
export type ChannelManagerCallbacks = {
EventUpdate: ChannelEventHandler;
}
export type DMClientEventCallback = {
EventUpdate: DMEventHandler;
}
export type Notifications = {
AddToken: (newToken: string, app: string) => void;
RemoveToken: () => void;
SetMaxState: (maxState: number) => void;
GetMaxState: () => number;
GetID: () => number;
}
export type XXDKUtils = {
NewCmix: (
ndf: string,
storageDir: string,
password: Uint8Array,
registrationCode: string
) => Promise<void>;
NewSynchronizedCmix: (
ndf: string,
storageDir: string,
remoteStoragePrefixPath: string,
password: Uint8Array,
remoteStore: RemoteStore,
) => Promise<void>;
LoadCmix: (
storageDirectory: string,
password: Uint8Array,
cmixParams: Uint8Array
) => Promise<CMix>;
LoadSynchronizedCmix: (
storageDirectory: string,
password: Uint8Array,
remoteStore: RemoteStore,
cmixParams: Uint8Array
) => Promise<CMix>;
LoadNotifications: (
cmixId: number
) => Notifications;
LoadNotificationsDummy: (
cmixId: number
) => Notifications;
GetDefaultCMixParams: () => Uint8Array;
GetChannelInfo: (prettyPrint: string) => Uint8Array;
GetLogger: () => Logger,
Base64ToUint8Array: (base64: string) => Uint8Array;
GenerateChannelIdentity: (cmixId: number) => Uint8Array;
NewChannelsManagerWithIndexedDb: (
cmixId: number,
wasmJsPath: string,
privateIdentity: Uint8Array,
extensionBuilderIDsJSON: Uint8Array,
notificationsId: number,
callbacks: ChannelManagerCallbacks,
channelDbCipher: number
) => Promise<ChannelManager>;
NewDMClientWithIndexedDb: (
cmixId: number,
notificationsId: number,
cipherId: number,
wasmJsPath: string,
privateIdentity: Uint8Array,
eventCallback: DMClientEventCallback
) => Promise<DMClient>;
NewDatabaseCipher: (
cmixId: number,
storagePassword: Uint8Array,
payloadMaximumSize: number
) => DBCipher;
LoadChannelsManagerWithIndexedDb: (
cmixId: number,
wasmJsPath: string,
storageTag: string,
extensionBuilderIDsJSON: Uint8Array,
notificationsId: number,
callbacks: ChannelManagerCallbacks,
channelDbCipher: number
) => Promise<ChannelManager>;
GetPublicChannelIdentityFromPrivate: (privateKey: Uint8Array) => Uint8Array;
IsNicknameValid: (nickname: string) => null;
GetShareUrlType: (url: string) => PrivacyLevel;
GetVersion: () => string;
GetClientVersion: () => string;
GetOrInitPassword: (password: string) => Promise<Uint8Array>;
ImportPrivateIdentity: (password: string, privateIdentity: Uint8Array) => Uint8Array;
ConstructIdentity: (publicKey: Uint8Array, codesetVersion: number) => Uint8Array;
DecodePrivateURL: (url: string, password: string) => string;
DecodePublicURL: (url: string) => string;
GetChannelJSON: (prettyPrint: string) => Uint8Array;
NewDummyTrafficManager: (
cmixId: number,
maximumOfMessagesPerCycle: number,
durationToWaitBetweenSendsMilliseconds: number,
upperBoundIntervalBetweenCyclesMilliseconds: number
) => DummyTrafficController;
GetWasmSemanticVersion: () => Uint8Array;
Purge: (userPassword: string) => void;
ValidForever: () => number;
}
\ No newline at end of file
File moved
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment