@buildonspark/spark-sdk 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/bare/index.cjs +547 -1238
- package/dist/bare/index.d.cts +676 -79
- package/dist/bare/index.d.ts +676 -79
- package/dist/bare/index.js +543 -1058
- package/dist/chunk-EHKP3Y65.js +140 -0
- package/dist/chunk-FJ7LTA2O.js +605 -0
- package/dist/chunk-LIZFXQWK.js +7 -0
- package/dist/{chunk-KIQTO4FX.js → chunk-XPHYQ2L6.js} +8128 -8727
- package/dist/{client-DWml6sjL.d.cts → client-AHn11NHe.d.cts} +1 -1
- package/dist/{client-DBZ43pJT.d.ts → client-GOlkXliC.d.ts} +1 -1
- package/dist/debug.cjs +581 -1222
- package/dist/debug.d.cts +8 -8
- package/dist/debug.d.ts +8 -8
- package/dist/debug.js +5 -3
- package/dist/graphql/objects/index.d.cts +3 -3
- package/dist/graphql/objects/index.d.ts +3 -3
- package/dist/index.cjs +531 -1231
- package/dist/index.d.cts +7 -18
- package/dist/index.d.ts +7 -18
- package/dist/index.js +5 -4
- package/dist/index.node.cjs +1200 -1441
- package/dist/index.node.d.cts +6 -7
- package/dist/index.node.d.ts +6 -7
- package/dist/index.node.js +7 -66
- package/dist/{logging-BUpzk4Z6.d.cts → logging-CW3kwBaM.d.cts} +3 -3
- package/dist/{logging-Dt2ooQiP.d.ts → logging-D7ukPwRA.d.ts} +3 -3
- package/dist/native/{chunk-D3SZRO65.js → chunk-X2QXUON7.js} +15 -0
- package/dist/native/index.cjs +702 -1214
- package/dist/native/index.d.cts +1077 -477
- package/dist/native/index.d.ts +1077 -477
- package/dist/native/index.js +700 -1042
- package/dist/native/{wasm-KT5NZXRN.js → wasm-GKEDPGTM.js} +1 -2
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/dist/proto/spark_token.d.cts +1 -1
- package/dist/proto/spark_token.d.ts +1 -1
- package/dist/{spark-DasxuVfm.d.cts → spark-WA_4wcBr.d.cts} +1 -1
- package/dist/{spark-DasxuVfm.d.ts → spark-WA_4wcBr.d.ts} +1 -1
- package/dist/{spark-wallet-jlC0XN5f.d.ts → spark-wallet-NxG55m7K.d.cts} +105 -74
- package/dist/{spark-wallet-BoMIOPWW.d.cts → spark-wallet-jwNvWvpK.d.ts} +105 -74
- package/dist/spark-wallet.browser-Cg4fB-Nm.d.ts +26 -0
- package/dist/spark-wallet.browser-Db7Y95Kt.d.cts +26 -0
- package/dist/spark-wallet.node-DB3ZqtJG.d.ts +90 -0
- package/dist/spark-wallet.node-HEG2ahNd.d.cts +90 -0
- package/dist/tests/test-utils.cjs +17560 -7615
- package/dist/tests/test-utils.d.cts +7 -21
- package/dist/tests/test-utils.d.ts +7 -21
- package/dist/tests/test-utils.js +30 -4
- package/dist/{token-transactions-DscJaJOE.d.ts → token-transactions-B2-BO7Oz.d.ts} +2 -2
- package/dist/{token-transactions-BDzCrQSk.d.cts → token-transactions-BAN68xwg.d.cts} +2 -2
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +7 -13
- package/src/bare/index.ts +1 -1
- package/src/debug.ts +1 -1
- package/src/index.node.ts +2 -1
- package/src/index.ts +2 -1
- package/src/native/index.ts +3 -2
- package/src/services/connection/connection.browser.ts +130 -0
- package/src/services/connection/connection.node.ts +158 -0
- package/src/services/{connection.ts → connection/connection.ts} +48 -259
- package/src/services/coop-exit.ts +3 -3
- package/src/services/deposit.ts +1 -1
- package/src/services/index.ts +1 -1
- package/src/services/lightning.ts +1 -1
- package/src/services/token-transactions.ts +1 -1
- package/src/services/transfer.ts +1 -1
- package/src/spark-wallet/spark-wallet.bare.ts +12 -0
- package/src/spark-wallet/spark-wallet.browser.ts +10 -24
- package/src/spark-wallet/spark-wallet.node.ts +4 -24
- package/src/spark-wallet/spark-wallet.react-native.ts +15 -0
- package/src/spark-wallet/spark-wallet.ts +87 -75
- package/src/spark-wallet/types.ts +4 -2
- package/src/tests/integration/coop-exit.test.ts +3 -3
- package/src/tests/integration/lightning.test.ts +4 -4
- package/src/tests/integration/ssp/coop-exit-validation.test.ts +3 -5
- package/src/tests/integration/ssp/coop-exit.test.ts +3 -5
- package/src/tests/integration/ssp/lightning.test.ts +1 -1
- package/src/tests/integration/ssp/static-deposit-validation.test.ts +2 -2
- package/src/tests/integration/ssp/static_deposit.test.ts +49 -66
- package/src/tests/integration/ssp/swap.test.ts +4 -5
- package/src/tests/integration/ssp/transfers.test.ts +10 -11
- package/src/tests/integration/static_deposit.test.ts +4 -4
- package/src/tests/integration/token-output.test.ts +2 -2
- package/src/tests/integration/transfer.test.ts +30 -26
- package/src/tests/integration/watchtower.test.ts +3 -3
- package/src/tests/spark-wallet/queryNodes.test.ts +1 -2
- package/src/tests/test-utils.ts +3 -3
- package/src/tests/token-outputs.test.ts +1 -1
- package/src/tests/utils/spark-testing-wallet.ts +18 -58
- package/src/tests/utils/utils.ts +63 -0
- package/src/tests/wrapWithOtelSpan.test.ts +7 -0
- package/src/utils/network.ts +11 -10
- package/dist/bare/xhr-transport-EEEC7FYA.js +0 -165
- package/dist/chunk-YH7MDVTT.js +0 -70
- package/dist/native/chunk-C3WN3D4O.js +0 -19
- package/dist/native/xhr-transport-TNCG4HTW.js +0 -168
- package/dist/spark-wallet.node-07PksUHH.d.cts +0 -12
- package/dist/spark-wallet.node-CdWkKMSq.d.ts +0 -12
- package/dist/xhr-transport-IWJPYF7F.js +0 -167
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConnectionManager,
|
|
3
|
+
NetworkError,
|
|
4
|
+
SparkWallet,
|
|
5
|
+
clientEnv
|
|
6
|
+
} from "./chunk-XPHYQ2L6.js";
|
|
7
|
+
import {
|
|
8
|
+
Empty
|
|
9
|
+
} from "./chunk-IC4IUEOS.js";
|
|
10
|
+
|
|
11
|
+
// src/services/connection/connection.node.ts
|
|
12
|
+
import {
|
|
13
|
+
createClient,
|
|
14
|
+
createChannel,
|
|
15
|
+
createClientFactory,
|
|
16
|
+
ChannelCredentials
|
|
17
|
+
} from "nice-grpc";
|
|
18
|
+
import { Metadata } from "nice-grpc-common";
|
|
19
|
+
|
|
20
|
+
// src/proto/mock.ts
|
|
21
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
22
|
+
function interruptTransferRequest_InterruptTransferActionFromJSON(object) {
|
|
23
|
+
switch (object) {
|
|
24
|
+
case 0:
|
|
25
|
+
case "NONE":
|
|
26
|
+
return 0 /* NONE */;
|
|
27
|
+
case 1:
|
|
28
|
+
case "INTERRUPT":
|
|
29
|
+
return 1 /* INTERRUPT */;
|
|
30
|
+
case 2:
|
|
31
|
+
case "RESUME":
|
|
32
|
+
return 2 /* RESUME */;
|
|
33
|
+
case -1:
|
|
34
|
+
case "UNRECOGNIZED":
|
|
35
|
+
default:
|
|
36
|
+
return -1 /* UNRECOGNIZED */;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function interruptTransferRequest_InterruptTransferActionToJSON(object) {
|
|
40
|
+
switch (object) {
|
|
41
|
+
case 0 /* NONE */:
|
|
42
|
+
return "NONE";
|
|
43
|
+
case 1 /* INTERRUPT */:
|
|
44
|
+
return "INTERRUPT";
|
|
45
|
+
case 2 /* RESUME */:
|
|
46
|
+
return "RESUME";
|
|
47
|
+
case -1 /* UNRECOGNIZED */:
|
|
48
|
+
default:
|
|
49
|
+
return "UNRECOGNIZED";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function interruptCoopExitRequest_InterruptCoopExitActionFromJSON(object) {
|
|
53
|
+
switch (object) {
|
|
54
|
+
case 0:
|
|
55
|
+
case "NONE":
|
|
56
|
+
return 0 /* NONE */;
|
|
57
|
+
case 1:
|
|
58
|
+
case "INTERRUPT":
|
|
59
|
+
return 1 /* INTERRUPT */;
|
|
60
|
+
case 2:
|
|
61
|
+
case "RESUME":
|
|
62
|
+
return 2 /* RESUME */;
|
|
63
|
+
case -1:
|
|
64
|
+
case "UNRECOGNIZED":
|
|
65
|
+
default:
|
|
66
|
+
return -1 /* UNRECOGNIZED */;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function interruptCoopExitRequest_InterruptCoopExitActionToJSON(object) {
|
|
70
|
+
switch (object) {
|
|
71
|
+
case 0 /* NONE */:
|
|
72
|
+
return "NONE";
|
|
73
|
+
case 1 /* INTERRUPT */:
|
|
74
|
+
return "INTERRUPT";
|
|
75
|
+
case 2 /* RESUME */:
|
|
76
|
+
return "RESUME";
|
|
77
|
+
case -1 /* UNRECOGNIZED */:
|
|
78
|
+
default:
|
|
79
|
+
return "UNRECOGNIZED";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function createBaseCleanUpPreimageShareRequest() {
|
|
83
|
+
return { paymentHash: new Uint8Array(0) };
|
|
84
|
+
}
|
|
85
|
+
var CleanUpPreimageShareRequest = {
|
|
86
|
+
encode(message, writer = new BinaryWriter()) {
|
|
87
|
+
if (message.paymentHash.length !== 0) {
|
|
88
|
+
writer.uint32(10).bytes(message.paymentHash);
|
|
89
|
+
}
|
|
90
|
+
return writer;
|
|
91
|
+
},
|
|
92
|
+
decode(input, length) {
|
|
93
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
94
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
95
|
+
const message = createBaseCleanUpPreimageShareRequest();
|
|
96
|
+
while (reader.pos < end) {
|
|
97
|
+
const tag = reader.uint32();
|
|
98
|
+
switch (tag >>> 3) {
|
|
99
|
+
case 1: {
|
|
100
|
+
if (tag !== 10) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
message.paymentHash = reader.bytes();
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
reader.skip(tag & 7);
|
|
111
|
+
}
|
|
112
|
+
return message;
|
|
113
|
+
},
|
|
114
|
+
fromJSON(object) {
|
|
115
|
+
return { paymentHash: isSet(object.paymentHash) ? bytesFromBase64(object.paymentHash) : new Uint8Array(0) };
|
|
116
|
+
},
|
|
117
|
+
toJSON(message) {
|
|
118
|
+
const obj = {};
|
|
119
|
+
if (message.paymentHash.length !== 0) {
|
|
120
|
+
obj.paymentHash = base64FromBytes(message.paymentHash);
|
|
121
|
+
}
|
|
122
|
+
return obj;
|
|
123
|
+
},
|
|
124
|
+
create(base) {
|
|
125
|
+
return CleanUpPreimageShareRequest.fromPartial(base ?? {});
|
|
126
|
+
},
|
|
127
|
+
fromPartial(object) {
|
|
128
|
+
const message = createBaseCleanUpPreimageShareRequest();
|
|
129
|
+
message.paymentHash = object.paymentHash ?? new Uint8Array(0);
|
|
130
|
+
return message;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
function createBaseInterruptTransferRequest() {
|
|
134
|
+
return { action: 0 };
|
|
135
|
+
}
|
|
136
|
+
var InterruptTransferRequest = {
|
|
137
|
+
encode(message, writer = new BinaryWriter()) {
|
|
138
|
+
if (message.action !== 0) {
|
|
139
|
+
writer.uint32(8).int32(message.action);
|
|
140
|
+
}
|
|
141
|
+
return writer;
|
|
142
|
+
},
|
|
143
|
+
decode(input, length) {
|
|
144
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
145
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
146
|
+
const message = createBaseInterruptTransferRequest();
|
|
147
|
+
while (reader.pos < end) {
|
|
148
|
+
const tag = reader.uint32();
|
|
149
|
+
switch (tag >>> 3) {
|
|
150
|
+
case 1: {
|
|
151
|
+
if (tag !== 8) {
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
message.action = reader.int32();
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
reader.skip(tag & 7);
|
|
162
|
+
}
|
|
163
|
+
return message;
|
|
164
|
+
},
|
|
165
|
+
fromJSON(object) {
|
|
166
|
+
return {
|
|
167
|
+
action: isSet(object.action) ? interruptTransferRequest_InterruptTransferActionFromJSON(object.action) : 0
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
toJSON(message) {
|
|
171
|
+
const obj = {};
|
|
172
|
+
if (message.action !== 0) {
|
|
173
|
+
obj.action = interruptTransferRequest_InterruptTransferActionToJSON(message.action);
|
|
174
|
+
}
|
|
175
|
+
return obj;
|
|
176
|
+
},
|
|
177
|
+
create(base) {
|
|
178
|
+
return InterruptTransferRequest.fromPartial(base ?? {});
|
|
179
|
+
},
|
|
180
|
+
fromPartial(object) {
|
|
181
|
+
const message = createBaseInterruptTransferRequest();
|
|
182
|
+
message.action = object.action ?? 0;
|
|
183
|
+
return message;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
function createBaseUpdateNodesStatusRequest() {
|
|
187
|
+
return { nodeIds: [], status: "" };
|
|
188
|
+
}
|
|
189
|
+
var UpdateNodesStatusRequest = {
|
|
190
|
+
encode(message, writer = new BinaryWriter()) {
|
|
191
|
+
for (const v of message.nodeIds) {
|
|
192
|
+
writer.uint32(10).string(v);
|
|
193
|
+
}
|
|
194
|
+
if (message.status !== "") {
|
|
195
|
+
writer.uint32(18).string(message.status);
|
|
196
|
+
}
|
|
197
|
+
return writer;
|
|
198
|
+
},
|
|
199
|
+
decode(input, length) {
|
|
200
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
201
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
202
|
+
const message = createBaseUpdateNodesStatusRequest();
|
|
203
|
+
while (reader.pos < end) {
|
|
204
|
+
const tag = reader.uint32();
|
|
205
|
+
switch (tag >>> 3) {
|
|
206
|
+
case 1: {
|
|
207
|
+
if (tag !== 10) {
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
message.nodeIds.push(reader.string());
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
case 2: {
|
|
214
|
+
if (tag !== 18) {
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
message.status = reader.string();
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
reader.skip(tag & 7);
|
|
225
|
+
}
|
|
226
|
+
return message;
|
|
227
|
+
},
|
|
228
|
+
fromJSON(object) {
|
|
229
|
+
return {
|
|
230
|
+
nodeIds: globalThis.Array.isArray(object?.nodeIds) ? object.nodeIds.map((e) => globalThis.String(e)) : [],
|
|
231
|
+
status: isSet(object.status) ? globalThis.String(object.status) : ""
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
toJSON(message) {
|
|
235
|
+
const obj = {};
|
|
236
|
+
if (message.nodeIds?.length) {
|
|
237
|
+
obj.nodeIds = message.nodeIds;
|
|
238
|
+
}
|
|
239
|
+
if (message.status !== "") {
|
|
240
|
+
obj.status = message.status;
|
|
241
|
+
}
|
|
242
|
+
return obj;
|
|
243
|
+
},
|
|
244
|
+
create(base) {
|
|
245
|
+
return UpdateNodesStatusRequest.fromPartial(base ?? {});
|
|
246
|
+
},
|
|
247
|
+
fromPartial(object) {
|
|
248
|
+
const message = createBaseUpdateNodesStatusRequest();
|
|
249
|
+
message.nodeIds = object.nodeIds?.map((e) => e) || [];
|
|
250
|
+
message.status = object.status ?? "";
|
|
251
|
+
return message;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
function createBaseTriggerTaskRequest() {
|
|
255
|
+
return { taskName: "" };
|
|
256
|
+
}
|
|
257
|
+
var TriggerTaskRequest = {
|
|
258
|
+
encode(message, writer = new BinaryWriter()) {
|
|
259
|
+
if (message.taskName !== "") {
|
|
260
|
+
writer.uint32(10).string(message.taskName);
|
|
261
|
+
}
|
|
262
|
+
return writer;
|
|
263
|
+
},
|
|
264
|
+
decode(input, length) {
|
|
265
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
266
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
267
|
+
const message = createBaseTriggerTaskRequest();
|
|
268
|
+
while (reader.pos < end) {
|
|
269
|
+
const tag = reader.uint32();
|
|
270
|
+
switch (tag >>> 3) {
|
|
271
|
+
case 1: {
|
|
272
|
+
if (tag !== 10) {
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
message.taskName = reader.string();
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
reader.skip(tag & 7);
|
|
283
|
+
}
|
|
284
|
+
return message;
|
|
285
|
+
},
|
|
286
|
+
fromJSON(object) {
|
|
287
|
+
return { taskName: isSet(object.taskName) ? globalThis.String(object.taskName) : "" };
|
|
288
|
+
},
|
|
289
|
+
toJSON(message) {
|
|
290
|
+
const obj = {};
|
|
291
|
+
if (message.taskName !== "") {
|
|
292
|
+
obj.taskName = message.taskName;
|
|
293
|
+
}
|
|
294
|
+
return obj;
|
|
295
|
+
},
|
|
296
|
+
create(base) {
|
|
297
|
+
return TriggerTaskRequest.fromPartial(base ?? {});
|
|
298
|
+
},
|
|
299
|
+
fromPartial(object) {
|
|
300
|
+
const message = createBaseTriggerTaskRequest();
|
|
301
|
+
message.taskName = object.taskName ?? "";
|
|
302
|
+
return message;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
function createBaseInterruptCoopExitRequest() {
|
|
306
|
+
return { action: 0, targetOperator: "" };
|
|
307
|
+
}
|
|
308
|
+
var InterruptCoopExitRequest = {
|
|
309
|
+
encode(message, writer = new BinaryWriter()) {
|
|
310
|
+
if (message.action !== 0) {
|
|
311
|
+
writer.uint32(8).int32(message.action);
|
|
312
|
+
}
|
|
313
|
+
if (message.targetOperator !== "") {
|
|
314
|
+
writer.uint32(18).string(message.targetOperator);
|
|
315
|
+
}
|
|
316
|
+
return writer;
|
|
317
|
+
},
|
|
318
|
+
decode(input, length) {
|
|
319
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
320
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
321
|
+
const message = createBaseInterruptCoopExitRequest();
|
|
322
|
+
while (reader.pos < end) {
|
|
323
|
+
const tag = reader.uint32();
|
|
324
|
+
switch (tag >>> 3) {
|
|
325
|
+
case 1: {
|
|
326
|
+
if (tag !== 8) {
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
message.action = reader.int32();
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
case 2: {
|
|
333
|
+
if (tag !== 18) {
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
message.targetOperator = reader.string();
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
reader.skip(tag & 7);
|
|
344
|
+
}
|
|
345
|
+
return message;
|
|
346
|
+
},
|
|
347
|
+
fromJSON(object) {
|
|
348
|
+
return {
|
|
349
|
+
action: isSet(object.action) ? interruptCoopExitRequest_InterruptCoopExitActionFromJSON(object.action) : 0,
|
|
350
|
+
targetOperator: isSet(object.targetOperator) ? globalThis.String(object.targetOperator) : ""
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
toJSON(message) {
|
|
354
|
+
const obj = {};
|
|
355
|
+
if (message.action !== 0) {
|
|
356
|
+
obj.action = interruptCoopExitRequest_InterruptCoopExitActionToJSON(message.action);
|
|
357
|
+
}
|
|
358
|
+
if (message.targetOperator !== "") {
|
|
359
|
+
obj.targetOperator = message.targetOperator;
|
|
360
|
+
}
|
|
361
|
+
return obj;
|
|
362
|
+
},
|
|
363
|
+
create(base) {
|
|
364
|
+
return InterruptCoopExitRequest.fromPartial(base ?? {});
|
|
365
|
+
},
|
|
366
|
+
fromPartial(object) {
|
|
367
|
+
const message = createBaseInterruptCoopExitRequest();
|
|
368
|
+
message.action = object.action ?? 0;
|
|
369
|
+
message.targetOperator = object.targetOperator ?? "";
|
|
370
|
+
return message;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
var MockServiceDefinition = {
|
|
374
|
+
name: "MockService",
|
|
375
|
+
fullName: "mock.MockService",
|
|
376
|
+
methods: {
|
|
377
|
+
clean_up_preimage_share: {
|
|
378
|
+
name: "clean_up_preimage_share",
|
|
379
|
+
requestType: CleanUpPreimageShareRequest,
|
|
380
|
+
requestStream: false,
|
|
381
|
+
responseType: Empty,
|
|
382
|
+
responseStream: false,
|
|
383
|
+
options: {}
|
|
384
|
+
},
|
|
385
|
+
interrupt_transfer: {
|
|
386
|
+
name: "interrupt_transfer",
|
|
387
|
+
requestType: InterruptTransferRequest,
|
|
388
|
+
requestStream: false,
|
|
389
|
+
responseType: Empty,
|
|
390
|
+
responseStream: false,
|
|
391
|
+
options: {}
|
|
392
|
+
},
|
|
393
|
+
interrupt_coop_exit: {
|
|
394
|
+
name: "interrupt_coop_exit",
|
|
395
|
+
requestType: InterruptCoopExitRequest,
|
|
396
|
+
requestStream: false,
|
|
397
|
+
responseType: Empty,
|
|
398
|
+
responseStream: false,
|
|
399
|
+
options: {}
|
|
400
|
+
},
|
|
401
|
+
update_nodes_status: {
|
|
402
|
+
name: "update_nodes_status",
|
|
403
|
+
requestType: UpdateNodesStatusRequest,
|
|
404
|
+
requestStream: false,
|
|
405
|
+
responseType: Empty,
|
|
406
|
+
responseStream: false,
|
|
407
|
+
options: {}
|
|
408
|
+
},
|
|
409
|
+
/** Triggers the execution of a scheduled task immediately by name. Used by hermetic tests */
|
|
410
|
+
trigger_task: {
|
|
411
|
+
name: "trigger_task",
|
|
412
|
+
requestType: TriggerTaskRequest,
|
|
413
|
+
requestStream: false,
|
|
414
|
+
responseType: Empty,
|
|
415
|
+
responseStream: false,
|
|
416
|
+
options: {}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
function bytesFromBase64(b64) {
|
|
421
|
+
if (globalThis.Buffer) {
|
|
422
|
+
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
|
|
423
|
+
} else {
|
|
424
|
+
const bin = globalThis.atob(b64);
|
|
425
|
+
const arr = new Uint8Array(bin.length);
|
|
426
|
+
for (let i = 0; i < bin.length; ++i) {
|
|
427
|
+
arr[i] = bin.charCodeAt(i);
|
|
428
|
+
}
|
|
429
|
+
return arr;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function base64FromBytes(arr) {
|
|
433
|
+
if (globalThis.Buffer) {
|
|
434
|
+
return globalThis.Buffer.from(arr).toString("base64");
|
|
435
|
+
} else {
|
|
436
|
+
const bin = [];
|
|
437
|
+
arr.forEach((byte) => {
|
|
438
|
+
bin.push(globalThis.String.fromCharCode(byte));
|
|
439
|
+
});
|
|
440
|
+
return globalThis.btoa(bin.join(""));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function isSet(value) {
|
|
444
|
+
return value !== null && value !== void 0;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// src/services/connection/connection.node.ts
|
|
448
|
+
import { openTelemetryClientMiddleware } from "nice-grpc-opentelemetry";
|
|
449
|
+
import { retryMiddleware } from "nice-grpc-client-middleware-retry";
|
|
450
|
+
import fs from "fs";
|
|
451
|
+
var ConnectionManagerNodeJS = class extends ConnectionManager {
|
|
452
|
+
constructor(config) {
|
|
453
|
+
super(config);
|
|
454
|
+
}
|
|
455
|
+
async createMockClient(address) {
|
|
456
|
+
const channel = await this.createChannelWithTLS(address);
|
|
457
|
+
const client = createClient(MockServiceDefinition, channel);
|
|
458
|
+
return { ...client, close: () => channel.close() };
|
|
459
|
+
}
|
|
460
|
+
async createChannelWithTLS(address, certPath) {
|
|
461
|
+
try {
|
|
462
|
+
if (certPath) {
|
|
463
|
+
try {
|
|
464
|
+
const cert = fs.readFileSync(certPath);
|
|
465
|
+
return createChannel(address, ChannelCredentials.createSsl(cert));
|
|
466
|
+
} catch (error) {
|
|
467
|
+
console.error("Error reading certificate:", error);
|
|
468
|
+
return createChannel(
|
|
469
|
+
address,
|
|
470
|
+
ChannelCredentials.createSsl(null, null, null, {
|
|
471
|
+
rejectUnauthorized: false
|
|
472
|
+
})
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
} else {
|
|
476
|
+
return createChannel(
|
|
477
|
+
address,
|
|
478
|
+
ChannelCredentials.createSsl(null, null, null, {
|
|
479
|
+
rejectUnauthorized: false
|
|
480
|
+
})
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
} catch (error) {
|
|
484
|
+
console.error("Channel creation error:", error);
|
|
485
|
+
throw new NetworkError(
|
|
486
|
+
"Failed to create channel",
|
|
487
|
+
{
|
|
488
|
+
url: address,
|
|
489
|
+
operation: "createChannel",
|
|
490
|
+
errorCount: 1,
|
|
491
|
+
errors: error instanceof Error ? error.message : String(error)
|
|
492
|
+
},
|
|
493
|
+
error
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
createAuthnMiddleware() {
|
|
498
|
+
return async function* (call, options) {
|
|
499
|
+
const metadata = Metadata(options.metadata).set(
|
|
500
|
+
"X-Client-Env",
|
|
501
|
+
clientEnv
|
|
502
|
+
);
|
|
503
|
+
return yield* call.next(call.request, {
|
|
504
|
+
...options,
|
|
505
|
+
metadata
|
|
506
|
+
});
|
|
507
|
+
}.bind(this);
|
|
508
|
+
}
|
|
509
|
+
createMiddleware(address, initialAuthToken) {
|
|
510
|
+
return async function* (call, options) {
|
|
511
|
+
const metadata = Metadata(options.metadata).set(
|
|
512
|
+
"X-Client-Env",
|
|
513
|
+
clientEnv
|
|
514
|
+
);
|
|
515
|
+
try {
|
|
516
|
+
return yield* call.next(call.request, {
|
|
517
|
+
...options,
|
|
518
|
+
metadata: metadata.set(
|
|
519
|
+
"Authorization",
|
|
520
|
+
`Bearer ${this.clients.get(address)?.authToken || initialAuthToken}`
|
|
521
|
+
)
|
|
522
|
+
});
|
|
523
|
+
} catch (error) {
|
|
524
|
+
return yield* this.handleMiddlewareError(
|
|
525
|
+
error,
|
|
526
|
+
address,
|
|
527
|
+
call,
|
|
528
|
+
metadata,
|
|
529
|
+
options
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
}.bind(this);
|
|
533
|
+
}
|
|
534
|
+
async createGrpcClient(defintion, channel, withRetries, middleware) {
|
|
535
|
+
const retryOptions = {
|
|
536
|
+
retry: true,
|
|
537
|
+
retryMaxAttempts: 3
|
|
538
|
+
};
|
|
539
|
+
let options = {};
|
|
540
|
+
let clientFactory = createClientFactory();
|
|
541
|
+
if (withRetries) {
|
|
542
|
+
options = retryOptions;
|
|
543
|
+
clientFactory = clientFactory.use(openTelemetryClientMiddleware()).use(retryMiddleware);
|
|
544
|
+
}
|
|
545
|
+
if (middleware) {
|
|
546
|
+
clientFactory = clientFactory.use(middleware);
|
|
547
|
+
}
|
|
548
|
+
const client = clientFactory.create(defintion, channel, {
|
|
549
|
+
"*": options
|
|
550
|
+
});
|
|
551
|
+
return {
|
|
552
|
+
...client,
|
|
553
|
+
close: channel.close.bind(channel)
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// src/spark-wallet/spark-wallet.node.ts
|
|
559
|
+
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
560
|
+
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
|
|
561
|
+
import { W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
562
|
+
import { registerInstrumentations } from "@opentelemetry/instrumentation";
|
|
563
|
+
import { UndiciInstrumentation } from "@opentelemetry/instrumentation-undici";
|
|
564
|
+
var SparkWalletNodeJS = class extends SparkWallet {
|
|
565
|
+
buildConnectionManager(config) {
|
|
566
|
+
return new ConnectionManagerNodeJS(config);
|
|
567
|
+
}
|
|
568
|
+
initializeTracerEnv({
|
|
569
|
+
spanProcessors,
|
|
570
|
+
traceUrls
|
|
571
|
+
}) {
|
|
572
|
+
initializeTracerEnvNodeJS({ spanProcessors, traceUrls });
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
function initializeTracerEnvNodeJS({
|
|
576
|
+
spanProcessors,
|
|
577
|
+
traceUrls
|
|
578
|
+
}) {
|
|
579
|
+
const provider = new NodeTracerProvider({ spanProcessors });
|
|
580
|
+
provider.register({
|
|
581
|
+
contextManager: new AsyncLocalStorageContextManager(),
|
|
582
|
+
propagator: new W3CTraceContextPropagator()
|
|
583
|
+
});
|
|
584
|
+
registerInstrumentations({
|
|
585
|
+
instrumentations: [
|
|
586
|
+
new UndiciInstrumentation({
|
|
587
|
+
ignoreRequestHook: (request) => {
|
|
588
|
+
try {
|
|
589
|
+
return !traceUrls.some(
|
|
590
|
+
(prefix) => request.origin.startsWith(prefix)
|
|
591
|
+
);
|
|
592
|
+
} catch {
|
|
593
|
+
return true;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
})
|
|
597
|
+
]
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
export {
|
|
602
|
+
ConnectionManagerNodeJS,
|
|
603
|
+
SparkWalletNodeJS,
|
|
604
|
+
initializeTracerEnvNodeJS
|
|
605
|
+
};
|