keymaster-connect 0.0.0-stage → 0.1.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 +661 -0
- package/README.md +37 -2
- package/dist/chunk-JDAJD3SX.js +66 -0
- package/dist/chunk-JDAJD3SX.js.map +1 -0
- package/dist/index.d.ts +345 -0
- package/dist/index.js +655 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +682 -0
- package/dist/protocol.js +3 -0
- package/dist/protocol.js.map +1 -0
- package/dist/server.d.ts +162 -0
- package/dist/server.js +985 -0
- package/dist/server.js.map +1 -0
- package/package.json +32 -4
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
/** Connect v1 公开契约。独立于钱包内部执行 DTO、能力框架和持久化。 */
|
|
2
|
+
/** 身份网络在创建/导入时确定;公钥相同也不能跨网复用业务身份。 */
|
|
3
|
+
type BsvNetwork = "main" | "test";
|
|
4
|
+
interface NetworkIdentity {
|
|
5
|
+
readonly bsvNetwork: BsvNetwork;
|
|
6
|
+
readonly publicKeyHex: string;
|
|
7
|
+
}
|
|
8
|
+
declare function validateBsvNetwork(value: unknown): BsvNetwork;
|
|
9
|
+
declare function validateNetworkIdentity(value: unknown): NetworkIdentity;
|
|
10
|
+
declare function sameNetworkIdentity(left: NetworkIdentity, right: NetworkIdentity): boolean;
|
|
11
|
+
type AppRequirement = "private-key" | "storage";
|
|
12
|
+
interface AppIdentityProofV1 {
|
|
13
|
+
version: 1;
|
|
14
|
+
publisherPublicKey: string;
|
|
15
|
+
app: {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
requirements: AppRequirement[];
|
|
21
|
+
signature: string;
|
|
22
|
+
}
|
|
23
|
+
interface VerifiedAppIdentity {
|
|
24
|
+
version: 1;
|
|
25
|
+
publisherPublicKeyHex: string;
|
|
26
|
+
appId: string;
|
|
27
|
+
appName: string;
|
|
28
|
+
identityDigestHex: string;
|
|
29
|
+
}
|
|
30
|
+
type AppIdentitySnapshot = VerifiedAppIdentity;
|
|
31
|
+
/** ChannelProtocol/SSP 共用的递归 JSON 值。 */
|
|
32
|
+
type JSONValue = null | boolean | number | string | JSONValue[] | {
|
|
33
|
+
[key: string]: JSONValue;
|
|
34
|
+
};
|
|
35
|
+
interface ChannelPublishParams {
|
|
36
|
+
/** 要发布到的 SSP 精确频道;不允许通配符。 */
|
|
37
|
+
channel: string;
|
|
38
|
+
/** App 自己定义的 JSON 内容;协议标识也应放在这里。 */
|
|
39
|
+
content: JSONValue;
|
|
40
|
+
}
|
|
41
|
+
interface ChannelPublishResult {
|
|
42
|
+
/** 由 Keymaster/ChannelProtocol 生成的消息编号。 */
|
|
43
|
+
messageId: string;
|
|
44
|
+
/**
|
|
45
|
+
* 出站签名明文的精确字节(已签名、未加密);只有私密发布返回。
|
|
46
|
+
* 调用方可把它作为出站证据原样保存,不需要也不允许重新签名。
|
|
47
|
+
*/
|
|
48
|
+
signedMessage?: Uint8Array;
|
|
49
|
+
}
|
|
50
|
+
interface ChannelSubscriptionSetParams {
|
|
51
|
+
/** 替换当前 caller 的完整精确频道集合;空数组表示释放全部订阅。 */
|
|
52
|
+
channels: string[];
|
|
53
|
+
}
|
|
54
|
+
interface ChannelSubscriptionSetResult {
|
|
55
|
+
/** Coordinator 已接受的当前 caller 逻辑期望集合;不代表 Supplier 物理订阅已完成。 */
|
|
56
|
+
channels: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Coordinator/Mux 返回的当前物理状态快照。
|
|
59
|
+
* 旧 runtime 可以省略该字段;当前 Coordinator 会为每个 accepted
|
|
60
|
+
* channel 返回一份权威快照,使新 caller 不必等待下一次状态事件。
|
|
61
|
+
*/
|
|
62
|
+
statuses?: ChannelSubscriptionStatus[];
|
|
63
|
+
}
|
|
64
|
+
/** 当前 caller union 在 Coordinator/SSP 侧的物理订阅阶段。 */
|
|
65
|
+
type ChannelSubscriptionPhase = "idle" | "subscribing" | "subscribed" | "retrying" | "blocked";
|
|
66
|
+
/** 订阅失败的稳定业务错误码;不得把底层异常/堆栈直接暴露给插件。 */
|
|
67
|
+
type ChannelSubscriptionErrorCode = "config" | "connect" | "identity" | "protocol" | "balance" | "unknown_result" | "validation" | "unavailable" | "conflict";
|
|
68
|
+
interface ChannelSubscriptionStatus {
|
|
69
|
+
channel: string;
|
|
70
|
+
phase: ChannelSubscriptionPhase;
|
|
71
|
+
errorCode: ChannelSubscriptionErrorCode | null;
|
|
72
|
+
errorMessage: string | null;
|
|
73
|
+
updatedAtMs: number;
|
|
74
|
+
}
|
|
75
|
+
interface ChannelMessageReceivedEventData {
|
|
76
|
+
/** 实际收到的精确频道。 */
|
|
77
|
+
channel: string;
|
|
78
|
+
/** ChannelProtocol 验签得到的作者压缩公钥 hex。 */
|
|
79
|
+
publisherPublicKeyHex: string;
|
|
80
|
+
/** ChannelProtocol 消息编号。 */
|
|
81
|
+
messageId: string;
|
|
82
|
+
/** 已验签的 App JSON 内容。 */
|
|
83
|
+
content: JSONValue;
|
|
84
|
+
/**
|
|
85
|
+
* 入站私密消息的加密信封精确字节(受信任插件用于原样留证)。
|
|
86
|
+
* 公共消息或旧 Coordinator 可以省略。
|
|
87
|
+
*/
|
|
88
|
+
rawEnvelope?: Uint8Array;
|
|
89
|
+
}
|
|
90
|
+
interface StorageListParams {
|
|
91
|
+
/** 目录前缀。 */
|
|
92
|
+
prefix?: string;
|
|
93
|
+
/** 分页游标。 */
|
|
94
|
+
cursor?: string;
|
|
95
|
+
/** 每页数量。 */
|
|
96
|
+
limit?: number;
|
|
97
|
+
}
|
|
98
|
+
interface StorageListEntry {
|
|
99
|
+
/** Connect 可见的相对路径。 */
|
|
100
|
+
path: string;
|
|
101
|
+
/** 当前目录下的文件名。 */
|
|
102
|
+
name: string;
|
|
103
|
+
/** 文件大小(字节)。 */
|
|
104
|
+
size: number;
|
|
105
|
+
/** 抽象版本标签。 */
|
|
106
|
+
revision?: string;
|
|
107
|
+
/** 最后修改时间。 */
|
|
108
|
+
lastModified?: string;
|
|
109
|
+
}
|
|
110
|
+
interface StorageListResult {
|
|
111
|
+
/** 当前目录前缀。 */
|
|
112
|
+
prefix: string;
|
|
113
|
+
/** 父目录前缀。 */
|
|
114
|
+
parentPrefix: string;
|
|
115
|
+
/** 虚拟目录列表。 */
|
|
116
|
+
directories: Array<{
|
|
117
|
+
path: string;
|
|
118
|
+
name: string;
|
|
119
|
+
}>;
|
|
120
|
+
/** 当前页文件。 */
|
|
121
|
+
files: StorageListEntry[];
|
|
122
|
+
/** 目录 marker 路径。 */
|
|
123
|
+
markerPath?: string;
|
|
124
|
+
/** 下一页游标。 */
|
|
125
|
+
nextCursor?: string;
|
|
126
|
+
}
|
|
127
|
+
interface StorageDirectoryParams {
|
|
128
|
+
/** 目录路径。 */
|
|
129
|
+
path: string;
|
|
130
|
+
/** 是否允许覆盖已有 marker。 */
|
|
131
|
+
overwrite?: boolean;
|
|
132
|
+
}
|
|
133
|
+
interface StorageDirectoryResult {
|
|
134
|
+
/** 目录路径。 */
|
|
135
|
+
path: string;
|
|
136
|
+
/** 是否创建。 */
|
|
137
|
+
created?: boolean;
|
|
138
|
+
/** 是否删除。 */
|
|
139
|
+
deleted?: boolean;
|
|
140
|
+
}
|
|
141
|
+
interface StoragePutParams {
|
|
142
|
+
/** 文件路径。 */
|
|
143
|
+
path: string;
|
|
144
|
+
/** 二进制文件内容。 */
|
|
145
|
+
content: BinaryField;
|
|
146
|
+
/** MIME 类型。 */
|
|
147
|
+
contentType?: string;
|
|
148
|
+
/** 是否覆盖已有对象。 */
|
|
149
|
+
overwrite?: boolean;
|
|
150
|
+
}
|
|
151
|
+
interface StoragePutResult {
|
|
152
|
+
/** 文件路径。 */
|
|
153
|
+
path: string;
|
|
154
|
+
/** 写入大小(字节)。 */
|
|
155
|
+
size: number;
|
|
156
|
+
/** 抽象版本标签。 */
|
|
157
|
+
revision?: string;
|
|
158
|
+
/** 写入时间戳(毫秒)。 */
|
|
159
|
+
updatedAt: number;
|
|
160
|
+
}
|
|
161
|
+
interface StorageGetParams {
|
|
162
|
+
/** 文件路径。 */
|
|
163
|
+
path: string;
|
|
164
|
+
/** 起始偏移(字节)。 */
|
|
165
|
+
offset?: number;
|
|
166
|
+
/** 读取长度(字节)。 */
|
|
167
|
+
length?: number;
|
|
168
|
+
/** 期望的抽象版本标签。 */
|
|
169
|
+
ifMatch?: string;
|
|
170
|
+
}
|
|
171
|
+
interface StorageGetResult {
|
|
172
|
+
/** 文件路径。 */
|
|
173
|
+
path: string;
|
|
174
|
+
/** 二进制内容。 */
|
|
175
|
+
content: BinaryField;
|
|
176
|
+
/** MIME 类型。 */
|
|
177
|
+
contentType?: string;
|
|
178
|
+
/** 实际起始偏移。 */
|
|
179
|
+
offset: number;
|
|
180
|
+
/** 文件总大小(字节)。 */
|
|
181
|
+
totalSize: number;
|
|
182
|
+
/** 是否已读到文件结尾。 */
|
|
183
|
+
eof: boolean;
|
|
184
|
+
/** 抽象版本标签。 */
|
|
185
|
+
revision?: string;
|
|
186
|
+
/** 最后修改时间。 */
|
|
187
|
+
lastModified?: string;
|
|
188
|
+
}
|
|
189
|
+
interface StorageDeleteParams {
|
|
190
|
+
/** 文件路径。 */
|
|
191
|
+
path: string;
|
|
192
|
+
}
|
|
193
|
+
interface StorageDeleteResult {
|
|
194
|
+
/** 文件路径。 */
|
|
195
|
+
path: string;
|
|
196
|
+
/** 固定成功标记。 */
|
|
197
|
+
deleted: true;
|
|
198
|
+
/** 删除时间戳(毫秒)。 */
|
|
199
|
+
updatedAt: number;
|
|
200
|
+
}
|
|
201
|
+
/** K-V 引擎的硬限制;字段名和单位均在此集中定义。 */
|
|
202
|
+
declare const STORAGE_MAX_PAYLOAD_BYTES: number;
|
|
203
|
+
declare const STORAGE_DEFAULT_LIST_LIMIT = 200;
|
|
204
|
+
declare const STORAGE_MAX_LIST_LIMIT = 1000;
|
|
205
|
+
/** libp2p protocol ID;wire 真值来自 MSFile Proxy Wire Messages v1。 */
|
|
206
|
+
declare const MSFILE_PROTOCOL_ID = "/msfile/1.0.0";
|
|
207
|
+
/** Frame / 内容硬上限。与 wire 规范一致,两层共同执行。 */
|
|
208
|
+
declare const MSFILE_MAX_HEADER_BYTES = 65536;
|
|
209
|
+
declare const MSFILE_MAX_SEED_BYTES: number;
|
|
210
|
+
declare const MSFILE_MAX_BLOCK_BYTES: number;
|
|
211
|
+
declare const MSFILE_MAX_CONTENT_BYTES: number;
|
|
212
|
+
declare const MSFILE_MAX_ERROR_MESSAGE_BYTES = 1024;
|
|
213
|
+
declare const MSFILE_BLOCK_SIZE_BYTES: number;
|
|
214
|
+
declare const MSFILE_DIGEST_SIZE_BYTES = 32;
|
|
215
|
+
/** 单个内容对象的最高金额。规范十进制字符串:"0" 表示显式不限。 */
|
|
216
|
+
type MsFileSatoshiAmount = string;
|
|
217
|
+
/** Keymaster 内置本地 BitFS 来源的稳定路由标识。 */
|
|
218
|
+
declare const MSFILE_LOCAL_SOURCE_ID = "local-bitfs";
|
|
219
|
+
/** MSFile 来源类型;本地来源不经过 `/msfile/1.0.0`。 */
|
|
220
|
+
type MsFileSourceKind = "local-bitfs" | "remote-proxy";
|
|
221
|
+
/** 校验 MSFile 来源路由标识;拒绝路径字符和无界文本。 */
|
|
222
|
+
declare function isValidMsFileSourceId(input: unknown): input is string;
|
|
223
|
+
interface MsFileStatParams {
|
|
224
|
+
seedHashHex: string;
|
|
225
|
+
}
|
|
226
|
+
interface MsFileStatAvailableEntry {
|
|
227
|
+
supplierPublicKeyHex: string;
|
|
228
|
+
status: "available";
|
|
229
|
+
recommendedFilename: string;
|
|
230
|
+
/** 十进制字符串形式的 uint64 字节数。 */
|
|
231
|
+
fileSizeBytes: MsFileSatoshiAmount;
|
|
232
|
+
mediaType: string;
|
|
233
|
+
}
|
|
234
|
+
interface MsFileStatAbsentEntry {
|
|
235
|
+
supplierPublicKeyHex: string;
|
|
236
|
+
status: "absent";
|
|
237
|
+
}
|
|
238
|
+
interface MsFileStatDiscoveringEntry {
|
|
239
|
+
supplierPublicKeyHex: string;
|
|
240
|
+
status: "discovering";
|
|
241
|
+
retryAfterMs: number;
|
|
242
|
+
}
|
|
243
|
+
interface MsFileStatQuotedEntry {
|
|
244
|
+
supplierPublicKeyHex: string;
|
|
245
|
+
status: "quoted";
|
|
246
|
+
recommendedFilename: string;
|
|
247
|
+
fileSizeBytes: MsFileSatoshiAmount;
|
|
248
|
+
mediaType: string;
|
|
249
|
+
minSeedPriceSatoshis: MsFileSatoshiAmount;
|
|
250
|
+
maxSeedPriceSatoshis: MsFileSatoshiAmount;
|
|
251
|
+
minFullBlockPriceSatoshis: MsFileSatoshiAmount;
|
|
252
|
+
maxFullBlockPriceSatoshis: MsFileSatoshiAmount;
|
|
253
|
+
}
|
|
254
|
+
interface MsFileStatNetworkErrorEntry {
|
|
255
|
+
supplierPublicKeyHex: string;
|
|
256
|
+
status: "network-error";
|
|
257
|
+
}
|
|
258
|
+
type MsFileSupplierStat = MsFileStatAvailableEntry | MsFileStatAbsentEntry | MsFileStatDiscoveringEntry | MsFileStatQuotedEntry | MsFileStatNetworkErrorEntry;
|
|
259
|
+
/** 远程 Proxy 结果补充来源路由信息后的公共视图。 */ type MsFileRemoteSourceStat<T> = T extends MsFileSupplierStat ? T & {
|
|
260
|
+
sourceId: string; /** 固定为远程 Proxy。 */
|
|
261
|
+
sourceKind: "remote-proxy";
|
|
262
|
+
} : never;
|
|
263
|
+
/** local 结果没有远程供应商公钥,不能用假公钥占位。 */ type MsFileLocalSourceStat<T> = T extends MsFileSupplierStat ? Omit<T, "supplierPublicKeyHex"> & {
|
|
264
|
+
sourceId: typeof MSFILE_LOCAL_SOURCE_ID; /** 固定为本地 BitFS。 */
|
|
265
|
+
sourceKind: "local-bitfs";
|
|
266
|
+
} : never;
|
|
267
|
+
/** 统一 MSFile API 返回的 local/remote 来源状态。 */
|
|
268
|
+
type MsFileSourceStat = MsFileRemoteSourceStat<MsFileSupplierStat> | MsFileLocalSourceStat<MsFileSupplierStat>;
|
|
269
|
+
interface MsFileStatResult {
|
|
270
|
+
seedHashHex: string;
|
|
271
|
+
/** 所有本地与远程来源;本地来源固定排在第一位。 */
|
|
272
|
+
sources: MsFileSourceStat[];
|
|
273
|
+
}
|
|
274
|
+
interface MsFileSeedReadParams {
|
|
275
|
+
/** 要读取的来源路由标识。 */
|
|
276
|
+
sourceId: string;
|
|
277
|
+
seedHashHex: string;
|
|
278
|
+
}
|
|
279
|
+
interface MsFileBlockReadParams {
|
|
280
|
+
/** 要读取的来源路由标识。 */
|
|
281
|
+
sourceId: string;
|
|
282
|
+
/** Block 所属 Seed;remote wire 不发送该字段。 */
|
|
283
|
+
seedHashHex: string;
|
|
284
|
+
blockHashHex: string;
|
|
285
|
+
}
|
|
286
|
+
interface MsFileReadResult {
|
|
287
|
+
contentHashHex: string;
|
|
288
|
+
content: BinaryField;
|
|
289
|
+
}
|
|
290
|
+
interface BinaryField {
|
|
291
|
+
/** 固定 "binary"。缺省 / 其它值一律拒绝。 */
|
|
292
|
+
$type: "binary";
|
|
293
|
+
/** 真实字节;`structured clone` 会原样传过去。 */
|
|
294
|
+
bytes: ArrayBuffer;
|
|
295
|
+
/** 可选的内容类型;密文 / 图片 / 文件等有明确类型时填写。 */
|
|
296
|
+
mime?: string;
|
|
297
|
+
}
|
|
298
|
+
/** 协议版本号;当前固定为 1。 */
|
|
299
|
+
declare const PROTOCOL_VERSION = 1;
|
|
300
|
+
/**
|
|
301
|
+
* 协议错误码。`error.message` 走英文;UI 展示由调用方决定。
|
|
302
|
+
* 错误码集合是稳定可判定的:第三方接入方写 switch 时不会因为新加错误
|
|
303
|
+
* 类型而误把"未识别"分支当作"成功"。
|
|
304
|
+
*
|
|
305
|
+
* 触发语义(施工单 001 收口):
|
|
306
|
+
* - invalid_request 顶层 message 结构 / 字段类型 / aud-iat-exp
|
|
307
|
+
* 规则 / BinaryField 形状不合法;
|
|
308
|
+
* 第一条非法 request 直接被 popup 忽略,
|
|
309
|
+
* 不回 result("情况 B")。
|
|
310
|
+
* - invalid_origin identity.get / intent.sign 的
|
|
311
|
+
* `params.aud !== event.origin`。
|
|
312
|
+
* - user_rejected 用户在确认页或解锁页点"取消"。
|
|
313
|
+
* - active_key_unavailable vault 已 unlocked,但 walletState 没有 ready
|
|
314
|
+
* active key("情况 D")。
|
|
315
|
+
* - decrypt_failed cipher.decrypt 失败;origin 不匹配 / nonce
|
|
316
|
+
* 错误 / 密文被篡改 / 内层结构不合法,V1
|
|
317
|
+
* 统一为这一种错误。
|
|
318
|
+
* - internal_error 兜底:用户可见但不属于以上分类的失败。
|
|
319
|
+
*
|
|
320
|
+
* 注意:V1 **不**对外暴露 `wallet_locked` 错误码。locked 态在 popup 内
|
|
321
|
+
* 直接走解锁页("情况 C"),用户取消解锁统一回 `user_rejected`。任何
|
|
322
|
+
* "locked 时直接拒绝"的中间态都不属于 V1 公开语义。
|
|
323
|
+
*/
|
|
324
|
+
type ProtocolErrorCode =
|
|
325
|
+
/** Transport authority was revoked or belongs to another wallet/Worker generation. */
|
|
326
|
+
"connection_expired" | "invalid_request" | "invalid_origin" | "user_rejected" | "active_key_unavailable" | "decrypt_failed"
|
|
327
|
+
/**
|
|
328
|
+
* 请求资产与连接绑定的钱包网络不一致;accept 阶段拒绝,不进入业务执行。
|
|
329
|
+
*/
|
|
330
|
+
| "asset_not_enabled"
|
|
331
|
+
/** Connect v1 明确排除的方法族(新费用池签名等)。 */
|
|
332
|
+
| "unsupported_scope"
|
|
333
|
+
/** 通用支付需要已验证 App 身份(publisher 是归属唯一基准)。 */
|
|
334
|
+
| "identity_required"
|
|
335
|
+
/** 当前硬件后端缺少 Connect 支付所需的受信展示/结构检查。 */
|
|
336
|
+
| "hardware_connect_payment_unsupported" | "payment_not_found"
|
|
337
|
+
/** Too many non-terminal Connect payment responsibilities. */
|
|
338
|
+
| "payment_pending_limit"
|
|
339
|
+
/** Same stable payment key with different frozen facts. */
|
|
340
|
+
| "id_conflict" | "storage_not_configured" | "storage_unavailable" | "storage_invalid_path" | "storage_not_found" | "storage_conflict" | "storage_forbidden" | "storage_limit_exceeded" | "storage_provider_error" | "storage_identity_required" | "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";
|
|
341
|
+
interface ProtocolError {
|
|
342
|
+
code: ProtocolErrorCode;
|
|
343
|
+
message: string;
|
|
344
|
+
}
|
|
345
|
+
interface ProtocolReadyMessage {
|
|
346
|
+
v: typeof PROTOCOL_VERSION;
|
|
347
|
+
type: "ready";
|
|
348
|
+
}
|
|
349
|
+
interface ProtocolClosingMessage {
|
|
350
|
+
v: typeof PROTOCOL_VERSION;
|
|
351
|
+
type: "closing";
|
|
352
|
+
}
|
|
353
|
+
interface ProtocolCancelMessage {
|
|
354
|
+
/** Present for cancellation of an already-bound business request. */
|
|
355
|
+
bindingId?: string;
|
|
356
|
+
v: typeof PROTOCOL_VERSION;
|
|
357
|
+
type: "cancel";
|
|
358
|
+
/** 要取消的原 `request.id`。 */
|
|
359
|
+
id: string;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* 协议对外 event 名常量集合(server-pushed 事件)。
|
|
363
|
+
*
|
|
364
|
+
* 设计缘由:
|
|
365
|
+
* - `channel.message_received` 是已验签的 Channel 公开消息,只发送给
|
|
366
|
+
* 当前 session 已精确订阅的频道;
|
|
367
|
+
*/
|
|
368
|
+
type ProtocolEventName = "channel.message_received";
|
|
369
|
+
interface IdentityGetParams {
|
|
370
|
+
/** 目标站点 origin;必须等于 `event.origin`,否则拒绝。 */
|
|
371
|
+
aud: string;
|
|
372
|
+
/** 签发时间(unix seconds)。 */
|
|
373
|
+
iat: number;
|
|
374
|
+
/** 过期时间(unix seconds);必须严格大于 iat。 */
|
|
375
|
+
exp: number;
|
|
376
|
+
/** 人类可读确认文案。 */
|
|
377
|
+
text: string;
|
|
378
|
+
/**
|
|
379
|
+
* 请求索要的 claim 名列表。
|
|
380
|
+
* - Keymaster 只返回请求里明确列出且当前本地有真值来源的 claim;
|
|
381
|
+
* - 不存在的 claim 直接省略,不报错。
|
|
382
|
+
*/
|
|
383
|
+
claims?: string[];
|
|
384
|
+
}
|
|
385
|
+
/** identity.get 解析后的 claim 真值。 */
|
|
386
|
+
type ResolvedClaimValue = string | number | boolean | null | BinaryField | ResolvedClaimValue[] | {
|
|
387
|
+
[key: string]: ResolvedClaimValue;
|
|
388
|
+
};
|
|
389
|
+
interface IdentityGetResult {
|
|
390
|
+
/** Identity 信封最终真值字节(Deterministic CBOR)。 */
|
|
391
|
+
identityEnvelope: BinaryField;
|
|
392
|
+
/** 签名(compact 64-byte secp256k1)。 */
|
|
393
|
+
signature: BinaryField;
|
|
394
|
+
/** 签名主体公钥(33-byte compressed)。 */
|
|
395
|
+
subject: {
|
|
396
|
+
publicKey: BinaryField;
|
|
397
|
+
};
|
|
398
|
+
/** Keymaster 本次实际返回给调用方的 claim 真值。 */
|
|
399
|
+
resolvedClaims: Record<string, ResolvedClaimValue>;
|
|
400
|
+
}
|
|
401
|
+
interface IntentSignParams {
|
|
402
|
+
/** 目标站点 origin;必须等于 `event.origin`,否则拒绝。 */
|
|
403
|
+
aud: string;
|
|
404
|
+
/** 签发时间(unix seconds)。 */
|
|
405
|
+
iat: number;
|
|
406
|
+
/** 过期时间(unix seconds);必须严格大于 iat。 */
|
|
407
|
+
exp: number;
|
|
408
|
+
/** 人类可读确认文案。 */
|
|
409
|
+
text: string;
|
|
410
|
+
/** 调用方自定义的内容类型。 */
|
|
411
|
+
contentType: string;
|
|
412
|
+
/** 调用方准备好的最终二进制内容。允许为空字节。 */
|
|
413
|
+
content: BinaryField;
|
|
414
|
+
}
|
|
415
|
+
interface IntentSignResult {
|
|
416
|
+
/** 签名信封最终真值字节(Deterministic CBOR)。 */
|
|
417
|
+
signedEnvelope: BinaryField;
|
|
418
|
+
/** 签名(compact 64-byte secp256k1)。 */
|
|
419
|
+
signature: BinaryField;
|
|
420
|
+
}
|
|
421
|
+
interface CipherEncryptParams {
|
|
422
|
+
/** 人类可读确认文案。 */
|
|
423
|
+
text: string;
|
|
424
|
+
/** 调用方自定义的内容类型;与 contentBytes 一起进入密文内层结构。 */
|
|
425
|
+
contentType: string;
|
|
426
|
+
/** 业务字节本体。 */
|
|
427
|
+
content: BinaryField;
|
|
428
|
+
}
|
|
429
|
+
interface CipherEncryptResult {
|
|
430
|
+
/** 本次加密随机生成的 12 字节 nonce。 */
|
|
431
|
+
nonce: BinaryField;
|
|
432
|
+
/** AES-GCM 密文字节(含认证 tag)。 */
|
|
433
|
+
cipherbytes: BinaryField;
|
|
434
|
+
}
|
|
435
|
+
interface CipherDecryptParams {
|
|
436
|
+
/** 人类可读确认文案。 */
|
|
437
|
+
text: string;
|
|
438
|
+
/** 加密时保存的 12 字节 nonce。 */
|
|
439
|
+
nonce: BinaryField;
|
|
440
|
+
/** 加密时保存的密文字节。 */
|
|
441
|
+
cipherbytes: BinaryField;
|
|
442
|
+
}
|
|
443
|
+
interface CipherDecryptResult {
|
|
444
|
+
/** 密文内层结构里的 contentType。 */
|
|
445
|
+
contentType: string;
|
|
446
|
+
/** 还原后的业务字节。 */
|
|
447
|
+
content: BinaryField;
|
|
448
|
+
}
|
|
449
|
+
interface PaymentChannelRegisterParams {
|
|
450
|
+
channelName: string;
|
|
451
|
+
paymentType: "p2pkh" | "p2pk";
|
|
452
|
+
}
|
|
453
|
+
interface PaymentChannelRegisterResult {
|
|
454
|
+
channelId: string;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Connect 公开的 P2PKH 资产标识。
|
|
458
|
+
*
|
|
459
|
+
* 设计缘由(施工单 2026-09-18 001 多资产硬切换):
|
|
460
|
+
* - 公开命名固定 `bsv-mainnet` / `bsv-testnet`,不暴露 p2pkh 内部
|
|
461
|
+
* 的 `bsv` / `bsvtest`;
|
|
462
|
+
* - 资产由连接绑定的钱包网络决定,调用方不能选择或覆盖该网络。
|
|
463
|
+
*/
|
|
464
|
+
type P2pkhTransferAssetId = "bsv-mainnet" | "bsv-testnet";
|
|
465
|
+
interface P2pkhTransferParams {
|
|
466
|
+
/** 先注册取得的完整渠道编号;不允许宿主代填或省略。 */
|
|
467
|
+
channelId: string;
|
|
468
|
+
/** 主网或 testnet P2PKH 地址(base58check,version 0x00 / 0x6f)。 */
|
|
469
|
+
recipientAddress: string;
|
|
470
|
+
/** 正整数 satoshis。 */
|
|
471
|
+
amountSatoshis: number;
|
|
472
|
+
/** 可选费率(sat/kB),>= 1;缺省由钱包当前网络的有效费率策略决定。 */
|
|
473
|
+
feeRateSatoshisPerKb?: number;
|
|
474
|
+
}
|
|
475
|
+
interface P2pkhTransferResult {
|
|
476
|
+
/** 本次实际转账的资产,与连接绑定的钱包网络一致。 */
|
|
477
|
+
assetId: P2pkhTransferAssetId;
|
|
478
|
+
/** 已广播交易的 canonical txid。 */
|
|
479
|
+
txid: string;
|
|
480
|
+
/** 已签名交易 raw hex。 */
|
|
481
|
+
rawTxHex: string;
|
|
482
|
+
/** 实际花费的 fee satoshis。 */
|
|
483
|
+
feeSatoshis: number;
|
|
484
|
+
}
|
|
485
|
+
/** Connect v1 支付方案;业务种类(businessKind)是独立维度。 */
|
|
486
|
+
type ConnectPaymentType = "p2pkh" | "p2pk";
|
|
487
|
+
type ConnectPaymentRecipientOwnership = "app-publisher" | "third-party" | "unknown";
|
|
488
|
+
type ConnectPaymentStatus = "pending" | "not_signed" | "signed_not_dispatched" | "unknown" | "failed" | "accepted" | "already_known";
|
|
489
|
+
/** 收款材料:类型必须与 paymentType 一致。 */
|
|
490
|
+
type ConnectPaymentRecipient = {
|
|
491
|
+
type: "p2pkh";
|
|
492
|
+
address: string;
|
|
493
|
+
} | {
|
|
494
|
+
type: "p2pk";
|
|
495
|
+
publicKeyHex: string;
|
|
496
|
+
};
|
|
497
|
+
interface PaymentPayParams {
|
|
498
|
+
channelId: string;
|
|
499
|
+
/** 稳定幂等身份,1–128 字符。 */
|
|
500
|
+
clientRequestId: string;
|
|
501
|
+
paymentType: ConnectPaymentType;
|
|
502
|
+
/** App 声明的业务用途;展示时不是可信商业结论。 */
|
|
503
|
+
businessKind: string;
|
|
504
|
+
/** 业务金额(聪,不含矿工费)。 */
|
|
505
|
+
amountSatoshis: number;
|
|
506
|
+
/** 可选希望费率(sat/kB);缺省由钱包当前网络的有效费率策略决定。 */
|
|
507
|
+
feeRateSatoshisPerKb?: number;
|
|
508
|
+
recipient: ConnectPaymentRecipient;
|
|
509
|
+
}
|
|
510
|
+
interface PaymentReleaseSummary {
|
|
511
|
+
/** Historical amount safely released, NOT the current wallet balance. */
|
|
512
|
+
releasedSatoshis: string;
|
|
513
|
+
releasedInputCount: number;
|
|
514
|
+
spentInputCount: number;
|
|
515
|
+
heldInputCount: number;
|
|
516
|
+
}
|
|
517
|
+
interface PaymentPayResult {
|
|
518
|
+
paymentId: string;
|
|
519
|
+
clientRequestId: string;
|
|
520
|
+
status: ConnectPaymentStatus;
|
|
521
|
+
assetId: P2pkhTransferAssetId;
|
|
522
|
+
paymentType: ConnectPaymentType;
|
|
523
|
+
recipientOwnership: ConnectPaymentRecipientOwnership;
|
|
524
|
+
/** 只有 accepted/already_known 才有 canonical txid。 */
|
|
525
|
+
txid?: string;
|
|
526
|
+
feeSatoshis?: number;
|
|
527
|
+
changeSatoshis?: number;
|
|
528
|
+
approval?: "automatic" | "manual" | "unknown";
|
|
529
|
+
/** 稳定原因码;不包含签名/交易原文。 */
|
|
530
|
+
reason?: string;
|
|
531
|
+
release?: PaymentReleaseSummary;
|
|
532
|
+
}
|
|
533
|
+
interface PaymentStatusParams {
|
|
534
|
+
clientRequestId: string;
|
|
535
|
+
}
|
|
536
|
+
type PaymentStatusResult = PaymentPayResult;
|
|
537
|
+
interface ConnectLoginParams {
|
|
538
|
+
/** 人类可读确认文案。 */
|
|
539
|
+
text: string;
|
|
540
|
+
/**
|
|
541
|
+
* 请求索要的 claim 名列表(与 `identity.get` 同语义)。
|
|
542
|
+
* 缺省 = `[]`,不返回任何 claim;通常 caller 想获取 profile.* 时必须显式列出。
|
|
543
|
+
*/
|
|
544
|
+
claims?: string[];
|
|
545
|
+
/** 发布者签名的 caller identity proof;缺省时建立无 storage 的普通 session。 */
|
|
546
|
+
appIdentity?: AppIdentityProofV1;
|
|
547
|
+
}
|
|
548
|
+
interface ConnectLoginResult {
|
|
549
|
+
networkIdentity: NetworkIdentity;
|
|
550
|
+
/** 本次 login 时一次解析的 claims 真值快照。 */
|
|
551
|
+
resolvedClaims: Record<string, ResolvedClaimValue>;
|
|
552
|
+
/** 本次解析时间(unix milliseconds)。 */
|
|
553
|
+
resolvedAt: number;
|
|
554
|
+
appIdentity?: AppIdentitySnapshot;
|
|
555
|
+
}
|
|
556
|
+
interface ConnectResumeParams {
|
|
557
|
+
/** 本地数据重置后重新验证已有发行人签名 proof。 */
|
|
558
|
+
appIdentity?: AppIdentityProofV1;
|
|
559
|
+
}
|
|
560
|
+
interface ConnectResumeResult {
|
|
561
|
+
networkIdentity: NetworkIdentity;
|
|
562
|
+
resolvedClaims: Record<string, ResolvedClaimValue>;
|
|
563
|
+
/**
|
|
564
|
+
* 解析时间——本次 resume 时间戳,**不**是 connect.login 时的快照时间。
|
|
565
|
+
* 给 caller 用来做"是否要重新登录"的客户端超时策略。
|
|
566
|
+
*/
|
|
567
|
+
resolvedAt: number;
|
|
568
|
+
appIdentity?: AppIdentitySnapshot;
|
|
569
|
+
}
|
|
570
|
+
interface ConnectLogoutParams extends Record<string, never> {
|
|
571
|
+
}
|
|
572
|
+
interface ConnectLogoutResult {
|
|
573
|
+
/** 吊销时间(unix milliseconds)。 */
|
|
574
|
+
revokedAt: number;
|
|
575
|
+
}
|
|
576
|
+
interface ConnectLaunchParams {
|
|
577
|
+
/** 由 launcher 写入 client app 启动 URL 的 launchToken。一次性消费。 */
|
|
578
|
+
launchToken: string;
|
|
579
|
+
/** 与 launcher 预建 session 绑定的完整签名 proof。 */
|
|
580
|
+
appIdentity: AppIdentityProofV1;
|
|
581
|
+
}
|
|
582
|
+
interface ConnectLaunchResult {
|
|
583
|
+
networkIdentity: NetworkIdentity;
|
|
584
|
+
resolvedClaims: Record<string, ResolvedClaimValue>;
|
|
585
|
+
resolvedAt: number;
|
|
586
|
+
appIdentity?: AppIdentitySnapshot;
|
|
587
|
+
}
|
|
588
|
+
/** 协议方法名常量集合。 */
|
|
589
|
+
declare const PROTOCOL_METHODS: readonly ["identity.get", "intent.sign", "cipher.encrypt", "cipher.decrypt", "p2pkh.transfer", "payment.pay", "payment.status", "payment.channel.register", "connect.login", "connect.resume", "connect.logout", "connect.launch", "channel.publish", "channel.subscription_set", "storage.list", "storage.directory.create", "storage.directory.delete", "storage.put", "storage.get", "storage.delete", "msfile.stat", "msfile.seed.read", "msfile.block.read"];
|
|
590
|
+
type ProtocolMethod = (typeof PROTOCOL_METHODS)[number];
|
|
591
|
+
/**
|
|
592
|
+
* 方法 -> 请求参数类型 的映射。`MethodParams<M>` 是计算出的参数类型。
|
|
593
|
+
* 业务代码里直接 `MethodParams<"identity.get">` 等价于 `IdentityGetParams`。
|
|
594
|
+
*/
|
|
595
|
+
interface MethodParamsMap {
|
|
596
|
+
"payment.channel.register": PaymentChannelRegisterParams;
|
|
597
|
+
"identity.get": IdentityGetParams;
|
|
598
|
+
"intent.sign": IntentSignParams;
|
|
599
|
+
"cipher.encrypt": CipherEncryptParams;
|
|
600
|
+
"cipher.decrypt": CipherDecryptParams;
|
|
601
|
+
"p2pkh.transfer": P2pkhTransferParams;
|
|
602
|
+
"payment.pay": PaymentPayParams;
|
|
603
|
+
"payment.status": PaymentStatusParams;
|
|
604
|
+
"connect.login": ConnectLoginParams;
|
|
605
|
+
"connect.resume": ConnectResumeParams;
|
|
606
|
+
"connect.logout": ConnectLogoutParams;
|
|
607
|
+
"connect.launch": ConnectLaunchParams;
|
|
608
|
+
"channel.publish": ChannelPublishParams;
|
|
609
|
+
"channel.subscription_set": ChannelSubscriptionSetParams;
|
|
610
|
+
"storage.list": StorageListParams;
|
|
611
|
+
"storage.directory.create": StorageDirectoryParams;
|
|
612
|
+
"storage.directory.delete": StorageDirectoryParams;
|
|
613
|
+
"storage.put": StoragePutParams;
|
|
614
|
+
"storage.get": StorageGetParams;
|
|
615
|
+
"storage.delete": StorageDeleteParams;
|
|
616
|
+
"msfile.stat": MsFileStatParams;
|
|
617
|
+
"msfile.seed.read": MsFileSeedReadParams;
|
|
618
|
+
"msfile.block.read": MsFileBlockReadParams;
|
|
619
|
+
}
|
|
620
|
+
interface MethodResultMap {
|
|
621
|
+
"payment.channel.register": PaymentChannelRegisterResult;
|
|
622
|
+
"identity.get": IdentityGetResult;
|
|
623
|
+
"intent.sign": IntentSignResult;
|
|
624
|
+
"cipher.encrypt": CipherEncryptResult;
|
|
625
|
+
"cipher.decrypt": CipherDecryptResult;
|
|
626
|
+
"p2pkh.transfer": P2pkhTransferResult;
|
|
627
|
+
"payment.pay": PaymentPayResult;
|
|
628
|
+
"payment.status": PaymentStatusResult;
|
|
629
|
+
"connect.login": ConnectLoginResult;
|
|
630
|
+
"connect.resume": ConnectResumeResult;
|
|
631
|
+
"connect.logout": ConnectLogoutResult;
|
|
632
|
+
"connect.launch": ConnectLaunchResult;
|
|
633
|
+
"channel.publish": ChannelPublishResult;
|
|
634
|
+
"channel.subscription_set": ChannelSubscriptionSetResult;
|
|
635
|
+
"storage.list": StorageListResult;
|
|
636
|
+
"storage.directory.create": StorageDirectoryResult;
|
|
637
|
+
"storage.directory.delete": StorageDirectoryResult;
|
|
638
|
+
"storage.put": StoragePutResult;
|
|
639
|
+
"storage.get": StorageGetResult;
|
|
640
|
+
"storage.delete": StorageDeleteResult;
|
|
641
|
+
"msfile.stat": MsFileStatResult;
|
|
642
|
+
"msfile.seed.read": MsFileReadResult;
|
|
643
|
+
"msfile.block.read": MsFileReadResult;
|
|
644
|
+
}
|
|
645
|
+
type MethodParams<M extends ProtocolMethod> = M extends ProtocolMethod ? keyof MethodParamsMap[M] extends never ? Record<string, never> : MethodParamsMap[M] : never;
|
|
646
|
+
type MethodResult<M extends ProtocolMethod = ProtocolMethod> = MethodResultMap[M];
|
|
647
|
+
type ProtocolEventPayload = {
|
|
648
|
+
v: typeof PROTOCOL_VERSION;
|
|
649
|
+
type: "event";
|
|
650
|
+
event: "channel.message_received";
|
|
651
|
+
data: ChannelMessageReceivedEventData;
|
|
652
|
+
};
|
|
653
|
+
type ProtocolEventMessage = ProtocolEventPayload & {
|
|
654
|
+
networkIdentity: NetworkIdentity;
|
|
655
|
+
bindingId: string;
|
|
656
|
+
};
|
|
657
|
+
interface ProtocolRequestMessage<M extends ProtocolMethod = ProtocolMethod> {
|
|
658
|
+
v: typeof PROTOCOL_VERSION;
|
|
659
|
+
type: "request";
|
|
660
|
+
id: string;
|
|
661
|
+
method: M;
|
|
662
|
+
params: MethodParams<M>;
|
|
663
|
+
bindingId?: string;
|
|
664
|
+
}
|
|
665
|
+
type ProtocolResultMessage = {
|
|
666
|
+
v: typeof PROTOCOL_VERSION;
|
|
667
|
+
type: "result";
|
|
668
|
+
id: string;
|
|
669
|
+
ok: true;
|
|
670
|
+
result: MethodResult;
|
|
671
|
+
networkIdentity: NetworkIdentity;
|
|
672
|
+
bindingId: string;
|
|
673
|
+
} | {
|
|
674
|
+
v: typeof PROTOCOL_VERSION;
|
|
675
|
+
type: "result";
|
|
676
|
+
id: string;
|
|
677
|
+
ok: false;
|
|
678
|
+
error: ProtocolError;
|
|
679
|
+
networkIdentity?: NetworkIdentity;
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
export { type AppIdentityProofV1, type AppIdentitySnapshot, type AppRequirement, type BinaryField, type BsvNetwork, type ChannelMessageReceivedEventData, type ChannelPublishParams, type ChannelPublishResult, type ChannelSubscriptionErrorCode, type ChannelSubscriptionPhase, type ChannelSubscriptionSetParams, type ChannelSubscriptionSetResult, type ChannelSubscriptionStatus, type CipherDecryptParams, type CipherDecryptResult, type CipherEncryptParams, type CipherEncryptResult, type ConnectLaunchParams, type ConnectLaunchResult, type ConnectLoginParams, type ConnectLoginResult, type ConnectLogoutParams, type ConnectLogoutResult, type ConnectPaymentRecipient, type ConnectPaymentRecipientOwnership, type ConnectPaymentStatus, type ConnectPaymentType, type ConnectResumeParams, type ConnectResumeResult, type IdentityGetParams, type IdentityGetResult, type IntentSignParams, type IntentSignResult, type JSONValue, 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, type MethodParams, type MethodParamsMap, type MethodResult, type MethodResultMap, type MsFileBlockReadParams, type MsFileLocalSourceStat, type MsFileReadResult, type MsFileRemoteSourceStat, type MsFileSatoshiAmount, type MsFileSeedReadParams, type MsFileSourceKind, type MsFileSourceStat, type MsFileStatAbsentEntry, type MsFileStatAvailableEntry, type MsFileStatDiscoveringEntry, type MsFileStatNetworkErrorEntry, type MsFileStatParams, type MsFileStatQuotedEntry, type MsFileStatResult, type MsFileSupplierStat, type NetworkIdentity, type P2pkhTransferAssetId, type P2pkhTransferParams, type P2pkhTransferResult, PROTOCOL_METHODS, PROTOCOL_VERSION, type PaymentChannelRegisterParams, type PaymentChannelRegisterResult, type PaymentPayParams, type PaymentPayResult, type PaymentReleaseSummary, type PaymentStatusParams, type PaymentStatusResult, type ProtocolCancelMessage, type ProtocolClosingMessage, type ProtocolError, type ProtocolErrorCode, type ProtocolEventMessage, type ProtocolEventName, type ProtocolEventPayload, type ProtocolMethod, type ProtocolReadyMessage, type ProtocolRequestMessage, type ProtocolResultMessage, type ResolvedClaimValue, STORAGE_DEFAULT_LIST_LIMIT, STORAGE_MAX_LIST_LIMIT, STORAGE_MAX_PAYLOAD_BYTES, type StorageDeleteParams, type StorageDeleteResult, type StorageDirectoryParams, type StorageDirectoryResult, type StorageGetParams, type StorageGetResult, type StorageListEntry, type StorageListParams, type StorageListResult, type StoragePutParams, type StoragePutResult, type VerifiedAppIdentity, isValidMsFileSourceId, sameNetworkIdentity, validateBsvNetwork, validateNetworkIdentity };
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +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, STORAGE_DEFAULT_LIST_LIMIT, STORAGE_MAX_LIST_LIMIT, STORAGE_MAX_PAYLOAD_BYTES, isValidMsFileSourceId, sameNetworkIdentity, validateBsvNetwork, validateNetworkIdentity } from './chunk-JDAJD3SX.js';
|
|
2
|
+
//# sourceMappingURL=protocol.js.map
|
|
3
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"protocol.js"}
|