keymaster-connect 0.1.4 → 0.1.5
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 +22 -2
- package/dist/{chunk-2EYARFS3.js → chunk-ZDIFZJYD.js} +4 -4
- package/dist/chunk-ZDIFZJYD.js.map +1 -0
- package/dist/index.d.ts +109 -13
- package/dist/index.js +298 -26
- package/dist/index.js.map +1 -1
- package/dist/{protocol-NcRDmEKZ.d.ts → protocol-C8z30CKK.d.ts} +18 -64
- 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 +3 -3
- package/dist/server.js +41 -73
- package/dist/server.js.map +1 -1
- package/package.json +3 -2
- package/dist/chunk-2EYARFS3.js.map +0 -1
|
@@ -410,7 +410,7 @@ declare const PROTOCOL_VERSION = 1;
|
|
|
410
410
|
*/
|
|
411
411
|
type ProtocolErrorCode =
|
|
412
412
|
/** 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"
|
|
413
|
+
"connection_expired" | "authorization_expired" | "invalid_request" | "invalid_origin" | "user_rejected" | "active_key_unavailable" | "decrypt_failed"
|
|
414
414
|
/**
|
|
415
415
|
* 请求资产与连接绑定的钱包网络不一致;accept 阶段拒绝,不进入业务执行。
|
|
416
416
|
*/
|
|
@@ -533,66 +533,20 @@ interface CipherDecryptResult {
|
|
|
533
533
|
/** 还原后的业务字节。 */
|
|
534
534
|
content: BinaryField;
|
|
535
535
|
}
|
|
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
536
|
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";
|
|
537
|
+
/** Connect v1 输出支付:业务输出数组,顺序即链上顺序。 */
|
|
538
|
+
interface PaymentOutput {
|
|
539
|
+
/** 聪,允许 0(数据输出)。必须为非负安全整数。 */
|
|
540
|
+
amount: number;
|
|
541
|
+
/** locking script hex;偶数长度 hex,允许空字符串(零长度锁定脚本)。 */
|
|
542
|
+
script: string;
|
|
543
|
+
}
|
|
575
544
|
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
545
|
interface PaymentPayParams {
|
|
585
|
-
channelId: string;
|
|
586
546
|
/** 稳定幂等身份,1–128 字符。 */
|
|
587
547
|
clientRequestId: string;
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
businessKind: string;
|
|
591
|
-
/** 业务金额(聪,不含矿工费)。 */
|
|
592
|
-
amountSatoshis: number;
|
|
593
|
-
/** 可选希望费率(sat/kB);缺省由钱包当前网络的有效费率策略决定。 */
|
|
594
|
-
feeRateSatoshisPerKb?: number;
|
|
595
|
-
recipient: ConnectPaymentRecipient;
|
|
548
|
+
/** 业务输出;非空,顺序即链上顺序,找零由钱包追加。 */
|
|
549
|
+
outputs: PaymentOutput[];
|
|
596
550
|
}
|
|
597
551
|
interface PaymentReleaseSummary {
|
|
598
552
|
/** Historical amount safely released, NOT the current wallet balance. */
|
|
@@ -606,8 +560,6 @@ interface PaymentPayResult {
|
|
|
606
560
|
clientRequestId: string;
|
|
607
561
|
status: ConnectPaymentStatus;
|
|
608
562
|
assetId: P2pkhTransferAssetId;
|
|
609
|
-
paymentType: ConnectPaymentType;
|
|
610
|
-
recipientOwnership: ConnectPaymentRecipientOwnership;
|
|
611
563
|
/** 只有 accepted/already_known 才有 canonical txid。 */
|
|
612
564
|
txid?: string;
|
|
613
565
|
feeSatoshis?: number;
|
|
@@ -677,19 +629,17 @@ interface ConnectLaunchResult {
|
|
|
677
629
|
appIdentity?: AppIdentitySnapshot;
|
|
678
630
|
}
|
|
679
631
|
/** 协议方法名常量集合。 */
|
|
680
|
-
declare const PROTOCOL_METHODS: readonly ["identity.get", "intent.sign", "cipher.encrypt", "cipher.decrypt", "
|
|
632
|
+
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
633
|
type ProtocolMethod = (typeof PROTOCOL_METHODS)[number];
|
|
682
634
|
/**
|
|
683
635
|
* 方法 -> 请求参数类型 的映射。`MethodParams<M>` 是计算出的参数类型。
|
|
684
636
|
* 业务代码里直接 `MethodParams<"identity.get">` 等价于 `IdentityGetParams`。
|
|
685
637
|
*/
|
|
686
638
|
interface MethodParamsMap {
|
|
687
|
-
"payment.channel.register": PaymentChannelRegisterParams;
|
|
688
639
|
"identity.get": IdentityGetParams;
|
|
689
640
|
"intent.sign": IntentSignParams;
|
|
690
641
|
"cipher.encrypt": CipherEncryptParams;
|
|
691
642
|
"cipher.decrypt": CipherDecryptParams;
|
|
692
|
-
"p2pkh.transfer": P2pkhTransferParams;
|
|
693
643
|
"payment.pay": PaymentPayParams;
|
|
694
644
|
"payment.status": PaymentStatusParams;
|
|
695
645
|
"connect.login": ConnectLoginParams;
|
|
@@ -702,19 +652,19 @@ interface MethodParamsMap {
|
|
|
702
652
|
"storage.directory.create": StorageDirectoryParams;
|
|
703
653
|
"storage.directory.delete": StorageDirectoryParams;
|
|
704
654
|
"storage.put": StoragePutParams;
|
|
655
|
+
"storage.encrypted.put": StoragePutParams;
|
|
705
656
|
"storage.get": StorageGetParams;
|
|
657
|
+
"storage.encrypted.get": StorageGetParams;
|
|
706
658
|
"storage.delete": StorageDeleteParams;
|
|
707
659
|
"msfile.stat": MsFileStatParams;
|
|
708
660
|
"msfile.seed.read": MsFileSeedReadParams;
|
|
709
661
|
"msfile.block.read": MsFileBlockReadParams;
|
|
710
662
|
}
|
|
711
663
|
interface MethodResultMap {
|
|
712
|
-
"payment.channel.register": PaymentChannelRegisterResult;
|
|
713
664
|
"identity.get": IdentityGetResult;
|
|
714
665
|
"intent.sign": IntentSignResult;
|
|
715
666
|
"cipher.encrypt": CipherEncryptResult;
|
|
716
667
|
"cipher.decrypt": CipherDecryptResult;
|
|
717
|
-
"p2pkh.transfer": P2pkhTransferResult;
|
|
718
668
|
"payment.pay": PaymentPayResult;
|
|
719
669
|
"payment.status": PaymentStatusResult;
|
|
720
670
|
"connect.login": ConnectLoginResult;
|
|
@@ -727,7 +677,9 @@ interface MethodResultMap {
|
|
|
727
677
|
"storage.directory.create": StorageDirectoryResult;
|
|
728
678
|
"storage.directory.delete": StorageDirectoryResult;
|
|
729
679
|
"storage.put": StoragePutResult;
|
|
680
|
+
"storage.encrypted.put": StoragePutResult;
|
|
730
681
|
"storage.get": StorageGetResult;
|
|
682
|
+
"storage.encrypted.get": StorageGetResult;
|
|
731
683
|
"storage.delete": StorageDeleteResult;
|
|
732
684
|
"msfile.stat": MsFileStatResult;
|
|
733
685
|
"msfile.seed.read": MsFileReadResult;
|
|
@@ -752,6 +704,8 @@ interface ProtocolReconnectMessage {
|
|
|
752
704
|
id: string;
|
|
753
705
|
authorizationId: string;
|
|
754
706
|
bindingId?: string;
|
|
707
|
+
/** 刷新恢复时提交的当前入口 proof;后台心跳可省略,宿主按原授权核对。 */
|
|
708
|
+
appIdentity?: AppIdentityProofV1;
|
|
755
709
|
}
|
|
756
710
|
interface ProtocolRequestMessage<M extends ProtocolMethod = ProtocolMethod> {
|
|
757
711
|
v: typeof PROTOCOL_VERSION;
|
|
@@ -778,4 +732,4 @@ type ProtocolResultMessage = {
|
|
|
778
732
|
networkIdentity?: NetworkIdentity;
|
|
779
733
|
};
|
|
780
734
|
|
|
781
|
-
export { type
|
|
735
|
+
export { type AppRequirement 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 AppIdentityProofV1 as Z, type AppIdentitySnapshot as _, type AiToolsRegistered as a, type BsvNetwork as a0, type ChannelMessageReceivedEventData as a1, type ChannelSubscriptionErrorCode as a2, type ChannelSubscriptionPhase as a3, type ChannelSubscriptionStatus as a4, type ConnectLogoutParams as a5, type ConnectPaymentStatus as a6, type JSONValue as a7, MSFILE_BLOCK_SIZE_BYTES as a8, MSFILE_DIGEST_SIZE_BYTES as a9, type ProtocolClosingMessage as aA, type ProtocolError as aB, type ProtocolEventName as aC, type ProtocolEventPayload as aD, type ProtocolReadyMessage as aE, type ProtocolReconnectMessage as aF, type ProtocolRequestMessage as aG, type ProtocolResultMessage as aH, type ResolvedClaimValue as aI, STORAGE_DEFAULT_LIST_LIMIT as aJ, STORAGE_MAX_LIST_LIMIT as aK, STORAGE_MAX_PAYLOAD_BYTES as aL, type StorageListEntry as aM, type VerifiedAppIdentity as aN, assertToolJson as aO, assertToolPayload as aP, isAiToolMessage as aQ, isValidMsFileSourceId as aR, parseToolDefinitions as aS, sameNetworkIdentity as aT, validateBsvNetwork as aU, validateNetworkIdentity as aV, validateToolArguments as aW, MSFILE_LOCAL_SOURCE_ID as aa, MSFILE_MAX_BLOCK_BYTES as ab, MSFILE_MAX_CONTENT_BYTES as ac, MSFILE_MAX_ERROR_MESSAGE_BYTES as ad, MSFILE_MAX_HEADER_BYTES as ae, MSFILE_MAX_SEED_BYTES as af, MSFILE_PROTOCOL_ID as ag, type MethodParamsMap as ah, type MethodResultMap as ai, type MsFileLocalSourceStat as aj, type MsFileRemoteSourceStat as ak, type MsFileSatoshiAmount as al, type MsFileSourceKind as am, type MsFileSourceStat as an, type MsFileStatAbsentEntry as ao, type MsFileStatAvailableEntry as ap, type MsFileStatDiscoveringEntry as aq, type MsFileStatNetworkErrorEntry as ar, type MsFileStatQuotedEntry as as, type MsFileSupplierStat as at, type P2pkhTransferAssetId as au, PROTOCOL_METHODS as av, PROTOCOL_VERSION as aw, type PaymentOutput as ax, type PaymentReleaseSummary as ay, type ProtocolCancelMessage 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, Z as AppIdentityProofV1, _ as AppIdentitySnapshot, $ as AppRequirement, B as BinaryField, a0 as BsvNetwork, a1 as ChannelMessageReceivedEventData, u as ChannelPublishParams, v as ChannelPublishResult, a2 as ChannelSubscriptionErrorCode, a3 as ChannelSubscriptionPhase, w as ChannelSubscriptionSetParams, x as ChannelSubscriptionSetResult, a4 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, a5 as ConnectLogoutParams, g as ConnectLogoutResult, a6 as ConnectPaymentStatus, e as ConnectResumeParams, f as ConnectResumeResult, I as IdentityGetParams, j as IdentityGetResult, k as IntentSignParams, l as IntentSignResult, a7 as JSONValue, a8 as MSFILE_BLOCK_SIZE_BYTES, a9 as MSFILE_DIGEST_SIZE_BYTES, aa as MSFILE_LOCAL_SOURCE_ID, ab as MSFILE_MAX_BLOCK_BYTES, ac as MSFILE_MAX_CONTENT_BYTES, ad as MSFILE_MAX_ERROR_MESSAGE_BYTES, ae as MSFILE_MAX_HEADER_BYTES, af as MSFILE_MAX_SEED_BYTES, ag as MSFILE_PROTOCOL_ID, M as MethodParams, ah as MethodParamsMap, c as MethodResult, ai as MethodResultMap, T as MsFileBlockReadParams, aj as MsFileLocalSourceStat, R as MsFileReadResult, ak as MsFileRemoteSourceStat, al as MsFileSatoshiAmount, Q as MsFileSeedReadParams, am as MsFileSourceKind, an as MsFileSourceStat, ao as MsFileStatAbsentEntry, ap as MsFileStatAvailableEntry, aq as MsFileStatDiscoveringEntry, ar as MsFileStatNetworkErrorEntry, L as MsFileStatParams, as as MsFileStatQuotedEntry, O as MsFileStatResult, at as MsFileSupplierStat, N as NetworkIdentity, au as P2pkhTransferAssetId, av as PROTOCOL_METHODS, aw as PROTOCOL_VERSION, ax as PaymentOutput, q as PaymentPayParams, r as PaymentPayResult, ay as PaymentReleaseSummary, s as PaymentStatusParams, t as PaymentStatusResult, az as ProtocolCancelMessage, aA as ProtocolClosingMessage, aB as ProtocolError, U as ProtocolErrorCode, P as ProtocolEventMessage, aC as ProtocolEventName, aD as ProtocolEventPayload, b as ProtocolMethod, aE as ProtocolReadyMessage, aF as ProtocolReconnectMessage, aG as ProtocolRequestMessage, aH as ProtocolResultMessage, aI as ResolvedClaimValue, aJ as STORAGE_DEFAULT_LIST_LIMIT, aK as STORAGE_MAX_LIST_LIMIT, aL as STORAGE_MAX_PAYLOAD_BYTES, J as StorageDeleteParams, K as StorageDeleteResult, z as StorageDirectoryParams, D as StorageDirectoryResult, G as StorageGetParams, H as StorageGetResult, aM as StorageListEntry, S as StorageListParams, y as StorageListResult, E as StoragePutParams, F as StoragePutResult, aN as VerifiedAppIdentity, aR as isValidMsFileSourceId, aT as sameNetworkIdentity, aU as validateBsvNetwork, aV as validateNetworkIdentity } from './protocol-C8z30CKK.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-ZDIFZJYD.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 { ax as PaymentOutput } from './protocol-C8z30CKK.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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/script.ts"],"names":[],"mappings":";;;;AAkEA,SAAS,WAAW,GAAA,EAAgC;AAClD,EAAA,IAAI,GAAA,CAAI,MAAA,GAAS,CAAA,KAAM,CAAA,IAAM,GAAA,CAAI,MAAA,GAAS,CAAA,IAAK,CAAC,iBAAA,CAAkB,IAAA,CAAK,GAAG,CAAA,EAAI,OAAO,IAAA;AACrF,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,GAAA,CAAI,SAAS,CAAC,CAAA;AACzC,EAAA,KAAA,IAAS,IAAI,CAAA,EAAG,CAAA,GAAI,IAAI,MAAA,EAAQ,CAAA,EAAA,MAAS,CAAC,CAAA,GAAI,QAAA,CAAS,GAAA,CAAI,MAAM,CAAA,GAAI,CAAA,EAAG,IAAI,CAAA,GAAI,CAAC,GAAG,EAAE,CAAA;AACtF,EAAA,OAAO,GAA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,CAAE,CAAA;AACJ;AAGO,SAAS,kBAAkB,OAAA,EAAkC;AAClE,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,KAAA,MAAW,MAAA,IAAU,OAAA,EAAS,KAAA,IAAS,MAAA,CAAO,MAAA;AAC9C,EAAA,OAAO,KAAA;AACT","file":"script.js","sourcesContent":["/** Connect v1 业务脚本解释:只做展示,不决定是否允许支付。 */\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { ripemd160 } from \"@noble/hashes/legacy.js\";\nimport type { PaymentOutput } from \"./protocol.js\";\n\nexport type PaymentScriptKind = \"p2pkh\" | \"p2pk\" | \"multisig\" | \"op_return\" | \"unknown\";\n\nexport interface PaymentScriptP2pkh {\n kind: \"p2pkh\";\n scriptHex: string;\n amountSats: number;\n hash160Hex: string;\n addressMainnet: string;\n addressTestnet: string;\n summary: string;\n}\n\nexport interface PaymentScriptP2pk {\n kind: \"p2pk\";\n scriptHex: string;\n amountSats: number;\n publicKeyHex: string;\n summary: string;\n}\n\nexport interface PaymentScriptMultisig {\n kind: \"multisig\";\n scriptHex: string;\n amountSats: number;\n m: number;\n n: number;\n publicKeysHex: string[];\n summary: string;\n}\n\nexport interface PaymentScriptOpReturn {\n kind: \"op_return\";\n scriptHex: string;\n amountSats: number;\n dataHex: string;\n dataText: string;\n summary: string;\n}\n\nexport interface PaymentScriptUnknown {\n kind: \"unknown\";\n scriptHex: string;\n amountSats: number;\n reason: string;\n summary: string;\n}\n\nexport type PaymentScriptInterpretation =\n | PaymentScriptP2pkh\n | PaymentScriptP2pk\n | PaymentScriptMultisig\n | PaymentScriptOpReturn\n | PaymentScriptUnknown;\n\nexport interface InterpretedPaymentOutput {\n index: number;\n amountSats: number;\n scriptHex: string;\n interpretation: PaymentScriptInterpretation;\n}\n\nfunction hexToBytes(hex: string): Uint8Array | null {\n if (hex.length % 2 !== 0 || (hex.length > 0 && !/^[0-9a-fA-F]+$/u.test(hex))) return null;\n const out = new Uint8Array(hex.length / 2);\n for (let i = 0; i < out.length; i++) out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n return out;\n}\n\nfunction bytesToHex(bytes: Uint8Array): string {\n return Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\nconst BASE58_ALPHABET = \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\n\nfunction base58Encode(bytes: Uint8Array): string {\n if (bytes.length === 0) return \"\";\n const digits: number[] = [0];\n for (const byte of bytes) {\n let carry = byte;\n for (let i = 0; i < digits.length; i++) {\n const v = digits[i]! * 256 + carry;\n digits[i] = v % 58;\n carry = Math.floor(v / 58);\n }\n while (carry > 0) {\n digits.push(carry % 58);\n carry = Math.floor(carry / 58);\n }\n }\n let leadingZeros = 0;\n for (const b of bytes) {\n if (b === 0) leadingZeros++;\n else break;\n }\n let result = \"1\".repeat(leadingZeros);\n for (let i = digits.length - 1; i >= 0; i--) result += BASE58_ALPHABET[digits[i]!];\n return result;\n}\n\nfunction p2pkhAddress(hash160: Uint8Array, version: number): string {\n const payload = new Uint8Array(1 + hash160.length);\n payload[0] = version;\n payload.set(hash160, 1);\n const checksum = sha256(sha256(payload)).slice(0, 4);\n const full = new Uint8Array(payload.length + 4);\n full.set(payload, 0);\n full.set(checksum, payload.length);\n return base58Encode(full);\n}\n\nfunction hash160Of(data: Uint8Array): Uint8Array {\n return ripemd160(sha256(data));\n}\n\nfunction decodeText(bytes: Uint8Array): string {\n try {\n return new TextDecoder(\"utf-8\", { fatal: false }).decode(bytes);\n } catch {\n return \"\";\n }\n}\n\nfunction parsePushes(bytes: Uint8Array, offset: number): { pushes: Uint8Array[]; consumed: number } | null {\n const pushes: Uint8Array[] = [];\n let pos = offset;\n while (pos < bytes.length) {\n const op = bytes[pos]!;\n if (op >= 0x01 && op <= 0x4b) {\n const len = op;\n if (pos + 1 + len > bytes.length) return null;\n pushes.push(bytes.slice(pos + 1, pos + 1 + len));\n pos += 1 + len;\n } else if (op === 0x4c) {\n if (pos + 2 > bytes.length) return null;\n const len = bytes[pos + 1]!;\n if (pos + 2 + len > bytes.length) return null;\n pushes.push(bytes.slice(pos + 2, pos + 2 + len));\n pos += 2 + len;\n } else if (op === 0x4d) {\n if (pos + 3 > bytes.length) return null;\n const len = bytes[pos + 1]! | (bytes[pos + 2]! << 8);\n if (pos + 3 + len > bytes.length) return null;\n pushes.push(bytes.slice(pos + 3, pos + 3 + len));\n pos += 3 + len;\n } else if (op === 0x4e) {\n if (pos + 5 > bytes.length) return null;\n const len = bytes[pos + 1]! | (bytes[pos + 2]! << 8) | (bytes[pos + 3]! << 16) | (bytes[pos + 4]! * 0x1000000);\n if (len < 0 || pos + 5 + len > bytes.length) return null;\n pushes.push(bytes.slice(pos + 5, pos + 5 + len));\n pos += 5 + len;\n } else if (op === 0x00) {\n pushes.push(new Uint8Array(0));\n pos += 1;\n } else if (op >= 0x51 && op <= 0x60) {\n // OP_1..OP_16 are not data pushes for OP_RETURN payload parsing;\n // treat as terminator for generic push parsing.\n return null;\n } else {\n return null;\n }\n }\n return { pushes, consumed: pos };\n}\n\nfunction isCompressedPubkey(bytes: Uint8Array): boolean {\n return bytes.length === 33 && (bytes[0] === 0x02 || bytes[0] === 0x03);\n}\n\nfunction isUncompressedPubkey(bytes: Uint8Array): boolean {\n return bytes.length === 65 && bytes[0] === 0x04;\n}\n\nfunction isPubkey(bytes: Uint8Array): boolean {\n return isCompressedPubkey(bytes) || isUncompressedPubkey(bytes);\n}\n\nfunction unknown(scriptHex: string, amountSats: number): PaymentScriptUnknown {\n return {\n kind: \"unknown\",\n scriptHex,\n amountSats,\n reason: \"不认识此脚本,无法解释其用途\",\n summary: \"不认识此脚本,无法解释其用途\",\n };\n}\n\n/** 解释单个 locking script;匹配必须完整,失败按未知脚本展示。 */\nexport function interpretLockingScript(scriptHexRaw: string, amountSats: number): PaymentScriptInterpretation {\n const scriptHex = scriptHexRaw.toLowerCase();\n const bytes = hexToBytes(scriptHex);\n if (!bytes) return unknown(scriptHex, amountSats);\n // P2PKH: 76 a9 14 <20> 88 ac\n if (bytes.length === 25 && bytes[0] === 0x76 && bytes[1] === 0xa9 && bytes[2] === 0x14 && bytes[23] === 0x88 && bytes[24] === 0xac) {\n const hash = bytes.slice(3, 23);\n const hashHex = bytesToHex(hash);\n return {\n kind: \"p2pkh\",\n scriptHex,\n amountSats,\n hash160Hex: hashHex,\n addressMainnet: p2pkhAddress(hash, 0x00),\n addressTestnet: p2pkhAddress(hash, 0x6f),\n summary: `P2PKH 收款地址 ${p2pkhAddress(hash, 0x00)} / ${p2pkhAddress(hash, 0x6f)},金额 ${amountSats} sat`,\n };\n }\n // P2PK: <pubkey> OP_CHECKSIG\n if (bytes.length >= 2 && bytes[bytes.length - 1] === 0xac) {\n const pushOp = bytes[0]!;\n const pubLen = (pushOp >= 0x01 && pushOp <= 0x4b) ? pushOp : -1;\n if (pubLen > 0 && bytes.length === 1 + pubLen + 1) {\n const pub = bytes.slice(1, 1 + pubLen);\n if (isPubkey(pub)) {\n const pubHex = bytesToHex(pub);\n return {\n kind: \"p2pk\",\n scriptHex,\n amountSats,\n publicKeyHex: pubHex,\n summary: `P2PK 收款公钥 ${pubHex},金额 ${amountSats} sat`,\n };\n }\n }\n }\n // 标准多签: OP_m <pubkey>* OP_n OP_CHECKMULTISIG\n if (bytes.length >= 3 && bytes[bytes.length - 1] === 0xae) {\n const mOp = bytes[0]!;\n const nOp = bytes[bytes.length - 2]!;\n if (mOp >= 0x51 && mOp <= 0x60 && nOp >= 0x51 && nOp <= 0x60) {\n const m = mOp - 0x50;\n const n = nOp - 0x50;\n // 中间必须全是 push,且数量 == n\n let pos = 1;\n const pubs: Uint8Array[] = [];\n let ok = true;\n for (let i = 0; i < n; i++) {\n if (pos >= bytes.length - 2) { ok = false; break; }\n const op = bytes[pos]!;\n let len = -1;\n let header = 1;\n if (op >= 0x01 && op <= 0x4b) { len = op; header = 1; }\n else { ok = false; break; }\n if (pos + header + len > bytes.length - 2) { ok = false; break; }\n const pub = bytes.slice(pos + header, pos + header + len);\n if (!isPubkey(pub)) { ok = false; break; }\n pubs.push(pub);\n pos += header + len;\n }\n if (ok && pubs.length === n && pos === bytes.length - 2 && m >= 1 && m <= n && n >= 1 && n <= 16) {\n const hexes = pubs.map(bytesToHex);\n return {\n kind: \"multisig\",\n scriptHex,\n amountSats,\n m,\n n,\n publicKeysHex: hexes,\n summary: `标准多签 ${m}/${n},公钥 ${hexes.join(\", \")},金额 ${amountSats} sat`,\n };\n }\n }\n }\n // OP_RETURN / OP_FALSE OP_RETURN\n {\n let dataStart = -1;\n if (bytes.length >= 1 && bytes[0] === 0x6a) dataStart = 1;\n else if (bytes.length >= 2 && bytes[0] === 0x00 && bytes[1] === 0x6a) dataStart = 2;\n if (dataStart >= 0) {\n const rest = bytes.slice(dataStart);\n if (rest.length === 0) {\n return {\n kind: \"op_return\",\n scriptHex,\n amountSats,\n dataHex: \"\",\n dataText: \"\",\n summary: `数据输出,空数据,金额 ${amountSats} sat`,\n };\n }\n const parsed = parsePushes(rest, 0);\n if (parsed && parsed.consumed === rest.length) {\n const combined = parsed.pushes.reduce((acc, cur) => {\n const next = new Uint8Array(acc.length + cur.length);\n next.set(acc, 0);\n next.set(cur, acc.length);\n return next;\n }, new Uint8Array(0));\n const dataHex = bytesToHex(combined);\n const dataText = decodeText(combined);\n return {\n kind: \"op_return\",\n scriptHex,\n amountSats,\n dataHex,\n dataText,\n summary: `数据输出,数据 ${dataHex || \"(空)\"},金额 ${amountSats} sat`,\n };\n }\n // 剩余字节不是标准 push:按未知处理,避免误导性解释。\n return unknown(scriptHex, amountSats);\n }\n }\n return unknown(scriptHex, amountSats);\n}\n\n/** 按 App 顺序逐项解释业务输出。 */\nexport function interpretPaymentOutputs(outputs: PaymentOutput[]): InterpretedPaymentOutput[] {\n return outputs.map((output, index) => ({\n index,\n amountSats: output.amount,\n scriptHex: output.script.toLowerCase(),\n interpretation: interpretLockingScript(output.script, output.amount),\n }));\n}\n\n/** 业务输出总额(不含矿工费与找零)。 */\nexport function totalBusinessSats(outputs: PaymentOutput[]): number {\n let total = 0;\n for (const output of outputs) total += output.amount;\n return total;\n}\n"]}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { U as ProtocolErrorCode, au as P2pkhTransferAssetId, aG as ProtocolRequestMessage, N as NetworkIdentity, b as ProtocolMethod, M as MethodParams, Z as AppIdentityProofV1, aN as VerifiedAppIdentity, X as AiToolMessage, W as AiToolDefinition, a7 as JSONValue, aH as ProtocolResultMessage, aE as ProtocolReadyMessage, aA as ProtocolClosingMessage, c as MethodResult, aB as ProtocolError, aD as ProtocolEventPayload, aF as ProtocolReconnectMessage } from './protocol-C8z30CKK.js';
|
|
2
|
+
export { V as AI_TOOLS_MAX_JSON_CHARS, A as AiTool, Y as AiToolSchema, a as AiToolsRegistered, aO as assertToolJson, aP as assertToolPayload, aQ as isAiToolMessage, aS as parseToolDefinitions, aW as validateToolArguments } from './protocol-C8z30CKK.js';
|
|
3
3
|
|
|
4
4
|
/** 校验失败:抛出的对象。service 会捕获并组装 ProtocolError。 */
|
|
5
5
|
declare class ProtocolValidationError extends Error {
|
|
@@ -144,7 +144,7 @@ interface ReceiverRequest<M extends ProtocolMethod = ProtocolMethod> {
|
|
|
144
144
|
/** 判断建立连接的方法;ready 只表示传输可用,不属于身份授权。 */
|
|
145
145
|
declare function isEstablishing(method: string): boolean;
|
|
146
146
|
/** 生产钱包与闭环测试共用同一接收端,不内置测试业务或默认自动授权。 */
|
|
147
|
-
/**
|
|
147
|
+
/** 外部恢复控制只携带不透明授权引用和可选当前入口 proof,不能夹带业务参数或钱包选择器。 */
|
|
148
148
|
declare function parseReconnectMessage(data: unknown): ProtocolReconnectMessage | null;
|
|
149
149
|
declare class KeymasterConnectReceiver {
|
|
150
150
|
private readonly options;
|