@imweapp/openclaw-imwe 2026.4.12-alpha.1
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/LICENSE +21 -0
- package/README.md +172 -0
- package/index.ts +16 -0
- package/openclaw.plugin.json +58 -0
- package/package.json +73 -0
- package/proto/PbBoxPullProto.proto +43 -0
- package/proto/PbChatAudioContent.proto +23 -0
- package/proto/PbChatDeliverMsg.proto +38 -0
- package/proto/PbChatFileMeta.proto +34 -0
- package/proto/PbChatMsg.proto +93 -0
- package/proto/PbChatRichMediaContent.proto +31 -0
- package/proto/PbChatTextContent.proto +38 -0
- package/proto/PbMarkdownContent.proto +18 -0
- package/proto/PbMsgReadStampContent.proto +11 -0
- package/proto/PbPacket.proto +61 -0
- package/proto/PbSingleChatMsg.proto +60 -0
- package/setup-entry.ts +17 -0
- package/src/accounts.ts +109 -0
- package/src/api-client.ts +740 -0
- package/src/bot-info-cache.ts +49 -0
- package/src/channel.runtime.ts +29 -0
- package/src/channel.ts +456 -0
- package/src/config-schema.ts +26 -0
- package/src/e2ee/api.ts +261 -0
- package/src/e2ee/canonical.ts +59 -0
- package/src/e2ee/errors.ts +103 -0
- package/src/e2ee/index.ts +8 -0
- package/src/e2ee/proper-lockfile.d.ts +61 -0
- package/src/e2ee/service.ts +1273 -0
- package/src/e2ee/store.ts +174 -0
- package/src/e2ee/types.ts +113 -0
- package/src/e2ee/vodozemac.ts +373 -0
- package/src/file-transfer/api.ts +364 -0
- package/src/file-transfer/concurrency.ts +77 -0
- package/src/file-transfer/download.ts +261 -0
- package/src/file-transfer/file-crypto.ts +93 -0
- package/src/file-transfer/index.ts +18 -0
- package/src/file-transfer/scheduler.ts +185 -0
- package/src/file-transfer/types.ts +195 -0
- package/src/file-transfer/upload.ts +656 -0
- package/src/markdown-detect.ts +119 -0
- package/src/media-upload.ts +338 -0
- package/src/media-utils.ts +110 -0
- package/src/monitor.ts +838 -0
- package/src/proto/codec.ts +54 -0
- package/src/proto/inbound.codec.ts +624 -0
- package/src/proto/proto-types.ts +291 -0
- package/src/proto/registry.ts +226 -0
- package/src/proto/send.codec.ts +535 -0
- package/src/recent-message-cache.ts +350 -0
- package/src/send.ts +792 -0
- package/src/setup-core.ts +62 -0
- package/src/types.ts +153 -0
- package/src/vodozemackit/index.ts +297 -0
- package/src/vodozemackit/pkg/vodozemackit_wasm.d.ts +138 -0
- package/src/vodozemackit/pkg/vodozemackit_wasm.js +24 -0
- package/src/vodozemackit/pkg/vodozemackit_wasm_bg.js +1172 -0
- package/src/vodozemackit/pkg/vodozemackit_wasm_bg.wasm +0 -0
- package/src/vodozemackit/pkg/vodozemackit_wasm_bg.wasm.d.ts +109 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* setup-core.ts — setup 适配器
|
|
3
|
+
*
|
|
4
|
+
* 处理 `openclaw setup imwe` 命令的配置写入逻辑。
|
|
5
|
+
* 用户需要提供:
|
|
6
|
+
* --http-url <apiBaseUrl> imwe API 地址
|
|
7
|
+
* --token <appKey> AppKey(复用 --token 参数)
|
|
8
|
+
* --private-key <appSecret> AppSecret(复用 --private-key 参数)
|
|
9
|
+
*
|
|
10
|
+
* 或通过环境变量(仅 default 账号):
|
|
11
|
+
* IMWE_API_BASE_URL
|
|
12
|
+
* IMWE_APP_KEY
|
|
13
|
+
* IMWE_APP_SECRET
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
createPatchedAccountSetupAdapter,
|
|
18
|
+
createSetupInputPresenceValidator,
|
|
19
|
+
} from 'openclaw/plugin-sdk/setup';
|
|
20
|
+
|
|
21
|
+
export const imweSetupAdapter = createPatchedAccountSetupAdapter({
|
|
22
|
+
channelKey: 'imwe',
|
|
23
|
+
|
|
24
|
+
validateInput: createSetupInputPresenceValidator({
|
|
25
|
+
defaultAccountOnlyEnvError: 'IMWE_APP_KEY / IMWE_APP_SECRET 只能用于 default 账号。',
|
|
26
|
+
whenNotUseEnv: [
|
|
27
|
+
{
|
|
28
|
+
someOf: ['httpUrl'],
|
|
29
|
+
message: 'imwe 需要提供 API 地址(--http-url)。',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
someOf: ['token'],
|
|
33
|
+
message: 'imwe 需要提供 AppKey(--token)。',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
someOf: ['privateKey'],
|
|
37
|
+
message: 'imwe 需要提供 AppSecret(--private-key)。',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
}),
|
|
41
|
+
|
|
42
|
+
buildPatch: (input) => {
|
|
43
|
+
// useEnv=true 时只写入 apiBaseUrl,凭证依赖环境变量
|
|
44
|
+
if (input.useEnv) {
|
|
45
|
+
return input.httpUrl ? { apiBaseUrl: input.httpUrl } : {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const patch: Record<string, unknown> = {};
|
|
49
|
+
if (input.httpUrl) {
|
|
50
|
+
patch.apiBaseUrl = input.httpUrl;
|
|
51
|
+
}
|
|
52
|
+
// --token 复用为 appKey
|
|
53
|
+
if (input.token) {
|
|
54
|
+
patch.appKey = input.token;
|
|
55
|
+
}
|
|
56
|
+
// --private-key 复用为 appSecret
|
|
57
|
+
if (input.privateKey) {
|
|
58
|
+
patch.appSecret = input.privateKey;
|
|
59
|
+
}
|
|
60
|
+
return patch;
|
|
61
|
+
},
|
|
62
|
+
});
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* types.ts — imwe 插件的所有类型定义
|
|
3
|
+
*
|
|
4
|
+
* 分三层:
|
|
5
|
+
* 1. ImweAccountConfig — 原始 JSON 配置(字段全部可选,对应用户写的 openclaw.json)
|
|
6
|
+
* 2. ImweConfig — 渠道级配置(含顶层默认值 + 多账号 map)
|
|
7
|
+
* 3. ResolvedImweAccount — 运行时已解析对象(字段全部确定,core 直接使用)
|
|
8
|
+
*
|
|
9
|
+
* 认证方式:AppKey + AppSecret HMAC-SHA256 签名
|
|
10
|
+
* 每次 HTTP 请求时,api-client.ts 用 AppSecret 对请求内容签名,
|
|
11
|
+
* 签名放入请求头,平台验证签名合法性。
|
|
12
|
+
* 无需 token、无需登录流程、无需持久化任何凭证。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
16
|
+
// 第一层:原始配置(对应 openclaw.json 里用户写的内容)
|
|
17
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
export type ImweAccountConfig = {
|
|
20
|
+
/** 账号显示名称,用于 CLI/UI 列表 */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** 是否启用该账号,默认 true */
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
/** imwe API 基础地址,例如 https://api.imwe.example.com */
|
|
25
|
+
apiBaseUrl?: string;
|
|
26
|
+
/**
|
|
27
|
+
* 应用 Key,由 imwe 开放平台颁发,用于标识调用方身份。
|
|
28
|
+
* 也可通过环境变量 IMWE_APP_KEY 提供。
|
|
29
|
+
*/
|
|
30
|
+
appKey?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 应用 Secret,与 AppKey 配对,用于 HMAC-SHA256 签名。
|
|
33
|
+
* 请勿明文提交到版本控制,建议通过环境变量 IMWE_APP_SECRET 提供。
|
|
34
|
+
*/
|
|
35
|
+
appSecret?: string;
|
|
36
|
+
/** DM 安全策略:pairing(配对审批)| allowlist | open | disabled */
|
|
37
|
+
dmPolicy?: 'pairing' | 'allowlist' | 'open' | 'disabled';
|
|
38
|
+
/** DM 发送者白名单(imwe userId 列表) */
|
|
39
|
+
allowFrom?: Array<string | number>;
|
|
40
|
+
/**
|
|
41
|
+
* 短轮询间隔(毫秒),默认 3000。
|
|
42
|
+
* 每次请求完成后等待此时间再发起下一次,控制请求频率。
|
|
43
|
+
* 建议不低于 1000,避免对平台造成过大压力。
|
|
44
|
+
*/
|
|
45
|
+
pollIntervalMs?: number;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
49
|
+
// 第二层:渠道级配置(包含顶层默认值 + 多账号 map)
|
|
50
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
export type ImweConfig = ImweAccountConfig & {
|
|
53
|
+
/** 多账号时使用,key 为 accountId */
|
|
54
|
+
accounts?: Record<string, ImweAccountConfig>;
|
|
55
|
+
/** 多账号时的默认 accountId */
|
|
56
|
+
defaultAccount?: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
60
|
+
// 第三层:运行时已解析账号(所有字段已确定,不再有 undefined)
|
|
61
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
62
|
+
|
|
63
|
+
export type ResolvedImweAccount = {
|
|
64
|
+
/** 账号 id(单账号时为 "default") */
|
|
65
|
+
accountId: string;
|
|
66
|
+
/** 显示名称 */
|
|
67
|
+
name?: string;
|
|
68
|
+
/** 是否启用 */
|
|
69
|
+
enabled: boolean;
|
|
70
|
+
/** API 基础地址(已解析) */
|
|
71
|
+
apiBaseUrl: string;
|
|
72
|
+
/** API Key(ak_ 前缀,由 imwe 开放平台颁发) */
|
|
73
|
+
appKey: string;
|
|
74
|
+
/** API Secret(与 appKey 配对,用于 HMAC-SHA256 签名) */
|
|
75
|
+
appSecret: string;
|
|
76
|
+
/** 凭证来源,用于 status 展示 */
|
|
77
|
+
credentialSource: 'config' | 'env' | 'none';
|
|
78
|
+
/** 合并后的完整配置 */
|
|
79
|
+
config: ImweAccountConfig;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
83
|
+
// HTTP API 相关类型(imwe 平台接口的数据结构)
|
|
84
|
+
// 注意:HTTP 传输使用 Protobuf 二进制,encode/decode 由 src/proto/codec.ts 负责。
|
|
85
|
+
// 这里只定义 TypeScript 侧的数据结构,与 proto/ 目录中的 .proto 定义对应。
|
|
86
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
/** 入站消息附件 */
|
|
89
|
+
export type ImweAttachment = {
|
|
90
|
+
/** 附件类型 */
|
|
91
|
+
type: 'image' | 'video' | 'audio' | 'file';
|
|
92
|
+
/** 文件下载 URL(来自 PbChatFileMeta.url) */
|
|
93
|
+
url: string;
|
|
94
|
+
/** 文件 MIME 类型(从 fileType 推断) */
|
|
95
|
+
mimeType?: string;
|
|
96
|
+
/** 文件名 */
|
|
97
|
+
fileName?: string;
|
|
98
|
+
/** 文件大小(字节) */
|
|
99
|
+
fileSize?: number;
|
|
100
|
+
/** 图片/视频宽度(像素) */
|
|
101
|
+
width?: number;
|
|
102
|
+
/** 图片/视频高度(像素) */
|
|
103
|
+
height?: number;
|
|
104
|
+
/** 音频/视频时长(秒) */
|
|
105
|
+
duration?: number;
|
|
106
|
+
/** 图片/视频文字描述 */
|
|
107
|
+
caption?: string;
|
|
108
|
+
/** AES-256 文件加密密钥(32 字节,E2EE 文件传输时存在) */
|
|
109
|
+
fileKey?: Uint8Array;
|
|
110
|
+
/** AES-CTR 初始向量(16 字节,E2EE 文件传输时存在) */
|
|
111
|
+
fileIv?: Uint8Array;
|
|
112
|
+
/** SHA256(plaintext) 小写十六进制摘要 */
|
|
113
|
+
fileDigest?: string;
|
|
114
|
+
/** 明文长度(字节) */
|
|
115
|
+
plaintextLength?: number;
|
|
116
|
+
/** 操作凭证(下载回调用) */
|
|
117
|
+
opCreds?: string;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 平台推送的入站消息结构(解包后的 TypeScript 表示)
|
|
122
|
+
* 对应 proto/envelope.proto: PbChatTextContent
|
|
123
|
+
*/
|
|
124
|
+
export type ImweInboundMessage = {
|
|
125
|
+
/** 消息唯一 id(来自 PbChatMsgDeliverBody.clientMsgId) */
|
|
126
|
+
msgId: string;
|
|
127
|
+
/** 发送者 userId(来自 PbChatMsgDeliverBody.fromId) */
|
|
128
|
+
senderId: string;
|
|
129
|
+
/** 接收者 userId(来自 PbChatMsgDeliverBody.toId) */
|
|
130
|
+
toId: string;
|
|
131
|
+
/** 消息文本内容(来自 PbChatTextContent.text) */
|
|
132
|
+
content: string;
|
|
133
|
+
/** 消息时间戳(Unix 毫秒,来自 PbChatMsgDeliverBody.serverStamp) */
|
|
134
|
+
timestampMs: number;
|
|
135
|
+
/** 正文范围(@、超链接等,来自 PbChatTextContent.bodyRanges) */
|
|
136
|
+
bodyRanges?: Array<{ key: 0 | 1 | 2; payload: string; start?: number; length?: number }>;
|
|
137
|
+
/** 引用消息的 clientMsgId(来自 PbChatTextContent.referenceClientMsgId) */
|
|
138
|
+
referenceClientMsgId?: string;
|
|
139
|
+
/** 多媒体附件列表(文本消息时为 undefined) */
|
|
140
|
+
attachments?: ImweAttachment[];
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 发送消息响应
|
|
145
|
+
* 对应 proto/send.proto: SendResponse
|
|
146
|
+
*/
|
|
147
|
+
export type ImweSendResponse = {
|
|
148
|
+
ok: boolean;
|
|
149
|
+
msgId?: string;
|
|
150
|
+
/** 本次出站请求使用的 clientMsgId(插件本地生成) */
|
|
151
|
+
clientMsgId?: string;
|
|
152
|
+
error?: string;
|
|
153
|
+
};
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import * as wasm from './pkg/vodozemackit_wasm';
|
|
2
|
+
|
|
3
|
+
export type KeyMap = Record<string, string>;
|
|
4
|
+
|
|
5
|
+
function toKeyMap(value: unknown): KeyMap {
|
|
6
|
+
if (value instanceof Map) {
|
|
7
|
+
return Object.fromEntries(value.entries()) as KeyMap;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return value as KeyMap;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class EncryptedMessage {
|
|
14
|
+
private readonly inner: wasm.EncryptedMessage;
|
|
15
|
+
|
|
16
|
+
constructor(bodyOrInner: Uint8Array | wasm.EncryptedMessage) {
|
|
17
|
+
this.inner =
|
|
18
|
+
bodyOrInner instanceof Uint8Array ? new wasm.EncryptedMessage(bodyOrInner) : bodyOrInner;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static fromRaw(inner: wasm.EncryptedMessage): EncryptedMessage {
|
|
22
|
+
return new EncryptedMessage(inner);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get body(): Uint8Array {
|
|
26
|
+
return this.inner.body;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
raw(): wasm.EncryptedMessage {
|
|
30
|
+
return this.inner;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class Session {
|
|
35
|
+
private readonly inner: wasm.Session;
|
|
36
|
+
|
|
37
|
+
constructor(inner: wasm.Session) {
|
|
38
|
+
this.inner = inner;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
sessionId(): string {
|
|
42
|
+
return this.inner.sessionId();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
pickle(pickleKey: Uint8Array): string {
|
|
46
|
+
return this.inner.pickle(pickleKey);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
encrypt(payload: Uint8Array): EncryptedMessage {
|
|
50
|
+
return EncryptedMessage.fromRaw(this.inner.encrypt(payload));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
decrypt(message: EncryptedMessage): Uint8Array {
|
|
54
|
+
return this.inner.decrypt(message.raw());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sessionMatches(message: EncryptedMessage): boolean {
|
|
58
|
+
return this.inner.sessionMatches(message.raw());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
raw(): wasm.Session {
|
|
62
|
+
return this.inner;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Detailed info for a single unpublished one-time key.
|
|
68
|
+
*/
|
|
69
|
+
export interface OneTimeKeyInfo {
|
|
70
|
+
/** Key ID (base64 encoded). */
|
|
71
|
+
keyId: string;
|
|
72
|
+
/** Public key (base64 encoded). */
|
|
73
|
+
publicKey: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The result of generating one-time keys.
|
|
78
|
+
*
|
|
79
|
+
* - `created` contains the newly created keys with their ids.
|
|
80
|
+
* - `removed` contains the base64 public keys that were evicted to make room
|
|
81
|
+
* for the new keys (may be empty).
|
|
82
|
+
*/
|
|
83
|
+
export interface OneTimeKeyGenerationInfo {
|
|
84
|
+
created: OneTimeKeyInfo[];
|
|
85
|
+
removed: string[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function toOneTimeKeyInfo(raw: wasm.OneTimeKeyInfo): OneTimeKeyInfo {
|
|
89
|
+
return { keyId: raw.keyId, publicKey: raw.publicKey };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface InboundCreationResult {
|
|
93
|
+
session: Session;
|
|
94
|
+
plaintext: Uint8Array;
|
|
95
|
+
/**
|
|
96
|
+
* The base64 encoded one-time key that was carried in the incoming pre-key
|
|
97
|
+
* message. Useful for correlating an inbound session with a previously
|
|
98
|
+
* uploaded OTK batch.
|
|
99
|
+
*/
|
|
100
|
+
oneTimeKey: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export class Account {
|
|
104
|
+
private readonly inner: wasm.Account;
|
|
105
|
+
|
|
106
|
+
constructor(inner?: wasm.Account) {
|
|
107
|
+
this.inner = inner ?? new wasm.Account();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static fromPickle(pickle: string, pickleKey: Uint8Array): Account {
|
|
111
|
+
return new Account(wasm.accountFromPickle(pickle, pickleKey));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
pickle(pickleKey: Uint8Array): string {
|
|
115
|
+
return this.inner.pickle(pickleKey);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
ed25519Key(): string {
|
|
119
|
+
return this.inner.ed25519Key();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
curve25519Key(): string {
|
|
123
|
+
return this.inner.curve25519Key();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
sign(message: string): string {
|
|
127
|
+
return this.inner.sign(message);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
generateOneTimeKeys(numberOfKeys: number): void {
|
|
131
|
+
this.inner.generateOneTimeKeys(numberOfKeys);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Generate one-time keys and return detailed info about the newly created
|
|
136
|
+
* keys, along with any keys that were evicted to make room for them.
|
|
137
|
+
*/
|
|
138
|
+
generateOneTimeKeysWithInfo(numberOfKeys: number): OneTimeKeyGenerationInfo {
|
|
139
|
+
const result = this.inner.generateOneTimeKeysWithInfo(numberOfKeys);
|
|
140
|
+
const created = result.created.map(toOneTimeKeyInfo);
|
|
141
|
+
const removed = [...result.removed];
|
|
142
|
+
return { created, removed };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
oneTimeKeys(): KeyMap {
|
|
146
|
+
return toKeyMap(this.inner.oneTimeKeys());
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Returns the list of currently unpublished one-time keys along with their
|
|
151
|
+
* key ids. Mirrors `Account.oneTimeKeys` but preserves the key id.
|
|
152
|
+
*/
|
|
153
|
+
oneTimeKeysWithInfo(): OneTimeKeyInfo[] {
|
|
154
|
+
return this.inner.oneTimeKeysWithInfo().map(toOneTimeKeyInfo);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Returns the number of one-time keys that are generated but not yet marked
|
|
159
|
+
* as published.
|
|
160
|
+
*/
|
|
161
|
+
unpublishedOneTimeKeyCount(): number {
|
|
162
|
+
return this.inner.unpublishedOneTimeKeyCount();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
maxNumberOfOneTimeKeys(): number {
|
|
166
|
+
return this.inner.maxNumberOfOneTimeKeys();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
markKeysAsPublished(): void {
|
|
170
|
+
this.inner.markKeysAsPublished();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
fallbackKey(): KeyMap {
|
|
174
|
+
return toKeyMap(this.inner.fallbackKey());
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
generateFallbackKey(): void {
|
|
178
|
+
this.inner.generateFallbackKey();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
createOutboundSession(identityKey: string, oneTimeKey: string): Session {
|
|
182
|
+
return new Session(this.inner.createOutboundSession(identityKey, oneTimeKey));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
createInboundSession(message: EncryptedMessage): InboundCreationResult {
|
|
186
|
+
const result = this.inner.createInboundSession(message.raw());
|
|
187
|
+
return {
|
|
188
|
+
session: new Session(result.takeSession()),
|
|
189
|
+
plaintext: result.plaintext(),
|
|
190
|
+
oneTimeKey: result.oneTimeKey(),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
raw(): wasm.Account {
|
|
195
|
+
return this.inner;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function accountFromPickle(pickle: string, pickleKey: Uint8Array): Account {
|
|
200
|
+
return Account.fromPickle(pickle, pickleKey);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function sessionFromPickle(pickle: string, pickleKey: Uint8Array): Session {
|
|
204
|
+
return new Session(wasm.sessionFromPickle(pickle, pickleKey));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface DecryptedMessage {
|
|
208
|
+
plaintext: Uint8Array;
|
|
209
|
+
messageIndex: number;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export class GroupSession {
|
|
213
|
+
private readonly inner: wasm.GroupSession;
|
|
214
|
+
|
|
215
|
+
constructor(inner?: wasm.GroupSession) {
|
|
216
|
+
this.inner = inner ?? new wasm.GroupSession();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
sessionId(): string {
|
|
220
|
+
return this.inner.sessionId();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
sessionKey(): string {
|
|
224
|
+
return this.inner.sessionKey();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
messageIndex(): number {
|
|
228
|
+
return this.inner.messageIndex();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
encrypt(payload: Uint8Array): EncryptedMessage {
|
|
232
|
+
return EncryptedMessage.fromRaw(this.inner.encrypt(payload));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
pickle(pickleKey: Uint8Array): string {
|
|
236
|
+
return this.inner.pickle(pickleKey);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
raw(): wasm.GroupSession {
|
|
240
|
+
return this.inner;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export class InboundGroupSession {
|
|
245
|
+
private readonly inner: wasm.InboundGroupSession;
|
|
246
|
+
|
|
247
|
+
constructor(inner: wasm.InboundGroupSession) {
|
|
248
|
+
this.inner = inner;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
sessionId(): string {
|
|
252
|
+
return this.inner.sessionId();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
firstKnownIndex(): number {
|
|
256
|
+
return this.inner.firstKnownIndex();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
exportAt(index: number): string | undefined {
|
|
260
|
+
return this.inner.exportAt(index);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
decrypt(payload: Uint8Array): DecryptedMessage {
|
|
264
|
+
const decrypted = this.inner.decrypt(payload);
|
|
265
|
+
return {
|
|
266
|
+
plaintext: decrypted.plaintext,
|
|
267
|
+
messageIndex: decrypted.messageIndex,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
pickle(pickleKey: Uint8Array): string {
|
|
272
|
+
return this.inner.pickle(pickleKey);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
raw(): wasm.InboundGroupSession {
|
|
276
|
+
return this.inner;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function groupSessionFromPickle(pickle: string, pickleKey: Uint8Array): GroupSession {
|
|
281
|
+
return new GroupSession(wasm.groupSessionFromPickle(pickle, pickleKey));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function newInboundGroupSession(sessionKey: string): InboundGroupSession {
|
|
285
|
+
return new InboundGroupSession(wasm.newInboundGroupSession(sessionKey));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function importInboundGroupSession(sessionKey: string): InboundGroupSession {
|
|
289
|
+
return new InboundGroupSession(wasm.importInboundGroupSession(sessionKey));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function inboundGroupSessionFromPickle(
|
|
293
|
+
pickle: string,
|
|
294
|
+
pickleKey: Uint8Array,
|
|
295
|
+
): InboundGroupSession {
|
|
296
|
+
return new InboundGroupSession(wasm.inboundGroupSessionFromPickle(pickle, pickleKey));
|
|
297
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class Account {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
createInboundSession(message: EncryptedMessage): InboundCreationResult;
|
|
8
|
+
createOutboundSession(identity_key: string, one_time_key: string): Session;
|
|
9
|
+
curve25519Key(): string;
|
|
10
|
+
ed25519Key(): string;
|
|
11
|
+
fallbackKey(): any;
|
|
12
|
+
generateFallbackKey(): void;
|
|
13
|
+
generateOneTimeKeys(number_of_keys: number): void;
|
|
14
|
+
/**
|
|
15
|
+
* Generates one-time keys and returns metadata about the keys that were
|
|
16
|
+
* created along with any keys evicted to make room. Mirrors
|
|
17
|
+
* `Account.generate_one_time_keys_with_info` on the UniFFI side.
|
|
18
|
+
*/
|
|
19
|
+
generateOneTimeKeysWithInfo(number_of_keys: number): OneTimeKeyGenerationInfo;
|
|
20
|
+
markKeysAsPublished(): void;
|
|
21
|
+
maxNumberOfOneTimeKeys(): number;
|
|
22
|
+
constructor();
|
|
23
|
+
oneTimeKeys(): any;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the full list of currently unpublished one-time keys as
|
|
26
|
+
* `OneTimeKeyInfo` entries. Mirrors `Account.one_time_keys_with_info` on
|
|
27
|
+
* the UniFFI side.
|
|
28
|
+
*/
|
|
29
|
+
oneTimeKeysWithInfo(): OneTimeKeyInfo[];
|
|
30
|
+
pickle(pickle_key: Uint8Array): string;
|
|
31
|
+
sign(message: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the number of one-time keys that are generated but not yet
|
|
34
|
+
* marked as published.
|
|
35
|
+
*/
|
|
36
|
+
unpublishedOneTimeKeyCount(): number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class DecryptedMessage {
|
|
40
|
+
private constructor();
|
|
41
|
+
free(): void;
|
|
42
|
+
[Symbol.dispose](): void;
|
|
43
|
+
readonly messageIndex: number;
|
|
44
|
+
readonly plaintext: Uint8Array;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class EncryptedMessage {
|
|
48
|
+
free(): void;
|
|
49
|
+
[Symbol.dispose](): void;
|
|
50
|
+
constructor(body: Uint8Array);
|
|
51
|
+
readonly body: Uint8Array;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class GroupSession {
|
|
55
|
+
free(): void;
|
|
56
|
+
[Symbol.dispose](): void;
|
|
57
|
+
encrypt(payload: Uint8Array): EncryptedMessage;
|
|
58
|
+
messageIndex(): number;
|
|
59
|
+
constructor();
|
|
60
|
+
pickle(pickle_key: Uint8Array): string;
|
|
61
|
+
sessionId(): string;
|
|
62
|
+
sessionKey(): string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class InboundCreationResult {
|
|
66
|
+
private constructor();
|
|
67
|
+
free(): void;
|
|
68
|
+
[Symbol.dispose](): void;
|
|
69
|
+
/**
|
|
70
|
+
* The base64 encoded one-time key that was used in the pre-key message
|
|
71
|
+
* to establish the inbound session.
|
|
72
|
+
*/
|
|
73
|
+
oneTimeKey(): string;
|
|
74
|
+
plaintext(): Uint8Array;
|
|
75
|
+
takeSession(): Session;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export class InboundGroupSession {
|
|
79
|
+
private constructor();
|
|
80
|
+
free(): void;
|
|
81
|
+
[Symbol.dispose](): void;
|
|
82
|
+
decrypt(payload: Uint8Array): DecryptedMessage;
|
|
83
|
+
exportAt(index: number): string | undefined;
|
|
84
|
+
firstKnownIndex(): number;
|
|
85
|
+
pickle(pickle_key: Uint8Array): string;
|
|
86
|
+
sessionId(): string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Result of generating one-time keys, containing detailed info about newly
|
|
91
|
+
* created keys and the base64 public keys that were evicted.
|
|
92
|
+
*/
|
|
93
|
+
export class OneTimeKeyGenerationInfo {
|
|
94
|
+
private constructor();
|
|
95
|
+
free(): void;
|
|
96
|
+
[Symbol.dispose](): void;
|
|
97
|
+
readonly created: OneTimeKeyInfo[];
|
|
98
|
+
readonly removed: string[];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Detailed info about a single one-time key.
|
|
103
|
+
*/
|
|
104
|
+
export class OneTimeKeyInfo {
|
|
105
|
+
private constructor();
|
|
106
|
+
free(): void;
|
|
107
|
+
[Symbol.dispose](): void;
|
|
108
|
+
readonly keyId: string;
|
|
109
|
+
readonly publicKey: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export class Session {
|
|
113
|
+
private constructor();
|
|
114
|
+
free(): void;
|
|
115
|
+
[Symbol.dispose](): void;
|
|
116
|
+
decrypt(message: EncryptedMessage): Uint8Array;
|
|
117
|
+
encrypt(payload: Uint8Array): EncryptedMessage;
|
|
118
|
+
pickle(pickle_key: Uint8Array): string;
|
|
119
|
+
sessionId(): string;
|
|
120
|
+
sessionMatches(message: EncryptedMessage): boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function accountFromPickle(pickle: string, pickle_key: Uint8Array): Account;
|
|
124
|
+
|
|
125
|
+
export function groupSessionFromPickle(pickle: string, pickle_key: Uint8Array): GroupSession;
|
|
126
|
+
|
|
127
|
+
export function importInboundGroupSession(session_key: string): InboundGroupSession;
|
|
128
|
+
|
|
129
|
+
export function inboundGroupSessionFromPickle(
|
|
130
|
+
pickle: string,
|
|
131
|
+
pickle_key: Uint8Array,
|
|
132
|
+
): InboundGroupSession;
|
|
133
|
+
|
|
134
|
+
export function newInboundGroupSession(session_key: string): InboundGroupSession;
|
|
135
|
+
|
|
136
|
+
export function sessionFromPickle(pickle: string, pickle_key: Uint8Array): Session;
|
|
137
|
+
|
|
138
|
+
export function start(): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* @ts-self-types="./vodozemackit_wasm.d.ts" */
|
|
2
|
+
import * as wasm from './vodozemackit_wasm_bg.wasm';
|
|
3
|
+
import { __wbg_set_wasm } from './vodozemackit_wasm_bg.js';
|
|
4
|
+
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
6
|
+
wasm.__wbindgen_start();
|
|
7
|
+
export {
|
|
8
|
+
Account,
|
|
9
|
+
DecryptedMessage,
|
|
10
|
+
EncryptedMessage,
|
|
11
|
+
GroupSession,
|
|
12
|
+
InboundCreationResult,
|
|
13
|
+
InboundGroupSession,
|
|
14
|
+
OneTimeKeyGenerationInfo,
|
|
15
|
+
OneTimeKeyInfo,
|
|
16
|
+
Session,
|
|
17
|
+
accountFromPickle,
|
|
18
|
+
groupSessionFromPickle,
|
|
19
|
+
importInboundGroupSession,
|
|
20
|
+
inboundGroupSessionFromPickle,
|
|
21
|
+
newInboundGroupSession,
|
|
22
|
+
sessionFromPickle,
|
|
23
|
+
start,
|
|
24
|
+
} from './vodozemackit_wasm_bg.js';
|