@trustbaseai/protocol 0.1.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.
Files changed (42) hide show
  1. package/README.md +348 -0
  2. package/dist/bundle-hash.d.ts +54 -0
  3. package/dist/bundle-hash.d.ts.map +1 -0
  4. package/dist/bundle-hash.js +105 -0
  5. package/dist/bundle-hash.js.map +1 -0
  6. package/dist/canonical.d.ts +65 -0
  7. package/dist/canonical.d.ts.map +1 -0
  8. package/dist/canonical.js +215 -0
  9. package/dist/canonical.js.map +1 -0
  10. package/dist/constants.d.ts +200 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/constants.js +216 -0
  13. package/dist/constants.js.map +1 -0
  14. package/dist/endpoint-protocol.d.ts +143 -0
  15. package/dist/endpoint-protocol.d.ts.map +1 -0
  16. package/dist/endpoint-protocol.js +236 -0
  17. package/dist/endpoint-protocol.js.map +1 -0
  18. package/dist/errors.d.ts +13 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +21 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/index.d.ts +24 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +121 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/registry.d.ts +116 -0
  27. package/dist/registry.d.ts.map +1 -0
  28. package/dist/registry.js +637 -0
  29. package/dist/registry.js.map +1 -0
  30. package/dist/sp-framework.d.ts +686 -0
  31. package/dist/sp-framework.d.ts.map +1 -0
  32. package/dist/sp-framework.js +187 -0
  33. package/dist/sp-framework.js.map +1 -0
  34. package/dist/validation.d.ts +37 -0
  35. package/dist/validation.d.ts.map +1 -0
  36. package/dist/validation.js +85 -0
  37. package/dist/validation.js.map +1 -0
  38. package/dist/ws-protocol.d.ts +242 -0
  39. package/dist/ws-protocol.d.ts.map +1 -0
  40. package/dist/ws-protocol.js +289 -0
  41. package/dist/ws-protocol.js.map +1 -0
  42. package/package.json +34 -0
@@ -0,0 +1,116 @@
1
+ /**
2
+ * 链消息类型注册表 —— 跨侧唯一事实来源。
3
+ *
4
+ * ## 这个文件为什么必须"较真"
5
+ *
6
+ * CosmJS 把 `@type` 字符串(type URL)直接当注册表键查。写错的症状是:
7
+ *
8
+ * ```
9
+ * unable to resolve type URL /trustchain.order.v1.MsgCreateOrder
10
+ * ```
11
+ *
12
+ * 或者更糟 —— **不报错,但语义错位**(比如把 `MsgConfirmPayment` 的 `authority`
13
+ * 写成签名账户,链上按 `params.payment_authority` 校验后拒绝,
14
+ * 报错信息看起来像"权限不足",实际是字段填错)。这类"静默失败"是本项目真机上
15
+ * 踩过的坑,所以注册表**逐条从 proto 核对**,并标注 `文件:行号`。
16
+ *
17
+ * ## 出处与快照
18
+ *
19
+ * - proto 目录:`trustchain-relmerge/proto/trustchain/<模块>/v1/tx.proto`
20
+ * - 快照:`trustchain-relmerge@40d16543fe604e39009c8dbf72a54bcb81419e52`(2026-09-22)
21
+ * ⚠️ 其中 `proto/trustchain/endpoint/`、`x/endpoint/`、`indexer/src/core/ws-query-provider.ts`
22
+ * 在该提交里**尚未提交**(工作区未跟踪/已修改),出自 2026-09-22 的工作区状态。
23
+ * - **2026-09-23 追加核对**(D2 争议申诉 + D3 保险索赔,均为该日工作区改动,尚未 commit):
24
+ * `order/v1/tx.proto`(CreateOrder/CancelOrder signer → seller;ConfirmOrder/DisputeOrder
25
+ * signer → submitter 且新增字段 `submitter = 5`)、`order/v1/params.proto`(新增
26
+ * `dispute_authority = 6`)、`insurance/v1/tx.proto`(`MsgSubmitClaim.order_id = 6` 必填)、
27
+ * `insurance/v1/query.proto`(`Claim.order_id = 12` / `Claim.beneficiary = 13`)。
28
+ * - 已跑通参考:`trustbase-seller-backend/core/chain-signer.js:22-46`(`CUSTOM_TYPE_URLS`,
29
+ * 真机联调过的 type URL 清单)、`routes/chain-writes*.js`、`routes/onboard.js`
30
+ *
31
+ * ⚠️ `provenBy` 引用的两个外部仓库(seller-backend / indexer)**都有人在改**,
32
+ * 行号会漂移;它们只是"去这里看真机怎么发的"的线索,不是机器校验的引用。
33
+ * proto 的 `source` 行号才是硬引用(有工具校验)。
34
+ *
35
+ * **出处不是手抄的**:`tools/check-proto-citations.cjs` 会拿真实 proto 逐条核对
36
+ * message 名、字段名、字段类型、signer 注解,并做**反向完整性检查**(proto 有而注册表漏 = 失败)。
37
+ * 有链码 checkout 的人跑:
38
+ *
39
+ * ```bash
40
+ * npm run build
41
+ * node tools/check-proto-citations.cjs /path/to/trustchain-relmerge # 校验
42
+ * node tools/check-proto-citations.cjs /path/to/trustchain-relmerge --fix # 顺手收紧行号
43
+ * ```
44
+ *
45
+ * ## 收录口径
46
+ *
47
+ * 收录**业务方(卖家/买家/服务商)实际要发的消息**,加 gov/authority-only 的划转类。
48
+ * 不收录 `MsgUpdateParams`(纯治理,SDK 用户不会发)。
49
+ *
50
+ * `kind` 与 proto 标量的对应:
51
+ * - `uint64` / `int64` → wire JSON 里是**字符串**(proto3 JSON 规范)
52
+ * - `bytes` → wire JSON 里是 **base64**(不是 hex!本仓库真机踩过:
53
+ * `routes/chain-writes-products.js:205` 把 hex 的 content_hash 转成 base64 再发链)
54
+ * - `enum` → wire JSON 里是枚举**名字符串**(如 `PRODUCT_TYPE_PHYSICAL`)
55
+ */
56
+ export type ProtoFieldKind = 'string' | 'uint32' | 'uint64' | 'int64' | 'bool' | 'bytes' | 'enum';
57
+ export interface MsgFieldSpec {
58
+ /** proto 字段名(snake_case,与链上 proto JSON 同名 —— protobufjs 用 keepCase) */
59
+ name: string;
60
+ kind: ProtoFieldKind;
61
+ /** proto3 语义下"必填"不存在,这里表达的是**业务必填**:不填链上会拒或语义错 */
62
+ required: boolean;
63
+ /** `kind === 'enum'` 时的枚举全名 */
64
+ enumType?: string;
65
+ /** 取值约束 / 踩坑提示 */
66
+ note?: string;
67
+ }
68
+ export interface MsgTypeSpec {
69
+ /** 形如 `/trustchain.order.v1.MsgCreateOrder` —— 直接作为 cosmjs `@type` 使用 */
70
+ typeUrl: string;
71
+ /** proto message 全名(typeUrl 去掉前导 `/`) */
72
+ protoMessage: string;
73
+ /**
74
+ * `option (cosmos.msg.v1.signer)` 指名的字段 —— 交易签名者必须是**这个字段里的地址**,
75
+ * 否则链上拒签(`intended signer does not match`)。`null` 表示该 proto 没声明 signer 注解。
76
+ */
77
+ signer: string | null;
78
+ /** amino 名(有声明才填)。走 amino/ledger 序列化路径时需要,proto JSON 路径不需要。 */
79
+ aminoName?: string;
80
+ /** 一句话说明用途(中文) */
81
+ summary: string;
82
+ /** 字段清单,按 proto 里的字段号顺序 */
83
+ fields: readonly MsgFieldSpec[];
84
+ /** 出处:`proto 相对路径:行号`。多行用 `,` 分隔。 */
85
+ source: string;
86
+ /** 真机已跑通的参考实现(可选) */
87
+ provenBy?: string;
88
+ }
89
+ /** 出处:`proto/trustchain/marketplace/v1/product.proto:7-13` */
90
+ export declare const PRODUCT_TYPE: {
91
+ readonly PRODUCT_TYPE_UNSPECIFIED: 0;
92
+ readonly PRODUCT_TYPE_PHYSICAL: 1;
93
+ readonly PRODUCT_TYPE_DIGITAL: 2;
94
+ readonly PRODUCT_TYPE_SAAS: 3;
95
+ readonly PRODUCT_TYPE_SERVICE: 4;
96
+ };
97
+ export type ProductTypeName = keyof typeof PRODUCT_TYPE;
98
+ export type ProductTypeValue = (typeof PRODUCT_TYPE)[ProductTypeName];
99
+ /** 出处:`proto/trustchain/marketplace/v1/product.proto:16-21` */
100
+ export declare const LICENSE_TYPE: {
101
+ readonly LICENSE_TYPE_UNSPECIFIED: 0;
102
+ readonly LICENSE_TYPE_PERPETUAL: 1;
103
+ readonly LICENSE_TYPE_SUBSCRIPTION: 2;
104
+ readonly LICENSE_TYPE_TRIAL: 3;
105
+ };
106
+ export type LicenseTypeName = keyof typeof LICENSE_TYPE;
107
+ export type LicenseTypeValue = (typeof LICENSE_TYPE)[LicenseTypeName];
108
+ export declare const MSG_TYPES: readonly MsgTypeSpec[];
109
+ /** 全部 type URL(保持注册顺序) */
110
+ export declare const MSG_TYPE_URLS: readonly string[];
111
+ /** 按 type URL 取注册项;未注册返回 undefined(调用方应把它翻成"模块未上线/拼错"提示) */
112
+ export declare function getMsgType(typeUrl: string): MsgTypeSpec | undefined;
113
+ export declare function isKnownMsgType(typeUrl: unknown): typeUrl is string;
114
+ /** 按 proto message 全名反查(`trustchain.order.v1.MsgCreateOrder`) */
115
+ export declare function getMsgTypeByProtoMessage(protoMessage: string): MsgTypeSpec | undefined;
116
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,MAAM,GACN,OAAO,GACP,MAAM,CAAC;AAEX,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;IACrB,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC;IAClB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;IAChC,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,QAAQ,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