@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,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConnectionManager,
|
|
3
|
+
NetworkError,
|
|
4
|
+
SparkWallet,
|
|
5
|
+
clientEnv
|
|
6
|
+
} from "./chunk-XPHYQ2L6.js";
|
|
7
|
+
|
|
8
|
+
// src/services/connection/connection.browser.ts
|
|
9
|
+
import {
|
|
10
|
+
createChannel,
|
|
11
|
+
FetchTransport,
|
|
12
|
+
createClientFactory
|
|
13
|
+
} from "nice-grpc-web";
|
|
14
|
+
import { Metadata } from "nice-grpc-common";
|
|
15
|
+
import { retryMiddleware } from "nice-grpc-client-middleware-retry";
|
|
16
|
+
var ConnectionManagerBrowser = class extends ConnectionManager {
|
|
17
|
+
transport;
|
|
18
|
+
constructor(config, transport = FetchTransport()) {
|
|
19
|
+
super(config);
|
|
20
|
+
this.transport = transport;
|
|
21
|
+
}
|
|
22
|
+
async createChannelWithTLS(address, certPath) {
|
|
23
|
+
try {
|
|
24
|
+
return createChannel(address, this.transport);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error("Channel creation error:", error);
|
|
27
|
+
throw new NetworkError(
|
|
28
|
+
"Failed to create channel",
|
|
29
|
+
{
|
|
30
|
+
url: address,
|
|
31
|
+
operation: "createChannel",
|
|
32
|
+
errorCount: 1,
|
|
33
|
+
errors: error instanceof Error ? error.message : String(error)
|
|
34
|
+
},
|
|
35
|
+
error
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
createAuthnMiddleware() {
|
|
40
|
+
return async function* (call, options) {
|
|
41
|
+
const metadata = Metadata(options.metadata).set("X-Requested-With", "XMLHttpRequest").set("X-Grpc-Web", "1").set("X-Client-Env", clientEnv).set("Content-Type", "application/grpc-web+proto");
|
|
42
|
+
return yield* call.next(call.request, {
|
|
43
|
+
...options,
|
|
44
|
+
metadata
|
|
45
|
+
});
|
|
46
|
+
}.bind(this);
|
|
47
|
+
}
|
|
48
|
+
createMiddleware(address, initialAuthToken) {
|
|
49
|
+
return async function* (call, options) {
|
|
50
|
+
const metadata = Metadata(options.metadata).set("X-Requested-With", "XMLHttpRequest").set("X-Grpc-Web", "1").set("X-Client-Env", clientEnv).set("Content-Type", "application/grpc-web+proto");
|
|
51
|
+
try {
|
|
52
|
+
return yield* call.next(call.request, {
|
|
53
|
+
...options,
|
|
54
|
+
metadata: metadata.set(
|
|
55
|
+
"Authorization",
|
|
56
|
+
`Bearer ${this.clients.get(address)?.authToken || initialAuthToken}`
|
|
57
|
+
)
|
|
58
|
+
});
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return yield* this.handleMiddlewareError(
|
|
61
|
+
error,
|
|
62
|
+
address,
|
|
63
|
+
call,
|
|
64
|
+
metadata,
|
|
65
|
+
options
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}.bind(this);
|
|
69
|
+
}
|
|
70
|
+
async createGrpcClient(defintion, channel, withRetries, middleware) {
|
|
71
|
+
let clientFactory;
|
|
72
|
+
const retryOptions = {
|
|
73
|
+
retry: true,
|
|
74
|
+
retryMaxAttempts: 3
|
|
75
|
+
};
|
|
76
|
+
let options = {};
|
|
77
|
+
clientFactory = createClientFactory();
|
|
78
|
+
if (withRetries) {
|
|
79
|
+
options = retryOptions;
|
|
80
|
+
clientFactory = clientFactory.use(retryMiddleware);
|
|
81
|
+
}
|
|
82
|
+
if (middleware) {
|
|
83
|
+
clientFactory = clientFactory.use(middleware);
|
|
84
|
+
}
|
|
85
|
+
const client = clientFactory.create(defintion, channel, {
|
|
86
|
+
"*": options
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
...client,
|
|
90
|
+
close: void 0
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/spark-wallet/spark-wallet.browser.ts
|
|
96
|
+
import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
|
|
97
|
+
import { registerInstrumentations } from "@opentelemetry/instrumentation";
|
|
98
|
+
import { FetchInstrumentation } from "@opentelemetry/instrumentation-fetch";
|
|
99
|
+
import { W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
100
|
+
import { propagation } from "@opentelemetry/api";
|
|
101
|
+
var SparkWalletBrowser = class extends SparkWallet {
|
|
102
|
+
buildConnectionManager(config) {
|
|
103
|
+
return new ConnectionManagerBrowser(config);
|
|
104
|
+
}
|
|
105
|
+
initializeTracerEnv({
|
|
106
|
+
spanProcessors,
|
|
107
|
+
traceUrls
|
|
108
|
+
}) {
|
|
109
|
+
console.log("initializeTracerEnvBrowser");
|
|
110
|
+
initializeTracerEnvBrowser({ spanProcessors, traceUrls });
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
function initializeTracerEnvBrowser({
|
|
114
|
+
spanProcessors,
|
|
115
|
+
traceUrls
|
|
116
|
+
}) {
|
|
117
|
+
const provider = new WebTracerProvider({ spanProcessors });
|
|
118
|
+
provider.register();
|
|
119
|
+
propagation.setGlobalPropagator(new W3CTraceContextPropagator());
|
|
120
|
+
registerInstrumentations({
|
|
121
|
+
instrumentations: [
|
|
122
|
+
new FetchInstrumentation({
|
|
123
|
+
ignoreUrls: [
|
|
124
|
+
/* Since we're wrapping global fetch we should be careful to avoid
|
|
125
|
+
adding headers for unrelated requests */
|
|
126
|
+
new RegExp(
|
|
127
|
+
`^(?!(${traceUrls.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")}))`
|
|
128
|
+
)
|
|
129
|
+
],
|
|
130
|
+
propagateTraceHeaderCorsUrls: /.*/
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export {
|
|
137
|
+
ConnectionManagerBrowser,
|
|
138
|
+
SparkWalletBrowser,
|
|
139
|
+
initializeTracerEnvBrowser
|
|
140
|
+
};
|