@bitboxswiss/bitbox-api 0.1.0 → 0.2.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 (175) hide show
  1. package/CONTRIBUTING.md +4 -2
  2. package/README.md +69 -9
  3. package/dist/index.d.ts +337 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +451 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/internal/cardano/methods.d.ts +7 -0
  8. package/dist/internal/cardano/methods.d.ts.map +1 -0
  9. package/dist/internal/cardano/methods.js +199 -0
  10. package/dist/internal/cardano/methods.js.map +1 -0
  11. package/dist/internal/cardano/query.d.ts +4 -0
  12. package/dist/internal/cardano/query.d.ts.map +1 -0
  13. package/dist/internal/cardano/query.js +20 -0
  14. package/dist/internal/cardano/query.js.map +1 -0
  15. package/dist/internal/connect-simulator.d.ts +2 -0
  16. package/dist/internal/connect-simulator.d.ts.map +1 -0
  17. package/dist/internal/connect-simulator.js +25 -0
  18. package/dist/internal/connect-simulator.js.map +1 -0
  19. package/dist/internal/connect.d.ts +2 -0
  20. package/dist/internal/connect.d.ts.map +1 -0
  21. package/dist/internal/connect.js +54 -0
  22. package/dist/internal/connect.js.map +1 -0
  23. package/dist/internal/constants.d.ts +2 -0
  24. package/dist/internal/constants.d.ts.map +1 -0
  25. package/dist/internal/constants.js +16 -0
  26. package/dist/internal/constants.js.map +1 -0
  27. package/dist/internal/device.d.ts +5 -0
  28. package/dist/internal/device.d.ts.map +1 -0
  29. package/dist/internal/device.js +40 -0
  30. package/dist/internal/device.js.map +1 -0
  31. package/dist/internal/errors.d.ts +2 -0
  32. package/dist/internal/errors.d.ts.map +1 -0
  33. package/dist/internal/errors.js +220 -0
  34. package/dist/internal/errors.js.map +1 -0
  35. package/dist/internal/eth/antiklepto.d.ts +5 -0
  36. package/dist/internal/eth/antiklepto.d.ts.map +1 -0
  37. package/dist/internal/eth/antiklepto.js +59 -0
  38. package/dist/internal/eth/antiklepto.js.map +1 -0
  39. package/dist/internal/eth/eip712.d.ts +25 -0
  40. package/dist/internal/eth/eip712.d.ts.map +1 -0
  41. package/dist/internal/eth/eip712.js +303 -0
  42. package/dist/internal/eth/eip712.js.map +1 -0
  43. package/dist/internal/eth/methods.d.ts +10 -0
  44. package/dist/internal/eth/methods.d.ts.map +1 -0
  45. package/dist/internal/eth/methods.js +245 -0
  46. package/dist/internal/eth/methods.js.map +1 -0
  47. package/dist/internal/eth/query.d.ts +4 -0
  48. package/dist/internal/eth/query.d.ts.map +1 -0
  49. package/dist/internal/eth/query.js +20 -0
  50. package/dist/internal/eth/query.js.map +1 -0
  51. package/dist/internal/eth/streaming.d.ts +4 -0
  52. package/dist/internal/eth/streaming.d.ts.map +1 -0
  53. package/dist/internal/eth/streaming.js +22 -0
  54. package/dist/internal/eth/streaming.js.map +1 -0
  55. package/dist/internal/eth/version.d.ts +2 -0
  56. package/dist/internal/eth/version.d.ts.map +1 -0
  57. package/dist/internal/eth/version.js +3 -0
  58. package/dist/internal/eth/version.js.map +1 -0
  59. package/dist/internal/hww.d.ts +2 -0
  60. package/dist/internal/hww.d.ts.map +1 -0
  61. package/dist/internal/hww.js +240 -0
  62. package/dist/internal/hww.js.map +1 -0
  63. package/dist/internal/keypath.d.ts +4 -0
  64. package/dist/internal/keypath.d.ts.map +1 -0
  65. package/dist/internal/keypath.js +47 -0
  66. package/dist/internal/keypath.js.map +1 -0
  67. package/dist/internal/message-queue.d.ts +2 -0
  68. package/dist/internal/message-queue.d.ts.map +1 -0
  69. package/dist/internal/message-queue.js +29 -0
  70. package/dist/internal/message-queue.js.map +1 -0
  71. package/dist/internal/noise-config.d.ts +2 -0
  72. package/dist/internal/noise-config.d.ts.map +1 -0
  73. package/dist/internal/noise-config.js +160 -0
  74. package/dist/internal/noise-config.js.map +1 -0
  75. package/dist/internal/noise.d.ts +2 -0
  76. package/dist/internal/noise.d.ts.map +1 -0
  77. package/dist/internal/noise.js +270 -0
  78. package/dist/internal/noise.js.map +1 -0
  79. package/dist/internal/pairing.d.ts +2 -0
  80. package/dist/internal/pairing.d.ts.map +1 -0
  81. package/dist/internal/pairing.js +130 -0
  82. package/dist/internal/pairing.js.map +1 -0
  83. package/dist/internal/proto-query.d.ts +5 -0
  84. package/dist/internal/proto-query.d.ts.map +1 -0
  85. package/dist/internal/proto-query.js +28 -0
  86. package/dist/internal/proto-query.js.map +1 -0
  87. package/dist/internal/read-write.d.ts +2 -0
  88. package/dist/internal/read-write.d.ts.map +1 -0
  89. package/dist/internal/read-write.js +40 -0
  90. package/dist/internal/read-write.js.map +1 -0
  91. package/dist/internal/restore.d.ts +3 -0
  92. package/dist/internal/restore.d.ts.map +1 -0
  93. package/dist/internal/restore.js +27 -0
  94. package/dist/internal/restore.js.map +1 -0
  95. package/dist/internal/transport-bridge.d.ts +2 -0
  96. package/dist/internal/transport-bridge.d.ts.map +1 -0
  97. package/dist/internal/transport-bridge.js +97 -0
  98. package/dist/internal/transport-bridge.js.map +1 -0
  99. package/dist/internal/transport-simulator.d.ts +2 -0
  100. package/dist/internal/transport-simulator.d.ts.map +1 -0
  101. package/dist/internal/transport-simulator.js +83 -0
  102. package/dist/internal/transport-simulator.js.map +1 -0
  103. package/dist/internal/transport-webhid.d.ts +2 -0
  104. package/dist/internal/transport-webhid.d.ts.map +1 -0
  105. package/dist/internal/transport-webhid.js +69 -0
  106. package/dist/internal/transport-webhid.js.map +1 -0
  107. package/dist/internal/u2f-framing.d.ts +2 -0
  108. package/dist/internal/u2f-framing.d.ts.map +1 -0
  109. package/dist/internal/u2f-framing.js +155 -0
  110. package/dist/internal/u2f-framing.js.map +1 -0
  111. package/dist/internal/utils.d.ts +2 -0
  112. package/dist/internal/utils.d.ts.map +1 -0
  113. package/dist/internal/utils.js +90 -0
  114. package/dist/internal/utils.js.map +1 -0
  115. package/dist/internal/version.d.ts +8 -0
  116. package/dist/internal/version.d.ts.map +1 -0
  117. package/dist/internal/version.js +9 -0
  118. package/dist/internal/version.js.map +1 -0
  119. package/dist/proto/gen/antiklepto_pb.d.ts +49 -0
  120. package/dist/proto/gen/antiklepto_pb.d.ts.map +1 -0
  121. package/dist/proto/gen/antiklepto_pb.js +22 -0
  122. package/dist/proto/gen/antiklepto_pb.js.map +1 -0
  123. package/dist/proto/gen/backup_commands_pb.d.ts +124 -0
  124. package/dist/proto/gen/backup_commands_pb.d.ts.map +1 -0
  125. package/dist/proto/gen/backup_commands_pb.js +42 -0
  126. package/dist/proto/gen/backup_commands_pb.js.map +1 -0
  127. package/dist/proto/gen/backup_pb.d.ts +150 -0
  128. package/dist/proto/gen/backup_pb.d.ts.map +1 -0
  129. package/dist/proto/gen/backup_pb.js +46 -0
  130. package/dist/proto/gen/backup_pb.js.map +1 -0
  131. package/dist/proto/gen/bitbox02_system_pb.d.ts +207 -0
  132. package/dist/proto/gen/bitbox02_system_pb.d.ts.map +1 -0
  133. package/dist/proto/gen/bitbox02_system_pb.js +80 -0
  134. package/dist/proto/gen/bitbox02_system_pb.js.map +1 -0
  135. package/dist/proto/gen/bluetooth_pb.d.ts +135 -0
  136. package/dist/proto/gen/bluetooth_pb.d.ts.map +1 -0
  137. package/dist/proto/gen/bluetooth_pb.js +42 -0
  138. package/dist/proto/gen/bluetooth_pb.js.map +1 -0
  139. package/dist/proto/gen/btc_pb.d.ts +1166 -0
  140. package/dist/proto/gen/btc_pb.d.ts.map +1 -0
  141. package/dist/proto/gen/btc_pb.js +442 -0
  142. package/dist/proto/gen/btc_pb.js.map +1 -0
  143. package/dist/proto/gen/cardano_pb.d.ts +504 -0
  144. package/dist/proto/gen/cardano_pb.d.ts.map +1 -0
  145. package/dist/proto/gen/cardano_pb.js +142 -0
  146. package/dist/proto/gen/cardano_pb.js.map +1 -0
  147. package/dist/proto/gen/common_pb.d.ts +129 -0
  148. package/dist/proto/gen/common_pb.d.ts.map +1 -0
  149. package/dist/proto/gen/common_pb.js +42 -0
  150. package/dist/proto/gen/common_pb.js.map +1 -0
  151. package/dist/proto/gen/eth_pb.d.ts +662 -0
  152. package/dist/proto/gen/eth_pb.d.ts.map +1 -0
  153. package/dist/proto/gen/eth_pb.js +221 -0
  154. package/dist/proto/gen/eth_pb.js.map +1 -0
  155. package/dist/proto/gen/hww_pb.d.ts +349 -0
  156. package/dist/proto/gen/hww_pb.d.ts.map +1 -0
  157. package/dist/proto/gen/hww_pb.js +38 -0
  158. package/dist/proto/gen/hww_pb.js.map +1 -0
  159. package/dist/proto/gen/keystore_pb.d.ts +108 -0
  160. package/dist/proto/gen/keystore_pb.d.ts.map +1 -0
  161. package/dist/proto/gen/keystore_pb.js +33 -0
  162. package/dist/proto/gen/keystore_pb.js.map +1 -0
  163. package/dist/proto/gen/mnemonic_pb.d.ts +48 -0
  164. package/dist/proto/gen/mnemonic_pb.d.ts.map +1 -0
  165. package/dist/proto/gen/mnemonic_pb.js +22 -0
  166. package/dist/proto/gen/mnemonic_pb.js.map +1 -0
  167. package/dist/proto/gen/perform_attestation_pb.d.ts +57 -0
  168. package/dist/proto/gen/perform_attestation_pb.d.ts.map +1 -0
  169. package/dist/proto/gen/perform_attestation_pb.js +17 -0
  170. package/dist/proto/gen/perform_attestation_pb.js.map +1 -0
  171. package/dist/proto/gen/system_pb.d.ts +38 -0
  172. package/dist/proto/gen/system_pb.d.ts.map +1 -0
  173. package/dist/proto/gen/system_pb.js +30 -0
  174. package/dist/proto/gen/system_pb.js.map +1 -0
  175. package/package.json +2 -1
@@ -0,0 +1,303 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { create } from '@bufbuild/protobuf';
3
+ import { ETHSignTypedMessageRequest_DataType as DataType, ETHSignTypedMessageRequest_MemberSchema, ETHSignTypedMessageRequest_MemberTypeSchema, ETHSignTypedMessageRequest_StructTypeSchema, ETHTypedMessageValueResponse_RootObject as RootObject, } from '../../proto/gen/eth_pb.js';
4
+ import { ethTypedMessageError } from '../errors.js';
5
+ import { bigIntToSignedBytesBE, bigUintToBytesBE, hexToBytes, utf8ToBytes, } from '../utils.js';
6
+ export { DataType };
7
+ export class TypedMessageError extends Error {
8
+ code = 'eth-typed-message';
9
+ constructor(detail) {
10
+ super(ethTypedMessageError(detail).message);
11
+ }
12
+ }
13
+ function isRecord(value) {
14
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
15
+ }
16
+ function parseTypes(input) {
17
+ if (!isRecord(input)) {
18
+ throw new TypedMessageError('Could not parse EIP-712 JSON message');
19
+ }
20
+ const types = {};
21
+ for (const [name, members] of Object.entries(input)) {
22
+ if (!Array.isArray(members)) {
23
+ throw new TypedMessageError('Could not parse EIP-712 JSON message');
24
+ }
25
+ types[name] = members.map((member) => {
26
+ if (!isRecord(member) || typeof member.name !== 'string' || typeof member.type !== 'string') {
27
+ throw new TypedMessageError('Could not parse EIP-712 JSON message');
28
+ }
29
+ return { name: member.name, type: member.type };
30
+ });
31
+ }
32
+ return types;
33
+ }
34
+ export function parseEip712Message(input) {
35
+ if (!isRecord(input) || typeof input.primaryType !== 'string') {
36
+ throw new TypedMessageError('Could not parse EIP-712 JSON message');
37
+ }
38
+ if (!isRecord(input.domain) || !isRecord(input.message)) {
39
+ throw new TypedMessageError('Could not parse EIP-712 JSON message');
40
+ }
41
+ return {
42
+ types: parseTypes(input.types),
43
+ primaryType: input.primaryType,
44
+ domain: input.domain,
45
+ message: input.message,
46
+ };
47
+ }
48
+ function makeMemberType(init) {
49
+ return create(ETHSignTypedMessageRequest_MemberTypeSchema, {
50
+ type: init.type,
51
+ size: init.size ?? 0,
52
+ structName: init.structName ?? '',
53
+ ...(init.arrayType !== undefined ? { arrayType: init.arrayType } : {}),
54
+ });
55
+ }
56
+ export function parseType(typ, types) {
57
+ if (typ.endsWith(']')) {
58
+ const open = typ.lastIndexOf('[');
59
+ if (open < 0) {
60
+ throw new TypedMessageError(`Invalid type format: ${typ}`);
61
+ }
62
+ const inner = typ.slice(0, open);
63
+ const sizeStr = typ.slice(open + 1, typ.length - 1);
64
+ let size = 0;
65
+ if (sizeStr !== '') {
66
+ if (!/^\d+$/.test(sizeStr)) {
67
+ throw new TypedMessageError(`Error parsing size: ${sizeStr}`);
68
+ }
69
+ size = Number(sizeStr);
70
+ }
71
+ return makeMemberType({
72
+ type: DataType.ARRAY,
73
+ size,
74
+ arrayType: parseType(inner, types),
75
+ });
76
+ }
77
+ if (typ.startsWith('bytes') && typ !== 'bytes') {
78
+ const sizeStr = typ.slice('bytes'.length);
79
+ if (!/^\d+$/.test(sizeStr)) {
80
+ throw new TypedMessageError(`Error parsing size: ${sizeStr}`);
81
+ }
82
+ return makeMemberType({ type: DataType.BYTES, size: Number(sizeStr) });
83
+ }
84
+ if (typ === 'bytes') {
85
+ return makeMemberType({ type: DataType.BYTES, size: 0 });
86
+ }
87
+ if (typ.startsWith('uint')) {
88
+ const sizeStr = typ.slice('uint'.length);
89
+ if (sizeStr === '') {
90
+ throw new TypedMessageError('uint must be sized');
91
+ }
92
+ if (!/^\d+$/.test(sizeStr)) {
93
+ throw new TypedMessageError(`Error parsing size: ${sizeStr}`);
94
+ }
95
+ return makeMemberType({ type: DataType.UINT, size: Number(sizeStr) / 8 });
96
+ }
97
+ if (typ.startsWith('int')) {
98
+ const sizeStr = typ.slice('int'.length);
99
+ if (sizeStr === '') {
100
+ throw new TypedMessageError('int must be sized');
101
+ }
102
+ if (!/^\d+$/.test(sizeStr)) {
103
+ throw new TypedMessageError(`Error parsing size: ${sizeStr}`);
104
+ }
105
+ return makeMemberType({ type: DataType.INT, size: Number(sizeStr) / 8 });
106
+ }
107
+ if (typ === 'bool') {
108
+ return makeMemberType({ type: DataType.BOOL });
109
+ }
110
+ if (typ === 'address') {
111
+ return makeMemberType({ type: DataType.ADDRESS });
112
+ }
113
+ if (typ === 'string') {
114
+ return makeMemberType({ type: DataType.STRING });
115
+ }
116
+ if (Object.prototype.hasOwnProperty.call(types, typ)) {
117
+ return makeMemberType({ type: DataType.STRUCT, structName: typ });
118
+ }
119
+ throw new TypedMessageError(`Can't recognize type: ${typ}`);
120
+ }
121
+ export function buildStructTypes(types) {
122
+ return Object.entries(types).map(([name, members]) => {
123
+ const protoMembers = members.map((member) => create(ETHSignTypedMessageRequest_MemberSchema, {
124
+ name: member.name,
125
+ type: parseType(member.type, types),
126
+ }));
127
+ return create(ETHSignTypedMessageRequest_StructTypeSchema, {
128
+ name,
129
+ members: protoMembers,
130
+ });
131
+ });
132
+ }
133
+ function decodeHex(s) {
134
+ try {
135
+ return hexToBytes(s.slice(2));
136
+ }
137
+ catch {
138
+ throw new TypedMessageError(`invalid hex: ${s}`);
139
+ }
140
+ }
141
+ function parseUintValue(value) {
142
+ if (typeof value === 'string') {
143
+ if (value.startsWith('0x') || value.startsWith('0X')) {
144
+ try {
145
+ return BigInt(value);
146
+ }
147
+ catch {
148
+ throw new TypedMessageError(`could not parse ${value} as hex`);
149
+ }
150
+ }
151
+ if (!/^\d+$/.test(value)) {
152
+ throw new TypedMessageError(`could not parse ${value} as uint`);
153
+ }
154
+ return BigInt(value);
155
+ }
156
+ if (typeof value === 'number') {
157
+ if (!Number.isInteger(value) || value < 0) {
158
+ throw new TypedMessageError('Number is not an uint');
159
+ }
160
+ return BigInt(value);
161
+ }
162
+ if (typeof value === 'bigint') {
163
+ if (value < 0n) {
164
+ throw new TypedMessageError('Number is not an uint');
165
+ }
166
+ return value;
167
+ }
168
+ throw new TypedMessageError('Wrong type for uint');
169
+ }
170
+ function parseIntValue(value) {
171
+ if (typeof value === 'string') {
172
+ if (!/^-?\d+$/.test(value)) {
173
+ throw new TypedMessageError(`could not parse ${value} as int`);
174
+ }
175
+ return BigInt(value);
176
+ }
177
+ if (typeof value === 'number') {
178
+ if (!Number.isInteger(value)) {
179
+ throw new TypedMessageError('Number is not an int');
180
+ }
181
+ return BigInt(value);
182
+ }
183
+ if (typeof value === 'bigint') {
184
+ return value;
185
+ }
186
+ throw new TypedMessageError('Wrong type for int');
187
+ }
188
+ export function encodeValue(typ, value) {
189
+ switch (typ.type) {
190
+ case DataType.BYTES: {
191
+ if (typeof value !== 'string') {
192
+ throw new TypedMessageError('Expected a string for bytes type');
193
+ }
194
+ if (value.startsWith('0x') || value.startsWith('0X')) {
195
+ return decodeHex(value);
196
+ }
197
+ return utf8ToBytes(value);
198
+ }
199
+ case DataType.UINT: {
200
+ const n = parseUintValue(value);
201
+ return bigUintToBytesBE(n);
202
+ }
203
+ case DataType.INT: {
204
+ const n = parseIntValue(value);
205
+ if (typeof value === 'number') {
206
+ const bytes = bigIntToSignedBytesBE(n);
207
+ if (bytes.length > 0 && bytes[0] === 0x00) {
208
+ return bytes.subarray(1);
209
+ }
210
+ return bytes;
211
+ }
212
+ return bigIntToSignedBytesBE(n);
213
+ }
214
+ case DataType.BOOL: {
215
+ if (typeof value !== 'boolean') {
216
+ throw new TypedMessageError('Expected a boolean value');
217
+ }
218
+ return new Uint8Array([value ? 1 : 0]);
219
+ }
220
+ case DataType.ADDRESS:
221
+ case DataType.STRING: {
222
+ if (typeof value !== 'string') {
223
+ throw new TypedMessageError('Expected a string value');
224
+ }
225
+ return utf8ToBytes(value);
226
+ }
227
+ case DataType.ARRAY: {
228
+ if (!Array.isArray(value)) {
229
+ throw new TypedMessageError('Expected an array');
230
+ }
231
+ const len = value.length;
232
+ const out = new Uint8Array(4);
233
+ const view = new DataView(out.buffer);
234
+ view.setUint32(0, len, false);
235
+ return out;
236
+ }
237
+ default:
238
+ throw new TypedMessageError('looked up value must not be a map or array');
239
+ }
240
+ }
241
+ export function getValue(what, msg) {
242
+ let currentValue;
243
+ let currentType;
244
+ switch (what.rootObject) {
245
+ case RootObject.DOMAIN:
246
+ currentValue = msg.domain;
247
+ currentType = parseType('EIP712Domain', msg.types);
248
+ break;
249
+ case RootObject.MESSAGE:
250
+ currentValue = msg.message;
251
+ currentType = parseType(msg.primaryType, msg.types);
252
+ break;
253
+ default:
254
+ throw new TypedMessageError('unknown root object');
255
+ }
256
+ for (const elementRaw of what.path) {
257
+ const element = elementRaw;
258
+ if (currentType.type === DataType.STRUCT) {
259
+ const struct = msg.types[currentType.structName];
260
+ if (struct === undefined) {
261
+ throw new TypedMessageError(`could not lookup type of name: ${currentType.structName}`);
262
+ }
263
+ const member = struct[element];
264
+ if (member === undefined) {
265
+ throw new TypedMessageError(`could not lookup member #${element} of type: ${currentType.structName}`);
266
+ }
267
+ if (typeof currentValue !== 'object' || currentValue === null) {
268
+ throw new TypedMessageError('expected object value at struct position');
269
+ }
270
+ const obj = currentValue;
271
+ if (!Object.prototype.hasOwnProperty.call(obj, member.name)) {
272
+ throw new TypedMessageError(`could not lookup: ${member.name}`);
273
+ }
274
+ currentValue = obj[member.name];
275
+ currentType = parseType(member.type, msg.types);
276
+ }
277
+ else if (currentType.type === DataType.ARRAY) {
278
+ if (!Array.isArray(currentValue)) {
279
+ throw new TypedMessageError('expected array at array position');
280
+ }
281
+ if (element >= currentValue.length) {
282
+ throw new TypedMessageError(`could not lookup array index: ${element}`);
283
+ }
284
+ currentValue = currentValue[element];
285
+ if (currentType.arrayType === undefined) {
286
+ throw new TypedMessageError('array type missing inner type');
287
+ }
288
+ currentType = currentType.arrayType;
289
+ }
290
+ else {
291
+ throw new TypedMessageError('path element does not point to struct or array');
292
+ }
293
+ }
294
+ if (currentType.type === DataType.STRUCT ||
295
+ (currentType.type === DataType.ARRAY && !Array.isArray(currentValue))) {
296
+ throw new TypedMessageError('path points to struct or array; value expected');
297
+ }
298
+ return {
299
+ value: encodeValue(currentType, currentValue),
300
+ dataType: currentType.type,
301
+ };
302
+ }
303
+ //# sourceMappingURL=eip712.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eip712.js","sourceRoot":"","sources":["../../../src/internal/eth/eip712.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,mCAAmC,IAAI,QAAQ,EAC/C,uCAAuC,EACvC,2CAA2C,EAC3C,2CAA2C,EAC3C,uCAAuC,IAAI,UAAU,GAKtD,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAA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,KAAK,SAAS,EAAE,CAAC;gBACxC,MAAM,IAAI,iBAAiB,CAAC,+BAA+B,CAAC,CAAC;YAC/D,CAAC;YACD,WAAW,GAAG,WAAW,CAAC,SAAS,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,iBAAiB,CAAC,gDAAgD,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;IAED,IACE,WAAW,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM;QACpC,CAAC,WAAW,CAAC,IAAI,KAAK,QAAQ,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EACrE,CAAC;QACD,MAAM,IAAI,iBAAiB,CAAC,gDAAgD,CAAC,CAAC;IAChF,CAAC;IAED,OAAO;QACL,KAAK,EAAE,WAAW,CAAC,WAAW,EAAE,YAAY,CAAC;QAC7C,QAAQ,EAAE,WAAW,CAAC,IAAI;KAC3B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Eth1559Transaction, EthAddressCase, EthSignature, EthTransaction, Keypath } from '../../index.js';
2
+ import type { Info } from '../hww.js';
3
+ import type { EncryptedChannel } from '../pairing.js';
4
+ export declare function ethXpub(channel: EncryptedChannel, keypath: Keypath): Promise<string>;
5
+ export declare function ethAddress(channel: EncryptedChannel, chainId: bigint, keypath: Keypath, display: boolean): Promise<string>;
6
+ export declare function ethSignTransaction(channel: EncryptedChannel, info: Info, chainId: bigint, keypath: Keypath, tx: EthTransaction, addressCase: EthAddressCase | undefined): Promise<EthSignature>;
7
+ export declare function ethSign1559Transaction(channel: EncryptedChannel, info: Info, keypath: Keypath, tx: Eth1559Transaction, addressCase: EthAddressCase | undefined): Promise<EthSignature>;
8
+ export declare function ethSignMessage(channel: EncryptedChannel, info: Info, chainId: bigint, keypath: Keypath, msg: Uint8Array): Promise<EthSignature>;
9
+ export declare function ethSignTypedMessage(channel: EncryptedChannel, info: Info, chainId: bigint, keypath: Keypath, msgInput: unknown, useAntiklepto: boolean | undefined): Promise<EthSignature>;
10
+ //# sourceMappingURL=methods.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.d.ts","sourceRoot":"","sources":["../../../src/internal/eth/methods.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,cAAc,EACd,OAAO,EACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AA8GtD,wBAAsB,OAAO,CAC3B,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED,wBAAsB,UAAU,CAC9B,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,cAAc,EAClB,WAAW,EAAE,cAAc,GAAG,SAAS,GACtC,OAAO,CAAC,YAAY,CAAC,CA+BvB;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,kBAAkB,EACtB,WAAW,EAAE,cAAc,GAAG,SAAS,GACtC,OAAO,CAAC,YAAY,CAAC,CAkCvB;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,YAAY,CAAC,CAgBvB;AAED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,OAAO,GAAG,SAAS,GACjC,OAAO,CAAC,YAAY,CAAC,CAmDvB"}
@@ -0,0 +1,245 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { create } from '@bufbuild/protobuf';
3
+ import { AntiKleptoHostNonceCommitmentSchema, AntiKleptoSignatureRequestSchema, } from '../../proto/gen/antiklepto_pb.js';
4
+ import { ETHAddressCase as PbAddressCase, ETHPubRequestSchema, ETHPubRequest_OutputType, ETHSignEIP1559RequestSchema, ETHSignMessageRequestSchema, ETHSignRequestSchema, ETHSignTypedMessageRequestSchema, ETHTypedMessageValueRequestSchema, } from '../../proto/gen/eth_pb.js';
5
+ import { unexpectedResponse } from '../proto-query.js';
6
+ import { genHostNonce, hostCommit, verifyEcdsa } from './antiklepto.js';
7
+ import { buildStructTypes, DataType, getValue, parseEip712Message, parseType, TypedMessageError, } from './eip712.js';
8
+ import { parseKeypath } from '../keypath.js';
9
+ import { queryEth } from './query.js';
10
+ import { handleEthDataStreaming } from './streaming.js';
11
+ import { STREAMING_THRESHOLD } from './version.js';
12
+ import { requireVersion } from '../version.js';
13
+ import { chainIdTooLargeError, invalidTypeError } from '../errors.js';
14
+ import { bigUintToBytesBE, stripLeadingZeroes, UINT64_MAX, validateUint64, } from '../utils.js';
15
+ const ETH_TX_DETAIL = 'wrong type for EthTransaction';
16
+ const ETH_1559_TX_DETAIL = 'wrong type for Eth1559Transaction';
17
+ function validateSafeUint64Number(value, detail) {
18
+ if (!Number.isSafeInteger(value) || value < 0) {
19
+ throw invalidTypeError(detail);
20
+ }
21
+ return validateUint64(BigInt(value), detail);
22
+ }
23
+ function validateRecipient(recipient, detail) {
24
+ if (!(recipient instanceof Uint8Array) || recipient.length !== 20) {
25
+ throw invalidTypeError(detail);
26
+ }
27
+ }
28
+ function mapAddressCase(value) {
29
+ switch (value) {
30
+ case 'upper':
31
+ return PbAddressCase.ETH_ADDRESS_CASE_UPPER;
32
+ case 'lower':
33
+ return PbAddressCase.ETH_ADDRESS_CASE_LOWER;
34
+ case 'mixed':
35
+ case undefined:
36
+ return PbAddressCase.ETH_ADDRESS_CASE_MIXED;
37
+ default:
38
+ throw invalidTypeError('wrong type for EthAddressCase');
39
+ }
40
+ }
41
+ function makeHostNonceCommitment(hostNonce) {
42
+ return create(AntiKleptoHostNonceCommitmentSchema, {
43
+ commitment: hostCommit(hostNonce),
44
+ });
45
+ }
46
+ async function antikleptoFinish(channel, response, hostNonce) {
47
+ if (response.case !== 'antikleptoSignerCommitment') {
48
+ throw unexpectedResponse('expected antiklepto signer commitment');
49
+ }
50
+ const signerCommitment = response.value.commitment;
51
+ const sigResp = await queryEth(channel, {
52
+ case: 'antikleptoSignature',
53
+ value: create(AntiKleptoSignatureRequestSchema, { hostNonce }),
54
+ });
55
+ if (sigResp.case !== 'sign') {
56
+ throw unexpectedResponse('expected sign response after antiklepto');
57
+ }
58
+ const signature = sigResp.value.signature;
59
+ if (signature.length !== 65) {
60
+ throw unexpectedResponse('signature must be 65 bytes');
61
+ }
62
+ verifyEcdsa(hostNonce, signerCommitment, signature);
63
+ return signature;
64
+ }
65
+ function unwrapDirectSignature(response) {
66
+ if (response.case !== 'sign') {
67
+ throw unexpectedResponse('expected sign response');
68
+ }
69
+ if (response.value.signature.length !== 65) {
70
+ throw unexpectedResponse('signature must be 65 bytes');
71
+ }
72
+ return response.value.signature;
73
+ }
74
+ function shapeLegacyV(recid, chainId) {
75
+ const v = BigInt(recid) + 27n + chainId * 2n + 8n;
76
+ if (v > UINT64_MAX) {
77
+ throw chainIdTooLargeError(chainId);
78
+ }
79
+ return Array.from(bigUintToBytesBE(v));
80
+ }
81
+ function buildSignature(signature, v) {
82
+ return {
83
+ r: Array.from(signature.subarray(0, 32)),
84
+ s: Array.from(signature.subarray(32, 64)),
85
+ v,
86
+ };
87
+ }
88
+ export async function ethXpub(channel, keypath) {
89
+ const response = await queryEth(channel, {
90
+ case: 'pub',
91
+ value: create(ETHPubRequestSchema, {
92
+ keypath: parseKeypath(keypath),
93
+ coin: 0,
94
+ outputType: ETHPubRequest_OutputType.XPUB,
95
+ display: false,
96
+ contractAddress: new Uint8Array(),
97
+ chainId: 0n,
98
+ }),
99
+ });
100
+ if (response.case !== 'pub') {
101
+ throw unexpectedResponse();
102
+ }
103
+ return response.value.pub;
104
+ }
105
+ export async function ethAddress(channel, chainId, keypath, display) {
106
+ validateUint64(chainId, 'chainId');
107
+ const response = await queryEth(channel, {
108
+ case: 'pub',
109
+ value: create(ETHPubRequestSchema, {
110
+ keypath: parseKeypath(keypath),
111
+ coin: 0,
112
+ outputType: ETHPubRequest_OutputType.ADDRESS,
113
+ display,
114
+ contractAddress: new Uint8Array(),
115
+ chainId,
116
+ }),
117
+ });
118
+ if (response.case !== 'pub') {
119
+ throw unexpectedResponse();
120
+ }
121
+ return response.value.pub;
122
+ }
123
+ export async function ethSignTransaction(channel, info, chainId, keypath, tx, addressCase) {
124
+ requireVersion(info, { major: 9, minor: 10, patch: 0 });
125
+ const useStreaming = tx.data.length > STREAMING_THRESHOLD;
126
+ if (useStreaming) {
127
+ requireVersion(info, { major: 9, minor: 26, patch: 0 });
128
+ }
129
+ validateUint64(chainId, 'chainId');
130
+ validateRecipient(tx.recipient, ETH_TX_DETAIL);
131
+ const hostNonce = genHostNonce();
132
+ const req = create(ETHSignRequestSchema, {
133
+ coin: 0,
134
+ keypath: parseKeypath(keypath),
135
+ nonce: stripLeadingZeroes(tx.nonce),
136
+ gasPrice: stripLeadingZeroes(tx.gasPrice),
137
+ gasLimit: stripLeadingZeroes(tx.gasLimit),
138
+ recipient: tx.recipient,
139
+ value: stripLeadingZeroes(tx.value),
140
+ data: useStreaming ? new Uint8Array() : tx.data,
141
+ hostNonceCommitment: makeHostNonceCommitment(hostNonce),
142
+ chainId,
143
+ addressCase: mapAddressCase(addressCase),
144
+ dataLength: useStreaming ? tx.data.length : 0,
145
+ });
146
+ let response = await queryEth(channel, { case: 'sign', value: req });
147
+ if (useStreaming) {
148
+ response = await handleEthDataStreaming(channel, tx.data, response);
149
+ }
150
+ const signature = await antikleptoFinish(channel, response, hostNonce);
151
+ return buildSignature(signature, shapeLegacyV(signature[64], chainId));
152
+ }
153
+ export async function ethSign1559Transaction(channel, info, keypath, tx, addressCase) {
154
+ requireVersion(info, { major: 9, minor: 16, patch: 0 });
155
+ const useStreaming = tx.data.length > STREAMING_THRESHOLD;
156
+ if (useStreaming) {
157
+ requireVersion(info, { major: 9, minor: 26, patch: 0 });
158
+ }
159
+ const chainId = typeof tx.chainId === 'bigint'
160
+ ? validateUint64(tx.chainId, ETH_1559_TX_DETAIL)
161
+ : validateSafeUint64Number(tx.chainId, ETH_1559_TX_DETAIL);
162
+ validateRecipient(tx.recipient, ETH_1559_TX_DETAIL);
163
+ const hostNonce = genHostNonce();
164
+ const req = create(ETHSignEIP1559RequestSchema, {
165
+ chainId,
166
+ keypath: parseKeypath(keypath),
167
+ nonce: stripLeadingZeroes(tx.nonce),
168
+ maxPriorityFeePerGas: stripLeadingZeroes(tx.maxPriorityFeePerGas),
169
+ maxFeePerGas: stripLeadingZeroes(tx.maxFeePerGas),
170
+ gasLimit: stripLeadingZeroes(tx.gasLimit),
171
+ recipient: tx.recipient,
172
+ value: stripLeadingZeroes(tx.value),
173
+ data: useStreaming ? new Uint8Array() : tx.data,
174
+ hostNonceCommitment: makeHostNonceCommitment(hostNonce),
175
+ addressCase: mapAddressCase(addressCase),
176
+ dataLength: useStreaming ? tx.data.length : 0,
177
+ });
178
+ let response = await queryEth(channel, { case: 'signEip1559', value: req });
179
+ if (useStreaming) {
180
+ response = await handleEthDataStreaming(channel, tx.data, response);
181
+ }
182
+ const signature = await antikleptoFinish(channel, response, hostNonce);
183
+ return buildSignature(signature, [signature[64]]);
184
+ }
185
+ export async function ethSignMessage(channel, info, chainId, keypath, msg) {
186
+ requireVersion(info, { major: 9, minor: 10, patch: 0 });
187
+ validateUint64(chainId, 'chainId');
188
+ const hostNonce = genHostNonce();
189
+ const req = create(ETHSignMessageRequestSchema, {
190
+ coin: 0,
191
+ keypath: parseKeypath(keypath),
192
+ msg,
193
+ hostNonceCommitment: makeHostNonceCommitment(hostNonce),
194
+ chainId,
195
+ });
196
+ const response = await queryEth(channel, { case: 'signMsg', value: req });
197
+ const signature = await antikleptoFinish(channel, response, hostNonce);
198
+ return buildSignature(signature, [(signature[64] + 27) & 0xff]);
199
+ }
200
+ export async function ethSignTypedMessage(channel, info, chainId, keypath, msgInput, useAntiklepto) {
201
+ requireVersion(info, { major: 9, minor: 12, patch: 0 });
202
+ const enableAntiklepto = useAntiklepto ?? true;
203
+ if (!enableAntiklepto) {
204
+ requireVersion(info, { major: 9, minor: 26, patch: 0 });
205
+ }
206
+ validateUint64(chainId, 'chainId');
207
+ const msg = parseEip712Message(msgInput);
208
+ const types = buildStructTypes(msg.types);
209
+ // Validate primary type and EIP712Domain are parseable up front.
210
+ parseType(msg.primaryType, msg.types);
211
+ parseType('EIP712Domain', msg.types);
212
+ const hostNonce = enableAntiklepto ? genHostNonce() : undefined;
213
+ const initialReq = create(ETHSignTypedMessageRequestSchema, {
214
+ chainId,
215
+ keypath: parseKeypath(keypath),
216
+ types,
217
+ primaryType: msg.primaryType,
218
+ ...(hostNonce !== undefined
219
+ ? { hostNonceCommitment: makeHostNonceCommitment(hostNonce) }
220
+ : {}),
221
+ });
222
+ let response = await queryEth(channel, { case: 'signTypedMsg', value: initialReq });
223
+ while (response.case === 'typedMsgValue') {
224
+ const { value, dataType } = getValue(response.value, msg);
225
+ if (dataType === DataType.STRING && value.length > STREAMING_THRESHOLD) {
226
+ throw new TypedMessageError('string value exceeds maximum size');
227
+ }
228
+ const useStreaming = value.length > STREAMING_THRESHOLD;
229
+ response = await queryEth(channel, {
230
+ case: 'typedMsgValue',
231
+ value: create(ETHTypedMessageValueRequestSchema, {
232
+ value: useStreaming ? new Uint8Array() : value,
233
+ dataLength: useStreaming ? value.length : 0,
234
+ }),
235
+ });
236
+ if (useStreaming) {
237
+ response = await handleEthDataStreaming(channel, value, response);
238
+ }
239
+ }
240
+ const signature = enableAntiklepto && hostNonce !== undefined
241
+ ? await antikleptoFinish(channel, response, hostNonce)
242
+ : unwrapDirectSignature(response);
243
+ return buildSignature(signature, [(signature[64] + 27) & 0xff]);
244
+ }
245
+ //# sourceMappingURL=methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.js","sourceRoot":"","sources":["../../../src/internal/eth/methods.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,mCAAmC,EACnC,gCAAgC,GACjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,cAAc,IAAI,aAAa,EAC/B,mBAAmB,EACnB,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B,EAC3B,oBAAoB,EACpB,gCAAgC,EAChC,iCAAiC,GAElC,MAAM,2BAA2B,CAAC;AAUnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,kBAAkB,EAClB,SAAS,EACT,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,gB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AE,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type ETHRequest, type ETHResponse } from '../../proto/gen/eth_pb.js';
2
+ import type { EncryptedChannel } from '../pairing.js';
3
+ export declare function queryEth(channel: EncryptedChannel, ethRequest: ETHRequest['request']): Promise<ETHResponse['response']>;
4
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/internal/eth/query.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,2BAA2B,CAAC;AAKnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC,GAChC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAalC"}
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { create } from '@bufbuild/protobuf';
3
+ import { ETHRequestSchema, } from '../../proto/gen/eth_pb.js';
4
+ import { RequestSchema, } from '../../proto/gen/hww_pb.js';
5
+ import { query, unexpectedResponse } from '../proto-query.js';
6
+ export async function queryEth(channel, ethRequest) {
7
+ const ethReq = create(ETHRequestSchema, { request: ethRequest });
8
+ const wrapped = create(RequestSchema, {
9
+ request: { case: 'eth', value: ethReq },
10
+ });
11
+ const response = await query(channel, wrapped);
12
+ if (response.response.case !== 'eth') {
13
+ throw unexpectedResponse();
14
+ }
15
+ if (response.response.value.response.case === undefined) {
16
+ throw unexpectedResponse('BitBox returned an empty ETH response');
17
+ }
18
+ return response.response.value.response;
19
+ }
20
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/internal/eth/query.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,gBAAgB,GAGjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,aAAa,GAEd,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,OAAyB,EACzB,UAAiC;IAEjC,MAAM,MAAM,GAAG,MAAM,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IACjE,MAAM,OAAO,GAAY,MAAM,CAAC,aAAa,EAAE;QAC7C,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE;KACxC,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/C,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACrC,MAAM,kBAAkB,EAAE,CAAC;IAC7B,CAAC;IACD,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACxD,MAAM,kBAAkB,CAAC,uCAAuC,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type ETHResponse } from '../../proto/gen/eth_pb.js';
2
+ import type { EncryptedChannel } from '../pairing.js';
3
+ export declare function handleEthDataStreaming(channel: EncryptedChannel, data: Uint8Array, initialResponse: ETHResponse['response']): Promise<ETHResponse['response']>;
4
+ //# sourceMappingURL=streaming.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../src/internal/eth/streaming.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,UAAU,EAChB,eAAe,EAAE,WAAW,CAAC,UAAU,CAAC,GACvC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAelC"}