keymaster-connect 0.1.6 → 0.1.7
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/README.md +8 -22
- package/dist/{chunk-THT6XHHY.js → chunk-D2RL3QGR.js} +4 -16
- package/dist/chunk-D2RL3QGR.js.map +1 -0
- package/dist/index.d.ts +13 -171
- package/dist/index.js +118 -542
- package/dist/index.js.map +1 -1
- package/dist/{protocol-GXCfd2ya.d.ts → protocol-B7bpi5ro.d.ts} +3 -156
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.js +1 -1
- package/dist/script.d.ts +1 -1
- package/dist/server.d.ts +6 -8
- package/dist/server.js +7 -151
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-THT6XHHY.js.map +0 -1
|
@@ -179,121 +179,6 @@ interface ChannelMessageReceivedEventData {
|
|
|
179
179
|
*/
|
|
180
180
|
rawEnvelope?: Uint8Array;
|
|
181
181
|
}
|
|
182
|
-
interface StorageListParams {
|
|
183
|
-
/** 目录前缀。 */
|
|
184
|
-
prefix?: string;
|
|
185
|
-
/** 分页游标。 */
|
|
186
|
-
cursor?: string;
|
|
187
|
-
/** 每页数量。 */
|
|
188
|
-
limit?: number;
|
|
189
|
-
}
|
|
190
|
-
interface StorageListEntry {
|
|
191
|
-
/** Connect 可见的相对路径。 */
|
|
192
|
-
path: string;
|
|
193
|
-
/** 当前目录下的文件名。 */
|
|
194
|
-
name: string;
|
|
195
|
-
/** 文件大小(字节)。 */
|
|
196
|
-
size: number;
|
|
197
|
-
/** 抽象版本标签。 */
|
|
198
|
-
revision?: string;
|
|
199
|
-
/** 最后修改时间。 */
|
|
200
|
-
lastModified?: string;
|
|
201
|
-
}
|
|
202
|
-
interface StorageListResult {
|
|
203
|
-
/** 当前目录前缀。 */
|
|
204
|
-
prefix: string;
|
|
205
|
-
/** 父目录前缀。 */
|
|
206
|
-
parentPrefix: string;
|
|
207
|
-
/** 虚拟目录列表。 */
|
|
208
|
-
directories: Array<{
|
|
209
|
-
path: string;
|
|
210
|
-
name: string;
|
|
211
|
-
}>;
|
|
212
|
-
/** 当前页文件。 */
|
|
213
|
-
files: StorageListEntry[];
|
|
214
|
-
/** 目录 marker 路径。 */
|
|
215
|
-
markerPath?: string;
|
|
216
|
-
/** 下一页游标。 */
|
|
217
|
-
nextCursor?: string;
|
|
218
|
-
}
|
|
219
|
-
interface StorageDirectoryParams {
|
|
220
|
-
/** 目录路径。 */
|
|
221
|
-
path: string;
|
|
222
|
-
/** 是否允许覆盖已有 marker。 */
|
|
223
|
-
overwrite?: boolean;
|
|
224
|
-
}
|
|
225
|
-
interface StorageDirectoryResult {
|
|
226
|
-
/** 目录路径。 */
|
|
227
|
-
path: string;
|
|
228
|
-
/** 是否创建。 */
|
|
229
|
-
created?: boolean;
|
|
230
|
-
/** 是否删除。 */
|
|
231
|
-
deleted?: boolean;
|
|
232
|
-
}
|
|
233
|
-
interface StoragePutParams {
|
|
234
|
-
/** 文件路径。 */
|
|
235
|
-
path: string;
|
|
236
|
-
/** 二进制文件内容。 */
|
|
237
|
-
content: BinaryField;
|
|
238
|
-
/** MIME 类型。 */
|
|
239
|
-
contentType?: string;
|
|
240
|
-
/** 是否覆盖已有对象。 */
|
|
241
|
-
overwrite?: boolean;
|
|
242
|
-
}
|
|
243
|
-
interface StoragePutResult {
|
|
244
|
-
/** 文件路径。 */
|
|
245
|
-
path: string;
|
|
246
|
-
/** 写入大小(字节)。 */
|
|
247
|
-
size: number;
|
|
248
|
-
/** 抽象版本标签。 */
|
|
249
|
-
revision?: string;
|
|
250
|
-
/** 写入时间戳(毫秒)。 */
|
|
251
|
-
updatedAt: number;
|
|
252
|
-
}
|
|
253
|
-
interface StorageGetParams {
|
|
254
|
-
/** 文件路径。 */
|
|
255
|
-
path: string;
|
|
256
|
-
/** 起始偏移(字节)。 */
|
|
257
|
-
offset?: number;
|
|
258
|
-
/** 读取长度(字节)。 */
|
|
259
|
-
length?: number;
|
|
260
|
-
/** 期望的抽象版本标签。 */
|
|
261
|
-
ifMatch?: string;
|
|
262
|
-
}
|
|
263
|
-
interface StorageGetResult {
|
|
264
|
-
/** 文件路径。 */
|
|
265
|
-
path: string;
|
|
266
|
-
/** 二进制内容。 */
|
|
267
|
-
content: BinaryField;
|
|
268
|
-
/** MIME 类型。 */
|
|
269
|
-
contentType?: string;
|
|
270
|
-
/** 实际起始偏移。 */
|
|
271
|
-
offset: number;
|
|
272
|
-
/** 文件总大小(字节)。 */
|
|
273
|
-
totalSize: number;
|
|
274
|
-
/** 是否已读到文件结尾。 */
|
|
275
|
-
eof: boolean;
|
|
276
|
-
/** 抽象版本标签。 */
|
|
277
|
-
revision?: string;
|
|
278
|
-
/** 最后修改时间。 */
|
|
279
|
-
lastModified?: string;
|
|
280
|
-
}
|
|
281
|
-
interface StorageDeleteParams {
|
|
282
|
-
/** 文件路径。 */
|
|
283
|
-
path: string;
|
|
284
|
-
}
|
|
285
|
-
interface StorageDeleteResult {
|
|
286
|
-
/** 文件路径。 */
|
|
287
|
-
path: string;
|
|
288
|
-
/** 固定成功标记。 */
|
|
289
|
-
deleted: true;
|
|
290
|
-
/** 删除时间戳(毫秒)。 */
|
|
291
|
-
updatedAt: number;
|
|
292
|
-
}
|
|
293
|
-
/** K-V 引擎的硬限制;字段名和单位均在此集中定义。 */
|
|
294
|
-
declare const STORAGE_MAX_PAYLOAD_BYTES: number;
|
|
295
|
-
declare const STORAGE_DEFAULT_LIST_LIMIT = 200;
|
|
296
|
-
declare const STORAGE_MAX_LIST_LIMIT = 1000;
|
|
297
182
|
/** libp2p protocol ID;wire 真值来自 MSFile Proxy Wire Messages v1。 */
|
|
298
183
|
declare const MSFILE_PROTOCOL_ID = "/msfile/1.0.0";
|
|
299
184
|
/** Frame / 内容硬上限。与 wire 规范一致,两层共同执行。 */
|
|
@@ -429,7 +314,7 @@ type ProtocolErrorCode =
|
|
|
429
314
|
/** Too many non-terminal Connect payment responsibilities. */
|
|
430
315
|
| "payment_pending_limit"
|
|
431
316
|
/** Same stable payment key with different frozen facts. */
|
|
432
|
-
| "id_conflict" | "
|
|
317
|
+
| "id_conflict" | "msfile_not_configured" | "msfile_unavailable" | "msfile_identity_required" | "msfile_supplier_not_found" | "msfile_supplier_disabled" | "msfile_invalid_hash" | "msfile_price_limit_exceeded" | "msfile_integrity_error" | "msfile_content_not_found" | "msfile_rate_limited" | "msfile_supplier_error" | "msfile_transport_error" | "msfile_protocol_error" | "internal_error";
|
|
433
318
|
interface ProtocolError {
|
|
434
319
|
code: ProtocolErrorCode;
|
|
435
320
|
message: string;
|
|
@@ -602,18 +487,6 @@ interface ConnectLoginResult {
|
|
|
602
487
|
/** 本次解析时间(unix milliseconds)。 */
|
|
603
488
|
resolvedAt: number;
|
|
604
489
|
}
|
|
605
|
-
interface ConnectResumeParams extends Record<string, never> {
|
|
606
|
-
}
|
|
607
|
-
interface ConnectResumeResult {
|
|
608
|
-
authorizationId: string;
|
|
609
|
-
networkIdentity: NetworkIdentity;
|
|
610
|
-
resolvedClaims: Record<string, ResolvedClaimValue>;
|
|
611
|
-
/**
|
|
612
|
-
* 解析时间——本次 resume 时间戳,**不**是 connect.login 时的快照时间。
|
|
613
|
-
* 给 caller 用来做"是否要重新登录"的客户端超时策略。
|
|
614
|
-
*/
|
|
615
|
-
resolvedAt: number;
|
|
616
|
-
}
|
|
617
490
|
interface ConnectLogoutParams extends Record<string, never> {
|
|
618
491
|
}
|
|
619
492
|
interface ConnectLogoutResult {
|
|
@@ -636,7 +509,7 @@ interface ConnectLaunchResult {
|
|
|
636
509
|
resolvedAt: number;
|
|
637
510
|
}
|
|
638
511
|
/** 协议方法名常量集合。 */
|
|
639
|
-
declare const PROTOCOL_METHODS: readonly ["identity.get", "intent.sign", "cipher.encrypt", "cipher.decrypt", "payment.pay", "payment.status", "connect.login", "connect.
|
|
512
|
+
declare const PROTOCOL_METHODS: readonly ["identity.get", "intent.sign", "cipher.encrypt", "cipher.decrypt", "payment.pay", "payment.status", "connect.login", "connect.logout", "connect.launch", "channel.publish", "channel.subscription_set", "msfile.stat", "msfile.seed.read", "msfile.block.read"];
|
|
640
513
|
type ProtocolMethod = (typeof PROTOCOL_METHODS)[number];
|
|
641
514
|
/**
|
|
642
515
|
* 方法 -> 请求参数类型 的映射。`MethodParams<M>` 是计算出的参数类型。
|
|
@@ -650,19 +523,10 @@ interface MethodParamsMap {
|
|
|
650
523
|
"payment.pay": PaymentPayParams;
|
|
651
524
|
"payment.status": PaymentStatusParams;
|
|
652
525
|
"connect.login": ConnectLoginParams;
|
|
653
|
-
"connect.resume": ConnectResumeParams;
|
|
654
526
|
"connect.logout": ConnectLogoutParams;
|
|
655
527
|
"connect.launch": ConnectLaunchParams;
|
|
656
528
|
"channel.publish": ChannelPublishParams;
|
|
657
529
|
"channel.subscription_set": ChannelSubscriptionSetParams;
|
|
658
|
-
"storage.list": StorageListParams;
|
|
659
|
-
"storage.directory.create": StorageDirectoryParams;
|
|
660
|
-
"storage.directory.delete": StorageDirectoryParams;
|
|
661
|
-
"storage.put": StoragePutParams;
|
|
662
|
-
"storage.encrypted.put": StoragePutParams;
|
|
663
|
-
"storage.get": StorageGetParams;
|
|
664
|
-
"storage.encrypted.get": StorageGetParams;
|
|
665
|
-
"storage.delete": StorageDeleteParams;
|
|
666
530
|
"msfile.stat": MsFileStatParams;
|
|
667
531
|
"msfile.seed.read": MsFileSeedReadParams;
|
|
668
532
|
"msfile.block.read": MsFileBlockReadParams;
|
|
@@ -675,19 +539,10 @@ interface MethodResultMap {
|
|
|
675
539
|
"payment.pay": PaymentPayResult;
|
|
676
540
|
"payment.status": PaymentStatusResult;
|
|
677
541
|
"connect.login": ConnectLoginResult;
|
|
678
|
-
"connect.resume": ConnectResumeResult;
|
|
679
542
|
"connect.logout": ConnectLogoutResult;
|
|
680
543
|
"connect.launch": ConnectLaunchResult;
|
|
681
544
|
"channel.publish": ChannelPublishResult;
|
|
682
545
|
"channel.subscription_set": ChannelSubscriptionSetResult;
|
|
683
|
-
"storage.list": StorageListResult;
|
|
684
|
-
"storage.directory.create": StorageDirectoryResult;
|
|
685
|
-
"storage.directory.delete": StorageDirectoryResult;
|
|
686
|
-
"storage.put": StoragePutResult;
|
|
687
|
-
"storage.encrypted.put": StoragePutResult;
|
|
688
|
-
"storage.get": StorageGetResult;
|
|
689
|
-
"storage.encrypted.get": StorageGetResult;
|
|
690
|
-
"storage.delete": StorageDeleteResult;
|
|
691
546
|
"msfile.stat": MsFileStatResult;
|
|
692
547
|
"msfile.seed.read": MsFileReadResult;
|
|
693
548
|
"msfile.block.read": MsFileReadResult;
|
|
@@ -704,14 +559,6 @@ type ProtocolEventMessage = ProtocolEventPayload & {
|
|
|
704
559
|
networkIdentity: NetworkIdentity;
|
|
705
560
|
bindingId: string;
|
|
706
561
|
};
|
|
707
|
-
/** 暂停恢复控制,不携带钱包选择参数,也不是业务请求重放。 */
|
|
708
|
-
interface ProtocolReconnectMessage {
|
|
709
|
-
v: typeof PROTOCOL_VERSION;
|
|
710
|
-
type: "reconnect";
|
|
711
|
-
id: string;
|
|
712
|
-
authorizationId: string;
|
|
713
|
-
bindingId?: string;
|
|
714
|
-
}
|
|
715
562
|
interface ProtocolRequestMessage<M extends ProtocolMethod = ProtocolMethod> {
|
|
716
563
|
v: typeof PROTOCOL_VERSION;
|
|
717
564
|
type: "request";
|
|
@@ -737,4 +584,4 @@ type ProtocolResultMessage = {
|
|
|
737
584
|
networkIdentity?: NetworkIdentity;
|
|
738
585
|
};
|
|
739
586
|
|
|
740
|
-
export {
|
|
587
|
+
export { MSFILE_MAX_HEADER_BYTES as $, type AiTool as A, type BinaryField as B, type ConnectLoginParams as C, type MsFileBlockReadParams as D, type ProtocolErrorCode as E, AI_TOOLS_MAX_JSON_CHARS as F, type AiToolDefinition as G, type AiToolMessage as H, type IdentityGetParams as I, type AiToolSchema as J, type BsvNetwork as K, type ChannelMessageReceivedEventData as L, type MethodParams as M, type NetworkIdentity as N, type ChannelSubscriptionErrorCode as O, type ProtocolEventMessage as P, type ChannelSubscriptionPhase as Q, type ChannelSubscriptionStatus as R, type ConnectLogoutParams as S, type ConnectPaymentStatus as T, type JSONValue as U, MSFILE_BLOCK_SIZE_BYTES as V, MSFILE_DIGEST_SIZE_BYTES as W, MSFILE_LOCAL_SOURCE_ID as X, MSFILE_MAX_BLOCK_BYTES as Y, MSFILE_MAX_CONTENT_BYTES as Z, MSFILE_MAX_ERROR_MESSAGE_BYTES as _, type AiToolsRegistered as a, MSFILE_MAX_SEED_BYTES as a0, MSFILE_PROTOCOL_ID as a1, type MethodParamsMap as a2, type MethodResultMap as a3, type MsFileLocalSourceStat as a4, type MsFileRemoteSourceStat as a5, type MsFileSatoshiAmount as a6, type MsFileSourceKind as a7, type MsFileSourceStat as a8, type MsFileStatAbsentEntry as a9, validateBsvNetwork as aA, validateNetworkIdentity as aB, validateToolArguments as aC, type MsFileStatAvailableEntry as aa, type MsFileStatDiscoveringEntry as ab, type MsFileStatNetworkErrorEntry as ac, type MsFileStatQuotedEntry as ad, type MsFileSupplierStat as ae, type P2pkhTransferAssetId as af, PROTOCOL_METHODS as ag, PROTOCOL_VERSION as ah, type PaymentOutput as ai, type PaymentReleaseSummary as aj, type ProtocolCancelMessage as ak, type ProtocolClosingMessage as al, type ProtocolError as am, type ProtocolEventName as an, type ProtocolEventPayload as ao, type ProtocolReadyMessage as ap, type ProtocolRequestMessage as aq, type ProtocolResultMessage as ar, type PublicationProof as as, type ResolvedClaimValue as at, assertToolJson as au, assertToolPayload as av, isAiToolMessage as aw, isValidMsFileSourceId as ax, parseToolDefinitions as ay, sameNetworkIdentity as az, type ProtocolMethod as b, type MethodResult as c, type ConnectLoginResult as d, type ConnectLogoutResult as e, type ConnectLaunchParams as f, type ConnectLaunchResult as g, type IdentityGetResult as h, type IntentSignParams as i, type IntentSignResult as j, type CipherEncryptParams as k, type CipherEncryptResult as l, type CipherDecryptParams as m, type CipherDecryptResult as n, type PaymentPayParams as o, type PaymentPayResult as p, type PaymentStatusParams as q, type PaymentStatusResult as r, type ChannelPublishParams as s, type ChannelPublishResult as t, type ChannelSubscriptionSetParams as u, type ChannelSubscriptionSetResult as v, type MsFileStatParams as w, type MsFileStatResult as x, type MsFileSeedReadParams as y, type MsFileReadResult as z };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { G as AiToolDefinition, H as AiToolMessage, J as AiToolSchema, a as AiToolsRegistered, B as BinaryField, K as BsvNetwork, L as ChannelMessageReceivedEventData, s as ChannelPublishParams, t as ChannelPublishResult, O as ChannelSubscriptionErrorCode, Q as ChannelSubscriptionPhase, u as ChannelSubscriptionSetParams, v as ChannelSubscriptionSetResult, R as ChannelSubscriptionStatus, m as CipherDecryptParams, n as CipherDecryptResult, k as CipherEncryptParams, l as CipherEncryptResult, f as ConnectLaunchParams, g as ConnectLaunchResult, C as ConnectLoginParams, d as ConnectLoginResult, S as ConnectLogoutParams, e as ConnectLogoutResult, T as ConnectPaymentStatus, I as IdentityGetParams, h as IdentityGetResult, i as IntentSignParams, j as IntentSignResult, U as JSONValue, V as MSFILE_BLOCK_SIZE_BYTES, W as MSFILE_DIGEST_SIZE_BYTES, X as MSFILE_LOCAL_SOURCE_ID, Y as MSFILE_MAX_BLOCK_BYTES, Z as MSFILE_MAX_CONTENT_BYTES, _ as MSFILE_MAX_ERROR_MESSAGE_BYTES, $ as MSFILE_MAX_HEADER_BYTES, a0 as MSFILE_MAX_SEED_BYTES, a1 as MSFILE_PROTOCOL_ID, M as MethodParams, a2 as MethodParamsMap, c as MethodResult, a3 as MethodResultMap, D as MsFileBlockReadParams, a4 as MsFileLocalSourceStat, z as MsFileReadResult, a5 as MsFileRemoteSourceStat, a6 as MsFileSatoshiAmount, y as MsFileSeedReadParams, a7 as MsFileSourceKind, a8 as MsFileSourceStat, a9 as MsFileStatAbsentEntry, aa as MsFileStatAvailableEntry, ab as MsFileStatDiscoveringEntry, ac as MsFileStatNetworkErrorEntry, w as MsFileStatParams, ad as MsFileStatQuotedEntry, x as MsFileStatResult, ae as MsFileSupplierStat, N as NetworkIdentity, af as P2pkhTransferAssetId, ag as PROTOCOL_METHODS, ah as PROTOCOL_VERSION, ai as PaymentOutput, o as PaymentPayParams, p as PaymentPayResult, aj as PaymentReleaseSummary, q as PaymentStatusParams, r as PaymentStatusResult, ak as ProtocolCancelMessage, al as ProtocolClosingMessage, am as ProtocolError, E as ProtocolErrorCode, P as ProtocolEventMessage, an as ProtocolEventName, ao as ProtocolEventPayload, b as ProtocolMethod, ap as ProtocolReadyMessage, aq as ProtocolRequestMessage, ar as ProtocolResultMessage, as as PublicationProof, at as ResolvedClaimValue, ax as isValidMsFileSourceId, az as sameNetworkIdentity, aA as validateBsvNetwork, aB as validateNetworkIdentity } from './protocol-B7bpi5ro.js';
|
package/dist/protocol.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { MSFILE_BLOCK_SIZE_BYTES, MSFILE_DIGEST_SIZE_BYTES, MSFILE_LOCAL_SOURCE_ID, MSFILE_MAX_BLOCK_BYTES, MSFILE_MAX_CONTENT_BYTES, MSFILE_MAX_ERROR_MESSAGE_BYTES, MSFILE_MAX_HEADER_BYTES, MSFILE_MAX_SEED_BYTES, MSFILE_PROTOCOL_ID, PROTOCOL_METHODS, PROTOCOL_VERSION,
|
|
1
|
+
export { MSFILE_BLOCK_SIZE_BYTES, MSFILE_DIGEST_SIZE_BYTES, MSFILE_LOCAL_SOURCE_ID, MSFILE_MAX_BLOCK_BYTES, MSFILE_MAX_CONTENT_BYTES, MSFILE_MAX_ERROR_MESSAGE_BYTES, MSFILE_MAX_HEADER_BYTES, MSFILE_MAX_SEED_BYTES, MSFILE_PROTOCOL_ID, PROTOCOL_METHODS, PROTOCOL_VERSION, isValidMsFileSourceId, sameNetworkIdentity, validateBsvNetwork, validateNetworkIdentity } from './chunk-D2RL3QGR.js';
|
|
2
2
|
//# sourceMappingURL=protocol.js.map
|
|
3
3
|
//# sourceMappingURL=protocol.js.map
|
package/dist/script.d.ts
CHANGED
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { E as ProtocolErrorCode, af as P2pkhTransferAssetId, aq as ProtocolRequestMessage, N as NetworkIdentity, b as ProtocolMethod, M as MethodParams, H as AiToolMessage, G as AiToolDefinition, U as JSONValue, ar as ProtocolResultMessage, ap as ProtocolReadyMessage, al as ProtocolClosingMessage, c as MethodResult, am as ProtocolError, ao as ProtocolEventPayload } from './protocol-B7bpi5ro.js';
|
|
2
|
+
export { F as AI_TOOLS_MAX_JSON_CHARS, A as AiTool, J as AiToolSchema, a as AiToolsRegistered, au as assertToolJson, av as assertToolPayload, aw as isAiToolMessage, ay as parseToolDefinitions, aC as validateToolArguments } from './protocol-B7bpi5ro.js';
|
|
3
3
|
|
|
4
4
|
/** 校验失败:抛出的对象。service 会捕获并组装 ProtocolError。 */
|
|
5
5
|
declare class ProtocolValidationError extends Error {
|
|
@@ -103,6 +103,8 @@ declare class KeymasterAiToolReceiver {
|
|
|
103
103
|
dispose(): void;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/** Connect v1 接收端。只拥有协议状态,不拥有钱包授权、私钥、余额或持久业务账本。 */
|
|
107
|
+
|
|
106
108
|
/** 窗口对象只作为消息源身份与发送目标;不读取跨源页面内容。 */
|
|
107
109
|
interface ConnectPeer {
|
|
108
110
|
postMessage(message: unknown, targetOrigin: string): void;
|
|
@@ -147,14 +149,10 @@ interface ReceiverRequest<M extends ProtocolMethod = ProtocolMethod> {
|
|
|
147
149
|
readonly walletGeneration: string;
|
|
148
150
|
readonly runGeneration: string;
|
|
149
151
|
readonly bindingId?: string;
|
|
150
|
-
readonly authorizationId?: string;
|
|
151
152
|
readonly signal: AbortSignal;
|
|
152
153
|
}
|
|
153
154
|
/** 判断建立连接的方法;ready 只表示传输可用,不属于身份授权。 */
|
|
154
155
|
declare function isEstablishing(method: string): boolean;
|
|
155
|
-
/** 生产钱包与闭环测试共用同一接收端,不内置测试业务或默认自动授权。 */
|
|
156
|
-
/** 外部恢复控制只携带不透明授权引用,不能夹带业务参数或钱包选择器。 */
|
|
157
|
-
declare function parseReconnectMessage(data: unknown): ProtocolReconnectMessage | null;
|
|
158
156
|
declare class KeymasterConnectReceiver {
|
|
159
157
|
private readonly options;
|
|
160
158
|
private readonly bindings;
|
|
@@ -181,7 +179,7 @@ declare class KeymasterConnectReceiver {
|
|
|
181
179
|
replyError(context: ReceiverRequest, error: ProtocolError): void;
|
|
182
180
|
/** 事件只给当前有效绑定添加接收端上下文;业务发布者不能自报绑定/钱包身份。 */
|
|
183
181
|
sendEvent(target: ConnectPeer, origin: string, event: ProtocolEventPayload): void;
|
|
184
|
-
/**
|
|
182
|
+
/** 只读核对现存瞬时绑定,不创建新连接。 */
|
|
185
183
|
matchesBinding(source: ConnectPeer, origin: string, id: string | undefined): boolean;
|
|
186
184
|
/** ready/closing 只承载生命周期,不携带授权或业务结果。 */
|
|
187
185
|
sendReady(target: ConnectPeer): void;
|
|
@@ -199,4 +197,4 @@ declare class KeymasterConnectReceiver {
|
|
|
199
197
|
private send;
|
|
200
198
|
}
|
|
201
199
|
|
|
202
|
-
export { AiToolDefinition, AiToolMessage, type AiToolReceiverOptions, type ConnectPeer, type ConnectReceiverOptions, KeymasterAiToolReceiver, KeymasterConnectReceiver, OriginValidationError, ProtocolEventPayload, ProtocolValidationError, type ReceiverLifecycle, type ReceiverMessage, type ReceiverPeerPolicy, type ReceiverRequest, assertCanonicalOrigin, assertCompressedPubkeyHex, assertMainnetP2pkhAddress, assertOriginMatches, assertP2pkhAddressForAsset, canonicalOrigin, canonicalizeJson, isEstablishing, isStructuredCloneRequestCandidate, parseCancelMessage, parseEntryUrl,
|
|
200
|
+
export { AiToolDefinition, AiToolMessage, type AiToolReceiverOptions, type ConnectPeer, type ConnectReceiverOptions, KeymasterAiToolReceiver, KeymasterConnectReceiver, OriginValidationError, ProtocolEventPayload, ProtocolValidationError, type ReceiverLifecycle, type ReceiverMessage, type ReceiverPeerPolicy, type ReceiverRequest, assertCanonicalOrigin, assertCompressedPubkeyHex, assertMainnetP2pkhAddress, assertOriginMatches, assertP2pkhAddressForAsset, canonicalOrigin, canonicalizeJson, isEstablishing, isStructuredCloneRequestCandidate, parseCancelMessage, parseEntryUrl, parseRequestMessage, validateExactChannel };
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAiToolMessage, parseToolDefinitions, validateToolArguments, assertToolPayload, validatePublicationProof } from './chunk-M2YEI4PG.js';
|
|
2
2
|
export { AI_TOOLS_MAX_JSON_CHARS, assertToolJson, assertToolPayload, isAiToolMessage, parseToolDefinitions, validateToolArguments } from './chunk-M2YEI4PG.js';
|
|
3
|
-
import { PROTOCOL_VERSION, PROTOCOL_METHODS, validateNetworkIdentity, sameNetworkIdentity,
|
|
3
|
+
import { PROTOCOL_VERSION, PROTOCOL_METHODS, validateNetworkIdentity, sameNetworkIdentity, isValidMsFileSourceId } from './chunk-D2RL3QGR.js';
|
|
4
4
|
|
|
5
5
|
// src/validation.ts
|
|
6
6
|
var ProtocolValidationError = class extends Error {
|
|
@@ -125,12 +125,6 @@ function validateConnectLoginParams(raw) {
|
|
|
125
125
|
}
|
|
126
126
|
return publicationProof === void 0 ? { text, claims } : { text, claims, publicationProof };
|
|
127
127
|
}
|
|
128
|
-
function validateConnectResumeParams(raw) {
|
|
129
|
-
const obj = expectObject(raw, "connect.resume params");
|
|
130
|
-
for (const field of Object.keys(obj))
|
|
131
|
-
throw new ProtocolValidationError("invalid_request", "connect.resume contains an unsupported field");
|
|
132
|
-
return {};
|
|
133
|
-
}
|
|
134
128
|
function validateConnectLogoutParams(raw) {
|
|
135
129
|
expectObject(raw, "connect.logout params");
|
|
136
130
|
return {};
|
|
@@ -216,107 +210,6 @@ function requireExactKeys(obj, keys, name) {
|
|
|
216
210
|
throw new ProtocolValidationError("invalid_request", `${name} contains unsupported fields`);
|
|
217
211
|
}
|
|
218
212
|
}
|
|
219
|
-
var STORAGE_FORBIDDEN_FIELDS = [
|
|
220
|
-
"appPublicKeyHex",
|
|
221
|
-
"appPublicKey",
|
|
222
|
-
"publicationProof",
|
|
223
|
-
"appProof",
|
|
224
|
-
"publisherPublicKeyHex",
|
|
225
|
-
"publisherPublicKey",
|
|
226
|
-
"appId",
|
|
227
|
-
"appName",
|
|
228
|
-
"appIdentity",
|
|
229
|
-
"namespaceRoot",
|
|
230
|
-
"bucket",
|
|
231
|
-
"endpoint",
|
|
232
|
-
"providerId",
|
|
233
|
-
"s3Key",
|
|
234
|
-
"s3UploadId",
|
|
235
|
-
"accessKeyId",
|
|
236
|
-
"secretAccessKey"
|
|
237
|
-
];
|
|
238
|
-
function storageObject(raw, name) {
|
|
239
|
-
const obj = expectObject(raw, name);
|
|
240
|
-
for (const field of STORAGE_FORBIDDEN_FIELDS) {
|
|
241
|
-
if (Object.prototype.hasOwnProperty.call(obj, field))
|
|
242
|
-
throw new ProtocolValidationError("invalid_request", `${name} contains a forbidden field`);
|
|
243
|
-
}
|
|
244
|
-
return obj;
|
|
245
|
-
}
|
|
246
|
-
function storagePath(value, field, allowEmpty = false) {
|
|
247
|
-
const path = expectString(value, field);
|
|
248
|
-
if (!allowEmpty && path.length === 0)
|
|
249
|
-
throw new ProtocolValidationError("invalid_request", `${field} must not be empty`);
|
|
250
|
-
const withoutTrailingSlash = path.endsWith("/") ? path.slice(0, -1) : path;
|
|
251
|
-
if (path.length > 1024 || path.startsWith("/") || path.includes("\\") || path.includes("\0") || /[\u0000-\u001f\u007f]/u.test(path) || /[\u2044\u2215\u29f8\uff0f]/u.test(path)) {
|
|
252
|
-
throw new ProtocolValidationError("invalid_request", `${field} is not a valid relative path`);
|
|
253
|
-
}
|
|
254
|
-
const segments = withoutTrailingSlash.split("/");
|
|
255
|
-
if (!withoutTrailingSlash && !allowEmpty || withoutTrailingSlash && segments.some((segment) => !segment || segment === "." || segment === ".." || segment.length > 255)) {
|
|
256
|
-
throw new ProtocolValidationError("invalid_request", `${field} is not a valid relative path`);
|
|
257
|
-
}
|
|
258
|
-
return path;
|
|
259
|
-
}
|
|
260
|
-
function storageBinary(value, field) {
|
|
261
|
-
const binary = parseBinaryField(value, field);
|
|
262
|
-
if (binary.bytes.byteLength > STORAGE_MAX_PAYLOAD_BYTES) {
|
|
263
|
-
throw new ProtocolValidationError("storage_limit_exceeded", `${field} exceeds the maximum payload size`);
|
|
264
|
-
}
|
|
265
|
-
return binary;
|
|
266
|
-
}
|
|
267
|
-
function validateStorageListParams(raw) {
|
|
268
|
-
const obj = storageObject(raw, "storage.list params");
|
|
269
|
-
const prefix = obj.prefix === void 0 ? "" : storagePath(obj.prefix, "prefix", true);
|
|
270
|
-
const cursor = obj.cursor === void 0 ? void 0 : expectNonEmptyString(obj.cursor, "cursor");
|
|
271
|
-
const limit = obj.limit === void 0 ? STORAGE_DEFAULT_LIST_LIMIT : obj.limit;
|
|
272
|
-
if (typeof limit !== "number" || !Number.isInteger(limit) || limit < 1 || limit > STORAGE_MAX_LIST_LIMIT) {
|
|
273
|
-
throw new ProtocolValidationError("invalid_request", "limit must be between 1 and 1000");
|
|
274
|
-
}
|
|
275
|
-
return { prefix, cursor, limit };
|
|
276
|
-
}
|
|
277
|
-
function validateStorageDirectoryParams(raw, name, allowOverwrite) {
|
|
278
|
-
const obj = storageObject(raw, `${name} params`);
|
|
279
|
-
const path = storagePath(obj.path, "path");
|
|
280
|
-
const overwrite = obj.overwrite === void 0 ? void 0 : obj.overwrite;
|
|
281
|
-
if (overwrite !== void 0 && typeof overwrite !== "boolean")
|
|
282
|
-
throw new ProtocolValidationError("invalid_request", "overwrite must be boolean");
|
|
283
|
-
return allowOverwrite ? { path, overwrite } : { path };
|
|
284
|
-
}
|
|
285
|
-
function validateStoragePutParams(raw) {
|
|
286
|
-
const obj = storageObject(raw, "storage.put params");
|
|
287
|
-
const path = storagePath(obj.path, "path");
|
|
288
|
-
if (path.endsWith("/"))
|
|
289
|
-
throw new ProtocolValidationError("invalid_request", "object path must not end with '/'");
|
|
290
|
-
const content = storageBinary(obj.content, "content");
|
|
291
|
-
const contentType = obj.contentType === void 0 ? void 0 : expectString(obj.contentType, "contentType");
|
|
292
|
-
const overwrite = obj.overwrite === void 0 ? void 0 : obj.overwrite;
|
|
293
|
-
if (overwrite !== void 0 && typeof overwrite !== "boolean")
|
|
294
|
-
throw new ProtocolValidationError("invalid_request", "overwrite must be boolean");
|
|
295
|
-
return { path, content, contentType, overwrite };
|
|
296
|
-
}
|
|
297
|
-
function validateStorageGetParams(raw) {
|
|
298
|
-
const obj = storageObject(raw, "storage.get params");
|
|
299
|
-
const path = storagePath(obj.path, "path");
|
|
300
|
-
if (path.endsWith("/"))
|
|
301
|
-
throw new ProtocolValidationError("invalid_request", "object path must not end with '/'");
|
|
302
|
-
const offset = obj.offset === void 0 ? 0 : obj.offset;
|
|
303
|
-
const length = obj.length === void 0 ? STORAGE_MAX_PAYLOAD_BYTES : obj.length;
|
|
304
|
-
if (typeof offset !== "number" || !Number.isSafeInteger(offset) || offset < 0)
|
|
305
|
-
throw new ProtocolValidationError("invalid_request", "offset must be a non-negative safe integer");
|
|
306
|
-
if (typeof length !== "number" || !Number.isSafeInteger(length) || length < 1 || length > STORAGE_MAX_PAYLOAD_BYTES)
|
|
307
|
-
throw new ProtocolValidationError("storage_limit_exceeded", "length exceeds the maximum payload size");
|
|
308
|
-
if (offset > Number.MAX_SAFE_INTEGER - (length - 1))
|
|
309
|
-
throw new ProtocolValidationError("storage_limit_exceeded", "requested range exceeds safe integer bounds");
|
|
310
|
-
const ifMatch = obj.ifMatch === void 0 ? void 0 : expectString(obj.ifMatch, "ifMatch");
|
|
311
|
-
return { path, offset, length, ifMatch };
|
|
312
|
-
}
|
|
313
|
-
function validateStorageDeleteParams(raw) {
|
|
314
|
-
const obj = storageObject(raw, "storage.delete params");
|
|
315
|
-
const path = storagePath(obj.path, "path");
|
|
316
|
-
if (path.endsWith("/"))
|
|
317
|
-
throw new ProtocolValidationError("invalid_request", "object path must not end with '/'");
|
|
318
|
-
return { path };
|
|
319
|
-
}
|
|
320
213
|
var MSFILE_FORBIDDEN_FIELDS = [
|
|
321
214
|
"appPublicKeyHex",
|
|
322
215
|
"appPublicKey",
|
|
@@ -527,9 +420,6 @@ function parseRequestMessage(raw, receiverIdentity) {
|
|
|
527
420
|
case "connect.login":
|
|
528
421
|
normalized = validateConnectLoginParams(params);
|
|
529
422
|
break;
|
|
530
|
-
case "connect.resume":
|
|
531
|
-
normalized = validateConnectResumeParams(params);
|
|
532
|
-
break;
|
|
533
423
|
case "connect.logout":
|
|
534
424
|
normalized = validateConnectLogoutParams(params);
|
|
535
425
|
break;
|
|
@@ -560,26 +450,6 @@ function parseRequestMessage(raw, receiverIdentity) {
|
|
|
560
450
|
case "channel.subscription_set":
|
|
561
451
|
normalized = validateChannelSubscriptionSetParams(params);
|
|
562
452
|
break;
|
|
563
|
-
case "storage.list":
|
|
564
|
-
normalized = validateStorageListParams(params);
|
|
565
|
-
break;
|
|
566
|
-
case "storage.directory.create":
|
|
567
|
-
normalized = validateStorageDirectoryParams(params, method, true);
|
|
568
|
-
break;
|
|
569
|
-
case "storage.directory.delete":
|
|
570
|
-
normalized = validateStorageDirectoryParams(params, method, false);
|
|
571
|
-
break;
|
|
572
|
-
case "storage.encrypted.put":
|
|
573
|
-
case "storage.put":
|
|
574
|
-
normalized = validateStoragePutParams(params);
|
|
575
|
-
break;
|
|
576
|
-
case "storage.encrypted.get":
|
|
577
|
-
case "storage.get":
|
|
578
|
-
normalized = validateStorageGetParams(params);
|
|
579
|
-
break;
|
|
580
|
-
case "storage.delete":
|
|
581
|
-
normalized = validateStorageDeleteParams(params);
|
|
582
|
-
break;
|
|
583
453
|
case "msfile.stat":
|
|
584
454
|
normalized = validateMsFileStatParams(params);
|
|
585
455
|
break;
|
|
@@ -775,13 +645,7 @@ var KeymasterAiToolReceiver = class {
|
|
|
775
645
|
|
|
776
646
|
// src/server.ts
|
|
777
647
|
function isEstablishing(method) {
|
|
778
|
-
return ["connect.login", "connect.
|
|
779
|
-
}
|
|
780
|
-
function parseReconnectMessage(data) {
|
|
781
|
-
if (!data || typeof data !== "object") return null;
|
|
782
|
-
const value = data;
|
|
783
|
-
if (value.v !== PROTOCOL_VERSION || value.type !== "reconnect" || typeof value.id !== "string" || !value.id || value.id.length > 128 || typeof value.authorizationId !== "string" || !value.authorizationId || value.authorizationId.length > 128 || value.bindingId !== void 0 && typeof value.bindingId !== "string" || Object.keys(value).some((key) => !["v", "type", "id", "authorizationId", "bindingId"].includes(key))) return null;
|
|
784
|
-
return value;
|
|
648
|
+
return ["connect.login", "connect.launch"].includes(method);
|
|
785
649
|
}
|
|
786
650
|
var KeymasterConnectReceiver = class {
|
|
787
651
|
constructor(options) {
|
|
@@ -818,8 +682,7 @@ var KeymasterConnectReceiver = class {
|
|
|
818
682
|
/** 校验并签发请求上下文。重复在途 ID 被忽略;非法可信请求返回标准错误。 */
|
|
819
683
|
async accept(event) {
|
|
820
684
|
if (!this.isAllowedPeer(event)) return null;
|
|
821
|
-
const
|
|
822
|
-
const raw = reconnect ? { v: PROTOCOL_VERSION, type: "request", id: reconnect.id, method: "connect.resume", params: {} } : event.data;
|
|
685
|
+
const raw = event.data;
|
|
823
686
|
if (!raw || typeof raw !== "object" || raw.type !== "request") return null;
|
|
824
687
|
if (typeof raw.id === "string" && this.pending.get(event.source)?.has(raw.id)) return null;
|
|
825
688
|
try {
|
|
@@ -853,7 +716,6 @@ var KeymasterConnectReceiver = class {
|
|
|
853
716
|
walletGeneration: before.walletGeneration,
|
|
854
717
|
runGeneration: before.runGeneration,
|
|
855
718
|
bindingId: establishing ? void 0 : binding.id,
|
|
856
|
-
...reconnect ? { authorizationId: reconnect.authorizationId } : {},
|
|
857
719
|
signal: abort.signal
|
|
858
720
|
});
|
|
859
721
|
this.isAllowedPeer(event, true);
|
|
@@ -899,14 +761,8 @@ var KeymasterConnectReceiver = class {
|
|
|
899
761
|
const connected = result;
|
|
900
762
|
if (!sameNetworkIdentity(validateNetworkIdentity(connected.networkIdentity), context.networkIdentity) || "walletPublicKeyHex" in connected || "ownerPublicKeyHex" in connected) throw new ProtocolValidationError("invalid_request", "Invalid public connection result");
|
|
901
763
|
publicResult = { ...result, networkIdentity: context.networkIdentity };
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
if (reusable) {
|
|
905
|
-
bindingId = existing.id;
|
|
906
|
-
} else {
|
|
907
|
-
bindingId = this.options.randomUUID?.() || crypto.randomUUID();
|
|
908
|
-
this.bindings.set(context.source, { id: bindingId, origin: context.origin, identity: context.networkIdentity, walletGeneration: context.walletGeneration, runGeneration: context.runGeneration });
|
|
909
|
-
}
|
|
764
|
+
bindingId = this.options.randomUUID?.() || crypto.randomUUID();
|
|
765
|
+
this.bindings.set(context.source, { id: bindingId, origin: context.origin, identity: context.networkIdentity, walletGeneration: context.walletGeneration, runGeneration: context.runGeneration });
|
|
910
766
|
}
|
|
911
767
|
this.finish(context);
|
|
912
768
|
if (context.method === "connect.logout") this.bindings.delete(context.source);
|
|
@@ -928,7 +784,7 @@ var KeymasterConnectReceiver = class {
|
|
|
928
784
|
} catch {
|
|
929
785
|
}
|
|
930
786
|
}
|
|
931
|
-
/**
|
|
787
|
+
/** 只读核对现存瞬时绑定,不创建新连接。 */
|
|
932
788
|
matchesBinding(source, origin, id) {
|
|
933
789
|
const binding = this.bindings.get(source), lifecycle = this.options.lifecycle();
|
|
934
790
|
return !!binding && binding.id === id && binding.origin === origin && binding.walletGeneration === lifecycle.walletGeneration && binding.runGeneration === lifecycle.runGeneration && this.isAllowedPeer({ source, origin, data: null });
|
|
@@ -983,6 +839,6 @@ var KeymasterConnectReceiver = class {
|
|
|
983
839
|
}
|
|
984
840
|
};
|
|
985
841
|
|
|
986
|
-
export { KeymasterAiToolReceiver, KeymasterConnectReceiver, OriginValidationError, ProtocolValidationError, assertCanonicalOrigin, assertCompressedPubkeyHex, assertMainnetP2pkhAddress, assertOriginMatches, assertP2pkhAddressForAsset, canonicalOrigin, canonicalizeJson, isEstablishing, isStructuredCloneRequestCandidate, parseCancelMessage, parseEntryUrl,
|
|
842
|
+
export { KeymasterAiToolReceiver, KeymasterConnectReceiver, OriginValidationError, ProtocolValidationError, assertCanonicalOrigin, assertCompressedPubkeyHex, assertMainnetP2pkhAddress, assertOriginMatches, assertP2pkhAddressForAsset, canonicalOrigin, canonicalizeJson, isEstablishing, isStructuredCloneRequestCandidate, parseCancelMessage, parseEntryUrl, parseRequestMessage, validateExactChannel };
|
|
987
843
|
//# sourceMappingURL=server.js.map
|
|
988
844
|
//# sourceMappingURL=server.js.map
|