@floegence/flowersec-core 0.1.1

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 (120) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +42 -0
  3. package/YAMUX_ALIGNMENT.md +127 -0
  4. package/dist/_examples/flowersec/demo/v1.facade.gen.d.ts +12 -0
  5. package/dist/_examples/flowersec/demo/v1.facade.gen.js +15 -0
  6. package/dist/_examples/flowersec/demo/v1.gen.d.ts +16 -0
  7. package/dist/_examples/flowersec/demo/v1.gen.js +86 -0
  8. package/dist/_examples/flowersec/demo/v1.rpc.gen.d.ts +11 -0
  9. package/dist/_examples/flowersec/demo/v1.rpc.gen.js +22 -0
  10. package/dist/browser/connect.d.ts +12 -0
  11. package/dist/browser/connect.js +31 -0
  12. package/dist/browser/index.d.ts +2 -0
  13. package/dist/browser/index.js +1 -0
  14. package/dist/client-connect/common.d.ts +26 -0
  15. package/dist/client-connect/common.js +167 -0
  16. package/dist/client-connect/connectCore.d.ts +42 -0
  17. package/dist/client-connect/connectCore.js +302 -0
  18. package/dist/client-connect/tunnelAttachCloseReason.d.ts +3 -0
  19. package/dist/client-connect/tunnelAttachCloseReason.js +16 -0
  20. package/dist/client.d.ts +17 -0
  21. package/dist/client.js +1 -0
  22. package/dist/direct-client/connect.d.ts +4 -0
  23. package/dist/direct-client/connect.js +67 -0
  24. package/dist/direct-client/index.d.ts +1 -0
  25. package/dist/direct-client/index.js +1 -0
  26. package/dist/e2ee/constants.d.ts +9 -0
  27. package/dist/e2ee/constants.js +18 -0
  28. package/dist/e2ee/errors.d.ts +5 -0
  29. package/dist/e2ee/errors.js +8 -0
  30. package/dist/e2ee/framing.d.ts +12 -0
  31. package/dist/e2ee/framing.js +57 -0
  32. package/dist/e2ee/handshake.d.ts +80 -0
  33. package/dist/e2ee/handshake.js +322 -0
  34. package/dist/e2ee/index.d.ts +7 -0
  35. package/dist/e2ee/index.js +7 -0
  36. package/dist/e2ee/kdf.d.ts +15 -0
  37. package/dist/e2ee/kdf.js +39 -0
  38. package/dist/e2ee/record.d.ts +11 -0
  39. package/dist/e2ee/record.js +69 -0
  40. package/dist/e2ee/secureChannel.d.ts +82 -0
  41. package/dist/e2ee/secureChannel.js +265 -0
  42. package/dist/e2ee/transcript.d.ts +23 -0
  43. package/dist/e2ee/transcript.js +31 -0
  44. package/dist/facade.d.ts +21 -0
  45. package/dist/facade.js +61 -0
  46. package/dist/gen/flowersec/controlplane/v1.gen.d.ts +36 -0
  47. package/dist/gen/flowersec/controlplane/v1.gen.js +135 -0
  48. package/dist/gen/flowersec/direct/v1.gen.d.ts +21 -0
  49. package/dist/gen/flowersec/direct/v1.gen.js +101 -0
  50. package/dist/gen/flowersec/e2ee/v1.gen.d.ts +68 -0
  51. package/dist/gen/flowersec/e2ee/v1.gen.js +194 -0
  52. package/dist/gen/flowersec/rpc/v1.gen.d.ts +30 -0
  53. package/dist/gen/flowersec/rpc/v1.gen.js +107 -0
  54. package/dist/gen/flowersec/tunnel/v1.gen.d.ts +23 -0
  55. package/dist/gen/flowersec/tunnel/v1.gen.js +104 -0
  56. package/dist/index.d.ts +19 -0
  57. package/dist/index.js +19 -0
  58. package/dist/node/connect.d.ts +9 -0
  59. package/dist/node/connect.js +13 -0
  60. package/dist/node/index.d.ts +2 -0
  61. package/dist/node/index.js +2 -0
  62. package/dist/node/wsFactory.d.ts +2 -0
  63. package/dist/node/wsFactory.js +69 -0
  64. package/dist/observability/index.d.ts +1 -0
  65. package/dist/observability/index.js +1 -0
  66. package/dist/observability/observer.d.ts +23 -0
  67. package/dist/observability/observer.js +28 -0
  68. package/dist/rpc/callError.d.ts +5 -0
  69. package/dist/rpc/callError.js +11 -0
  70. package/dist/rpc/caller.d.ts +8 -0
  71. package/dist/rpc/caller.js +1 -0
  72. package/dist/rpc/client.d.ts +22 -0
  73. package/dist/rpc/client.js +170 -0
  74. package/dist/rpc/framing.d.ts +4 -0
  75. package/dist/rpc/framing.js +24 -0
  76. package/dist/rpc/index.d.ts +6 -0
  77. package/dist/rpc/index.js +6 -0
  78. package/dist/rpc/server.d.ts +15 -0
  79. package/dist/rpc/server.js +67 -0
  80. package/dist/rpc/typed.d.ts +5 -0
  81. package/dist/rpc/typed.js +9 -0
  82. package/dist/rpc/validate.d.ts +2 -0
  83. package/dist/rpc/validate.js +27 -0
  84. package/dist/rpc-proxy/index.d.ts +1 -0
  85. package/dist/rpc-proxy/index.js +1 -0
  86. package/dist/rpc-proxy/rpcProxy.d.ts +13 -0
  87. package/dist/rpc-proxy/rpcProxy.js +59 -0
  88. package/dist/streamhello/index.d.ts +1 -0
  89. package/dist/streamhello/index.js +1 -0
  90. package/dist/streamhello/streamHello.d.ts +3 -0
  91. package/dist/streamhello/streamHello.js +13 -0
  92. package/dist/tunnel-client/connect.d.ts +7 -0
  93. package/dist/tunnel-client/connect.js +125 -0
  94. package/dist/tunnel-client/index.d.ts +1 -0
  95. package/dist/tunnel-client/index.js +1 -0
  96. package/dist/utils/base64url.d.ts +2 -0
  97. package/dist/utils/base64url.js +40 -0
  98. package/dist/utils/bin.d.ts +6 -0
  99. package/dist/utils/bin.js +55 -0
  100. package/dist/utils/errors.d.ts +26 -0
  101. package/dist/utils/errors.js +42 -0
  102. package/dist/utils/number.d.ts +2 -0
  103. package/dist/utils/number.js +9 -0
  104. package/dist/ws/index.d.ts +1 -0
  105. package/dist/ws/index.js +1 -0
  106. package/dist/ws-client/binaryTransport.d.ts +49 -0
  107. package/dist/ws-client/binaryTransport.js +301 -0
  108. package/dist/yamux/byteReader.d.ts +10 -0
  109. package/dist/yamux/byteReader.js +50 -0
  110. package/dist/yamux/constants.d.ts +10 -0
  111. package/dist/yamux/constants.js +14 -0
  112. package/dist/yamux/header.d.ts +17 -0
  113. package/dist/yamux/header.js +26 -0
  114. package/dist/yamux/index.d.ts +5 -0
  115. package/dist/yamux/index.js +5 -0
  116. package/dist/yamux/session.d.ts +44 -0
  117. package/dist/yamux/session.js +228 -0
  118. package/dist/yamux/stream.d.ts +30 -0
  119. package/dist/yamux/stream.js +222 -0
  120. package/package.json +112 -0
@@ -0,0 +1,101 @@
1
+ // Code generated by idlgen. DO NOT EDIT.
2
+ /** E2EE cipher suite identifier. */
3
+ export var Suite;
4
+ (function (Suite) {
5
+ /** P-256 + HKDF-SHA256 + AES-256-GCM. */
6
+ Suite[Suite["Suite_P256_HKDF_SHA256_AES_256_GCM"] = 2] = "Suite_P256_HKDF_SHA256_AES_256_GCM";
7
+ /** X25519 + HKDF-SHA256 + AES-256-GCM. */
8
+ Suite[Suite["Suite_X25519_HKDF_SHA256_AES_256_GCM"] = 1] = "Suite_X25519_HKDF_SHA256_AES_256_GCM";
9
+ })(Suite || (Suite = {}));
10
+ function isRecord(v) {
11
+ return typeof v === "object" && v != null && !Array.isArray(v);
12
+ }
13
+ function assertString(name, v) {
14
+ if (typeof v !== "string")
15
+ throw new Error(`bad ${name}`);
16
+ return v;
17
+ }
18
+ function assertBoolean(name, v) {
19
+ if (typeof v !== "boolean")
20
+ throw new Error(`bad ${name}`);
21
+ return v;
22
+ }
23
+ function assertSafeInt(name, v) {
24
+ if (typeof v !== "number" || !Number.isSafeInteger(v))
25
+ throw new Error(`bad ${name}`);
26
+ return v;
27
+ }
28
+ function assertU32(name, v) {
29
+ const n = assertSafeInt(name, v);
30
+ if (n < 0 || n > 0xffffffff)
31
+ throw new Error(`bad ${name}`);
32
+ return n;
33
+ }
34
+ function assertU16(name, v) {
35
+ const n = assertU32(name, v);
36
+ if (n > 0xffff)
37
+ throw new Error(`bad ${name}`);
38
+ return n;
39
+ }
40
+ function assertU8(name, v) {
41
+ const n = assertU32(name, v);
42
+ if (n > 0xff)
43
+ throw new Error(`bad ${name}`);
44
+ return n;
45
+ }
46
+ function assertU64(name, v) {
47
+ const n = assertSafeInt(name, v);
48
+ if (n < 0)
49
+ throw new Error(`bad ${name}`);
50
+ return n;
51
+ }
52
+ function assertI32(name, v) {
53
+ const n = assertSafeInt(name, v);
54
+ if (n < -2147483648 || n > 2147483647)
55
+ throw new Error(`bad ${name}`);
56
+ return n;
57
+ }
58
+ function assertI64(name, v) {
59
+ return assertSafeInt(name, v);
60
+ }
61
+ function assertStringMap(name, v) {
62
+ if (!isRecord(v))
63
+ throw new Error(`bad ${name}`);
64
+ for (const [k, vv] of Object.entries(v)) {
65
+ void k;
66
+ if (typeof vv !== "string")
67
+ throw new Error(`bad ${name}`);
68
+ }
69
+ return v;
70
+ }
71
+ const _SuiteValues = new Set([
72
+ 2,
73
+ 1,
74
+ ]);
75
+ function assertSuite(name, v) {
76
+ const n = assertSafeInt(name, v);
77
+ if (!_SuiteValues.has(n))
78
+ throw new Error(`bad ${name}`);
79
+ return n;
80
+ }
81
+ export function assertDirectConnectInfo(v) {
82
+ if (!isRecord(v))
83
+ throw new Error("bad DirectConnectInfo");
84
+ const o = v;
85
+ if (o["ws_url"] === undefined)
86
+ throw new Error("bad DirectConnectInfo.ws_url");
87
+ assertString("DirectConnectInfo.ws_url", o["ws_url"]);
88
+ if (o["channel_id"] === undefined)
89
+ throw new Error("bad DirectConnectInfo.channel_id");
90
+ assertString("DirectConnectInfo.channel_id", o["channel_id"]);
91
+ if (o["e2ee_psk_b64u"] === undefined)
92
+ throw new Error("bad DirectConnectInfo.e2ee_psk_b64u");
93
+ assertString("DirectConnectInfo.e2ee_psk_b64u", o["e2ee_psk_b64u"]);
94
+ if (o["channel_init_expire_at_unix_s"] === undefined)
95
+ throw new Error("bad DirectConnectInfo.channel_init_expire_at_unix_s");
96
+ assertI64("DirectConnectInfo.channel_init_expire_at_unix_s", o["channel_init_expire_at_unix_s"]);
97
+ if (o["default_suite"] === undefined)
98
+ throw new Error("bad DirectConnectInfo.default_suite");
99
+ assertSuite("DirectConnectInfo.default_suite", o["default_suite"]);
100
+ return o;
101
+ }
@@ -0,0 +1,68 @@
1
+ /** Feature bitset advertised during handshake. */
2
+ export declare enum E2EEFeatureBits {
3
+ /** Supports rekey control records. */
4
+ E2EEFeatureBits_rekey = 1
5
+ }
6
+ /** Record type indicator for encrypted frames. */
7
+ export declare enum RecordFlags {
8
+ /** Application data record. */
9
+ RecordFlags_app = 0,
10
+ /** Ping record. */
11
+ RecordFlags_ping = 1,
12
+ /** Rekey control record. */
13
+ RecordFlags_rekey = 2
14
+ }
15
+ /** Endpoint role for the E2EE handshake. */
16
+ export declare enum Role {
17
+ /** Client endpoint. */
18
+ Role_client = 1,
19
+ /** Server endpoint. */
20
+ Role_server = 2
21
+ }
22
+ /** E2EE cipher suite identifier. */
23
+ export declare enum Suite {
24
+ /** P-256 + HKDF-SHA256 + AES-256-GCM. */
25
+ Suite_P256_HKDF_SHA256_AES_256_GCM = 2,
26
+ /** X25519 + HKDF-SHA256 + AES-256-GCM. */
27
+ Suite_X25519_HKDF_SHA256_AES_256_GCM = 1
28
+ }
29
+ /** Client handshake ack payload. */
30
+ export interface E2EE_Ack {
31
+ /** Handshake identifier being acknowledged. */
32
+ handshake_id: string;
33
+ /** Client Unix timestamp used for the auth tag. */
34
+ timestamp_unix_s: number;
35
+ /** Base64url-encoded auth tag. */
36
+ auth_tag_b64u: string;
37
+ }
38
+ /** Client handshake init payload. */
39
+ export interface E2EE_Init {
40
+ /** Channel identifier. */
41
+ channel_id: string;
42
+ /** Role of the sender (client). */
43
+ role: Role;
44
+ /** Protocol version. */
45
+ version: number;
46
+ /** Requested cipher suite. */
47
+ suite: Suite;
48
+ /** Base64url-encoded client ephemeral public key. */
49
+ client_eph_pub_b64u: string;
50
+ /** Base64url-encoded client nonce (32 bytes). */
51
+ nonce_c_b64u: string;
52
+ /** Client feature bits. */
53
+ client_features: number;
54
+ }
55
+ /** Server handshake response payload. */
56
+ export interface E2EE_Resp {
57
+ /** Handshake identifier for retries. */
58
+ handshake_id: string;
59
+ /** Base64url-encoded server ephemeral public key. */
60
+ server_eph_pub_b64u: string;
61
+ /** Base64url-encoded server nonce (32 bytes). */
62
+ nonce_s_b64u: string;
63
+ /** Server feature bits. */
64
+ server_features: number;
65
+ }
66
+ export declare function assertE2EE_Ack(v: unknown): E2EE_Ack;
67
+ export declare function assertE2EE_Init(v: unknown): E2EE_Init;
68
+ export declare function assertE2EE_Resp(v: unknown): E2EE_Resp;
@@ -0,0 +1,194 @@
1
+ // Code generated by idlgen. DO NOT EDIT.
2
+ /** Feature bitset advertised during handshake. */
3
+ export var E2EEFeatureBits;
4
+ (function (E2EEFeatureBits) {
5
+ /** Supports rekey control records. */
6
+ E2EEFeatureBits[E2EEFeatureBits["E2EEFeatureBits_rekey"] = 1] = "E2EEFeatureBits_rekey";
7
+ })(E2EEFeatureBits || (E2EEFeatureBits = {}));
8
+ /** Record type indicator for encrypted frames. */
9
+ export var RecordFlags;
10
+ (function (RecordFlags) {
11
+ /** Application data record. */
12
+ RecordFlags[RecordFlags["RecordFlags_app"] = 0] = "RecordFlags_app";
13
+ /** Ping record. */
14
+ RecordFlags[RecordFlags["RecordFlags_ping"] = 1] = "RecordFlags_ping";
15
+ /** Rekey control record. */
16
+ RecordFlags[RecordFlags["RecordFlags_rekey"] = 2] = "RecordFlags_rekey";
17
+ })(RecordFlags || (RecordFlags = {}));
18
+ /** Endpoint role for the E2EE handshake. */
19
+ export var Role;
20
+ (function (Role) {
21
+ /** Client endpoint. */
22
+ Role[Role["Role_client"] = 1] = "Role_client";
23
+ /** Server endpoint. */
24
+ Role[Role["Role_server"] = 2] = "Role_server";
25
+ })(Role || (Role = {}));
26
+ /** E2EE cipher suite identifier. */
27
+ export var Suite;
28
+ (function (Suite) {
29
+ /** P-256 + HKDF-SHA256 + AES-256-GCM. */
30
+ Suite[Suite["Suite_P256_HKDF_SHA256_AES_256_GCM"] = 2] = "Suite_P256_HKDF_SHA256_AES_256_GCM";
31
+ /** X25519 + HKDF-SHA256 + AES-256-GCM. */
32
+ Suite[Suite["Suite_X25519_HKDF_SHA256_AES_256_GCM"] = 1] = "Suite_X25519_HKDF_SHA256_AES_256_GCM";
33
+ })(Suite || (Suite = {}));
34
+ function isRecord(v) {
35
+ return typeof v === "object" && v != null && !Array.isArray(v);
36
+ }
37
+ function assertString(name, v) {
38
+ if (typeof v !== "string")
39
+ throw new Error(`bad ${name}`);
40
+ return v;
41
+ }
42
+ function assertBoolean(name, v) {
43
+ if (typeof v !== "boolean")
44
+ throw new Error(`bad ${name}`);
45
+ return v;
46
+ }
47
+ function assertSafeInt(name, v) {
48
+ if (typeof v !== "number" || !Number.isSafeInteger(v))
49
+ throw new Error(`bad ${name}`);
50
+ return v;
51
+ }
52
+ function assertU32(name, v) {
53
+ const n = assertSafeInt(name, v);
54
+ if (n < 0 || n > 0xffffffff)
55
+ throw new Error(`bad ${name}`);
56
+ return n;
57
+ }
58
+ function assertU16(name, v) {
59
+ const n = assertU32(name, v);
60
+ if (n > 0xffff)
61
+ throw new Error(`bad ${name}`);
62
+ return n;
63
+ }
64
+ function assertU8(name, v) {
65
+ const n = assertU32(name, v);
66
+ if (n > 0xff)
67
+ throw new Error(`bad ${name}`);
68
+ return n;
69
+ }
70
+ function assertU64(name, v) {
71
+ const n = assertSafeInt(name, v);
72
+ if (n < 0)
73
+ throw new Error(`bad ${name}`);
74
+ return n;
75
+ }
76
+ function assertI32(name, v) {
77
+ const n = assertSafeInt(name, v);
78
+ if (n < -2147483648 || n > 2147483647)
79
+ throw new Error(`bad ${name}`);
80
+ return n;
81
+ }
82
+ function assertI64(name, v) {
83
+ return assertSafeInt(name, v);
84
+ }
85
+ function assertStringMap(name, v) {
86
+ if (!isRecord(v))
87
+ throw new Error(`bad ${name}`);
88
+ for (const [k, vv] of Object.entries(v)) {
89
+ void k;
90
+ if (typeof vv !== "string")
91
+ throw new Error(`bad ${name}`);
92
+ }
93
+ return v;
94
+ }
95
+ const _E2EEFeatureBitsValues = new Set([
96
+ 1,
97
+ ]);
98
+ function assertE2EEFeatureBits(name, v) {
99
+ const n = assertSafeInt(name, v);
100
+ if (!_E2EEFeatureBitsValues.has(n))
101
+ throw new Error(`bad ${name}`);
102
+ return n;
103
+ }
104
+ const _RecordFlagsValues = new Set([
105
+ 0,
106
+ 1,
107
+ 2,
108
+ ]);
109
+ function assertRecordFlags(name, v) {
110
+ const n = assertSafeInt(name, v);
111
+ if (!_RecordFlagsValues.has(n))
112
+ throw new Error(`bad ${name}`);
113
+ return n;
114
+ }
115
+ const _RoleValues = new Set([
116
+ 1,
117
+ 2,
118
+ ]);
119
+ function assertRole(name, v) {
120
+ const n = assertSafeInt(name, v);
121
+ if (!_RoleValues.has(n))
122
+ throw new Error(`bad ${name}`);
123
+ return n;
124
+ }
125
+ const _SuiteValues = new Set([
126
+ 2,
127
+ 1,
128
+ ]);
129
+ function assertSuite(name, v) {
130
+ const n = assertSafeInt(name, v);
131
+ if (!_SuiteValues.has(n))
132
+ throw new Error(`bad ${name}`);
133
+ return n;
134
+ }
135
+ export function assertE2EE_Ack(v) {
136
+ if (!isRecord(v))
137
+ throw new Error("bad E2EE_Ack");
138
+ const o = v;
139
+ if (o["handshake_id"] === undefined)
140
+ throw new Error("bad E2EE_Ack.handshake_id");
141
+ assertString("E2EE_Ack.handshake_id", o["handshake_id"]);
142
+ if (o["timestamp_unix_s"] === undefined)
143
+ throw new Error("bad E2EE_Ack.timestamp_unix_s");
144
+ assertU64("E2EE_Ack.timestamp_unix_s", o["timestamp_unix_s"]);
145
+ if (o["auth_tag_b64u"] === undefined)
146
+ throw new Error("bad E2EE_Ack.auth_tag_b64u");
147
+ assertString("E2EE_Ack.auth_tag_b64u", o["auth_tag_b64u"]);
148
+ return o;
149
+ }
150
+ export function assertE2EE_Init(v) {
151
+ if (!isRecord(v))
152
+ throw new Error("bad E2EE_Init");
153
+ const o = v;
154
+ if (o["channel_id"] === undefined)
155
+ throw new Error("bad E2EE_Init.channel_id");
156
+ assertString("E2EE_Init.channel_id", o["channel_id"]);
157
+ if (o["role"] === undefined)
158
+ throw new Error("bad E2EE_Init.role");
159
+ assertRole("E2EE_Init.role", o["role"]);
160
+ if (o["version"] === undefined)
161
+ throw new Error("bad E2EE_Init.version");
162
+ assertU8("E2EE_Init.version", o["version"]);
163
+ if (o["suite"] === undefined)
164
+ throw new Error("bad E2EE_Init.suite");
165
+ assertSuite("E2EE_Init.suite", o["suite"]);
166
+ if (o["client_eph_pub_b64u"] === undefined)
167
+ throw new Error("bad E2EE_Init.client_eph_pub_b64u");
168
+ assertString("E2EE_Init.client_eph_pub_b64u", o["client_eph_pub_b64u"]);
169
+ if (o["nonce_c_b64u"] === undefined)
170
+ throw new Error("bad E2EE_Init.nonce_c_b64u");
171
+ assertString("E2EE_Init.nonce_c_b64u", o["nonce_c_b64u"]);
172
+ if (o["client_features"] === undefined)
173
+ throw new Error("bad E2EE_Init.client_features");
174
+ assertU32("E2EE_Init.client_features", o["client_features"]);
175
+ return o;
176
+ }
177
+ export function assertE2EE_Resp(v) {
178
+ if (!isRecord(v))
179
+ throw new Error("bad E2EE_Resp");
180
+ const o = v;
181
+ if (o["handshake_id"] === undefined)
182
+ throw new Error("bad E2EE_Resp.handshake_id");
183
+ assertString("E2EE_Resp.handshake_id", o["handshake_id"]);
184
+ if (o["server_eph_pub_b64u"] === undefined)
185
+ throw new Error("bad E2EE_Resp.server_eph_pub_b64u");
186
+ assertString("E2EE_Resp.server_eph_pub_b64u", o["server_eph_pub_b64u"]);
187
+ if (o["nonce_s_b64u"] === undefined)
188
+ throw new Error("bad E2EE_Resp.nonce_s_b64u");
189
+ assertString("E2EE_Resp.nonce_s_b64u", o["nonce_s_b64u"]);
190
+ if (o["server_features"] === undefined)
191
+ throw new Error("bad E2EE_Resp.server_features");
192
+ assertU32("E2EE_Resp.server_features", o["server_features"]);
193
+ return o;
194
+ }
@@ -0,0 +1,30 @@
1
+ /** Envelope for RPC requests and responses. */
2
+ export interface RpcEnvelope {
3
+ /** Type identifier for routing. */
4
+ type_id: number;
5
+ /** Client-assigned request identifier. */
6
+ request_id: number;
7
+ /** Request identifier being responded to. */
8
+ response_to: number;
9
+ /** Request or response payload as JSON. */
10
+ payload: unknown;
11
+ /** Error payload for failed requests. */
12
+ error?: RpcError;
13
+ }
14
+ /** RPC error payload. */
15
+ export interface RpcError {
16
+ /** Application or transport error code. */
17
+ code: number;
18
+ /** Optional human-readable error message. */
19
+ message?: string;
20
+ }
21
+ /** Initial greeting sent on a new stream. */
22
+ export interface StreamHello {
23
+ /** Stream kind label (e.g. "rpc"). */
24
+ kind: string;
25
+ /** Stream protocol version. */
26
+ v: number;
27
+ }
28
+ export declare function assertRpcEnvelope(v: unknown): RpcEnvelope;
29
+ export declare function assertRpcError(v: unknown): RpcError;
30
+ export declare function assertStreamHello(v: unknown): StreamHello;
@@ -0,0 +1,107 @@
1
+ // Code generated by idlgen. DO NOT EDIT.
2
+ function isRecord(v) {
3
+ return typeof v === "object" && v != null && !Array.isArray(v);
4
+ }
5
+ function assertString(name, v) {
6
+ if (typeof v !== "string")
7
+ throw new Error(`bad ${name}`);
8
+ return v;
9
+ }
10
+ function assertBoolean(name, v) {
11
+ if (typeof v !== "boolean")
12
+ throw new Error(`bad ${name}`);
13
+ return v;
14
+ }
15
+ function assertSafeInt(name, v) {
16
+ if (typeof v !== "number" || !Number.isSafeInteger(v))
17
+ throw new Error(`bad ${name}`);
18
+ return v;
19
+ }
20
+ function assertU32(name, v) {
21
+ const n = assertSafeInt(name, v);
22
+ if (n < 0 || n > 0xffffffff)
23
+ throw new Error(`bad ${name}`);
24
+ return n;
25
+ }
26
+ function assertU16(name, v) {
27
+ const n = assertU32(name, v);
28
+ if (n > 0xffff)
29
+ throw new Error(`bad ${name}`);
30
+ return n;
31
+ }
32
+ function assertU8(name, v) {
33
+ const n = assertU32(name, v);
34
+ if (n > 0xff)
35
+ throw new Error(`bad ${name}`);
36
+ return n;
37
+ }
38
+ function assertU64(name, v) {
39
+ const n = assertSafeInt(name, v);
40
+ if (n < 0)
41
+ throw new Error(`bad ${name}`);
42
+ return n;
43
+ }
44
+ function assertI32(name, v) {
45
+ const n = assertSafeInt(name, v);
46
+ if (n < -2147483648 || n > 2147483647)
47
+ throw new Error(`bad ${name}`);
48
+ return n;
49
+ }
50
+ function assertI64(name, v) {
51
+ return assertSafeInt(name, v);
52
+ }
53
+ function assertStringMap(name, v) {
54
+ if (!isRecord(v))
55
+ throw new Error(`bad ${name}`);
56
+ for (const [k, vv] of Object.entries(v)) {
57
+ void k;
58
+ if (typeof vv !== "string")
59
+ throw new Error(`bad ${name}`);
60
+ }
61
+ return v;
62
+ }
63
+ export function assertRpcEnvelope(v) {
64
+ if (!isRecord(v))
65
+ throw new Error("bad RpcEnvelope");
66
+ const o = v;
67
+ if (o["type_id"] === undefined)
68
+ throw new Error("bad RpcEnvelope.type_id");
69
+ assertU32("RpcEnvelope.type_id", o["type_id"]);
70
+ if (o["request_id"] === undefined)
71
+ throw new Error("bad RpcEnvelope.request_id");
72
+ assertU64("RpcEnvelope.request_id", o["request_id"]);
73
+ if (o["response_to"] === undefined)
74
+ throw new Error("bad RpcEnvelope.response_to");
75
+ assertU64("RpcEnvelope.response_to", o["response_to"]);
76
+ if (o["payload"] === undefined)
77
+ throw new Error("bad RpcEnvelope.payload");
78
+ void o["payload"];
79
+ if (o["error"] !== undefined) {
80
+ assertRpcError(o["error"]);
81
+ }
82
+ return o;
83
+ }
84
+ export function assertRpcError(v) {
85
+ if (!isRecord(v))
86
+ throw new Error("bad RpcError");
87
+ const o = v;
88
+ if (o["code"] === undefined)
89
+ throw new Error("bad RpcError.code");
90
+ assertU32("RpcError.code", o["code"]);
91
+ if (o["message"] !== undefined) {
92
+ assertString("RpcError.message", o["message"]);
93
+ }
94
+ return o;
95
+ }
96
+ export function assertStreamHello(v) {
97
+ if (!isRecord(v))
98
+ throw new Error("bad StreamHello");
99
+ const o = v;
100
+ if (o["kind"] === undefined)
101
+ throw new Error("bad StreamHello.kind");
102
+ assertString("StreamHello.kind", o["kind"]);
103
+ if (o["v"] === undefined)
104
+ throw new Error("bad StreamHello.v");
105
+ assertU32("StreamHello.v", o["v"]);
106
+ return o;
107
+ }
@@ -0,0 +1,23 @@
1
+ /** Endpoint role for tunnel attach. */
2
+ export declare enum Role {
3
+ /** Client endpoint. */
4
+ Role_client = 1,
5
+ /** Server endpoint. */
6
+ Role_server = 2
7
+ }
8
+ /** Tunnel attach request payload. */
9
+ export interface Attach {
10
+ /** Attach envelope version. */
11
+ v: number;
12
+ /** Channel identifier. */
13
+ channel_id: string;
14
+ /** Endpoint role. */
15
+ role: Role;
16
+ /** Signed attach token. */
17
+ token: string;
18
+ /** Base64url-encoded endpoint instance ID. */
19
+ endpoint_instance_id: string;
20
+ /** Optional capability map. */
21
+ caps?: Record<string, string>;
22
+ }
23
+ export declare function assertAttach(v: unknown): Attach;
@@ -0,0 +1,104 @@
1
+ // Code generated by idlgen. DO NOT EDIT.
2
+ /** Endpoint role for tunnel attach. */
3
+ export var Role;
4
+ (function (Role) {
5
+ /** Client endpoint. */
6
+ Role[Role["Role_client"] = 1] = "Role_client";
7
+ /** Server endpoint. */
8
+ Role[Role["Role_server"] = 2] = "Role_server";
9
+ })(Role || (Role = {}));
10
+ function isRecord(v) {
11
+ return typeof v === "object" && v != null && !Array.isArray(v);
12
+ }
13
+ function assertString(name, v) {
14
+ if (typeof v !== "string")
15
+ throw new Error(`bad ${name}`);
16
+ return v;
17
+ }
18
+ function assertBoolean(name, v) {
19
+ if (typeof v !== "boolean")
20
+ throw new Error(`bad ${name}`);
21
+ return v;
22
+ }
23
+ function assertSafeInt(name, v) {
24
+ if (typeof v !== "number" || !Number.isSafeInteger(v))
25
+ throw new Error(`bad ${name}`);
26
+ return v;
27
+ }
28
+ function assertU32(name, v) {
29
+ const n = assertSafeInt(name, v);
30
+ if (n < 0 || n > 0xffffffff)
31
+ throw new Error(`bad ${name}`);
32
+ return n;
33
+ }
34
+ function assertU16(name, v) {
35
+ const n = assertU32(name, v);
36
+ if (n > 0xffff)
37
+ throw new Error(`bad ${name}`);
38
+ return n;
39
+ }
40
+ function assertU8(name, v) {
41
+ const n = assertU32(name, v);
42
+ if (n > 0xff)
43
+ throw new Error(`bad ${name}`);
44
+ return n;
45
+ }
46
+ function assertU64(name, v) {
47
+ const n = assertSafeInt(name, v);
48
+ if (n < 0)
49
+ throw new Error(`bad ${name}`);
50
+ return n;
51
+ }
52
+ function assertI32(name, v) {
53
+ const n = assertSafeInt(name, v);
54
+ if (n < -2147483648 || n > 2147483647)
55
+ throw new Error(`bad ${name}`);
56
+ return n;
57
+ }
58
+ function assertI64(name, v) {
59
+ return assertSafeInt(name, v);
60
+ }
61
+ function assertStringMap(name, v) {
62
+ if (!isRecord(v))
63
+ throw new Error(`bad ${name}`);
64
+ for (const [k, vv] of Object.entries(v)) {
65
+ void k;
66
+ if (typeof vv !== "string")
67
+ throw new Error(`bad ${name}`);
68
+ }
69
+ return v;
70
+ }
71
+ const _RoleValues = new Set([
72
+ 1,
73
+ 2,
74
+ ]);
75
+ function assertRole(name, v) {
76
+ const n = assertSafeInt(name, v);
77
+ if (!_RoleValues.has(n))
78
+ throw new Error(`bad ${name}`);
79
+ return n;
80
+ }
81
+ export function assertAttach(v) {
82
+ if (!isRecord(v))
83
+ throw new Error("bad Attach");
84
+ const o = v;
85
+ if (o["v"] === undefined)
86
+ throw new Error("bad Attach.v");
87
+ assertU32("Attach.v", o["v"]);
88
+ if (o["channel_id"] === undefined)
89
+ throw new Error("bad Attach.channel_id");
90
+ assertString("Attach.channel_id", o["channel_id"]);
91
+ if (o["role"] === undefined)
92
+ throw new Error("bad Attach.role");
93
+ assertRole("Attach.role", o["role"]);
94
+ if (o["token"] === undefined)
95
+ throw new Error("bad Attach.token");
96
+ assertString("Attach.token", o["token"]);
97
+ if (o["endpoint_instance_id"] === undefined)
98
+ throw new Error("bad Attach.endpoint_instance_id");
99
+ assertString("Attach.endpoint_instance_id", o["endpoint_instance_id"]);
100
+ if (o["caps"] !== undefined) {
101
+ assertStringMap("Attach.caps", o["caps"]);
102
+ }
103
+ return o;
104
+ }
@@ -0,0 +1,19 @@
1
+ export * from "./utils/base64url.js";
2
+ export * from "./utils/bin.js";
3
+ export * from "./utils/errors.js";
4
+ export * from "./e2ee/constants.js";
5
+ export * from "./e2ee/framing.js";
6
+ export * from "./e2ee/transcript.js";
7
+ export * from "./e2ee/kdf.js";
8
+ export * from "./e2ee/record.js";
9
+ export * from "./e2ee/secureChannel.js";
10
+ export * from "./e2ee/handshake.js";
11
+ export * from "./e2ee/errors.js";
12
+ export * from "./client.js";
13
+ export * from "./observability/index.js";
14
+ export * from "./ws-client/binaryTransport.js";
15
+ export * from "./yamux/index.js";
16
+ export * from "./rpc/index.js";
17
+ export * from "./streamhello/index.js";
18
+ export * from "./tunnel-client/index.js";
19
+ export * from "./direct-client/index.js";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ export * from "./utils/base64url.js";
2
+ export * from "./utils/bin.js";
3
+ export * from "./utils/errors.js";
4
+ export * from "./e2ee/constants.js";
5
+ export * from "./e2ee/framing.js";
6
+ export * from "./e2ee/transcript.js";
7
+ export * from "./e2ee/kdf.js";
8
+ export * from "./e2ee/record.js";
9
+ export * from "./e2ee/secureChannel.js";
10
+ export * from "./e2ee/handshake.js";
11
+ export * from "./e2ee/errors.js";
12
+ export * from "./client.js";
13
+ export * from "./observability/index.js";
14
+ export * from "./ws-client/binaryTransport.js";
15
+ export * from "./yamux/index.js";
16
+ export * from "./rpc/index.js";
17
+ export * from "./streamhello/index.js";
18
+ export * from "./tunnel-client/index.js";
19
+ export * from "./direct-client/index.js";
@@ -0,0 +1,9 @@
1
+ import type { Client } from "../client.js";
2
+ import type { DirectConnectOptions } from "../direct-client/connect.js";
3
+ import type { TunnelConnectOptions } from "../tunnel-client/connect.js";
4
+ import type { ChannelInitGrant } from "../gen/flowersec/controlplane/v1.gen.js";
5
+ import type { DirectConnectInfo } from "../gen/flowersec/direct/v1.gen.js";
6
+ export declare function connectNode(input: DirectConnectInfo, opts: DirectConnectOptions): Promise<Client>;
7
+ export declare function connectNode(input: ChannelInitGrant, opts: TunnelConnectOptions): Promise<Client>;
8
+ export declare function connectTunnelNode(grant: ChannelInitGrant, opts: TunnelConnectOptions): Promise<Client>;
9
+ export declare function connectDirectNode(info: DirectConnectInfo, opts: DirectConnectOptions): Promise<Client>;