keymaster-connect 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -5
- package/dist/{chunk-A4VCQSB5.js → chunk-QUZZ2OXO.js} +7 -2
- package/dist/chunk-QUZZ2OXO.js.map +1 -0
- package/dist/index.d.ts +22 -8
- package/dist/index.js +58 -5
- package/dist/index.js.map +1 -1
- package/dist/{protocol-Dfo305R9.d.ts → protocol-Czc3NgOD.d.ts} +110 -9
- 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 +2 -2
- package/dist/server.js +71 -7
- package/dist/server.js.map +1 -1
- package/dist/signing.d.ts +1 -1
- package/package.json +12 -15
- package/dist/chunk-A4VCQSB5.js.map +0 -1
|
@@ -175,6 +175,53 @@ declare function isValidMsFileSourceId(input: unknown): input is string;
|
|
|
175
175
|
interface MsFileStatParams {
|
|
176
176
|
seedHashHex: string;
|
|
177
177
|
}
|
|
178
|
+
interface MsFileContentReadParams extends MsFileStatParams {
|
|
179
|
+
clientRequestId?: string;
|
|
180
|
+
/** 本次下载任务的完整数据块单价上限,单位聪。 */
|
|
181
|
+
maxFullBlockPriceSatoshis?: string;
|
|
182
|
+
}
|
|
183
|
+
interface MsFileReadStatusParams {
|
|
184
|
+
clientRequestId: string;
|
|
185
|
+
}
|
|
186
|
+
type MsFileContentOpenParams = MsFileContentReadParams & MsFileReadStatusParams;
|
|
187
|
+
/** 查询钱包允许的块价范围,或按读取编号修改当前任务的手动块价。 */
|
|
188
|
+
interface MsFileDownloadPriceParams {
|
|
189
|
+
clientRequestId?: string;
|
|
190
|
+
maxFullBlockPriceSatoshis?: string;
|
|
191
|
+
}
|
|
192
|
+
interface MsFileDownloadPriceResult {
|
|
193
|
+
/** 钱包允许应用设置的最大完整块单价,单位聪。 */
|
|
194
|
+
walletMaxFullBlockPriceSatoshis: string;
|
|
195
|
+
}
|
|
196
|
+
interface MsFileContentRangeParams extends MsFileReadStatusParams {
|
|
197
|
+
offset: number;
|
|
198
|
+
length: number;
|
|
199
|
+
}
|
|
200
|
+
interface MsFileContentRangeResult {
|
|
201
|
+
fileSizeBytes?: number;
|
|
202
|
+
mediaType?: string;
|
|
203
|
+
content?: BinaryField;
|
|
204
|
+
}
|
|
205
|
+
interface MsFileReadStatusDetails {
|
|
206
|
+
clientRequestId: string;
|
|
207
|
+
seedHashHex: string;
|
|
208
|
+
taskId?: string;
|
|
209
|
+
verifiedBlockCount?: number;
|
|
210
|
+
totalBlockCount?: number;
|
|
211
|
+
funds?: "none" | "pending" | "settled" | "problem";
|
|
212
|
+
/** 此读取记录有权调整关联下载任务的手动块价。 */
|
|
213
|
+
priceAdjustable?: true;
|
|
214
|
+
/** 当前任务的完整数据块单价上限,单位聪。 */
|
|
215
|
+
currentMaxFullBlockPriceSatoshis?: string;
|
|
216
|
+
}
|
|
217
|
+
/** Action for the caller: wait for content, read the complete file, or stop waiting. */
|
|
218
|
+
type MsFileReadStatus = MsFileReadStatusDetails & ({
|
|
219
|
+
phase: "pending" | "available";
|
|
220
|
+
error?: never;
|
|
221
|
+
} | {
|
|
222
|
+
phase: "stopped";
|
|
223
|
+
error: ProtocolError;
|
|
224
|
+
});
|
|
178
225
|
interface MsFileStatAvailableEntry {
|
|
179
226
|
supplierPublicKeyHex: string;
|
|
180
227
|
status: "available";
|
|
@@ -288,8 +335,8 @@ type ProtocolErrorCode =
|
|
|
288
335
|
| "hardware_connect_payment_unsupported" | "payment_not_found"
|
|
289
336
|
/** Too many non-terminal Connect payment responsibilities. */
|
|
290
337
|
| "payment_pending_limit"
|
|
291
|
-
/** Same stable
|
|
292
|
-
| "id_conflict" | "name_not_found" | "invalid_name" | "invalid_public_key" | "primary_name_required" | "domain_service_not_configured" | "domain_service_unavailable" | "domain_network_mismatch" | "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";
|
|
338
|
+
/** Same stable request key with different facts, or a resumable MSFile read failure. */
|
|
339
|
+
| "id_conflict" | "msfile_read_not_found" | "msfile_read_interrupted" | "msfile_read_cancelled" | "msfile_range_timeout" | "name_not_found" | "invalid_name" | "invalid_public_key" | "primary_name_required" | "domain_service_not_configured" | "domain_service_unavailable" | "domain_network_mismatch" | "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";
|
|
293
340
|
interface ProtocolError {
|
|
294
341
|
code: ProtocolErrorCode;
|
|
295
342
|
message: string;
|
|
@@ -316,8 +363,15 @@ interface ProtocolCancelMessage {
|
|
|
316
363
|
* 设计缘由:
|
|
317
364
|
* - `channel.message_received` 是已验签的 Channel 公开消息,只发送给
|
|
318
365
|
* 当前 session 已精确订阅的频道;
|
|
366
|
+
* - `chain.height_changed` 是当前连接钱包已同步的链尖快照;
|
|
319
367
|
*/
|
|
320
|
-
type ProtocolEventName = "channel.message_received";
|
|
368
|
+
type ProtocolEventName = "channel.message_received" | "chain.height_changed";
|
|
369
|
+
/** 钱包同一次同步取得的链尖高度和哈希。 */
|
|
370
|
+
interface ChainHeightResult {
|
|
371
|
+
height: number;
|
|
372
|
+
/** 64 位小写十六进制区块哈希。 */
|
|
373
|
+
blockHash: string;
|
|
374
|
+
}
|
|
321
375
|
interface IdentityGetParams {
|
|
322
376
|
/** 目标站点 origin;必须等于 `event.origin`,否则拒绝。 */
|
|
323
377
|
aud: string;
|
|
@@ -495,6 +549,27 @@ type ChainTransactionResult = {
|
|
|
495
549
|
blockHash: string;
|
|
496
550
|
index: number;
|
|
497
551
|
};
|
|
552
|
+
type ChainTransactionBatchParams = {
|
|
553
|
+
txids: string[];
|
|
554
|
+
mode: "raw" | "status";
|
|
555
|
+
};
|
|
556
|
+
type ChainTransactionBatchEntry = {
|
|
557
|
+
txid: string;
|
|
558
|
+
} & ({
|
|
559
|
+
state: "not_observed";
|
|
560
|
+
} | {
|
|
561
|
+
state: "unconfirmed";
|
|
562
|
+
rawTxHex?: string;
|
|
563
|
+
} | {
|
|
564
|
+
state: "confirmed";
|
|
565
|
+
height: number;
|
|
566
|
+
blockHash: string;
|
|
567
|
+
rawTxHex?: string;
|
|
568
|
+
});
|
|
569
|
+
interface ChainTransactionBatchResult {
|
|
570
|
+
/** Missing IDs have no usable observation in this response and can be retried. */
|
|
571
|
+
entries: ChainTransactionBatchEntry[];
|
|
572
|
+
}
|
|
498
573
|
interface ChainBroadcastResult {
|
|
499
574
|
state: "accepted" | "rejected" | "unknown";
|
|
500
575
|
txid: string;
|
|
@@ -514,7 +589,14 @@ interface MsFileContentResult {
|
|
|
514
589
|
seed: BinaryField;
|
|
515
590
|
content: BinaryField;
|
|
516
591
|
}
|
|
592
|
+
/** Signed by the connected wallet over the canonical login-proof envelope. */
|
|
593
|
+
interface ConnectLoginProof {
|
|
594
|
+
envelope: BinaryField;
|
|
595
|
+
signature: BinaryField;
|
|
596
|
+
}
|
|
517
597
|
interface ConnectLoginParams {
|
|
598
|
+
/** One-time challenge issued by the application backend (32 bytes, lowercase hex). */
|
|
599
|
+
loginChallenge?: string;
|
|
518
600
|
/** 人类可读确认文案。 */
|
|
519
601
|
text: string;
|
|
520
602
|
/**
|
|
@@ -531,6 +613,8 @@ interface ConnectLoginParams {
|
|
|
531
613
|
publicationProof?: string;
|
|
532
614
|
}
|
|
533
615
|
interface ConnectLoginResult {
|
|
616
|
+
/** Present when the request includes loginChallenge. */
|
|
617
|
+
loginProof?: ConnectLoginProof;
|
|
534
618
|
/** 不透明恢复凭据,绑定原钱包和精确来源;不得写入日志或 URL。 */
|
|
535
619
|
authorizationId: string;
|
|
536
620
|
networkIdentity: NetworkIdentity;
|
|
@@ -546,6 +630,8 @@ interface ConnectLogoutResult {
|
|
|
546
630
|
revokedAt: number;
|
|
547
631
|
}
|
|
548
632
|
interface ConnectLaunchParams {
|
|
633
|
+
/** One-time challenge issued by the application backend (32 bytes, lowercase hex). */
|
|
634
|
+
loginChallenge?: string;
|
|
549
635
|
/** 由 launcher 写入 client app 启动 URL 的 launchToken。一次性消费。 */
|
|
550
636
|
launchToken: string;
|
|
551
637
|
/**
|
|
@@ -555,6 +641,8 @@ interface ConnectLaunchParams {
|
|
|
555
641
|
publicationProof?: string;
|
|
556
642
|
}
|
|
557
643
|
interface ConnectLaunchResult {
|
|
644
|
+
/** Present when the request includes loginChallenge. */
|
|
645
|
+
loginProof?: ConnectLoginProof;
|
|
558
646
|
authorizationId: string;
|
|
559
647
|
networkIdentity: NetworkIdentity;
|
|
560
648
|
resolvedClaims: Record<string, ResolvedClaimValue>;
|
|
@@ -594,7 +682,7 @@ interface DomainGetPublicKeyParams {
|
|
|
594
682
|
domain: string;
|
|
595
683
|
serviceId?: string;
|
|
596
684
|
}
|
|
597
|
-
declare const PROTOCOL_METHODS: readonly ["identity.get", "intent.sign", "cipher.encrypt", "cipher.decrypt", "payment.pay", "payment.status", "payment.prepare", "payment.commit", "payment.cancel", "chain.get_height", "chain.list_script_history", "chain.get_transaction", "chain.list_script_unspent", "chain.broadcast", "application.key", "application.sign_message", "application.sign_payment", "msfile.seller.status", "msfile.import", "msfile.content.read", "domain.profiles", "domain.get_public_key", "connect.login", "connect.logout", "connect.launch", "channel.publish", "channel.subscription_set", "msfile.stat", "msfile.seed.read", "msfile.block.read"];
|
|
685
|
+
declare const PROTOCOL_METHODS: readonly ["identity.get", "intent.sign", "cipher.encrypt", "cipher.decrypt", "payment.pay", "payment.status", "payment.prepare", "payment.commit", "payment.cancel", "chain.get_height", "chain.list_script_history", "chain.get_transaction", "chain.get_transactions", "chain.list_script_unspent", "chain.broadcast", "application.key", "application.sign_message", "application.sign_payment", "msfile.seller.status", "msfile.import", "msfile.content.read", "msfile.content.status", "msfile.content.open", "msfile.content.price", "msfile.content.range", "domain.profiles", "domain.get_public_key", "connect.login", "connect.logout", "connect.launch", "channel.publish", "channel.subscription_set", "msfile.stat", "msfile.seed.read", "msfile.block.read"];
|
|
598
686
|
type ProtocolMethod = (typeof PROTOCOL_METHODS)[number];
|
|
599
687
|
/**
|
|
600
688
|
* 方法 -> 请求参数类型 的映射。`MethodParams<M>` 是计算出的参数类型。
|
|
@@ -616,6 +704,7 @@ interface MethodParamsMap {
|
|
|
616
704
|
txid: string;
|
|
617
705
|
observedRawTxHex?: string;
|
|
618
706
|
};
|
|
707
|
+
"chain.get_transactions": ChainTransactionBatchParams;
|
|
619
708
|
"chain.list_script_unspent": {
|
|
620
709
|
script: string;
|
|
621
710
|
};
|
|
@@ -632,7 +721,11 @@ interface MethodParamsMap {
|
|
|
632
721
|
"application.sign_payment": ApplicationPaymentParams;
|
|
633
722
|
"msfile.seller.status": {};
|
|
634
723
|
"msfile.import": MsFileImportParams;
|
|
635
|
-
"msfile.content.read":
|
|
724
|
+
"msfile.content.read": MsFileContentReadParams;
|
|
725
|
+
"msfile.content.status": MsFileReadStatusParams;
|
|
726
|
+
"msfile.content.open": MsFileContentOpenParams;
|
|
727
|
+
"msfile.content.price": MsFileDownloadPriceParams;
|
|
728
|
+
"msfile.content.range": MsFileContentRangeParams;
|
|
636
729
|
"domain.profiles": DomainProfilesParams;
|
|
637
730
|
"domain.get_public_key": DomainGetPublicKeyParams;
|
|
638
731
|
"connect.login": ConnectLoginParams;
|
|
@@ -654,11 +747,10 @@ interface MethodResultMap {
|
|
|
654
747
|
"payment.prepare": PaymentPrepareResult;
|
|
655
748
|
"payment.commit": PaymentPayResult;
|
|
656
749
|
"payment.cancel": PaymentPayResult;
|
|
657
|
-
"chain.get_height":
|
|
658
|
-
height: number;
|
|
659
|
-
};
|
|
750
|
+
"chain.get_height": ChainHeightResult;
|
|
660
751
|
"chain.list_script_history": ChainScriptHistoryResult;
|
|
661
752
|
"chain.get_transaction": ChainTransactionResult;
|
|
753
|
+
"chain.get_transactions": ChainTransactionBatchResult;
|
|
662
754
|
"chain.list_script_unspent": {
|
|
663
755
|
outputs: Array<ChainOutpoint & {
|
|
664
756
|
satoshis: number;
|
|
@@ -682,6 +774,10 @@ interface MethodResultMap {
|
|
|
682
774
|
seedHashHex: string;
|
|
683
775
|
};
|
|
684
776
|
"msfile.content.read": MsFileContentResult;
|
|
777
|
+
"msfile.content.status": MsFileReadStatus;
|
|
778
|
+
"msfile.content.open": MsFileReadStatus;
|
|
779
|
+
"msfile.content.price": MsFileDownloadPriceResult;
|
|
780
|
+
"msfile.content.range": MsFileContentRangeResult;
|
|
685
781
|
"domain.profiles": DomainProfilesResult;
|
|
686
782
|
"domain.get_public_key": {
|
|
687
783
|
publicKeyHex: string;
|
|
@@ -702,6 +798,11 @@ type ProtocolEventPayload = {
|
|
|
702
798
|
type: "event";
|
|
703
799
|
event: "channel.message_received";
|
|
704
800
|
data: ChannelMessageReceivedEventData;
|
|
801
|
+
} | {
|
|
802
|
+
v: typeof PROTOCOL_VERSION;
|
|
803
|
+
type: "event";
|
|
804
|
+
event: "chain.height_changed";
|
|
805
|
+
data: ChainHeightResult;
|
|
705
806
|
};
|
|
706
807
|
type ProtocolEventMessage = ProtocolEventPayload & {
|
|
707
808
|
networkIdentity: NetworkIdentity;
|
|
@@ -732,4 +833,4 @@ type ProtocolResultMessage = {
|
|
|
732
833
|
networkIdentity?: NetworkIdentity;
|
|
733
834
|
};
|
|
734
835
|
|
|
735
|
-
export { type
|
|
836
|
+
export { type BsvNetwork as $, type AiTool as A, type BinaryField as B, type ConnectLoginParams as C, type DomainProfile as D, type MsFileReadStatus as E, type MsFileDownloadPriceResult as F, type MsFileContentRangeResult as G, type MsFileStatParams as H, type IdentityGetParams as I, type MsFileStatResult as J, type MsFileSeedReadParams as K, type MsFileReadResult as L, type MethodParams as M, type NetworkIdentity as N, type MsFileBlockReadParams as O, type ProtocolEventMessage as P, type PaymentStatusResult as Q, type ChannelPublishParams as R, type ChannelPublishResult as S, type ChannelSubscriptionSetParams as T, type ChannelSubscriptionSetResult as U, type ProtocolErrorCode as V, AI_TOOLS_MAX_JSON_CHARS as W, type AiToolDefinition as X, type AiToolMessage as Y, type AiToolSchema as Z, type ApplicationPaymentParams as _, type DomainProfilesResult as a, isAiToolMessage as a$, type ChainScriptHistoryParams as a0, type ChainTransactionBatchEntry as a1, type ChainTransactionBatchParams as a2, type ChannelMessageReceivedEventData as a3, type ChannelSubscriptionErrorCode as a4, type ChannelSubscriptionPhase as a5, type ChannelSubscriptionStatus as a6, type ConnectLoginProof as a7, type ConnectLogoutParams as a8, type ConnectPaymentStatus as a9, type MsFileStatAbsentEntry as aA, type MsFileStatAvailableEntry as aB, type MsFileStatDiscoveringEntry as aC, type MsFileStatNetworkErrorEntry as aD, type MsFileStatQuotedEntry as aE, type MsFileSupplierStat as aF, type P2pkhTransferAssetId as aG, PROTOCOL_METHODS as aH, PROTOCOL_VERSION as aI, type PaymentCommitParams as aJ, type PaymentDataSignature as aK, type PaymentOutput as aL, type PaymentPrepareParams as aM, type PaymentReleaseSummary as aN, type PaymentReservationParams as aO, type ProfileResult as aP, type ProtocolCancelMessage as aQ, type ProtocolClosingMessage as aR, type ProtocolError as aS, type ProtocolEventName as aT, type ProtocolEventPayload as aU, type ProtocolReadyMessage as aV, type ProtocolRequestMessage as aW, type ProtocolResultMessage as aX, type ResolvedClaimValue as aY, assertToolJson as aZ, assertToolPayload as a_, DOMAIN_MAX_PROFILES as aa, type DomainGetPublicKeyParams as ab, type DomainProfilesParams as ac, type JSONValue as ad, MSFILE_BLOCK_SIZE_BYTES as ae, MSFILE_DIGEST_SIZE_BYTES as af, MSFILE_LOCAL_SOURCE_ID as ag, MSFILE_MAX_BLOCK_BYTES as ah, MSFILE_MAX_CONTENT_BYTES as ai, MSFILE_MAX_ERROR_MESSAGE_BYTES as aj, MSFILE_MAX_HEADER_BYTES as ak, MSFILE_MAX_SEED_BYTES as al, MSFILE_PROTOCOL_ID as am, type MethodParamsMap as an, type MethodResultMap as ao, type MsFileContentOpenParams as ap, type MsFileContentRangeParams as aq, type MsFileContentReadParams as ar, type MsFileDownloadPriceParams as as, type MsFileImportParams as at, type MsFileLocalSourceStat as au, type MsFileReadStatusParams as av, type MsFileRemoteSourceStat as aw, type MsFileSatoshiAmount as ax, type MsFileSourceKind as ay, type MsFileSourceStat as az, type AiToolsRegistered as b, isValidMsFileSourceId as b0, parseToolDefinitions as b1, sameNetworkIdentity as b2, validateBsvNetwork as b3, validateNetworkIdentity as b4, validateToolArguments as b5, type ProtocolMethod as c, type MethodResult as d, type ConnectLoginResult as e, type ConnectLogoutResult as f, type ConnectLaunchParams as g, type ConnectLaunchResult as h, type IdentityGetResult as i, type IntentSignParams as j, type IntentSignResult as k, type CipherEncryptParams as l, type CipherEncryptResult as m, type CipherDecryptParams as n, type CipherDecryptResult as o, type PaymentPayParams as p, type PaymentPayResult as q, type PaymentPrepareResult as r, type PaymentStatusParams as s, type ChainHeightResult as t, type ChainScriptHistoryResult as u, type ChainTransactionResult as v, type ChainTransactionBatchResult as w, type ChainOutpoint as x, type ChainBroadcastResult as y, type MsFileContentResult as z };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { X as AiToolDefinition, Y as AiToolMessage, Z as AiToolSchema, b as AiToolsRegistered, _ as ApplicationPaymentParams, B as BinaryField, $ as BsvNetwork, y as ChainBroadcastResult, t as ChainHeightResult, x as ChainOutpoint, a0 as ChainScriptHistoryParams, u as ChainScriptHistoryResult, a1 as ChainTransactionBatchEntry, a2 as ChainTransactionBatchParams, w as ChainTransactionBatchResult, v as ChainTransactionResult, a3 as ChannelMessageReceivedEventData, R as ChannelPublishParams, S as ChannelPublishResult, a4 as ChannelSubscriptionErrorCode, a5 as ChannelSubscriptionPhase, T as ChannelSubscriptionSetParams, U as ChannelSubscriptionSetResult, a6 as ChannelSubscriptionStatus, n as CipherDecryptParams, o as CipherDecryptResult, l as CipherEncryptParams, m as CipherEncryptResult, g as ConnectLaunchParams, h as ConnectLaunchResult, C as ConnectLoginParams, a7 as ConnectLoginProof, e as ConnectLoginResult, a8 as ConnectLogoutParams, f as ConnectLogoutResult, a9 as ConnectPaymentStatus, aa as DOMAIN_MAX_PROFILES, ab as DomainGetPublicKeyParams, D as DomainProfile, ac as DomainProfilesParams, a as DomainProfilesResult, I as IdentityGetParams, i as IdentityGetResult, j as IntentSignParams, k as IntentSignResult, ad as JSONValue, ae as MSFILE_BLOCK_SIZE_BYTES, af as MSFILE_DIGEST_SIZE_BYTES, ag as MSFILE_LOCAL_SOURCE_ID, ah as MSFILE_MAX_BLOCK_BYTES, ai as MSFILE_MAX_CONTENT_BYTES, aj as MSFILE_MAX_ERROR_MESSAGE_BYTES, ak as MSFILE_MAX_HEADER_BYTES, al as MSFILE_MAX_SEED_BYTES, am as MSFILE_PROTOCOL_ID, M as MethodParams, an as MethodParamsMap, d as MethodResult, ao as MethodResultMap, O as MsFileBlockReadParams, ap as MsFileContentOpenParams, aq as MsFileContentRangeParams, G as MsFileContentRangeResult, ar as MsFileContentReadParams, z as MsFileContentResult, as as MsFileDownloadPriceParams, F as MsFileDownloadPriceResult, at as MsFileImportParams, au as MsFileLocalSourceStat, L as MsFileReadResult, E as MsFileReadStatus, av as MsFileReadStatusParams, aw as MsFileRemoteSourceStat, ax as MsFileSatoshiAmount, K as MsFileSeedReadParams, ay as MsFileSourceKind, az as MsFileSourceStat, aA as MsFileStatAbsentEntry, aB as MsFileStatAvailableEntry, aC as MsFileStatDiscoveringEntry, aD as MsFileStatNetworkErrorEntry, H as MsFileStatParams, aE as MsFileStatQuotedEntry, J as MsFileStatResult, aF as MsFileSupplierStat, N as NetworkIdentity, aG as P2pkhTransferAssetId, aH as PROTOCOL_METHODS, aI as PROTOCOL_VERSION, aJ as PaymentCommitParams, aK as PaymentDataSignature, aL as PaymentOutput, p as PaymentPayParams, q as PaymentPayResult, aM as PaymentPrepareParams, r as PaymentPrepareResult, aN as PaymentReleaseSummary, aO as PaymentReservationParams, s as PaymentStatusParams, Q as PaymentStatusResult, aP as ProfileResult, aQ as ProtocolCancelMessage, aR as ProtocolClosingMessage, aS as ProtocolError, V as ProtocolErrorCode, P as ProtocolEventMessage, aT as ProtocolEventName, aU as ProtocolEventPayload, c as ProtocolMethod, aV as ProtocolReadyMessage, aW as ProtocolRequestMessage, aX as ProtocolResultMessage, aY as ResolvedClaimValue, b0 as isValidMsFileSourceId, b2 as sameNetworkIdentity, b3 as validateBsvNetwork, b4 as validateNetworkIdentity } from './protocol-Czc3NgOD.js';
|
package/dist/protocol.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { DOMAIN_MAX_PROFILES, 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-
|
|
1
|
+
export { DOMAIN_MAX_PROFILES, 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-QUZZ2OXO.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 { V as ProtocolErrorCode, aG as P2pkhTransferAssetId, aW as ProtocolRequestMessage, N as NetworkIdentity, c as ProtocolMethod, M as MethodParams, Y as AiToolMessage, X as AiToolDefinition, ad as JSONValue, aX as ProtocolResultMessage, aV as ProtocolReadyMessage, aR as ProtocolClosingMessage, d as MethodResult, aS as ProtocolError, aU as ProtocolEventPayload } from './protocol-Czc3NgOD.js';
|
|
2
|
+
export { W as AI_TOOLS_MAX_JSON_CHARS, A as AiTool, Z as AiToolSchema, b as AiToolsRegistered, aZ as assertToolJson, a_ as assertToolPayload, a$ as isAiToolMessage, b1 as parseToolDefinitions, b5 as validateToolArguments } from './protocol-Czc3NgOD.js';
|
|
3
3
|
|
|
4
4
|
/** 校验失败:抛出的对象。service 会捕获并组装 ProtocolError。 */
|
|
5
5
|
declare class ProtocolValidationError extends Error {
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAiToolMessage, parseToolDefinitions, validateToolArguments, assertToolPayload } from './chunk-VVOTW5ZT.js';
|
|
2
2
|
export { AI_TOOLS_MAX_JSON_CHARS, assertToolJson, assertToolPayload, isAiToolMessage, parseToolDefinitions, validateToolArguments } from './chunk-VVOTW5ZT.js';
|
|
3
|
-
import { PROTOCOL_VERSION, PROTOCOL_METHODS, validateNetworkIdentity, sameNetworkIdentity, DOMAIN_MAX_PROFILES, isValidMsFileSourceId } from './chunk-
|
|
3
|
+
import { PROTOCOL_VERSION, PROTOCOL_METHODS, validateNetworkIdentity, sameNetworkIdentity, DOMAIN_MAX_PROFILES, isValidMsFileSourceId } from './chunk-QUZZ2OXO.js';
|
|
4
4
|
import { validateApplicationPurpose, assertPaymentSignatureSlot } from './chunk-7ZOCLB2S.js';
|
|
5
5
|
|
|
6
6
|
// src/validation.ts
|
|
@@ -128,6 +128,12 @@ function keys(obj, allowed) {
|
|
|
128
128
|
throw new ProtocolValidationError("invalid_request", "Unexpected request field");
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
+
function msfileBlockPrice(value) {
|
|
132
|
+
if (value === void 0) return void 0;
|
|
133
|
+
if (typeof value !== "string" || !/^[1-9][0-9]{0,15}$/u.test(value))
|
|
134
|
+
throw new ProtocolValidationError("invalid_request", "Invalid MSFile full block price limit");
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
131
137
|
function hex(value, field, pattern = /^(?:[0-9a-f]{2})+$/iu) {
|
|
132
138
|
const str = expectString(value, field);
|
|
133
139
|
if (!pattern.test(str)) throw new ProtocolValidationError("invalid_request", `Invalid ${field}`);
|
|
@@ -204,7 +210,7 @@ function validateApplicationPayment(obj) {
|
|
|
204
210
|
function validateConnectLoginParams(raw) {
|
|
205
211
|
const obj = expectObject(raw, "connect.login params");
|
|
206
212
|
for (const key of Object.keys(obj))
|
|
207
|
-
if (key !== "text" && key !== "claims" && key !== "publicationProof")
|
|
213
|
+
if (key !== "text" && key !== "claims" && key !== "publicationProof" && key !== "loginChallenge")
|
|
208
214
|
throw new ProtocolValidationError("invalid_request", "connect.login contains an unsupported field");
|
|
209
215
|
const text = expectString(obj.text, "text");
|
|
210
216
|
let claims;
|
|
@@ -217,7 +223,12 @@ function validateConnectLoginParams(raw) {
|
|
|
217
223
|
claims = [...obj.claims];
|
|
218
224
|
}
|
|
219
225
|
const publicationProof = expectPublicationRecordString(obj.publicationProof);
|
|
220
|
-
return
|
|
226
|
+
return {
|
|
227
|
+
text,
|
|
228
|
+
claims,
|
|
229
|
+
...publicationProof === void 0 ? {} : { publicationProof },
|
|
230
|
+
...validateLoginChallenge(obj.loginChallenge)
|
|
231
|
+
};
|
|
221
232
|
}
|
|
222
233
|
function validateConnectLogoutParams(raw) {
|
|
223
234
|
expectObject(raw, "connect.logout params");
|
|
@@ -225,12 +236,23 @@ function validateConnectLogoutParams(raw) {
|
|
|
225
236
|
}
|
|
226
237
|
function validateConnectLaunchParams(raw) {
|
|
227
238
|
const obj = expectObject(raw, "connect.launch params");
|
|
228
|
-
if (Object.keys(obj).some((key) => key !== "launchToken" && key !== "publicationProof")) {
|
|
239
|
+
if (Object.keys(obj).some((key) => key !== "launchToken" && key !== "publicationProof" && key !== "loginChallenge")) {
|
|
229
240
|
throw new ProtocolValidationError("invalid_request", "connect.launch contains an unsupported field");
|
|
230
241
|
}
|
|
231
242
|
const launchToken = expectNonEmptyString(obj.launchToken, "launchToken");
|
|
232
243
|
const publicationProof = expectPublicationRecordString(obj.publicationProof);
|
|
233
|
-
return
|
|
244
|
+
return {
|
|
245
|
+
launchToken,
|
|
246
|
+
...publicationProof === void 0 ? {} : { publicationProof },
|
|
247
|
+
...validateLoginChallenge(obj.loginChallenge)
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function validateLoginChallenge(value) {
|
|
251
|
+
if (value === void 0) return {};
|
|
252
|
+
if (typeof value !== "string" || !/^[0-9a-f]{64}$/u.test(value)) {
|
|
253
|
+
throw new ProtocolValidationError("invalid_request", "loginChallenge must be 32 bytes in lowercase hex");
|
|
254
|
+
}
|
|
255
|
+
return { loginChallenge: value };
|
|
234
256
|
}
|
|
235
257
|
function expectPublicationRecordString(value) {
|
|
236
258
|
if (value === void 0) return void 0;
|
|
@@ -564,6 +586,17 @@ function parseRequestMessage(raw, receiverIdentity) {
|
|
|
564
586
|
observedRawTxHex: params.observedRawTxHex === void 0 ? void 0 : hex(params.observedRawTxHex, "observedRawTxHex")
|
|
565
587
|
};
|
|
566
588
|
break;
|
|
589
|
+
case "chain.get_transactions": {
|
|
590
|
+
keys(params, ["txids", "mode"]);
|
|
591
|
+
const { txids, mode } = params;
|
|
592
|
+
if (!Array.isArray(txids) || !txids.length || txids.length > 20 || mode !== "raw" && mode !== "status") {
|
|
593
|
+
throw new ProtocolValidationError("invalid_request", "Expected 1 to 20 transaction IDs and a valid query mode");
|
|
594
|
+
}
|
|
595
|
+
const ids = Array.from(txids, (txid) => hex(txid, "txid", /^[0-9a-f]{64}$/iu));
|
|
596
|
+
if (new Set(ids).size !== ids.length) throw new ProtocolValidationError("invalid_request", "Duplicate transaction ID");
|
|
597
|
+
normalized = { txids: ids, mode };
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
567
600
|
case "chain.list_script_unspent":
|
|
568
601
|
keys(params, ["script"]);
|
|
569
602
|
normalized = { script: hex(params.script, "script") };
|
|
@@ -588,9 +621,40 @@ function parseRequestMessage(raw, receiverIdentity) {
|
|
|
588
621
|
normalized = { fileName: expectNonEmptyString(params.fileName, "fileName"), content: parseBinaryField(params.content, "content") };
|
|
589
622
|
break;
|
|
590
623
|
case "msfile.content.read":
|
|
591
|
-
|
|
592
|
-
|
|
624
|
+
case "msfile.content.open": {
|
|
625
|
+
keys(params, ["seedHashHex", "clientRequestId", "maxFullBlockPriceSatoshis"]);
|
|
626
|
+
const price = msfileBlockPrice(params.maxFullBlockPriceSatoshis);
|
|
627
|
+
const needsId = method === "msfile.content.open" || price !== void 0 || params.clientRequestId !== void 0;
|
|
628
|
+
normalized = {
|
|
629
|
+
...validateMsFileStatParams(params),
|
|
630
|
+
...needsId ? validatePaymentStatusParams({ clientRequestId: params.clientRequestId }) : {},
|
|
631
|
+
...price === void 0 ? {} : { maxFullBlockPriceSatoshis: price }
|
|
632
|
+
};
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
case "msfile.content.status":
|
|
636
|
+
normalized = validatePaymentStatusParams(params);
|
|
593
637
|
break;
|
|
638
|
+
case "msfile.content.price": {
|
|
639
|
+
keys(params, ["clientRequestId", "maxFullBlockPriceSatoshis"]);
|
|
640
|
+
const price = msfileBlockPrice(params.maxFullBlockPriceSatoshis);
|
|
641
|
+
normalized = price === void 0 && params.clientRequestId === void 0 ? {} : {
|
|
642
|
+
...validatePaymentStatusParams({ clientRequestId: params.clientRequestId }),
|
|
643
|
+
...price === void 0 ? {} : { maxFullBlockPriceSatoshis: price }
|
|
644
|
+
};
|
|
645
|
+
if (price === void 0 && params.clientRequestId !== void 0)
|
|
646
|
+
throw new ProtocolValidationError("invalid_request", "Expected a full block price limit");
|
|
647
|
+
break;
|
|
648
|
+
}
|
|
649
|
+
case "msfile.content.range": {
|
|
650
|
+
keys(params, ["clientRequestId", "offset", "length"]);
|
|
651
|
+
const { offset, length } = params;
|
|
652
|
+
if (typeof offset !== "number" || !Number.isSafeInteger(offset) || offset < 0 || typeof length !== "number" || !Number.isSafeInteger(length) || length < 0 || length > 256 * 1024 || !Number.isSafeInteger(offset + length)) {
|
|
653
|
+
throw new ProtocolValidationError("invalid_request", "Invalid MSFile byte range");
|
|
654
|
+
}
|
|
655
|
+
normalized = { ...validatePaymentStatusParams({ clientRequestId: params.clientRequestId }), offset, length };
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
594
658
|
case "domain.profiles":
|
|
595
659
|
normalized = validateDomainProfilesParams(params);
|
|
596
660
|
break;
|