keymaster-connect 0.1.8 → 0.3.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 +31 -1
- package/dist/chunk-7ZOCLB2S.js +68 -0
- package/dist/chunk-7ZOCLB2S.js.map +1 -0
- package/dist/{chunk-D2RL3QGR.js → chunk-A4VCQSB5.js} +20 -3
- package/dist/chunk-A4VCQSB5.js.map +1 -0
- package/dist/{chunk-M2YEI4PG.js → chunk-VVOTW5ZT.js} +3 -92
- package/dist/chunk-VVOTW5ZT.js.map +1 -0
- package/dist/index.d.ts +67 -26
- package/dist/index.js +76 -41
- package/dist/index.js.map +1 -1
- package/dist/{protocol-B7bpi5ro.d.ts → protocol-Dfo305R9.d.ts} +183 -35
- 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 +175 -22
- package/dist/server.js.map +1 -1
- package/dist/signing.d.ts +12 -0
- package/dist/signing.js +3 -0
- package/dist/signing.js.map +1 -0
- package/package.json +6 -1
- package/dist/chunk-D2RL3QGR.js.map +0 -1
- package/dist/chunk-M2YEI4PG.js.map +0 -1
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
interface AppFileEntry {
|
|
2
|
-
path: string;
|
|
3
|
-
mime: string;
|
|
4
|
-
size: number;
|
|
5
|
-
seedhashhex: string;
|
|
6
|
-
}
|
|
7
|
-
interface Publication {
|
|
8
|
-
version: 1;
|
|
9
|
-
kind: 'url' | 'files' | 'both';
|
|
10
|
-
appPublicKeyHex: string;
|
|
11
|
-
name: string;
|
|
12
|
-
description: string;
|
|
13
|
-
url?: {
|
|
14
|
-
address: string;
|
|
15
|
-
icon: string;
|
|
16
|
-
};
|
|
17
|
-
files?: {
|
|
18
|
-
entrySeedhashhex: string;
|
|
19
|
-
icon: string;
|
|
20
|
-
files: AppFileEntry[];
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
interface PublicationProof {
|
|
24
|
-
publication: Publication;
|
|
25
|
-
signatureHex: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
1
|
/** Connect wire v1 bidirectional AI tools. Never grants wallet payment/signing authority. */
|
|
29
2
|
|
|
30
3
|
interface AiToolSchema {
|
|
@@ -111,6 +84,8 @@ type AiToolMessage = {
|
|
|
111
84
|
};
|
|
112
85
|
declare function isAiToolMessage(value: unknown): value is AiToolMessage;
|
|
113
86
|
|
|
87
|
+
/** Connect v1 公开契约。独立于钱包内部执行 DTO、能力框架和持久化。 */
|
|
88
|
+
|
|
114
89
|
/** 身份网络在创建/导入时确定;公钥相同也不能跨网复用业务身份。 */
|
|
115
90
|
type BsvNetwork = "main" | "test";
|
|
116
91
|
interface NetworkIdentity {
|
|
@@ -314,7 +289,7 @@ type ProtocolErrorCode =
|
|
|
314
289
|
/** Too many non-terminal Connect payment responsibilities. */
|
|
315
290
|
| "payment_pending_limit"
|
|
316
291
|
/** Same stable payment key with different frozen facts. */
|
|
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";
|
|
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";
|
|
318
293
|
interface ProtocolError {
|
|
319
294
|
code: ProtocolErrorCode;
|
|
320
295
|
message: string;
|
|
@@ -463,6 +438,82 @@ interface PaymentStatusParams {
|
|
|
463
438
|
clientRequestId: string;
|
|
464
439
|
}
|
|
465
440
|
type PaymentStatusResult = PaymentPayResult;
|
|
441
|
+
interface ChainOutpoint {
|
|
442
|
+
txid: string;
|
|
443
|
+
vout: number;
|
|
444
|
+
}
|
|
445
|
+
interface PaymentDataSignature {
|
|
446
|
+
outputIndex: number;
|
|
447
|
+
offset: number;
|
|
448
|
+
prefixHex: string;
|
|
449
|
+
suffixHex: string;
|
|
450
|
+
}
|
|
451
|
+
interface PaymentPrepareParams extends PaymentStatusParams {
|
|
452
|
+
outputs: PaymentOutput[];
|
|
453
|
+
dataSignature: PaymentDataSignature;
|
|
454
|
+
}
|
|
455
|
+
type PaymentPrepareResult = PaymentPayResult & {
|
|
456
|
+
reservation?: {
|
|
457
|
+
reservationId: string;
|
|
458
|
+
inputs: ChainOutpoint[];
|
|
459
|
+
expiresAt: number;
|
|
460
|
+
};
|
|
461
|
+
};
|
|
462
|
+
interface PaymentReservationParams extends PaymentStatusParams {
|
|
463
|
+
reservationId: string;
|
|
464
|
+
}
|
|
465
|
+
interface PaymentCommitParams extends PaymentReservationParams {
|
|
466
|
+
signingObject: BinaryField;
|
|
467
|
+
}
|
|
468
|
+
type ChainScriptHistoryParams = {
|
|
469
|
+
script: string;
|
|
470
|
+
} & ({
|
|
471
|
+
state: "confirmed";
|
|
472
|
+
fromHeight: number;
|
|
473
|
+
toHeight: number;
|
|
474
|
+
cursor?: string;
|
|
475
|
+
} | {
|
|
476
|
+
state: "unconfirmed";
|
|
477
|
+
cursor?: string;
|
|
478
|
+
});
|
|
479
|
+
interface ChainScriptHistoryResult {
|
|
480
|
+
entries: Array<{
|
|
481
|
+
txid: string;
|
|
482
|
+
height: number | null;
|
|
483
|
+
}>;
|
|
484
|
+
cursor?: string;
|
|
485
|
+
}
|
|
486
|
+
type ChainTransactionResult = {
|
|
487
|
+
state: "not_observed" | "invalid";
|
|
488
|
+
} | {
|
|
489
|
+
state: "unconfirmed";
|
|
490
|
+
rawTxHex: string;
|
|
491
|
+
} | {
|
|
492
|
+
state: "confirmed";
|
|
493
|
+
rawTxHex: string;
|
|
494
|
+
height: number;
|
|
495
|
+
blockHash: string;
|
|
496
|
+
index: number;
|
|
497
|
+
};
|
|
498
|
+
interface ChainBroadcastResult {
|
|
499
|
+
state: "accepted" | "rejected" | "unknown";
|
|
500
|
+
txid: string;
|
|
501
|
+
}
|
|
502
|
+
interface ApplicationPaymentParams {
|
|
503
|
+
purpose: string;
|
|
504
|
+
inputs: ChainOutpoint[];
|
|
505
|
+
address: string;
|
|
506
|
+
feeSatoshis: number;
|
|
507
|
+
rawTxHex: string;
|
|
508
|
+
}
|
|
509
|
+
interface MsFileImportParams {
|
|
510
|
+
fileName: string;
|
|
511
|
+
content: BinaryField;
|
|
512
|
+
}
|
|
513
|
+
interface MsFileContentResult {
|
|
514
|
+
seed: BinaryField;
|
|
515
|
+
content: BinaryField;
|
|
516
|
+
}
|
|
466
517
|
interface ConnectLoginParams {
|
|
467
518
|
/** 人类可读确认文案。 */
|
|
468
519
|
text: string;
|
|
@@ -472,11 +523,12 @@ interface ConnectLoginParams {
|
|
|
472
523
|
*/
|
|
473
524
|
claims?: string[];
|
|
474
525
|
/**
|
|
475
|
-
* App
|
|
476
|
-
*
|
|
526
|
+
* App 入口的发布来源证明记录字符串(`base64url(规范JSON).签名hex`)。
|
|
527
|
+
* SDK 从当前入口 HTML 头读取并整体提交,不解码、不校验内容;
|
|
528
|
+
* 钱包解码、验签并核对证明 origin 与可信 event.origin,应用不能自报来源。
|
|
477
529
|
* 本地 Files 部署不依赖该字段(以 daemon 可信部署登记为准)。
|
|
478
530
|
*/
|
|
479
|
-
publicationProof?:
|
|
531
|
+
publicationProof?: string;
|
|
480
532
|
}
|
|
481
533
|
interface ConnectLoginResult {
|
|
482
534
|
/** 不透明恢复凭据,绑定原钱包和精确来源;不得写入日志或 URL。 */
|
|
@@ -497,10 +549,10 @@ interface ConnectLaunchParams {
|
|
|
497
549
|
/** 由 launcher 写入 client app 启动 URL 的 launchToken。一次性消费。 */
|
|
498
550
|
launchToken: string;
|
|
499
551
|
/**
|
|
500
|
-
* App
|
|
552
|
+
* App 入口的发布来源证明记录字符串(可选;钱包发起的目录启动一般不需要客户端提交,
|
|
501
553
|
* 钱包从所选入口自行读取;应用提交时钱包核对一致性,不能自报来源)。
|
|
502
554
|
*/
|
|
503
|
-
publicationProof?:
|
|
555
|
+
publicationProof?: string;
|
|
504
556
|
}
|
|
505
557
|
interface ConnectLaunchResult {
|
|
506
558
|
authorizationId: string;
|
|
@@ -509,7 +561,40 @@ interface ConnectLaunchResult {
|
|
|
509
561
|
resolvedAt: number;
|
|
510
562
|
}
|
|
511
563
|
/** 协议方法名常量集合。 */
|
|
512
|
-
declare const
|
|
564
|
+
declare const DOMAIN_MAX_PROFILES = 100;
|
|
565
|
+
interface DomainProfile {
|
|
566
|
+
publicKeyHex: string;
|
|
567
|
+
domain: string;
|
|
568
|
+
avatar?: {
|
|
569
|
+
seedHashHex: string;
|
|
570
|
+
};
|
|
571
|
+
header?: {
|
|
572
|
+
seedHashHex: string;
|
|
573
|
+
};
|
|
574
|
+
text?: Record<string, string>;
|
|
575
|
+
expiresAt: number;
|
|
576
|
+
}
|
|
577
|
+
type ProfileResult = {
|
|
578
|
+
publicKeyHex: string;
|
|
579
|
+
profile: DomainProfile;
|
|
580
|
+
} | {
|
|
581
|
+
publicKeyHex: string;
|
|
582
|
+
error: {
|
|
583
|
+
code: "invalid_public_key" | "name_not_found" | "primary_name_required";
|
|
584
|
+
};
|
|
585
|
+
};
|
|
586
|
+
interface DomainProfilesResult {
|
|
587
|
+
results: ProfileResult[];
|
|
588
|
+
}
|
|
589
|
+
interface DomainProfilesParams {
|
|
590
|
+
publicKeys: string[];
|
|
591
|
+
serviceId?: string;
|
|
592
|
+
}
|
|
593
|
+
interface DomainGetPublicKeyParams {
|
|
594
|
+
domain: string;
|
|
595
|
+
serviceId?: string;
|
|
596
|
+
}
|
|
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"];
|
|
513
598
|
type ProtocolMethod = (typeof PROTOCOL_METHODS)[number];
|
|
514
599
|
/**
|
|
515
600
|
* 方法 -> 请求参数类型 的映射。`MethodParams<M>` 是计算出的参数类型。
|
|
@@ -522,6 +607,34 @@ interface MethodParamsMap {
|
|
|
522
607
|
"cipher.decrypt": CipherDecryptParams;
|
|
523
608
|
"payment.pay": PaymentPayParams;
|
|
524
609
|
"payment.status": PaymentStatusParams;
|
|
610
|
+
"payment.prepare": PaymentPrepareParams;
|
|
611
|
+
"payment.commit": PaymentCommitParams;
|
|
612
|
+
"payment.cancel": PaymentReservationParams;
|
|
613
|
+
"chain.get_height": {};
|
|
614
|
+
"chain.list_script_history": ChainScriptHistoryParams;
|
|
615
|
+
"chain.get_transaction": {
|
|
616
|
+
txid: string;
|
|
617
|
+
observedRawTxHex?: string;
|
|
618
|
+
};
|
|
619
|
+
"chain.list_script_unspent": {
|
|
620
|
+
script: string;
|
|
621
|
+
};
|
|
622
|
+
"chain.broadcast": {
|
|
623
|
+
rawTxHex: string;
|
|
624
|
+
};
|
|
625
|
+
"application.key": {
|
|
626
|
+
purpose: string;
|
|
627
|
+
};
|
|
628
|
+
"application.sign_message": {
|
|
629
|
+
purpose: string;
|
|
630
|
+
message: BinaryField;
|
|
631
|
+
};
|
|
632
|
+
"application.sign_payment": ApplicationPaymentParams;
|
|
633
|
+
"msfile.seller.status": {};
|
|
634
|
+
"msfile.import": MsFileImportParams;
|
|
635
|
+
"msfile.content.read": MsFileStatParams;
|
|
636
|
+
"domain.profiles": DomainProfilesParams;
|
|
637
|
+
"domain.get_public_key": DomainGetPublicKeyParams;
|
|
525
638
|
"connect.login": ConnectLoginParams;
|
|
526
639
|
"connect.logout": ConnectLogoutParams;
|
|
527
640
|
"connect.launch": ConnectLaunchParams;
|
|
@@ -538,6 +651,41 @@ interface MethodResultMap {
|
|
|
538
651
|
"cipher.decrypt": CipherDecryptResult;
|
|
539
652
|
"payment.pay": PaymentPayResult;
|
|
540
653
|
"payment.status": PaymentStatusResult;
|
|
654
|
+
"payment.prepare": PaymentPrepareResult;
|
|
655
|
+
"payment.commit": PaymentPayResult;
|
|
656
|
+
"payment.cancel": PaymentPayResult;
|
|
657
|
+
"chain.get_height": {
|
|
658
|
+
height: number;
|
|
659
|
+
};
|
|
660
|
+
"chain.list_script_history": ChainScriptHistoryResult;
|
|
661
|
+
"chain.get_transaction": ChainTransactionResult;
|
|
662
|
+
"chain.list_script_unspent": {
|
|
663
|
+
outputs: Array<ChainOutpoint & {
|
|
664
|
+
satoshis: number;
|
|
665
|
+
}>;
|
|
666
|
+
};
|
|
667
|
+
"chain.broadcast": ChainBroadcastResult;
|
|
668
|
+
"application.key": {
|
|
669
|
+
publicKeyHex: string;
|
|
670
|
+
};
|
|
671
|
+
"application.sign_message": {
|
|
672
|
+
publicKeyHex: string;
|
|
673
|
+
signature: BinaryField;
|
|
674
|
+
};
|
|
675
|
+
"application.sign_payment": {
|
|
676
|
+
rawTxHex: string;
|
|
677
|
+
};
|
|
678
|
+
"msfile.seller.status": {
|
|
679
|
+
ready: boolean;
|
|
680
|
+
};
|
|
681
|
+
"msfile.import": {
|
|
682
|
+
seedHashHex: string;
|
|
683
|
+
};
|
|
684
|
+
"msfile.content.read": MsFileContentResult;
|
|
685
|
+
"domain.profiles": DomainProfilesResult;
|
|
686
|
+
"domain.get_public_key": {
|
|
687
|
+
publicKeyHex: string;
|
|
688
|
+
};
|
|
541
689
|
"connect.login": ConnectLoginResult;
|
|
542
690
|
"connect.logout": ConnectLogoutResult;
|
|
543
691
|
"connect.launch": ConnectLaunchResult;
|
|
@@ -584,4 +732,4 @@ type ProtocolResultMessage = {
|
|
|
584
732
|
networkIdentity?: NetworkIdentity;
|
|
585
733
|
};
|
|
586
734
|
|
|
587
|
-
export {
|
|
735
|
+
export { type ChannelSubscriptionStatus as $, type AiTool as A, type BinaryField as B, type ConnectLoginParams as C, type DomainProfile as D, type MsFileSeedReadParams as E, type MsFileReadResult as F, type MsFileBlockReadParams as G, type PaymentStatusResult as H, type IdentityGetParams as I, type ChannelPublishParams as J, type ChannelPublishResult as K, type ChannelSubscriptionSetParams as L, type MethodParams as M, type NetworkIdentity as N, type ChannelSubscriptionSetResult as O, type ProtocolEventMessage as P, type ProtocolErrorCode as Q, AI_TOOLS_MAX_JSON_CHARS as R, type AiToolDefinition as S, type AiToolMessage as T, type AiToolSchema as U, type ApplicationPaymentParams as V, type BsvNetwork as W, type ChainScriptHistoryParams as X, type ChannelMessageReceivedEventData as Y, type ChannelSubscriptionErrorCode as Z, type ChannelSubscriptionPhase as _, type DomainProfilesResult as a, type ConnectLogoutParams as a0, type ConnectPaymentStatus as a1, DOMAIN_MAX_PROFILES as a2, type DomainGetPublicKeyParams as a3, type DomainProfilesParams as a4, type JSONValue as a5, MSFILE_BLOCK_SIZE_BYTES as a6, MSFILE_DIGEST_SIZE_BYTES as a7, MSFILE_LOCAL_SOURCE_ID as a8, MSFILE_MAX_BLOCK_BYTES as a9, type PaymentReleaseSummary as aA, type PaymentReservationParams as aB, type ProfileResult as aC, type ProtocolCancelMessage as aD, type ProtocolClosingMessage as aE, type ProtocolError as aF, type ProtocolEventName as aG, type ProtocolEventPayload as aH, type ProtocolReadyMessage as aI, type ProtocolRequestMessage as aJ, type ProtocolResultMessage as aK, type ResolvedClaimValue as aL, assertToolJson as aM, assertToolPayload as aN, isAiToolMessage as aO, isValidMsFileSourceId as aP, parseToolDefinitions as aQ, sameNetworkIdentity as aR, validateBsvNetwork as aS, validateNetworkIdentity as aT, validateToolArguments as aU, MSFILE_MAX_CONTENT_BYTES as aa, MSFILE_MAX_ERROR_MESSAGE_BYTES as ab, MSFILE_MAX_HEADER_BYTES as ac, MSFILE_MAX_SEED_BYTES as ad, MSFILE_PROTOCOL_ID as ae, type MethodParamsMap as af, type MethodResultMap as ag, type MsFileImportParams as ah, type MsFileLocalSourceStat as ai, type MsFileRemoteSourceStat as aj, type MsFileSatoshiAmount as ak, type MsFileSourceKind as al, type MsFileSourceStat as am, type MsFileStatAbsentEntry as an, type MsFileStatAvailableEntry as ao, type MsFileStatDiscoveringEntry as ap, type MsFileStatNetworkErrorEntry as aq, type MsFileStatQuotedEntry as ar, type MsFileSupplierStat as as, type P2pkhTransferAssetId as at, PROTOCOL_METHODS as au, PROTOCOL_VERSION as av, type PaymentCommitParams as aw, type PaymentDataSignature as ax, type PaymentOutput as ay, type PaymentPrepareParams as az, type AiToolsRegistered as b, 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 ChainScriptHistoryResult as t, type ChainTransactionResult as u, type ChainOutpoint as v, type ChainBroadcastResult as w, type MsFileContentResult as x, type MsFileStatParams as y, type MsFileStatResult as z };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { S as AiToolDefinition, T as AiToolMessage, U as AiToolSchema, b as AiToolsRegistered, V as ApplicationPaymentParams, B as BinaryField, W as BsvNetwork, w as ChainBroadcastResult, v as ChainOutpoint, X as ChainScriptHistoryParams, t as ChainScriptHistoryResult, u as ChainTransactionResult, Y as ChannelMessageReceivedEventData, J as ChannelPublishParams, K as ChannelPublishResult, Z as ChannelSubscriptionErrorCode, _ as ChannelSubscriptionPhase, L as ChannelSubscriptionSetParams, O as ChannelSubscriptionSetResult, $ as ChannelSubscriptionStatus, n as CipherDecryptParams, o as CipherDecryptResult, l as CipherEncryptParams, m as CipherEncryptResult, g as ConnectLaunchParams, h as ConnectLaunchResult, C as ConnectLoginParams, e as ConnectLoginResult, a0 as ConnectLogoutParams, f as ConnectLogoutResult, a1 as ConnectPaymentStatus, a2 as DOMAIN_MAX_PROFILES, a3 as DomainGetPublicKeyParams, D as DomainProfile, a4 as DomainProfilesParams, a as DomainProfilesResult, I as IdentityGetParams, i as IdentityGetResult, j as IntentSignParams, k as IntentSignResult, a5 as JSONValue, a6 as MSFILE_BLOCK_SIZE_BYTES, a7 as MSFILE_DIGEST_SIZE_BYTES, a8 as MSFILE_LOCAL_SOURCE_ID, a9 as MSFILE_MAX_BLOCK_BYTES, aa as MSFILE_MAX_CONTENT_BYTES, ab as MSFILE_MAX_ERROR_MESSAGE_BYTES, ac as MSFILE_MAX_HEADER_BYTES, ad as MSFILE_MAX_SEED_BYTES, ae as MSFILE_PROTOCOL_ID, M as MethodParams, af as MethodParamsMap, d as MethodResult, ag as MethodResultMap, G as MsFileBlockReadParams, x as MsFileContentResult, ah as MsFileImportParams, ai as MsFileLocalSourceStat, F as MsFileReadResult, aj as MsFileRemoteSourceStat, ak as MsFileSatoshiAmount, E as MsFileSeedReadParams, al as MsFileSourceKind, am as MsFileSourceStat, an as MsFileStatAbsentEntry, ao as MsFileStatAvailableEntry, ap as MsFileStatDiscoveringEntry, aq as MsFileStatNetworkErrorEntry, y as MsFileStatParams, ar as MsFileStatQuotedEntry, z as MsFileStatResult, as as MsFileSupplierStat, N as NetworkIdentity, at as P2pkhTransferAssetId, au as PROTOCOL_METHODS, av as PROTOCOL_VERSION, aw as PaymentCommitParams, ax as PaymentDataSignature, ay as PaymentOutput, p as PaymentPayParams, q as PaymentPayResult, az as PaymentPrepareParams, r as PaymentPrepareResult, aA as PaymentReleaseSummary, aB as PaymentReservationParams, s as PaymentStatusParams, H as PaymentStatusResult, aC as ProfileResult, aD as ProtocolCancelMessage, aE as ProtocolClosingMessage, aF as ProtocolError, Q as ProtocolErrorCode, P as ProtocolEventMessage, aG as ProtocolEventName, aH as ProtocolEventPayload, c as ProtocolMethod, aI as ProtocolReadyMessage, aJ as ProtocolRequestMessage, aK as ProtocolResultMessage, aL as ResolvedClaimValue, aP as isValidMsFileSourceId, aR as sameNetworkIdentity, aS as validateBsvNetwork, aT as validateNetworkIdentity } from './protocol-Dfo305R9.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, 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-A4VCQSB5.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 { Q as ProtocolErrorCode, at as P2pkhTransferAssetId, aJ as ProtocolRequestMessage, N as NetworkIdentity, c as ProtocolMethod, M as MethodParams, T as AiToolMessage, S as AiToolDefinition, a5 as JSONValue, aK as ProtocolResultMessage, aI as ProtocolReadyMessage, aE as ProtocolClosingMessage, d as MethodResult, aF as ProtocolError, aH as ProtocolEventPayload } from './protocol-Dfo305R9.js';
|
|
2
|
+
export { R as AI_TOOLS_MAX_JSON_CHARS, A as AiTool, U as AiToolSchema, b as AiToolsRegistered, aM as assertToolJson, aN as assertToolPayload, aO as isAiToolMessage, aQ as parseToolDefinitions, aU as validateToolArguments } from './protocol-Dfo305R9.js';
|
|
3
3
|
|
|
4
4
|
/** 校验失败:抛出的对象。service 会捕获并组装 ProtocolError。 */
|
|
5
5
|
declare class ProtocolValidationError extends Error {
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { isAiToolMessage, parseToolDefinitions, validateToolArguments, assertToolPayload
|
|
2
|
-
export { AI_TOOLS_MAX_JSON_CHARS, assertToolJson, assertToolPayload, isAiToolMessage, parseToolDefinitions, validateToolArguments } from './chunk-
|
|
3
|
-
import { PROTOCOL_VERSION, PROTOCOL_METHODS, validateNetworkIdentity, sameNetworkIdentity, isValidMsFileSourceId } from './chunk-
|
|
1
|
+
import { isAiToolMessage, parseToolDefinitions, validateToolArguments, assertToolPayload } from './chunk-VVOTW5ZT.js';
|
|
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-A4VCQSB5.js';
|
|
4
|
+
import { validateApplicationPurpose, assertPaymentSignatureSlot } from './chunk-7ZOCLB2S.js';
|
|
4
5
|
|
|
5
6
|
// src/validation.ts
|
|
6
7
|
var ProtocolValidationError = class extends Error {
|
|
@@ -64,6 +65,28 @@ function assertOriginMatches(aud, eventOrigin) {
|
|
|
64
65
|
throw new ProtocolValidationError("invalid_origin", "aud does not match event origin");
|
|
65
66
|
}
|
|
66
67
|
}
|
|
68
|
+
function domainServiceID(params, input) {
|
|
69
|
+
if (Object.keys(params).some((key) => key !== input && key !== "serviceId")) {
|
|
70
|
+
throw new ProtocolValidationError("invalid_request", "Unexpected domain query parameter");
|
|
71
|
+
}
|
|
72
|
+
const id = params.serviceId;
|
|
73
|
+
if (id !== void 0 && (typeof id !== "string" || !/^[A-Za-z0-9_-]{1,64}$/u.test(id))) {
|
|
74
|
+
throw new ProtocolValidationError("invalid_request", "Invalid domain service ID");
|
|
75
|
+
}
|
|
76
|
+
return id;
|
|
77
|
+
}
|
|
78
|
+
function validateDomainProfilesParams(params) {
|
|
79
|
+
const serviceId = domainServiceID(params, "publicKeys");
|
|
80
|
+
const keys2 = params.publicKeys;
|
|
81
|
+
if (!Array.isArray(keys2) || keys2.length > DOMAIN_MAX_PROFILES) {
|
|
82
|
+
throw new ProtocolValidationError("invalid_request", "Expected up to 100 public keys");
|
|
83
|
+
}
|
|
84
|
+
const publicKeys = Array.from(keys2, (key) => {
|
|
85
|
+
if (typeof key !== "string") throw new ProtocolValidationError("invalid_request", "Public keys must be strings");
|
|
86
|
+
return key;
|
|
87
|
+
});
|
|
88
|
+
return { publicKeys, serviceId };
|
|
89
|
+
}
|
|
67
90
|
function validatePaymentPayParams(raw) {
|
|
68
91
|
const obj = expectObject(raw, "payment.pay params");
|
|
69
92
|
const allowed = ["clientRequestId", "outputs"];
|
|
@@ -100,6 +123,84 @@ function validatePaymentStatusParams(raw) {
|
|
|
100
123
|
throw new ProtocolValidationError("invalid_request", "clientRequestId is invalid");
|
|
101
124
|
return { clientRequestId };
|
|
102
125
|
}
|
|
126
|
+
function keys(obj, allowed) {
|
|
127
|
+
if (Object.keys(obj).some((key) => !allowed.includes(key))) {
|
|
128
|
+
throw new ProtocolValidationError("invalid_request", "Unexpected request field");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function hex(value, field, pattern = /^(?:[0-9a-f]{2})+$/iu) {
|
|
132
|
+
const str = expectString(value, field);
|
|
133
|
+
if (!pattern.test(str)) throw new ProtocolValidationError("invalid_request", `Invalid ${field}`);
|
|
134
|
+
return str.toLowerCase();
|
|
135
|
+
}
|
|
136
|
+
function natural(value, field, max = Number.MAX_SAFE_INTEGER) {
|
|
137
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0 || value > max) {
|
|
138
|
+
throw new ProtocolValidationError("invalid_request", `Invalid ${field}`);
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
function applicationPurpose(value) {
|
|
143
|
+
try {
|
|
144
|
+
return validateApplicationPurpose(expectString(value, "purpose"));
|
|
145
|
+
} catch {
|
|
146
|
+
throw new ProtocolValidationError("invalid_request", "Invalid application purpose");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function validatePrepare(obj) {
|
|
150
|
+
keys(obj, ["clientRequestId", "outputs", "dataSignature"]);
|
|
151
|
+
const { clientRequestId, outputs } = validatePaymentPayParams({ clientRequestId: obj.clientRequestId, outputs: obj.outputs });
|
|
152
|
+
const raw = expectObject(obj.dataSignature, "dataSignature");
|
|
153
|
+
keys(raw, ["outputIndex", "offset", "prefixHex", "suffixHex"]);
|
|
154
|
+
const dataSignature = {
|
|
155
|
+
outputIndex: natural(raw.outputIndex, "outputIndex"),
|
|
156
|
+
offset: natural(raw.offset, "offset"),
|
|
157
|
+
prefixHex: hex(raw.prefixHex, "prefixHex", /^(?:[0-9a-f]{2})*$/iu),
|
|
158
|
+
suffixHex: hex(raw.suffixHex, "suffixHex", /^(?:[0-9a-f]{2})*$/iu)
|
|
159
|
+
};
|
|
160
|
+
try {
|
|
161
|
+
assertPaymentSignatureSlot(outputs, dataSignature);
|
|
162
|
+
} catch {
|
|
163
|
+
throw new ProtocolValidationError("invalid_request", "Invalid payment signature slot");
|
|
164
|
+
}
|
|
165
|
+
return { clientRequestId, outputs, dataSignature };
|
|
166
|
+
}
|
|
167
|
+
function validateReservation(obj, commit) {
|
|
168
|
+
keys(obj, commit ? ["clientRequestId", "reservationId", "signingObject"] : ["clientRequestId", "reservationId"]);
|
|
169
|
+
const params = validatePaymentStatusParams({ clientRequestId: obj.clientRequestId });
|
|
170
|
+
const reservationId = hex(obj.reservationId, "reservationId", /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/iu);
|
|
171
|
+
return { ...params, reservationId, ...commit ? { signingObject: parseBinaryField(obj.signingObject, "signingObject") } : {} };
|
|
172
|
+
}
|
|
173
|
+
function validateScriptHistory(obj) {
|
|
174
|
+
const { state } = obj;
|
|
175
|
+
const script = hex(obj.script, "script");
|
|
176
|
+
const cursor = obj.cursor === void 0 ? void 0 : expectNonEmptyString(obj.cursor, "cursor");
|
|
177
|
+
if (state === "unconfirmed") {
|
|
178
|
+
keys(obj, ["state", "script", "cursor"]);
|
|
179
|
+
return { state, script, cursor };
|
|
180
|
+
}
|
|
181
|
+
if (state !== "confirmed") throw new ProtocolValidationError("invalid_request", "Invalid script history state");
|
|
182
|
+
keys(obj, ["state", "script", "cursor", "fromHeight", "toHeight"]);
|
|
183
|
+
const fromHeight = natural(obj.fromHeight, "fromHeight");
|
|
184
|
+
const toHeight = natural(obj.toHeight, "toHeight");
|
|
185
|
+
if (toHeight < fromHeight) throw new ProtocolValidationError("invalid_request", "Invalid height range");
|
|
186
|
+
return { state, script, cursor, fromHeight, toHeight };
|
|
187
|
+
}
|
|
188
|
+
function validateApplicationPayment(obj) {
|
|
189
|
+
keys(obj, ["purpose", "inputs", "address", "feeSatoshis", "rawTxHex"]);
|
|
190
|
+
if (!Array.isArray(obj.inputs) || obj.inputs.length === 0) throw new ProtocolValidationError("invalid_request", "Expected recovery inputs");
|
|
191
|
+
const inputs = Array.from(obj.inputs, (raw) => {
|
|
192
|
+
const row = expectObject(raw, "outpoint");
|
|
193
|
+
keys(row, ["txid", "vout"]);
|
|
194
|
+
return { txid: hex(row.txid, "txid", /^[0-9a-f]{64}$/iu), vout: natural(row.vout, "vout", 4294967295) };
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
purpose: applicationPurpose(obj.purpose),
|
|
198
|
+
inputs,
|
|
199
|
+
address: expectNonEmptyString(obj.address, "address"),
|
|
200
|
+
feeSatoshis: natural(obj.feeSatoshis, "feeSatoshis"),
|
|
201
|
+
rawTxHex: hex(obj.rawTxHex, "rawTxHex")
|
|
202
|
+
};
|
|
203
|
+
}
|
|
103
204
|
function validateConnectLoginParams(raw) {
|
|
104
205
|
const obj = expectObject(raw, "connect.login params");
|
|
105
206
|
for (const key of Object.keys(obj))
|
|
@@ -115,14 +216,7 @@ function validateConnectLoginParams(raw) {
|
|
|
115
216
|
throw new ProtocolValidationError("invalid_request", "claims entries must be strings");
|
|
116
217
|
claims = [...obj.claims];
|
|
117
218
|
}
|
|
118
|
-
|
|
119
|
-
if (obj.publicationProof !== void 0) {
|
|
120
|
-
try {
|
|
121
|
-
publicationProof = validatePublicationProof(obj.publicationProof);
|
|
122
|
-
} catch {
|
|
123
|
-
throw new ProtocolValidationError("invalid_request", "publicationProof is invalid");
|
|
124
|
-
}
|
|
125
|
-
}
|
|
219
|
+
const publicationProof = expectPublicationRecordString(obj.publicationProof);
|
|
126
220
|
return publicationProof === void 0 ? { text, claims } : { text, claims, publicationProof };
|
|
127
221
|
}
|
|
128
222
|
function validateConnectLogoutParams(raw) {
|
|
@@ -135,13 +229,15 @@ function validateConnectLaunchParams(raw) {
|
|
|
135
229
|
throw new ProtocolValidationError("invalid_request", "connect.launch contains an unsupported field");
|
|
136
230
|
}
|
|
137
231
|
const launchToken = expectNonEmptyString(obj.launchToken, "launchToken");
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
232
|
+
const publicationProof = expectPublicationRecordString(obj.publicationProof);
|
|
233
|
+
return publicationProof === void 0 ? { launchToken } : { launchToken, publicationProof };
|
|
234
|
+
}
|
|
235
|
+
function expectPublicationRecordString(value) {
|
|
236
|
+
if (value === void 0) return void 0;
|
|
237
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
238
|
+
throw new ProtocolValidationError("invalid_request", "publicationProof must be a non-empty record string");
|
|
144
239
|
}
|
|
240
|
+
return value;
|
|
145
241
|
}
|
|
146
242
|
function validateChannelPublishParams(raw) {
|
|
147
243
|
const obj = expectObject(raw, "channel.publish params");
|
|
@@ -203,9 +299,9 @@ function validateJsonValue(value, field, depth = 0) {
|
|
|
203
299
|
}
|
|
204
300
|
throw new ProtocolValidationError("invalid_request", `${field} must be a JSON value`);
|
|
205
301
|
}
|
|
206
|
-
function requireExactKeys(obj,
|
|
302
|
+
function requireExactKeys(obj, keys2, name) {
|
|
207
303
|
const actual = Object.keys(obj).sort();
|
|
208
|
-
const expected = [...
|
|
304
|
+
const expected = [...keys2].sort();
|
|
209
305
|
if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
|
|
210
306
|
throw new ProtocolValidationError("invalid_request", `${name} contains unsupported fields`);
|
|
211
307
|
}
|
|
@@ -290,11 +386,11 @@ function assertP2pkhAddressForAsset(addr, assetId) {
|
|
|
290
386
|
throw new ProtocolValidationError("invalid_request", `recipientAddress must be a ${networkLabel} P2PKH address`);
|
|
291
387
|
}
|
|
292
388
|
}
|
|
293
|
-
function assertCompressedPubkeyHex(
|
|
294
|
-
if (
|
|
389
|
+
function assertCompressedPubkeyHex(hex2) {
|
|
390
|
+
if (hex2.length !== 66) {
|
|
295
391
|
throw new ProtocolValidationError("invalid_request", "counterpartyPublicKeyHex must be a 33-byte compressed public key hex");
|
|
296
392
|
}
|
|
297
|
-
if (!/^[0-9a-fA-F]+$/.test(
|
|
393
|
+
if (!/^[0-9a-fA-F]+$/.test(hex2)) {
|
|
298
394
|
throw new ProtocolValidationError("invalid_request", "counterpartyPublicKeyHex must be hex");
|
|
299
395
|
}
|
|
300
396
|
}
|
|
@@ -444,6 +540,63 @@ function parseRequestMessage(raw, receiverIdentity) {
|
|
|
444
540
|
case "payment.status":
|
|
445
541
|
normalized = validatePaymentStatusParams(params);
|
|
446
542
|
break;
|
|
543
|
+
case "payment.prepare":
|
|
544
|
+
normalized = validatePrepare(params);
|
|
545
|
+
break;
|
|
546
|
+
case "payment.commit":
|
|
547
|
+
normalized = validateReservation(params, true);
|
|
548
|
+
break;
|
|
549
|
+
case "payment.cancel":
|
|
550
|
+
normalized = validateReservation(params, false);
|
|
551
|
+
break;
|
|
552
|
+
case "chain.get_height":
|
|
553
|
+
case "msfile.seller.status":
|
|
554
|
+
keys(params, []);
|
|
555
|
+
normalized = {};
|
|
556
|
+
break;
|
|
557
|
+
case "chain.list_script_history":
|
|
558
|
+
normalized = validateScriptHistory(params);
|
|
559
|
+
break;
|
|
560
|
+
case "chain.get_transaction":
|
|
561
|
+
keys(params, ["txid", "observedRawTxHex"]);
|
|
562
|
+
normalized = {
|
|
563
|
+
txid: hex(params.txid, "txid", /^[0-9a-f]{64}$/iu),
|
|
564
|
+
observedRawTxHex: params.observedRawTxHex === void 0 ? void 0 : hex(params.observedRawTxHex, "observedRawTxHex")
|
|
565
|
+
};
|
|
566
|
+
break;
|
|
567
|
+
case "chain.list_script_unspent":
|
|
568
|
+
keys(params, ["script"]);
|
|
569
|
+
normalized = { script: hex(params.script, "script") };
|
|
570
|
+
break;
|
|
571
|
+
case "chain.broadcast":
|
|
572
|
+
keys(params, ["rawTxHex"]);
|
|
573
|
+
normalized = { rawTxHex: hex(params.rawTxHex, "rawTxHex") };
|
|
574
|
+
break;
|
|
575
|
+
case "application.key":
|
|
576
|
+
keys(params, ["purpose"]);
|
|
577
|
+
normalized = { purpose: applicationPurpose(params.purpose) };
|
|
578
|
+
break;
|
|
579
|
+
case "application.sign_message":
|
|
580
|
+
keys(params, ["purpose", "message"]);
|
|
581
|
+
normalized = { purpose: applicationPurpose(params.purpose), message: parseBinaryField(params.message, "message") };
|
|
582
|
+
break;
|
|
583
|
+
case "application.sign_payment":
|
|
584
|
+
normalized = validateApplicationPayment(params);
|
|
585
|
+
break;
|
|
586
|
+
case "msfile.import":
|
|
587
|
+
keys(params, ["fileName", "content"]);
|
|
588
|
+
normalized = { fileName: expectNonEmptyString(params.fileName, "fileName"), content: parseBinaryField(params.content, "content") };
|
|
589
|
+
break;
|
|
590
|
+
case "msfile.content.read":
|
|
591
|
+
keys(params, ["seedHashHex"]);
|
|
592
|
+
normalized = validateMsFileStatParams(params);
|
|
593
|
+
break;
|
|
594
|
+
case "domain.profiles":
|
|
595
|
+
normalized = validateDomainProfilesParams(params);
|
|
596
|
+
break;
|
|
597
|
+
case "domain.get_public_key":
|
|
598
|
+
normalized = { domain: expectString(params.domain, "domain"), serviceId: domainServiceID(params, "domain") };
|
|
599
|
+
break;
|
|
447
600
|
case "channel.publish":
|
|
448
601
|
normalized = validateChannelPublishParams(params);
|
|
449
602
|
break;
|