sesame-kit 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/LICENSE +26 -0
  2. package/LICENSE.biz3 +21 -0
  3. package/README.ja.md +225 -0
  4. package/README.md +222 -0
  5. package/bin/sesame.js +8 -0
  6. package/clients/js/sesame-client.mjs +208 -0
  7. package/clients/python/pyproject.toml +5 -0
  8. package/clients/python/sesame_client.py +323 -0
  9. package/clients/python/setup.cfg +11 -0
  10. package/docs/architecture.ja.md +132 -0
  11. package/docs/architecture.md +105 -0
  12. package/docs/commands.ja.md +316 -0
  13. package/docs/commands.md +308 -0
  14. package/docs/library.ja.md +152 -0
  15. package/docs/library.md +152 -0
  16. package/docs/migration.ja.md +13 -0
  17. package/docs/migration.md +13 -0
  18. package/package.json +114 -0
  19. package/src/access.js +375 -0
  20. package/src/account.js +36 -0
  21. package/src/auth.js +248 -0
  22. package/src/ble/devicemodel.js +164 -0
  23. package/src/ble/index.js +185 -0
  24. package/src/ble/protocol.js +319 -0
  25. package/src/ble/session.js +235 -0
  26. package/src/ble/transport.js +279 -0
  27. package/src/cli/access.js +373 -0
  28. package/src/cli/company.js +104 -0
  29. package/src/cli/iot.js +400 -0
  30. package/src/cli/org.js +788 -0
  31. package/src/cli/presetir.js +188 -0
  32. package/src/cli/schedule.js +83 -0
  33. package/src/cli/serve.js +308 -0
  34. package/src/cli.js +1815 -0
  35. package/src/client.js +957 -0
  36. package/src/company.js +147 -0
  37. package/src/config.js +575 -0
  38. package/src/crypto.js +162 -0
  39. package/src/devices.js +228 -0
  40. package/src/index.js +55 -0
  41. package/src/iot.js +513 -0
  42. package/src/ir.js +341 -0
  43. package/src/itemcodes.js +29 -0
  44. package/src/lock.js +194 -0
  45. package/src/org.js +803 -0
  46. package/src/paths.js +30 -0
  47. package/src/presetir.js +525 -0
  48. package/src/prompts.js +74 -0
  49. package/src/schedule.js +108 -0
  50. package/src/serve/daemon.js +251 -0
  51. package/src/serve/framing/grpc.js +145 -0
  52. package/src/serve/framing/http.js +144 -0
  53. package/src/serve/framing/ndjson.js +75 -0
  54. package/src/serve/framing/socket.js +73 -0
  55. package/src/serve/framing/stdio.js +28 -0
  56. package/src/serve/framing/token.js +36 -0
  57. package/src/serve/framing/ws.js +56 -0
  58. package/src/serve/grpc-methods.generated.json +378 -0
  59. package/src/serve/jsonrpc.js +164 -0
  60. package/src/serve/registry.js +226 -0
  61. package/src/serve/rpc-params.generated.json +1746 -0
  62. package/src/serve/sesame.proto +470 -0
  63. package/src/session-ui.js +181 -0
  64. package/src/sharekey.js +130 -0
  65. package/src/tokens.js +53 -0
  66. package/src/transport.js +634 -0
  67. package/src/util.js +26 -0
  68. package/types/access.d.ts +193 -0
  69. package/types/access.d.ts.map +1 -0
  70. package/types/account.d.ts +13 -0
  71. package/types/account.d.ts.map +1 -0
  72. package/types/auth.d.ts +80 -0
  73. package/types/auth.d.ts.map +1 -0
  74. package/types/ble/devicemodel.d.ts +212 -0
  75. package/types/ble/devicemodel.d.ts.map +1 -0
  76. package/types/ble/index.d.ts +160 -0
  77. package/types/ble/index.d.ts.map +1 -0
  78. package/types/ble/protocol.d.ts +201 -0
  79. package/types/ble/protocol.d.ts.map +1 -0
  80. package/types/ble/session.d.ts +129 -0
  81. package/types/ble/session.d.ts.map +1 -0
  82. package/types/ble/transport.d.ts +67 -0
  83. package/types/ble/transport.d.ts.map +1 -0
  84. package/types/cli/access.d.ts +6 -0
  85. package/types/cli/access.d.ts.map +1 -0
  86. package/types/cli/company.d.ts +6 -0
  87. package/types/cli/company.d.ts.map +1 -0
  88. package/types/cli/iot.d.ts +6 -0
  89. package/types/cli/iot.d.ts.map +1 -0
  90. package/types/cli/org.d.ts +6 -0
  91. package/types/cli/org.d.ts.map +1 -0
  92. package/types/cli/presetir.d.ts +6 -0
  93. package/types/cli/presetir.d.ts.map +1 -0
  94. package/types/cli/schedule.d.ts +6 -0
  95. package/types/cli/schedule.d.ts.map +1 -0
  96. package/types/cli/serve.d.ts +2 -0
  97. package/types/cli/serve.d.ts.map +1 -0
  98. package/types/cli.d.ts +2 -0
  99. package/types/cli.d.ts.map +1 -0
  100. package/types/client.d.ts +463 -0
  101. package/types/client.d.ts.map +1 -0
  102. package/types/company.d.ts +94 -0
  103. package/types/company.d.ts.map +1 -0
  104. package/types/config.d.ts +111 -0
  105. package/types/config.d.ts.map +1 -0
  106. package/types/crypto.d.ts +61 -0
  107. package/types/crypto.d.ts.map +1 -0
  108. package/types/devices.d.ts +116 -0
  109. package/types/devices.d.ts.map +1 -0
  110. package/types/index.d.ts +23 -0
  111. package/types/index.d.ts.map +1 -0
  112. package/types/iot.d.ts +312 -0
  113. package/types/iot.d.ts.map +1 -0
  114. package/types/ir.d.ts +147 -0
  115. package/types/ir.d.ts.map +1 -0
  116. package/types/itemcodes.d.ts +21 -0
  117. package/types/itemcodes.d.ts.map +1 -0
  118. package/types/lock.d.ts +89 -0
  119. package/types/lock.d.ts.map +1 -0
  120. package/types/org.d.ts +468 -0
  121. package/types/org.d.ts.map +1 -0
  122. package/types/paths.d.ts +10 -0
  123. package/types/paths.d.ts.map +1 -0
  124. package/types/presetir.d.ts +286 -0
  125. package/types/presetir.d.ts.map +1 -0
  126. package/types/prompts.d.ts +39 -0
  127. package/types/prompts.d.ts.map +1 -0
  128. package/types/schedule.d.ts +71 -0
  129. package/types/schedule.d.ts.map +1 -0
  130. package/types/serve/daemon.d.ts +133 -0
  131. package/types/serve/daemon.d.ts.map +1 -0
  132. package/types/serve/framing/grpc.d.ts +14 -0
  133. package/types/serve/framing/grpc.d.ts.map +1 -0
  134. package/types/serve/framing/http.d.ts +14 -0
  135. package/types/serve/framing/http.d.ts.map +1 -0
  136. package/types/serve/framing/ndjson.d.ts +19 -0
  137. package/types/serve/framing/ndjson.d.ts.map +1 -0
  138. package/types/serve/framing/socket.d.ts +14 -0
  139. package/types/serve/framing/socket.d.ts.map +1 -0
  140. package/types/serve/framing/stdio.d.ts +11 -0
  141. package/types/serve/framing/stdio.d.ts.map +1 -0
  142. package/types/serve/framing/token.d.ts +11 -0
  143. package/types/serve/framing/token.d.ts.map +1 -0
  144. package/types/serve/framing/ws.d.ts +13 -0
  145. package/types/serve/framing/ws.d.ts.map +1 -0
  146. package/types/serve/jsonrpc.d.ts +118 -0
  147. package/types/serve/jsonrpc.d.ts.map +1 -0
  148. package/types/serve/registry.d.ts +41 -0
  149. package/types/serve/registry.d.ts.map +1 -0
  150. package/types/session-ui.d.ts +36 -0
  151. package/types/session-ui.d.ts.map +1 -0
  152. package/types/sharekey.d.ts +35 -0
  153. package/types/sharekey.d.ts.map +1 -0
  154. package/types/tokens.d.ts +20 -0
  155. package/types/tokens.d.ts.map +1 -0
  156. package/types/transport.d.ts +138 -0
  157. package/types/transport.d.ts.map +1 -0
  158. package/types/util.d.ts +20 -0
  159. package/types/util.d.ts.map +1 -0
  160. package/vendor/biz3/README.md +37 -0
  161. package/vendor/biz3/constants/cmdCode.d.ts +48 -0
  162. package/vendor/biz3/constants/cmdCode.d.ts.map +1 -0
  163. package/vendor/biz3/constants/cmdCode.js +92 -0
  164. package/vendor/biz3/constants/messageConstants.d.ts +28 -0
  165. package/vendor/biz3/constants/messageConstants.d.ts.map +1 -0
  166. package/vendor/biz3/constants/messageConstants.js +30 -0
  167. package/vendor/biz3/constants/sesameDeviceModel.d.ts +75 -0
  168. package/vendor/biz3/constants/sesameDeviceModel.d.ts.map +1 -0
  169. package/vendor/biz3/constants/sesameDeviceModel.js +77 -0
  170. package/vendor/biz3/package.json +5 -0
@@ -0,0 +1,201 @@
1
+ /** 結果コード → 名前 (未知は unknown(N))。 */
2
+ export function resultName(code: any): any;
3
+ /**
4
+ * 既存 secretKey と initial token から CCM セッション鍵 (16B) を導出する。
5
+ * token16 = AES-128-CMAC(secretKey, randomToken) (ssm_cmd.c:43 / CHSesameOS3LockBase.kt:109)
6
+ *
7
+ * @param {string|Buffer} secretKey 16B (32hex)
8
+ * @param {Buffer} token 4B (initial publish のランダム値)
9
+ * @returns {Buffer} 16B セッション鍵
10
+ */
11
+ export function deriveSessionKey(secretKey: string | Buffer, token: Buffer): Buffer;
12
+ /**
13
+ * login コマンドの平文ペイロード = [LOGIN(2)] ++ token16[0:4] (ssm_cmd.c:44-45 / CHSesameOS3LockBase.kt:118-120)。
14
+ * PLAINTEXT セグメントで送る。
15
+ * @param {Buffer} token16 deriveSessionKey の戻り
16
+ * @returns {Buffer} 5B
17
+ */
18
+ export function loginPayload(token16: Buffer): Buffer;
19
+ /**
20
+ * コマンド平文を CCM 暗号化し、末尾に 4B tag を付けて返す。
21
+ * @param {Buffer} token16 セッション鍵
22
+ * @param {number|bigint} count 送信カウンタ (送信ごと +1)
23
+ * @param {Buffer} token4 initial token
24
+ * @param {Buffer} plaintext 暗号化前フレーム ([item, ...data])
25
+ * @returns {Buffer} ciphertext ++ tag(4B)
26
+ */
27
+ export function ccmEncrypt(token16: Buffer, count: number | bigint, token4: Buffer, plaintext: Buffer): Buffer;
28
+ /**
29
+ * CCM 復号。入力は ciphertext ++ tag(4B)。tag 不一致なら throw。
30
+ * @param {Buffer} token16
31
+ * @param {number|bigint} count 受信カウンタ (受信ごと +1)
32
+ * @param {Buffer} token4
33
+ * @param {Buffer} ctWithTag ciphertext ++ tag(4B)
34
+ * @returns {Buffer} 復号平文
35
+ */
36
+ export function ccmDecrypt(token16: Buffer, count: number | bigint, token4: Buffer, ctWithTag: Buffer): Buffer;
37
+ /**
38
+ * 1 メッセージ (平文 or 暗号文+tag) を 20B パケット列に分割する。
39
+ * 先頭パケットのみ start bit、最終パケットで parsing type を立てる (中間は APPEND_ONLY)。
40
+ * @param {Buffer} payload 送るバイト列 (平文ならフレーム、暗号なら ct++tag)
41
+ * @param {number} parsingType SEG.PLAINTEXT | SEG.CIPHERTEXT
42
+ * @returns {Buffer[]} 各 ≤20B
43
+ */
44
+ export function splitSegments(payload: Buffer, parsingType: number): Buffer[];
45
+ /**
46
+ * 送信フレーム = [item_code] ++ data。op_code は送信時付与しない (CHSesameOS3.kt:495-499)。
47
+ * @param {number} itemCode
48
+ * @param {Buffer} [data]
49
+ * @returns {Buffer}
50
+ */
51
+ export function buildSendFrame(itemCode: number, data?: Buffer): Buffer;
52
+ /**
53
+ * 受信フレーム (復号後) = [op_code][item_code][body...] を分解。
54
+ * response(7) は body=[resultCode][payload...]、publish(8) は body=[payload...] (呼び出し側で解釈)。
55
+ * @param {Buffer} buf
56
+ * @returns {{opCode:number, itemCode:number, body:Buffer}}
57
+ */
58
+ export function parseRecvFrame(buf: Buffer): {
59
+ opCode: number;
60
+ itemCode: number;
61
+ body: Buffer;
62
+ };
63
+ /**
64
+ * lock/unlock の data = `[0x00, 0x0E] ++ historyTag`、先頭 20B に切詰め (CHDBModel.kt:37-57)。
65
+ * 先頭 2B `0x000E` (BE) は tag type = "Android user BLE UUID" (SesameProtocols.kt:70)。
66
+ *
67
+ * tag 省略時は type のみ (`[0x00,0x0E]`) を送る = SDK の `historytag=null` パスと同じ。
68
+ * tag を渡す場合は **Buffer (バイト列) を渡すこと**。type が UUID を示すため、任意 utf8 文字列を
69
+ * 入れると型と中身が不整合になる (操作ログ用途であり実害は小さいが、SDK 準拠なら bytes)。
70
+ *
71
+ * @param {Buffer|Uint8Array} [tag] 操作ログ用タグ (バイト列)。省略可。
72
+ * @returns {Buffer}
73
+ */
74
+ export function historyTagBLE(tag?: Buffer | Uint8Array): Buffer;
75
+ /**
76
+ * autolock の data = 2B LE 秒数 (delay.toShort().toReverseBytes()、CHSesame5Device.kt:96-105)。0=無効。
77
+ * @param {number} seconds 0..65535
78
+ * @returns {Buffer} 2B
79
+ */
80
+ export function autolockData(seconds: number): Buffer;
81
+ /**
82
+ * mech_status を OS3 デバイスの種別に応じて解析する。
83
+ *
84
+ * SDK は publish payload の **長さ** で具象 MechStatus クラスを選ぶ (CHSesame5Device.kt:213-218,
85
+ * CHSesameBot2Device.kt:245-248)。それに倣い長さで分岐する:
86
+ *
87
+ * 7B = CHSesame5MechStatus (Sesame5/6 系ロック)
88
+ * data[0..1]: 電池電圧 ADC 生値 (LE。換算式は本体に無くサーバ側 → ここでは batteryRaw として返すのみ)
89
+ * data[2..3]: target (i16 LE、-32768 は「未設定」→ null)
90
+ * data[4..5]: position (i16 LE)
91
+ * data[6] : flags — bit1 isInLockRange / bit3 critical / bit4 stop / bit5 batteryCritical
92
+ * 3B = CHSesameBot2MechStatus / CHSesameBike2MechStatus (Bot2/Bot3/Bike2/Bike3)
93
+ * data[0..1]: 電池電圧 ADC 生値 (LE)
94
+ * data[2] : flags — bit1 isInLockRange / bit2 stop
95
+ * position/target の概念なし (null)
96
+ *
97
+ * 施錠/解錠は **isInLockRange の有無のみ** で判定する。OS3 に unlock-range ビットも中間 (moved) も無い
98
+ * (CHSesame5.kt:24-32 / CHSesameBot2.kt:123-126: isInUnlockRange = !isInLockRange)。
99
+ *
100
+ * @param {Buffer} buf 3B (bot/bike) または 7B 以上 (lock)
101
+ * @returns {{state:string, isInLockRange:boolean, target:number|null, position:number|null,
102
+ * isStop:boolean, isCritical:boolean, isBatteryCritical:boolean, batteryRaw:number, flags:number}}
103
+ */
104
+ export function parseMechStatus(buf: Buffer): {
105
+ state: string;
106
+ isInLockRange: boolean;
107
+ target: number | null;
108
+ position: number | null;
109
+ isStop: boolean;
110
+ isCritical: boolean;
111
+ isBatteryCritical: boolean;
112
+ batteryRaw: number;
113
+ flags: number;
114
+ };
115
+ /** GATT (blecent.c:13-15 / SesameProtocols.kt:80-83)。 */
116
+ export const GATT: Readonly<{
117
+ SERVICE: "fd81";
118
+ WRITE_CHAR: "16860002-a5ae-9856-b6d3-dbb4c676993e";
119
+ NOTIFY_CHAR: "16860003-a5ae-9856-b6d3-dbb4c676993e";
120
+ }>;
121
+ /** advertise の company ID (LE 5A 05 = 0x055A)。blecent.c:132 */
122
+ export const COMPANY_ID: 1370;
123
+ /** op_code (candy.h:66-69 / SesameProtocols.kt:55-57)。受信で意味を持つのは response/publish。 */
124
+ export const OP: Readonly<{
125
+ CREATE: 1;
126
+ READ: 2;
127
+ UPDATE: 3;
128
+ DELETE: 4;
129
+ SYNC: 5;
130
+ ASYNC: 6;
131
+ RESPONSE: 7;
132
+ PUBLISH: 8;
133
+ }>;
134
+ /** item_code。クラウドと共通の正準ソース (src/itemcodes.js) を参照する (重複定義を避ける)。 */
135
+ export const ITEM: Readonly<{
136
+ NONE: 0;
137
+ REGISTRATION: 1;
138
+ LOGIN: 2;
139
+ USER: 3;
140
+ HISTORY: 4;
141
+ VERSION_TAG: 5;
142
+ TIME: 8;
143
+ AUTOLOCK: 11;
144
+ INITIAL: 14;
145
+ MAGNET: 17;
146
+ HISTORY_DELETE: 18;
147
+ MECH_SETTING: 80;
148
+ MECH_STATUS: 81;
149
+ LOCK: 82;
150
+ UNLOCK: 83;
151
+ MOVE_TO: 84;
152
+ TOGGLE: 88;
153
+ CLICK: 89;
154
+ }>;
155
+ /** セグメントの parsing type (candy.h:44-46 / SesameBleReceiver.kt:5)。ヘッダ = (type<<1) | startBit。 */
156
+ export const SEG: Readonly<{
157
+ APPEND_ONLY: 0;
158
+ PLAINTEXT: 1;
159
+ CIPHERTEXT: 2;
160
+ }>;
161
+ /**
162
+ * SESAME OS3 デバイスがコマンド応答 (response 0x07) の先頭バイトで返す結果コード。
163
+ * 出典: 公式 SesameSDK `enum SesameResultCode: UInt8`
164
+ * (references_ios/Sources/SesameSDK/Ble/CHDeviceProtocol.swift:195)。
165
+ * これは **デバイス層 (SesameOS3) の taxonomy** で BLE/WM2 で共通。クラウド (biz3) 経路は
166
+ * この code を surface しないため、利用できるのは BLE 直接経路のみ。
167
+ */
168
+ export const RESULT: Readonly<{
169
+ 0: "success";
170
+ 1: "invalidFormat";
171
+ 2: "notSupported";
172
+ 3: "resultStorageFail";
173
+ 4: "invalidSig";
174
+ 5: "notFound";
175
+ 6: "unknown";
176
+ 7: "busy";
177
+ 8: "invalidParam";
178
+ 9: "invalidAction";
179
+ }>;
180
+ /**
181
+ * 受信セグメントを結合するアセンブラ。feed() で 1 パケットずつ与え、メッセージ完結時に
182
+ * { type, data } を返す (未完なら null)。start bit でバッファをリセット。
183
+ */
184
+ export class SegmentAssembler {
185
+ _buf: any[];
186
+ /**
187
+ * @param {Buffer} packet notify で届いた 1 パケット
188
+ * @returns {{type:number, data:Buffer}|null} 完結時のみ {type, data}
189
+ */
190
+ feed(packet: Buffer): {
191
+ type: number;
192
+ data: Buffer;
193
+ } | null;
194
+ }
195
+ /** ロック状態。SESAME 5 (OS3) は施錠範囲フラグの有無の 2 値 (中間 "moved" は無い)。 */
196
+ export const MECH_STATE: Readonly<{
197
+ LOCKED: "locked";
198
+ UNLOCKED: "unlocked";
199
+ }>;
200
+ import { Buffer } from "node:buffer";
201
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/ble/protocol.js"],"names":[],"mappings":"AAqDA,mCAAmC;AACnC,2CAEC;AAOD;;;;;;;GAOG;AACH,4CAJW,MAAM,GAAC,MAAM,SACb,MAAM,GACJ,MAAM,CAQlB;AAED;;;;;GAKG;AACH,sCAHW,MAAM,GACJ,MAAM,CAIlB;AAgBD;;;;;;;GAOG;AACH,oCANW,MAAM,SACN,MAAM,GAAC,MAAM,UACb,MAAM,aACN,MAAM,GACJ,MAAM,CAQlB;AAED;;;;;;;GAOG;AACH,oCANW,MAAM,SACN,MAAM,GAAC,MAAM,UACb,MAAM,aACN,MAAM,GACJ,MAAM,CAWlB;AAID;;;;;;GAMG;AACH,uCAJW,MAAM,eACN,MAAM,GACJ,MAAM,EAAE,CAkBpB;AA4BD;;;;;GAKG;AACH,yCAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;GAKG;AACH,oCAHW,MAAM,GACJ;IAAC,MAAM,EAAC,MAAM,CAAC;IAAC,QAAQ,EAAC,MAAM,CAAC;IAAC,IAAI,EAAC,MAAM,CAAA;CAAC,CAKzD;AAID;;;;;;;;;;GAUG;AACH,oCAHW,MAAM,GAAC,UAAU,GACf,MAAM,CAQlB;AAED;;;;GAIG;AACH,sCAHW,MAAM,GACJ,MAAM,CASlB;AAOD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qCAJW,MAAM,GACJ;IAAC,KAAK,EAAC,MAAM,CAAC;IAAC,aAAa,EAAC,OAAO,CAAC;IAAC,MAAM,EAAC,MAAM,GAAC,IAAI,CAAC;IAAC,QAAQ,EAAC,MAAM,GAAC,IAAI,CAAC;IAC9E,MAAM,EAAC,OAAO,CAAC;IAAC,UAAU,EAAC,OAAO,CAAC;IAAC,iBAAiB,EAAC,OAAO,CAAC;IAAC,UAAU,EAAC,MAAM,CAAC;IAAC,KAAK,EAAC,MAAM,CAAA;CAAC,CAO5G;AArQD,yDAAyD;AACzD;;;;GAIG;AAEH,+DAA+D;AAC/D,yBAA0B,IAAM,CAAC;AAEjC,sFAAsF;AACtF;;;;;;;;;GAGG;AAEH,mEAAmE;AACnE;;;;;;;;;;;;;;;;;;;GAA+B;AAE/B,+FAA+F;AAC/F;;;;GAAkF;AAElF;;;;;;GAMG;AACH;;;;;;;;;;;GAGG;AAkHH;;;GAGG;AACH;IACkB,YAAc;IAE9B;;;OAGG;IACH,aAHW,MAAM,GACJ;QAAC,IAAI,EAAC,MAAM,CAAC;QAAC,IAAI,EAAC,MAAM,CAAA;KAAC,GAAC,IAAI,CAY3C;CACF;AA8DD,8DAA8D;AAC9D;;;GAAoF;uBA7O7D,aAAa"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * BLE デバイスが非 0 の resultCode を返したときのエラー。
3
+ * `resultName` (notFound/busy/invalidSig…) で機械的に分岐できる (SesameResultCode 由来)。
4
+ */
5
+ export class BleResultError extends Error {
6
+ /** @param {"login"|"command"} phase @param {number} resultCode @param {number|null} itemCode */
7
+ constructor(phase: "login" | "command", resultCode: number, itemCode?: number | null);
8
+ resultCode: number;
9
+ resultName: any;
10
+ itemCode: number;
11
+ }
12
+ /**
13
+ * @typedef {object} BleTransport BLE 無線 I/O アダプタ (transport.js のアダプタが満たす契約)。
14
+ * @property {(onPacket:(packet:Buffer)=>void)=>Promise<void>} connect 接続+notify購読。各 notify を onPacket へ。
15
+ * @property {(bytes:Buffer)=>void|Promise<void>} write Write Without Response。
16
+ * @property {()=>void|Promise<void>} disconnect 切断。
17
+ */
18
+ export class SesameBleSession {
19
+ /**
20
+ * @param {{transport:BleTransport, secretKey:string|Buffer, debug?:boolean,
21
+ * defaultTimeoutMs?:number}} opts
22
+ */
23
+ constructor({ transport, secretKey, debug, defaultTimeoutMs }: {
24
+ transport: BleTransport;
25
+ secretKey: string | Buffer;
26
+ debug?: boolean;
27
+ defaultTimeoutMs?: number;
28
+ });
29
+ _transport: BleTransport;
30
+ _secretKey: Buffer<ArrayBufferLike>;
31
+ _debug: boolean;
32
+ _defaultTimeoutMs: number;
33
+ _asm: SegmentAssembler;
34
+ _token: Buffer<any>;
35
+ _key: Buffer<ArrayBufferLike>;
36
+ _encCount: number;
37
+ _decCount: number;
38
+ _loggedIn: boolean;
39
+ /** @type {Map<number, Array<{resolve:Function, reject:Function, timer:any}>>} item → FIFO */
40
+ _pending: Map<number, Array<{
41
+ resolve: Function;
42
+ reject: Function;
43
+ timer: any;
44
+ }>>;
45
+ _statusListeners: Set<any>;
46
+ _publishListeners: Set<any>;
47
+ _lastStatus: {
48
+ state: string;
49
+ isInLockRange: boolean;
50
+ target: number | null;
51
+ position: number | null;
52
+ isStop: boolean;
53
+ isCritical: boolean;
54
+ isBatteryCritical: boolean;
55
+ batteryRaw: number;
56
+ flags: number;
57
+ };
58
+ _loginWaiter: {
59
+ resolve: (value: any) => void;
60
+ reject: (reason?: any) => void;
61
+ timer: NodeJS.Timeout;
62
+ };
63
+ _log(...a: any[]): void;
64
+ /** 最後に受信した mechStatus (parseMechStatus の結果)。未受信なら null。 */
65
+ get lastStatus(): {
66
+ state: string;
67
+ isInLockRange: boolean;
68
+ target: number | null;
69
+ position: number | null;
70
+ isStop: boolean;
71
+ isCritical: boolean;
72
+ isBatteryCritical: boolean;
73
+ batteryRaw: number;
74
+ flags: number;
75
+ };
76
+ get isLoggedIn(): boolean;
77
+ /** mechStatus publish を購読。戻り値 unsubscribe。 */
78
+ onStatus(fn: any): () => boolean;
79
+ /** 任意 publish を購読 ({opCode,itemCode,body})。戻り値 unsubscribe。 */
80
+ onPublish(fn: any): () => boolean;
81
+ /**
82
+ * 接続して login まで完了させる。
83
+ * @returns {Promise<void>} login 成功で resolve
84
+ */
85
+ connect(): Promise<void>;
86
+ disconnect(): Promise<void>;
87
+ /**
88
+ * 暗号化コマンドを送り、response(7)+item を待って返す。
89
+ * @param {number} itemCode
90
+ * @param {Buffer} [data]
91
+ * @param {{timeoutMs?:number}} [opts]
92
+ * @returns {Promise<{resultCode:number, payload:Buffer}>}
93
+ */
94
+ request(itemCode: number, data?: Buffer, { timeoutMs }?: {
95
+ timeoutMs?: number;
96
+ }): Promise<{
97
+ resultCode: number;
98
+ payload: Buffer;
99
+ }>;
100
+ /** 暗号化なしで item+data を送る (login 等のハンドシェイク用低レベル)。 */
101
+ _sendPlain(frame: any): void;
102
+ /** CCM 暗号化して送る (encCount++)。 */
103
+ _sendCipher(frame: any): void;
104
+ _dequeue(itemCode: any, entry: any): void;
105
+ _onPacket(packet: any): void;
106
+ _handleInitial(token: any): void;
107
+ _handleLoginResponse(resultCode: any): void;
108
+ _resolvePending(itemCode: any, resultCode: any, payload: any): void;
109
+ }
110
+ /**
111
+ * BLE 無線 I/O アダプタ (transport.js のアダプタが満たす契約)。
112
+ */
113
+ export type BleTransport = {
114
+ /**
115
+ * 接続+notify購読。各 notify を onPacket へ。
116
+ */
117
+ connect: (onPacket: (packet: Buffer) => void) => Promise<void>;
118
+ /**
119
+ * Write Without Response。
120
+ */
121
+ write: (bytes: Buffer) => void | Promise<void>;
122
+ /**
123
+ * 切断。
124
+ */
125
+ disconnect: () => void | Promise<void>;
126
+ };
127
+ import { Buffer } from "node:buffer";
128
+ import { SegmentAssembler } from "./protocol.js";
129
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/ble/session.js"],"names":[],"mappings":"AAwBA;;;GAGG;AACH;IACE,gGAAgG;IAChG,mBADY,OAAO,GAAC,SAAS,cAAgB,MAAM,aAAqB,MAAM,GAAC,IAAI,EAUlF;IAHC,mBAA4B;IAC5B,gBAAsB;IACtB,iBAAwB;CAE3B;AAED;;;;;GAKG;AAEH;IACE;;;OAGG;IACH,+DAHW;QAAC,SAAS,EAAC,YAAY,CAAC;QAAC,SAAS,EAAC,MAAM,GAAC,MAAM,CAAC;QAAC,KAAK,CAAC,EAAC,OAAO,CAAC;QAChE,gBAAgB,CAAC,EAAC,MAAM,CAAA;KAAC,EAuBpC;IAlBC,yBAA2B;IAC3B,oCAAwF;IACxF,gBAAmB;IACnB,0BAAyC;IAEzC,uBAAkC;IAClC,oBAAkB;IAClB,8BAAgB;IAChB,kBAAkB;IAClB,kBAAkB;IAClB,mBAAsB;IAEtB,6FAA6F;IAC7F,UADW,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC;QAAC,OAAO,WAAU;QAAC,MAAM,WAAU;QAAC,KAAK,EAAC,GAAG,CAAA;KAAC,CAAC,CAAC,CACpD;IACzB,2BAAiC;IACjC,4BAAkC;IAClC;;;;;;;;;;MAAuB;IACvB;;;;MAAwB;IAG1B,wBAA6D;IAE7D,2DAA2D;IAC3D;;;;;;;;;;MAA6C;IAC7C,0BAA2C;IAE3C,8CAA8C;IAC9C,iCAA8F;IAC9F,+DAA+D;IAC/D,kCAAiG;IAEjG;;;OAGG;IACH,WAFa,OAAO,CAAC,IAAI,CAAC,CAYzB;IAED,4BASC;IAED;;;;;;OAMG;IACH,kBALW,MAAM,SACN,MAAM,kBACN;QAAC,SAAS,CAAC,EAAC,MAAM,CAAA;KAAC,GACjB,OAAO,CAAC;QAAC,UAAU,EAAC,MAAM,CAAC;QAAC,OAAO,EAAC,MAAM,CAAA;KAAC,CAAC,CAgBxD;IAED,mDAAmD;IACnD,6BAEC;IAED,gCAAgC;IAChC,8BAIC;IAED,0CAMC;IAID,6BA4CC;IAED,iCAQC;IAED,4CAOC;IAED,oEAQC;CACF;;;;;;;;aA9La,CAAC,QAAQ,EAAC,CAAC,MAAM,EAAC,MAAM,KAAG,IAAI,KAAG,OAAO,CAAC,IAAI,CAAC;;;;WAC/C,CAAC,KAAK,EAAC,MAAM,KAAG,IAAI,GAAC,OAAO,CAAC,IAAI,CAAC;;;;gBAClC,MAAI,IAAI,GAAC,OAAO,CAAC,IAAI,CAAC;;uBAhCb,aAAa;iCAK7B,eAAe"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * SESAME の advertise manufacturerData から deviceUUID を抽出する。
3
+ * noble の manufacturerData は company ID (LE 5A 05 = 0x055A) を含む生バイト列
4
+ * (Sesame2BleAdvertisement.kt の valueAt(0) は company ID を除く点に注意 = こちらは +2 オフセット)。
5
+ * SS5/Touch 系: company(2) + productType(1) + flags(2) + deviceID(16) → deviceID は md[5..21]。
6
+ *
7
+ * @param {Buffer|Uint8Array|null|undefined} md
8
+ * @returns {string|null} "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" (小文字) or null
9
+ */
10
+ export function advToDeviceUUID(md: Buffer | Uint8Array | null | undefined): string | null;
11
+ /** このプロセスで noble をロード済みか (= 通常 exit ではプロセスが終わらない)。 */
12
+ export function bleWasUsed(): boolean;
13
+ /**
14
+ * **1 回のスキャン**で近接 SESAME を集める (マルチ接続用)。逐次スキャンを避けるための要。
15
+ * deviceUUIDs を指定すると、それらが**全て見つかった時点で即終了**、または timeout で打ち切り。
16
+ * 空指定なら timeout まで全 SESAME を収集。圏外のデバイスは結果に含まれない (= 即スキップ可)。
17
+ *
18
+ * @param {{deviceUUIDs?:string[], timeoutMs?:number, debug?:boolean}} opts
19
+ * @returns {Promise<Map<string, any>>} key = deviceUUID(小文字ダッシュ付き) → noble peripheral
20
+ */
21
+ export function scanSesames({ deviceUUIDs, timeoutMs, debug }?: {
22
+ deviceUUIDs?: string[];
23
+ timeoutMs?: number;
24
+ debug?: boolean;
25
+ }): Promise<Map<string, any>>;
26
+ /**
27
+ * 既定の BLE トランスポートを生成する (noble を遅延ロード)。
28
+ * @param {object} opts NobleTransport の opts
29
+ * @returns {NobleTransport}
30
+ */
31
+ export function createBleTransport(opts?: object): NobleTransport;
32
+ /**
33
+ * @abandonware/noble ベースの BLE トランスポート。
34
+ *
35
+ * @param {{
36
+ * deviceUUID?: string, // 対象 SESAME の deviceUUID (advertise から照合)
37
+ * address?: string, // BLE アドレスで照合 (deviceUUID が取れない環境向け)
38
+ * peripheral?: object, // 既にスキャン済みの noble peripheral (scanSesames の結果)。あればスキャンしない
39
+ * scanTimeoutMs?: number,
40
+ * debug?: boolean,
41
+ * }} opts
42
+ */
43
+ export class NobleTransport {
44
+ constructor(opts?: {});
45
+ _opts: {};
46
+ _noble: any;
47
+ _peripheral: any;
48
+ _scanned: boolean;
49
+ _writeChar: any;
50
+ _notifyChar: any;
51
+ _writeChain: Promise<void>;
52
+ _debug: boolean;
53
+ _log(...a: any[]): void;
54
+ /** @param {(packet:Buffer)=>void} onPacket */
55
+ connect(onPacket: (packet: Buffer) => void): Promise<void>;
56
+ /** Write Without Response。順序保証のため直列化。 */
57
+ write(bytes: any): Promise<void>;
58
+ disconnect(): Promise<void>;
59
+ _waitPoweredOn(noble: any): Promise<any>;
60
+ _scanForDevice(noble: any, { deviceUUID, address, scanTimeoutMs }: {
61
+ deviceUUID: any;
62
+ address: any;
63
+ scanTimeoutMs: any;
64
+ }): Promise<any>;
65
+ }
66
+ import { Buffer } from "node:buffer";
67
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/ble/transport.js"],"names":[],"mappings":"AA0BA;;;;;;;;GAQG;AACH,oCAHW,MAAM,GAAC,UAAU,GAAC,IAAI,GAAC,SAAS,GAC9B,MAAM,GAAC,IAAI,CAUvB;AAWD,sDAAsD;AACtD,sCAAqD;AAwDrD;;;;;;;GAOG;AACH,gEAHW;IAAC,WAAW,CAAC,EAAC,MAAM,EAAE,CAAC;IAAC,SAAS,CAAC,EAAC,MAAM,CAAC;IAAC,KAAK,CAAC,EAAC,OAAO,CAAA;CAAC,GACxD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAmCrC;AAuHD;;;;GAIG;AACH,0CAHW,MAAM,GACJ,cAAc,CAI1B;AA5HD;;;;;;;;;;GAUG;AACH;IACE,uBASC;IARC,UAAiB;IACjB,YAAkB;IAClB,iBAA0C;IAC1C,kBAAqB;IACrB,gBAAsB;IACtB,iBAAuB;IACvB,2BAAoC;IACpC,gBAA0B;IAG5B,wBAAmE;IAEnE,8CAA8C;IAC9C,kBADY,CAAC,MAAM,EAAC,MAAM,KAAG,IAAI,iBAgChC;IAED,yCAAyC;IACzC,iCAOC;IAED,4BAQC;IAED,yCAAiF;IAEjF;;;;qBAiCC;CACF;uBA/PsB,aAAa"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {import("commander").Command} program
3
+ * @param {object} ctx cli.js makeCtx() が供給する共有コンテキスト
4
+ */
5
+ export function registerAccessCommands(program: import("commander").Command, ctx: object): void;
6
+ //# sourceMappingURL=access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/cli/access.js"],"names":[],"mappings":"AAyEA;;;GAGG;AACH,gDAHW,OAAO,WAAW,EAAE,OAAO,OAC3B,MAAM,QAyShB"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {import("commander").Command} program
3
+ * @param {object} ctx cli.js makeCtx() が供給する共有コンテキスト
4
+ */
5
+ export function registerCompanyCommands(program: import("commander").Command, ctx: object): void;
6
+ //# sourceMappingURL=company.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"company.d.ts","sourceRoot":"","sources":["../../src/cli/company.js"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,iDAHW,OAAO,WAAW,EAAE,OAAO,OAC3B,MAAM,QAgFhB"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {import("commander").Command} program
3
+ * @param {object} ctx cli.js makeCtx() が供給する共有コンテキスト
4
+ */
5
+ export function registerIotCommands(program: import("commander").Command, ctx: object): void;
6
+ //# sourceMappingURL=iot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iot.d.ts","sourceRoot":"","sources":["../../src/cli/iot.js"],"names":[],"mappings":"AAwBA;;;GAGG;AACH,6CAHW,OAAO,WAAW,EAAE,OAAO,OAC3B,MAAM,QAuMhB"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {import("commander").Command} program
3
+ * @param {object} ctx cli.js makeCtx() が供給する共有コンテキスト
4
+ */
5
+ export function registerOrgCommands(program: import("commander").Command, ctx: object): void;
6
+ //# sourceMappingURL=org.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org.d.ts","sourceRoot":"","sources":["../../src/cli/org.js"],"names":[],"mappings":"AA2BA;;;GAGG;AACH,6CAHW,OAAO,WAAW,EAAE,OAAO,OAC3B,MAAM,QAsvBhB"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {import("commander").Command} program
3
+ * @param {object} ctx cli.js makeCtx() が供給する共有コンテキスト
4
+ */
5
+ export function registerPresetIrCommands(program: import("commander").Command, ctx: object): void;
6
+ //# sourceMappingURL=presetir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presetir.d.ts","sourceRoot":"","sources":["../../src/cli/presetir.js"],"names":[],"mappings":"AA2EA;;;GAGG;AACH,kDAHW,OAAO,WAAW,EAAE,OAAO,OAC3B,MAAM,QA8GhB"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {import("commander").Command} program
3
+ * @param {object} ctx cli.js makeCtx() が供給する共有コンテキスト
4
+ */
5
+ export function registerScheduleCommands(program: import("commander").Command, ctx: object): void;
6
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../src/cli/schedule.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH,kDAHW,OAAO,WAAW,EAAE,OAAO,OAC3B,MAAM,QAkEhB"}
@@ -0,0 +1,2 @@
1
+ export function registerServeCommand(program: any): void;
2
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/cli/serve.js"],"names":[],"mappings":"AA+DA,yDA0CC"}
package/types/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export function run(argv?: string[]): Promise<void>;
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.js"],"names":[],"mappings":"AA+9CA,oDAiQC"}