keymaster-connect 0.1.4 → 0.1.6
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 +29 -5
- package/dist/{chunk-VVOTW5ZT.js → chunk-M2YEI4PG.js} +92 -3
- package/dist/chunk-M2YEI4PG.js.map +1 -0
- package/dist/{chunk-2EYARFS3.js → chunk-THT6XHHY.js} +5 -5
- package/dist/chunk-THT6XHHY.js.map +1 -0
- package/dist/index.d.ts +109 -14
- package/dist/index.js +303 -28
- package/dist/index.js.map +1 -1
- package/dist/{protocol-NcRDmEKZ.d.ts → protocol-GXCfd2ya.d.ts} +57 -98
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.js +1 -1
- package/dist/script.d.ts +58 -0
- package/dist/script.js +253 -0
- package/dist/script.js.map +1 -0
- package/dist/server.d.ts +21 -12
- package/dist/server.js +144 -260
- package/dist/server.js.map +1 -1
- package/package.json +45 -10
- package/dist/chunk-2EYARFS3.js.map +0 -1
- package/dist/chunk-VVOTW5ZT.js.map +0 -1
|
@@ -1,3 +1,30 @@
|
|
|
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
|
+
|
|
1
28
|
/** Connect wire v1 bidirectional AI tools. Never grants wallet payment/signing authority. */
|
|
2
29
|
|
|
3
30
|
interface AiToolSchema {
|
|
@@ -84,8 +111,6 @@ type AiToolMessage = {
|
|
|
84
111
|
};
|
|
85
112
|
declare function isAiToolMessage(value: unknown): value is AiToolMessage;
|
|
86
113
|
|
|
87
|
-
/** Connect v1 公开契约。独立于钱包内部执行 DTO、能力框架和持久化。 */
|
|
88
|
-
|
|
89
114
|
/** 身份网络在创建/导入时确定;公钥相同也不能跨网复用业务身份。 */
|
|
90
115
|
type BsvNetwork = "main" | "test";
|
|
91
116
|
interface NetworkIdentity {
|
|
@@ -95,26 +120,6 @@ interface NetworkIdentity {
|
|
|
95
120
|
declare function validateBsvNetwork(value: unknown): BsvNetwork;
|
|
96
121
|
declare function validateNetworkIdentity(value: unknown): NetworkIdentity;
|
|
97
122
|
declare function sameNetworkIdentity(left: NetworkIdentity, right: NetworkIdentity): boolean;
|
|
98
|
-
type AppRequirement = "private-key" | "storage";
|
|
99
|
-
interface AppIdentityProofV1 {
|
|
100
|
-
version: 1;
|
|
101
|
-
publisherPublicKey: string;
|
|
102
|
-
app: {
|
|
103
|
-
id: string;
|
|
104
|
-
name: string;
|
|
105
|
-
description: string;
|
|
106
|
-
};
|
|
107
|
-
requirements: AppRequirement[];
|
|
108
|
-
signature: string;
|
|
109
|
-
}
|
|
110
|
-
interface VerifiedAppIdentity {
|
|
111
|
-
version: 1;
|
|
112
|
-
publisherPublicKeyHex: string;
|
|
113
|
-
appId: string;
|
|
114
|
-
appName: string;
|
|
115
|
-
identityDigestHex: string;
|
|
116
|
-
}
|
|
117
|
-
type AppIdentitySnapshot = VerifiedAppIdentity;
|
|
118
123
|
/** ChannelProtocol/SSP 共用的递归 JSON 值。 */
|
|
119
124
|
type JSONValue = null | boolean | number | string | JSONValue[] | {
|
|
120
125
|
[key: string]: JSONValue;
|
|
@@ -410,14 +415,14 @@ declare const PROTOCOL_VERSION = 1;
|
|
|
410
415
|
*/
|
|
411
416
|
type ProtocolErrorCode =
|
|
412
417
|
/** Transport authority was revoked or belongs to another wallet/Worker generation. */
|
|
413
|
-
"connection_expired" | "invalid_request" | "invalid_origin" | "user_rejected" | "active_key_unavailable" | "decrypt_failed"
|
|
418
|
+
"connection_expired" | "authorization_expired" | "invalid_request" | "invalid_origin" | "user_rejected" | "active_key_unavailable" | "decrypt_failed"
|
|
414
419
|
/**
|
|
415
420
|
* 请求资产与连接绑定的钱包网络不一致;accept 阶段拒绝,不进入业务执行。
|
|
416
421
|
*/
|
|
417
422
|
| "asset_not_enabled"
|
|
418
423
|
/** Connect v1 明确排除的方法族(新费用池签名等)。 */
|
|
419
424
|
| "unsupported_scope"
|
|
420
|
-
/**
|
|
425
|
+
/** 通用支付需要已建立的可信来源会话(origin 是归属唯一基准)。 */
|
|
421
426
|
| "identity_required"
|
|
422
427
|
/** 当前硬件后端缺少 Connect 支付所需的受信展示/结构检查。 */
|
|
423
428
|
| "hardware_connect_payment_unsupported" | "payment_not_found"
|
|
@@ -533,66 +538,20 @@ interface CipherDecryptResult {
|
|
|
533
538
|
/** 还原后的业务字节。 */
|
|
534
539
|
content: BinaryField;
|
|
535
540
|
}
|
|
536
|
-
interface PaymentChannelRegisterParams {
|
|
537
|
-
channelName: string;
|
|
538
|
-
paymentType: "p2pkh" | "p2pk";
|
|
539
|
-
}
|
|
540
|
-
interface PaymentChannelRegisterResult {
|
|
541
|
-
channelId: string;
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Connect 公开的 P2PKH 资产标识。
|
|
545
|
-
*
|
|
546
|
-
* 设计缘由(施工单 2026-09-18 001 多资产硬切换):
|
|
547
|
-
* - 公开命名固定 `bsv-mainnet` / `bsv-testnet`,不暴露 p2pkh 内部
|
|
548
|
-
* 的 `bsv` / `bsvtest`;
|
|
549
|
-
* - 资产由连接绑定的钱包网络决定,调用方不能选择或覆盖该网络。
|
|
550
|
-
*/
|
|
551
541
|
type P2pkhTransferAssetId = "bsv-mainnet" | "bsv-testnet";
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
/** 可选费率(sat/kB),>= 1;缺省由钱包当前网络的有效费率策略决定。 */
|
|
560
|
-
feeRateSatoshisPerKb?: number;
|
|
561
|
-
}
|
|
562
|
-
interface P2pkhTransferResult {
|
|
563
|
-
/** 本次实际转账的资产,与连接绑定的钱包网络一致。 */
|
|
564
|
-
assetId: P2pkhTransferAssetId;
|
|
565
|
-
/** 已广播交易的 canonical txid。 */
|
|
566
|
-
txid: string;
|
|
567
|
-
/** 已签名交易 raw hex。 */
|
|
568
|
-
rawTxHex: string;
|
|
569
|
-
/** 实际花费的 fee satoshis。 */
|
|
570
|
-
feeSatoshis: number;
|
|
571
|
-
}
|
|
572
|
-
/** Connect v1 支付方案;业务种类(businessKind)是独立维度。 */
|
|
573
|
-
type ConnectPaymentType = "p2pkh" | "p2pk";
|
|
574
|
-
type ConnectPaymentRecipientOwnership = "app-publisher" | "third-party" | "unknown";
|
|
542
|
+
/** Connect v1 输出支付:业务输出数组,顺序即链上顺序。 */
|
|
543
|
+
interface PaymentOutput {
|
|
544
|
+
/** 聪,允许 0(数据输出)。必须为非负安全整数。 */
|
|
545
|
+
amount: number;
|
|
546
|
+
/** locking script hex;偶数长度 hex,允许空字符串(零长度锁定脚本)。 */
|
|
547
|
+
script: string;
|
|
548
|
+
}
|
|
575
549
|
type ConnectPaymentStatus = "pending" | "not_signed" | "signed_not_dispatched" | "unknown" | "failed" | "accepted" | "already_known";
|
|
576
|
-
/** 收款材料:类型必须与 paymentType 一致。 */
|
|
577
|
-
type ConnectPaymentRecipient = {
|
|
578
|
-
type: "p2pkh";
|
|
579
|
-
address: string;
|
|
580
|
-
} | {
|
|
581
|
-
type: "p2pk";
|
|
582
|
-
publicKeyHex: string;
|
|
583
|
-
};
|
|
584
550
|
interface PaymentPayParams {
|
|
585
|
-
channelId: string;
|
|
586
551
|
/** 稳定幂等身份,1–128 字符。 */
|
|
587
552
|
clientRequestId: string;
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
businessKind: string;
|
|
591
|
-
/** 业务金额(聪,不含矿工费)。 */
|
|
592
|
-
amountSatoshis: number;
|
|
593
|
-
/** 可选希望费率(sat/kB);缺省由钱包当前网络的有效费率策略决定。 */
|
|
594
|
-
feeRateSatoshisPerKb?: number;
|
|
595
|
-
recipient: ConnectPaymentRecipient;
|
|
553
|
+
/** 业务输出;非空,顺序即链上顺序,找零由钱包追加。 */
|
|
554
|
+
outputs: PaymentOutput[];
|
|
596
555
|
}
|
|
597
556
|
interface PaymentReleaseSummary {
|
|
598
557
|
/** Historical amount safely released, NOT the current wallet balance. */
|
|
@@ -606,8 +565,6 @@ interface PaymentPayResult {
|
|
|
606
565
|
clientRequestId: string;
|
|
607
566
|
status: ConnectPaymentStatus;
|
|
608
567
|
assetId: P2pkhTransferAssetId;
|
|
609
|
-
paymentType: ConnectPaymentType;
|
|
610
|
-
recipientOwnership: ConnectPaymentRecipientOwnership;
|
|
611
568
|
/** 只有 accepted/already_known 才有 canonical txid。 */
|
|
612
569
|
txid?: string;
|
|
613
570
|
feeSatoshis?: number;
|
|
@@ -629,22 +586,23 @@ interface ConnectLoginParams {
|
|
|
629
586
|
* 缺省 = `[]`,不返回任何 claim;通常 caller 想获取 profile.* 时必须显式列出。
|
|
630
587
|
*/
|
|
631
588
|
claims?: string[];
|
|
632
|
-
/**
|
|
633
|
-
|
|
589
|
+
/**
|
|
590
|
+
* App 入口的 URL 来源证明(SDK 从当前入口 HTML 头读取并提交)。
|
|
591
|
+
* 钱包验签并核对证明 origin 与可信 event.origin 是否一致;应用不能自报来源。
|
|
592
|
+
* 本地 Files 部署不依赖该字段(以 daemon 可信部署登记为准)。
|
|
593
|
+
*/
|
|
594
|
+
publicationProof?: PublicationProof;
|
|
634
595
|
}
|
|
635
596
|
interface ConnectLoginResult {
|
|
636
|
-
/**
|
|
597
|
+
/** 不透明恢复凭据,绑定原钱包和精确来源;不得写入日志或 URL。 */
|
|
637
598
|
authorizationId: string;
|
|
638
599
|
networkIdentity: NetworkIdentity;
|
|
639
600
|
/** 本次 login 时一次解析的 claims 真值快照。 */
|
|
640
601
|
resolvedClaims: Record<string, ResolvedClaimValue>;
|
|
641
602
|
/** 本次解析时间(unix milliseconds)。 */
|
|
642
603
|
resolvedAt: number;
|
|
643
|
-
appIdentity?: AppIdentitySnapshot;
|
|
644
604
|
}
|
|
645
|
-
interface ConnectResumeParams {
|
|
646
|
-
/** 本地数据重置后重新验证已有发行人签名 proof。 */
|
|
647
|
-
appIdentity?: AppIdentityProofV1;
|
|
605
|
+
interface ConnectResumeParams extends Record<string, never> {
|
|
648
606
|
}
|
|
649
607
|
interface ConnectResumeResult {
|
|
650
608
|
authorizationId: string;
|
|
@@ -655,7 +613,6 @@ interface ConnectResumeResult {
|
|
|
655
613
|
* 给 caller 用来做"是否要重新登录"的客户端超时策略。
|
|
656
614
|
*/
|
|
657
615
|
resolvedAt: number;
|
|
658
|
-
appIdentity?: AppIdentitySnapshot;
|
|
659
616
|
}
|
|
660
617
|
interface ConnectLogoutParams extends Record<string, never> {
|
|
661
618
|
}
|
|
@@ -666,30 +623,30 @@ interface ConnectLogoutResult {
|
|
|
666
623
|
interface ConnectLaunchParams {
|
|
667
624
|
/** 由 launcher 写入 client app 启动 URL 的 launchToken。一次性消费。 */
|
|
668
625
|
launchToken: string;
|
|
669
|
-
/**
|
|
670
|
-
|
|
626
|
+
/**
|
|
627
|
+
* App 入口的 URL 来源证明(可选;钱包发起的目录启动一般不需要客户端提交,
|
|
628
|
+
* 钱包从所选入口自行读取;应用提交时钱包核对一致性,不能自报来源)。
|
|
629
|
+
*/
|
|
630
|
+
publicationProof?: PublicationProof;
|
|
671
631
|
}
|
|
672
632
|
interface ConnectLaunchResult {
|
|
673
633
|
authorizationId: string;
|
|
674
634
|
networkIdentity: NetworkIdentity;
|
|
675
635
|
resolvedClaims: Record<string, ResolvedClaimValue>;
|
|
676
636
|
resolvedAt: number;
|
|
677
|
-
appIdentity?: AppIdentitySnapshot;
|
|
678
637
|
}
|
|
679
638
|
/** 协议方法名常量集合。 */
|
|
680
|
-
declare const PROTOCOL_METHODS: readonly ["identity.get", "intent.sign", "cipher.encrypt", "cipher.decrypt", "
|
|
639
|
+
declare const PROTOCOL_METHODS: readonly ["identity.get", "intent.sign", "cipher.encrypt", "cipher.decrypt", "payment.pay", "payment.status", "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.encrypted.put", "storage.encrypted.get", "storage.delete", "msfile.stat", "msfile.seed.read", "msfile.block.read"];
|
|
681
640
|
type ProtocolMethod = (typeof PROTOCOL_METHODS)[number];
|
|
682
641
|
/**
|
|
683
642
|
* 方法 -> 请求参数类型 的映射。`MethodParams<M>` 是计算出的参数类型。
|
|
684
643
|
* 业务代码里直接 `MethodParams<"identity.get">` 等价于 `IdentityGetParams`。
|
|
685
644
|
*/
|
|
686
645
|
interface MethodParamsMap {
|
|
687
|
-
"payment.channel.register": PaymentChannelRegisterParams;
|
|
688
646
|
"identity.get": IdentityGetParams;
|
|
689
647
|
"intent.sign": IntentSignParams;
|
|
690
648
|
"cipher.encrypt": CipherEncryptParams;
|
|
691
649
|
"cipher.decrypt": CipherDecryptParams;
|
|
692
|
-
"p2pkh.transfer": P2pkhTransferParams;
|
|
693
650
|
"payment.pay": PaymentPayParams;
|
|
694
651
|
"payment.status": PaymentStatusParams;
|
|
695
652
|
"connect.login": ConnectLoginParams;
|
|
@@ -702,19 +659,19 @@ interface MethodParamsMap {
|
|
|
702
659
|
"storage.directory.create": StorageDirectoryParams;
|
|
703
660
|
"storage.directory.delete": StorageDirectoryParams;
|
|
704
661
|
"storage.put": StoragePutParams;
|
|
662
|
+
"storage.encrypted.put": StoragePutParams;
|
|
705
663
|
"storage.get": StorageGetParams;
|
|
664
|
+
"storage.encrypted.get": StorageGetParams;
|
|
706
665
|
"storage.delete": StorageDeleteParams;
|
|
707
666
|
"msfile.stat": MsFileStatParams;
|
|
708
667
|
"msfile.seed.read": MsFileSeedReadParams;
|
|
709
668
|
"msfile.block.read": MsFileBlockReadParams;
|
|
710
669
|
}
|
|
711
670
|
interface MethodResultMap {
|
|
712
|
-
"payment.channel.register": PaymentChannelRegisterResult;
|
|
713
671
|
"identity.get": IdentityGetResult;
|
|
714
672
|
"intent.sign": IntentSignResult;
|
|
715
673
|
"cipher.encrypt": CipherEncryptResult;
|
|
716
674
|
"cipher.decrypt": CipherDecryptResult;
|
|
717
|
-
"p2pkh.transfer": P2pkhTransferResult;
|
|
718
675
|
"payment.pay": PaymentPayResult;
|
|
719
676
|
"payment.status": PaymentStatusResult;
|
|
720
677
|
"connect.login": ConnectLoginResult;
|
|
@@ -727,7 +684,9 @@ interface MethodResultMap {
|
|
|
727
684
|
"storage.directory.create": StorageDirectoryResult;
|
|
728
685
|
"storage.directory.delete": StorageDirectoryResult;
|
|
729
686
|
"storage.put": StoragePutResult;
|
|
687
|
+
"storage.encrypted.put": StoragePutResult;
|
|
730
688
|
"storage.get": StorageGetResult;
|
|
689
|
+
"storage.encrypted.get": StorageGetResult;
|
|
731
690
|
"storage.delete": StorageDeleteResult;
|
|
732
691
|
"msfile.stat": MsFileStatResult;
|
|
733
692
|
"msfile.seed.read": MsFileReadResult;
|
|
@@ -778,4 +737,4 @@ type ProtocolResultMessage = {
|
|
|
778
737
|
networkIdentity?: NetworkIdentity;
|
|
779
738
|
};
|
|
780
739
|
|
|
781
|
-
export { type
|
|
740
|
+
export { type ChannelSubscriptionErrorCode as $, type AiTool as A, type BinaryField as B, type ConnectLoginParams as C, type StorageDirectoryResult as D, type StoragePutParams as E, type StoragePutResult as F, type StorageGetParams as G, type StorageGetResult as H, type IdentityGetParams as I, type StorageDeleteParams as J, type StorageDeleteResult as K, type MsFileStatParams as L, type MethodParams as M, type NetworkIdentity as N, type MsFileStatResult as O, type ProtocolEventMessage as P, type MsFileSeedReadParams as Q, type MsFileReadResult as R, type StorageListParams as S, type MsFileBlockReadParams as T, type ProtocolErrorCode as U, AI_TOOLS_MAX_JSON_CHARS as V, type AiToolDefinition as W, type AiToolMessage as X, type AiToolSchema as Y, type BsvNetwork as Z, type ChannelMessageReceivedEventData as _, type AiToolsRegistered as a, type ChannelSubscriptionPhase as a0, type ChannelSubscriptionStatus as a1, type ConnectLogoutParams as a2, type ConnectPaymentStatus as a3, type JSONValue as a4, MSFILE_BLOCK_SIZE_BYTES as a5, MSFILE_DIGEST_SIZE_BYTES as a6, MSFILE_LOCAL_SOURCE_ID as a7, MSFILE_MAX_BLOCK_BYTES as a8, MSFILE_MAX_CONTENT_BYTES as a9, type ProtocolEventPayload as aA, type ProtocolReadyMessage as aB, type ProtocolReconnectMessage as aC, type ProtocolRequestMessage as aD, type ProtocolResultMessage as aE, type PublicationProof as aF, type ResolvedClaimValue as aG, STORAGE_DEFAULT_LIST_LIMIT as aH, STORAGE_MAX_LIST_LIMIT as aI, STORAGE_MAX_PAYLOAD_BYTES as aJ, type StorageListEntry as aK, assertToolJson as aL, assertToolPayload as aM, isAiToolMessage as aN, isValidMsFileSourceId as aO, parseToolDefinitions as aP, sameNetworkIdentity as aQ, validateBsvNetwork as aR, validateNetworkIdentity as aS, validateToolArguments as aT, MSFILE_MAX_ERROR_MESSAGE_BYTES as aa, MSFILE_MAX_HEADER_BYTES as ab, MSFILE_MAX_SEED_BYTES as ac, MSFILE_PROTOCOL_ID as ad, type MethodParamsMap as ae, type MethodResultMap as af, type MsFileLocalSourceStat as ag, type MsFileRemoteSourceStat as ah, type MsFileSatoshiAmount as ai, type MsFileSourceKind as aj, type MsFileSourceStat as ak, type MsFileStatAbsentEntry as al, type MsFileStatAvailableEntry as am, type MsFileStatDiscoveringEntry as an, type MsFileStatNetworkErrorEntry as ao, type MsFileStatQuotedEntry as ap, type MsFileSupplierStat as aq, type P2pkhTransferAssetId as ar, PROTOCOL_METHODS as as, PROTOCOL_VERSION as at, type PaymentOutput as au, type PaymentReleaseSummary as av, type ProtocolCancelMessage as aw, type ProtocolClosingMessage as ax, type ProtocolError as ay, type ProtocolEventName as az, type ProtocolMethod as b, type MethodResult as c, type ConnectLoginResult as d, type ConnectResumeParams as e, type ConnectResumeResult as f, type ConnectLogoutResult as g, type ConnectLaunchParams as h, type ConnectLaunchResult as i, type IdentityGetResult as j, type IntentSignParams as k, type IntentSignResult as l, type CipherEncryptParams as m, type CipherEncryptResult as n, type CipherDecryptParams as o, type CipherDecryptResult as p, type PaymentPayParams as q, type PaymentPayResult as r, type PaymentStatusParams as s, type PaymentStatusResult as t, type ChannelPublishParams as u, type ChannelPublishResult as v, type ChannelSubscriptionSetParams as w, type ChannelSubscriptionSetResult as x, type StorageListResult as y, type StorageDirectoryParams as z };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { W as AiToolDefinition, X as AiToolMessage, Y as AiToolSchema, a as AiToolsRegistered, B as BinaryField, Z as BsvNetwork, _ as ChannelMessageReceivedEventData, u as ChannelPublishParams, v as ChannelPublishResult, $ as ChannelSubscriptionErrorCode, a0 as ChannelSubscriptionPhase, w as ChannelSubscriptionSetParams, x as ChannelSubscriptionSetResult, a1 as ChannelSubscriptionStatus, o as CipherDecryptParams, p as CipherDecryptResult, m as CipherEncryptParams, n as CipherEncryptResult, h as ConnectLaunchParams, i as ConnectLaunchResult, C as ConnectLoginParams, d as ConnectLoginResult, a2 as ConnectLogoutParams, g as ConnectLogoutResult, a3 as ConnectPaymentStatus, e as ConnectResumeParams, f as ConnectResumeResult, I as IdentityGetParams, j as IdentityGetResult, k as IntentSignParams, l as IntentSignResult, a4 as JSONValue, a5 as MSFILE_BLOCK_SIZE_BYTES, a6 as MSFILE_DIGEST_SIZE_BYTES, a7 as MSFILE_LOCAL_SOURCE_ID, a8 as MSFILE_MAX_BLOCK_BYTES, a9 as MSFILE_MAX_CONTENT_BYTES, aa as MSFILE_MAX_ERROR_MESSAGE_BYTES, ab as MSFILE_MAX_HEADER_BYTES, ac as MSFILE_MAX_SEED_BYTES, ad as MSFILE_PROTOCOL_ID, M as MethodParams, ae as MethodParamsMap, c as MethodResult, af as MethodResultMap, T as MsFileBlockReadParams, ag as MsFileLocalSourceStat, R as MsFileReadResult, ah as MsFileRemoteSourceStat, ai as MsFileSatoshiAmount, Q as MsFileSeedReadParams, aj as MsFileSourceKind, ak as MsFileSourceStat, al as MsFileStatAbsentEntry, am as MsFileStatAvailableEntry, an as MsFileStatDiscoveringEntry, ao as MsFileStatNetworkErrorEntry, L as MsFileStatParams, ap as MsFileStatQuotedEntry, O as MsFileStatResult, aq as MsFileSupplierStat, N as NetworkIdentity, ar as P2pkhTransferAssetId, as as PROTOCOL_METHODS, at as PROTOCOL_VERSION, au as PaymentOutput, q as PaymentPayParams, r as PaymentPayResult, av as PaymentReleaseSummary, s as PaymentStatusParams, t as PaymentStatusResult, aw as ProtocolCancelMessage, ax as ProtocolClosingMessage, ay as ProtocolError, U as ProtocolErrorCode, P as ProtocolEventMessage, az as ProtocolEventName, aA as ProtocolEventPayload, b as ProtocolMethod, aB as ProtocolReadyMessage, aC as ProtocolReconnectMessage, aD as ProtocolRequestMessage, aE as ProtocolResultMessage, aF as PublicationProof, aG as ResolvedClaimValue, aH as STORAGE_DEFAULT_LIST_LIMIT, aI as STORAGE_MAX_LIST_LIMIT, aJ as STORAGE_MAX_PAYLOAD_BYTES, J as StorageDeleteParams, K as StorageDeleteResult, z as StorageDirectoryParams, D as StorageDirectoryResult, G as StorageGetParams, H as StorageGetResult, aK as StorageListEntry, S as StorageListParams, y as StorageListResult, E as StoragePutParams, F as StoragePutResult, aO as isValidMsFileSourceId, aQ as sameNetworkIdentity, aR as validateBsvNetwork, aS as validateNetworkIdentity } from './protocol-GXCfd2ya.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, STORAGE_DEFAULT_LIST_LIMIT, STORAGE_MAX_LIST_LIMIT, STORAGE_MAX_PAYLOAD_BYTES, isValidMsFileSourceId, sameNetworkIdentity, validateBsvNetwork, validateNetworkIdentity } from './chunk-
|
|
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-THT6XHHY.js';
|
|
2
2
|
//# sourceMappingURL=protocol.js.map
|
|
3
3
|
//# sourceMappingURL=protocol.js.map
|
package/dist/script.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { au as PaymentOutput } from './protocol-GXCfd2ya.js';
|
|
2
|
+
|
|
3
|
+
type PaymentScriptKind = "p2pkh" | "p2pk" | "multisig" | "op_return" | "unknown";
|
|
4
|
+
interface PaymentScriptP2pkh {
|
|
5
|
+
kind: "p2pkh";
|
|
6
|
+
scriptHex: string;
|
|
7
|
+
amountSats: number;
|
|
8
|
+
hash160Hex: string;
|
|
9
|
+
addressMainnet: string;
|
|
10
|
+
addressTestnet: string;
|
|
11
|
+
summary: string;
|
|
12
|
+
}
|
|
13
|
+
interface PaymentScriptP2pk {
|
|
14
|
+
kind: "p2pk";
|
|
15
|
+
scriptHex: string;
|
|
16
|
+
amountSats: number;
|
|
17
|
+
publicKeyHex: string;
|
|
18
|
+
summary: string;
|
|
19
|
+
}
|
|
20
|
+
interface PaymentScriptMultisig {
|
|
21
|
+
kind: "multisig";
|
|
22
|
+
scriptHex: string;
|
|
23
|
+
amountSats: number;
|
|
24
|
+
m: number;
|
|
25
|
+
n: number;
|
|
26
|
+
publicKeysHex: string[];
|
|
27
|
+
summary: string;
|
|
28
|
+
}
|
|
29
|
+
interface PaymentScriptOpReturn {
|
|
30
|
+
kind: "op_return";
|
|
31
|
+
scriptHex: string;
|
|
32
|
+
amountSats: number;
|
|
33
|
+
dataHex: string;
|
|
34
|
+
dataText: string;
|
|
35
|
+
summary: string;
|
|
36
|
+
}
|
|
37
|
+
interface PaymentScriptUnknown {
|
|
38
|
+
kind: "unknown";
|
|
39
|
+
scriptHex: string;
|
|
40
|
+
amountSats: number;
|
|
41
|
+
reason: string;
|
|
42
|
+
summary: string;
|
|
43
|
+
}
|
|
44
|
+
type PaymentScriptInterpretation = PaymentScriptP2pkh | PaymentScriptP2pk | PaymentScriptMultisig | PaymentScriptOpReturn | PaymentScriptUnknown;
|
|
45
|
+
interface InterpretedPaymentOutput {
|
|
46
|
+
index: number;
|
|
47
|
+
amountSats: number;
|
|
48
|
+
scriptHex: string;
|
|
49
|
+
interpretation: PaymentScriptInterpretation;
|
|
50
|
+
}
|
|
51
|
+
/** 解释单个 locking script;匹配必须完整,失败按未知脚本展示。 */
|
|
52
|
+
declare function interpretLockingScript(scriptHexRaw: string, amountSats: number): PaymentScriptInterpretation;
|
|
53
|
+
/** 按 App 顺序逐项解释业务输出。 */
|
|
54
|
+
declare function interpretPaymentOutputs(outputs: PaymentOutput[]): InterpretedPaymentOutput[];
|
|
55
|
+
/** 业务输出总额(不含矿工费与找零)。 */
|
|
56
|
+
declare function totalBusinessSats(outputs: PaymentOutput[]): number;
|
|
57
|
+
|
|
58
|
+
export { type InterpretedPaymentOutput, type PaymentScriptInterpretation, type PaymentScriptKind, type PaymentScriptMultisig, type PaymentScriptOpReturn, type PaymentScriptP2pk, type PaymentScriptP2pkh, type PaymentScriptUnknown, interpretLockingScript, interpretPaymentOutputs, totalBusinessSats };
|
package/dist/script.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
2
|
+
import '@noble/hashes/legacy.js';
|
|
3
|
+
|
|
4
|
+
// src/script.ts
|
|
5
|
+
function hexToBytes(hex) {
|
|
6
|
+
if (hex.length % 2 !== 0 || hex.length > 0 && !/^[0-9a-fA-F]+$/u.test(hex)) return null;
|
|
7
|
+
const out = new Uint8Array(hex.length / 2);
|
|
8
|
+
for (let i = 0; i < out.length; i++) out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
11
|
+
function bytesToHex(bytes) {
|
|
12
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
13
|
+
}
|
|
14
|
+
var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
15
|
+
function base58Encode(bytes) {
|
|
16
|
+
if (bytes.length === 0) return "";
|
|
17
|
+
const digits = [0];
|
|
18
|
+
for (const byte of bytes) {
|
|
19
|
+
let carry = byte;
|
|
20
|
+
for (let i = 0; i < digits.length; i++) {
|
|
21
|
+
const v = digits[i] * 256 + carry;
|
|
22
|
+
digits[i] = v % 58;
|
|
23
|
+
carry = Math.floor(v / 58);
|
|
24
|
+
}
|
|
25
|
+
while (carry > 0) {
|
|
26
|
+
digits.push(carry % 58);
|
|
27
|
+
carry = Math.floor(carry / 58);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let leadingZeros = 0;
|
|
31
|
+
for (const b of bytes) {
|
|
32
|
+
if (b === 0) leadingZeros++;
|
|
33
|
+
else break;
|
|
34
|
+
}
|
|
35
|
+
let result = "1".repeat(leadingZeros);
|
|
36
|
+
for (let i = digits.length - 1; i >= 0; i--) result += BASE58_ALPHABET[digits[i]];
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function p2pkhAddress(hash160, version) {
|
|
40
|
+
const payload = new Uint8Array(1 + hash160.length);
|
|
41
|
+
payload[0] = version;
|
|
42
|
+
payload.set(hash160, 1);
|
|
43
|
+
const checksum = sha256(sha256(payload)).slice(0, 4);
|
|
44
|
+
const full = new Uint8Array(payload.length + 4);
|
|
45
|
+
full.set(payload, 0);
|
|
46
|
+
full.set(checksum, payload.length);
|
|
47
|
+
return base58Encode(full);
|
|
48
|
+
}
|
|
49
|
+
function decodeText(bytes) {
|
|
50
|
+
try {
|
|
51
|
+
return new TextDecoder("utf-8", { fatal: false }).decode(bytes);
|
|
52
|
+
} catch {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function parsePushes(bytes, offset) {
|
|
57
|
+
const pushes = [];
|
|
58
|
+
let pos = offset;
|
|
59
|
+
while (pos < bytes.length) {
|
|
60
|
+
const op = bytes[pos];
|
|
61
|
+
if (op >= 1 && op <= 75) {
|
|
62
|
+
const len = op;
|
|
63
|
+
if (pos + 1 + len > bytes.length) return null;
|
|
64
|
+
pushes.push(bytes.slice(pos + 1, pos + 1 + len));
|
|
65
|
+
pos += 1 + len;
|
|
66
|
+
} else if (op === 76) {
|
|
67
|
+
if (pos + 2 > bytes.length) return null;
|
|
68
|
+
const len = bytes[pos + 1];
|
|
69
|
+
if (pos + 2 + len > bytes.length) return null;
|
|
70
|
+
pushes.push(bytes.slice(pos + 2, pos + 2 + len));
|
|
71
|
+
pos += 2 + len;
|
|
72
|
+
} else if (op === 77) {
|
|
73
|
+
if (pos + 3 > bytes.length) return null;
|
|
74
|
+
const len = bytes[pos + 1] | bytes[pos + 2] << 8;
|
|
75
|
+
if (pos + 3 + len > bytes.length) return null;
|
|
76
|
+
pushes.push(bytes.slice(pos + 3, pos + 3 + len));
|
|
77
|
+
pos += 3 + len;
|
|
78
|
+
} else if (op === 78) {
|
|
79
|
+
if (pos + 5 > bytes.length) return null;
|
|
80
|
+
const len = bytes[pos + 1] | bytes[pos + 2] << 8 | bytes[pos + 3] << 16 | bytes[pos + 4] * 16777216;
|
|
81
|
+
if (len < 0 || pos + 5 + len > bytes.length) return null;
|
|
82
|
+
pushes.push(bytes.slice(pos + 5, pos + 5 + len));
|
|
83
|
+
pos += 5 + len;
|
|
84
|
+
} else if (op === 0) {
|
|
85
|
+
pushes.push(new Uint8Array(0));
|
|
86
|
+
pos += 1;
|
|
87
|
+
} else if (op >= 81 && op <= 96) {
|
|
88
|
+
return null;
|
|
89
|
+
} else {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { pushes, consumed: pos };
|
|
94
|
+
}
|
|
95
|
+
function isCompressedPubkey(bytes) {
|
|
96
|
+
return bytes.length === 33 && (bytes[0] === 2 || bytes[0] === 3);
|
|
97
|
+
}
|
|
98
|
+
function isUncompressedPubkey(bytes) {
|
|
99
|
+
return bytes.length === 65 && bytes[0] === 4;
|
|
100
|
+
}
|
|
101
|
+
function isPubkey(bytes) {
|
|
102
|
+
return isCompressedPubkey(bytes) || isUncompressedPubkey(bytes);
|
|
103
|
+
}
|
|
104
|
+
function unknown(scriptHex, amountSats) {
|
|
105
|
+
return {
|
|
106
|
+
kind: "unknown",
|
|
107
|
+
scriptHex,
|
|
108
|
+
amountSats,
|
|
109
|
+
reason: "\u4E0D\u8BA4\u8BC6\u6B64\u811A\u672C\uFF0C\u65E0\u6CD5\u89E3\u91CA\u5176\u7528\u9014",
|
|
110
|
+
summary: "\u4E0D\u8BA4\u8BC6\u6B64\u811A\u672C\uFF0C\u65E0\u6CD5\u89E3\u91CA\u5176\u7528\u9014"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function interpretLockingScript(scriptHexRaw, amountSats) {
|
|
114
|
+
const scriptHex = scriptHexRaw.toLowerCase();
|
|
115
|
+
const bytes = hexToBytes(scriptHex);
|
|
116
|
+
if (!bytes) return unknown(scriptHex, amountSats);
|
|
117
|
+
if (bytes.length === 25 && bytes[0] === 118 && bytes[1] === 169 && bytes[2] === 20 && bytes[23] === 136 && bytes[24] === 172) {
|
|
118
|
+
const hash = bytes.slice(3, 23);
|
|
119
|
+
const hashHex = bytesToHex(hash);
|
|
120
|
+
return {
|
|
121
|
+
kind: "p2pkh",
|
|
122
|
+
scriptHex,
|
|
123
|
+
amountSats,
|
|
124
|
+
hash160Hex: hashHex,
|
|
125
|
+
addressMainnet: p2pkhAddress(hash, 0),
|
|
126
|
+
addressTestnet: p2pkhAddress(hash, 111),
|
|
127
|
+
summary: `P2PKH \u6536\u6B3E\u5730\u5740 ${p2pkhAddress(hash, 0)} / ${p2pkhAddress(hash, 111)}\uFF0C\u91D1\u989D ${amountSats} sat`
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (bytes.length >= 2 && bytes[bytes.length - 1] === 172) {
|
|
131
|
+
const pushOp = bytes[0];
|
|
132
|
+
const pubLen = pushOp >= 1 && pushOp <= 75 ? pushOp : -1;
|
|
133
|
+
if (pubLen > 0 && bytes.length === 1 + pubLen + 1) {
|
|
134
|
+
const pub = bytes.slice(1, 1 + pubLen);
|
|
135
|
+
if (isPubkey(pub)) {
|
|
136
|
+
const pubHex = bytesToHex(pub);
|
|
137
|
+
return {
|
|
138
|
+
kind: "p2pk",
|
|
139
|
+
scriptHex,
|
|
140
|
+
amountSats,
|
|
141
|
+
publicKeyHex: pubHex,
|
|
142
|
+
summary: `P2PK \u6536\u6B3E\u516C\u94A5 ${pubHex}\uFF0C\u91D1\u989D ${amountSats} sat`
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (bytes.length >= 3 && bytes[bytes.length - 1] === 174) {
|
|
148
|
+
const mOp = bytes[0];
|
|
149
|
+
const nOp = bytes[bytes.length - 2];
|
|
150
|
+
if (mOp >= 81 && mOp <= 96 && nOp >= 81 && nOp <= 96) {
|
|
151
|
+
const m = mOp - 80;
|
|
152
|
+
const n = nOp - 80;
|
|
153
|
+
let pos = 1;
|
|
154
|
+
const pubs = [];
|
|
155
|
+
let ok = true;
|
|
156
|
+
for (let i = 0; i < n; i++) {
|
|
157
|
+
if (pos >= bytes.length - 2) {
|
|
158
|
+
ok = false;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
const op = bytes[pos];
|
|
162
|
+
let len = -1;
|
|
163
|
+
let header = 1;
|
|
164
|
+
if (op >= 1 && op <= 75) {
|
|
165
|
+
len = op;
|
|
166
|
+
header = 1;
|
|
167
|
+
} else {
|
|
168
|
+
ok = false;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
if (pos + header + len > bytes.length - 2) {
|
|
172
|
+
ok = false;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
const pub = bytes.slice(pos + header, pos + header + len);
|
|
176
|
+
if (!isPubkey(pub)) {
|
|
177
|
+
ok = false;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
pubs.push(pub);
|
|
181
|
+
pos += header + len;
|
|
182
|
+
}
|
|
183
|
+
if (ok && pubs.length === n && pos === bytes.length - 2 && m >= 1 && m <= n && n >= 1 && n <= 16) {
|
|
184
|
+
const hexes = pubs.map(bytesToHex);
|
|
185
|
+
return {
|
|
186
|
+
kind: "multisig",
|
|
187
|
+
scriptHex,
|
|
188
|
+
amountSats,
|
|
189
|
+
m,
|
|
190
|
+
n,
|
|
191
|
+
publicKeysHex: hexes,
|
|
192
|
+
summary: `\u6807\u51C6\u591A\u7B7E ${m}/${n}\uFF0C\u516C\u94A5 ${hexes.join(", ")}\uFF0C\u91D1\u989D ${amountSats} sat`
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
{
|
|
198
|
+
let dataStart = -1;
|
|
199
|
+
if (bytes.length >= 1 && bytes[0] === 106) dataStart = 1;
|
|
200
|
+
else if (bytes.length >= 2 && bytes[0] === 0 && bytes[1] === 106) dataStart = 2;
|
|
201
|
+
if (dataStart >= 0) {
|
|
202
|
+
const rest = bytes.slice(dataStart);
|
|
203
|
+
if (rest.length === 0) {
|
|
204
|
+
return {
|
|
205
|
+
kind: "op_return",
|
|
206
|
+
scriptHex,
|
|
207
|
+
amountSats,
|
|
208
|
+
dataHex: "",
|
|
209
|
+
dataText: "",
|
|
210
|
+
summary: `\u6570\u636E\u8F93\u51FA\uFF0C\u7A7A\u6570\u636E\uFF0C\u91D1\u989D ${amountSats} sat`
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const parsed = parsePushes(rest, 0);
|
|
214
|
+
if (parsed && parsed.consumed === rest.length) {
|
|
215
|
+
const combined = parsed.pushes.reduce((acc, cur) => {
|
|
216
|
+
const next = new Uint8Array(acc.length + cur.length);
|
|
217
|
+
next.set(acc, 0);
|
|
218
|
+
next.set(cur, acc.length);
|
|
219
|
+
return next;
|
|
220
|
+
}, new Uint8Array(0));
|
|
221
|
+
const dataHex = bytesToHex(combined);
|
|
222
|
+
const dataText = decodeText(combined);
|
|
223
|
+
return {
|
|
224
|
+
kind: "op_return",
|
|
225
|
+
scriptHex,
|
|
226
|
+
amountSats,
|
|
227
|
+
dataHex,
|
|
228
|
+
dataText,
|
|
229
|
+
summary: `\u6570\u636E\u8F93\u51FA\uFF0C\u6570\u636E ${dataHex || "(\u7A7A)"}\uFF0C\u91D1\u989D ${amountSats} sat`
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
return unknown(scriptHex, amountSats);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return unknown(scriptHex, amountSats);
|
|
236
|
+
}
|
|
237
|
+
function interpretPaymentOutputs(outputs) {
|
|
238
|
+
return outputs.map((output, index) => ({
|
|
239
|
+
index,
|
|
240
|
+
amountSats: output.amount,
|
|
241
|
+
scriptHex: output.script.toLowerCase(),
|
|
242
|
+
interpretation: interpretLockingScript(output.script, output.amount)
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
function totalBusinessSats(outputs) {
|
|
246
|
+
let total = 0;
|
|
247
|
+
for (const output of outputs) total += output.amount;
|
|
248
|
+
return total;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export { interpretLockingScript, interpretPaymentOutputs, totalBusinessSats };
|
|
252
|
+
//# sourceMappingURL=script.js.map
|
|
253
|
+
//# sourceMappingURL=script.js.map
|