@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
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Q as QueryTransfersResponse, T as Transfer,
|
|
2
|
-
import { b as ConfigOptions
|
|
3
|
-
import { S as SparkSigner, D as DefaultSparkSigner } from '../client-
|
|
4
|
-
import { S as SparkWalletNodeJS } from '../spark-wallet.node-
|
|
1
|
+
import { Q as QueryTransfersResponse, T as Transfer, c as TreeNode } from '../spark-WA_4wcBr.cjs';
|
|
2
|
+
import { b as ConfigOptions } from '../spark-wallet-NxG55m7K.cjs';
|
|
3
|
+
import { S as SparkSigner, D as DefaultSparkSigner } from '../client-AHn11NHe.cjs';
|
|
4
|
+
import { S as SparkWalletNodeJS } from '../spark-wallet.node-HEG2ahNd.cjs';
|
|
5
5
|
import { Transaction } from '@scure/btc-signer';
|
|
6
6
|
import { TransactionInput, TransactionOutput } from '@scure/btc-signer/psbt';
|
|
7
7
|
import '@bufbuild/protobuf/wire';
|
|
8
8
|
import 'nice-grpc-common';
|
|
9
9
|
import '../proto/spark_token.cjs';
|
|
10
|
-
import 'bitcoinjs-lib';
|
|
11
10
|
import 'nice-grpc';
|
|
12
11
|
import 'nice-grpc-web';
|
|
13
12
|
import '@scure/base';
|
|
@@ -47,22 +46,9 @@ declare class BitcoinFaucet {
|
|
|
47
46
|
getRawTransaction(txid: string): Promise<any>;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
getSigner(): SparkSigner;
|
|
52
|
-
queryPendingTransfers(): Promise<QueryTransfersResponse>;
|
|
53
|
-
verifyPendingTransfer(transfer: Transfer): Promise<Map<string, Uint8Array>>;
|
|
54
|
-
}
|
|
55
|
-
declare class SparkWalletTesting extends SparkWalletNodeJS implements ISparkWalletTesting {
|
|
56
|
-
private disableEvents;
|
|
57
|
-
constructor(options?: ConfigOptions, signer?: SparkSigner, disableEvents?: boolean);
|
|
58
|
-
static initialize(props: SparkWalletProps, disableEvents?: boolean): Promise<{
|
|
59
|
-
wallet: SparkWalletTesting;
|
|
60
|
-
mnemonic?: undefined;
|
|
61
|
-
} | {
|
|
62
|
-
wallet: SparkWalletTesting;
|
|
63
|
-
mnemonic: string | undefined;
|
|
64
|
-
}>;
|
|
49
|
+
declare class SparkWalletTesting extends SparkWalletNodeJS {
|
|
65
50
|
protected setupBackgroundStream(): Promise<void>;
|
|
51
|
+
protected proxyParentSetupBackgroundStream(): Promise<void>;
|
|
66
52
|
getSigner(): SparkSigner;
|
|
67
53
|
queryPendingTransfers(): Promise<QueryTransfersResponse>;
|
|
68
54
|
verifyPendingTransfer(transfer: Transfer): Promise<Map<string, Uint8Array>>;
|
|
@@ -87,4 +73,4 @@ declare function createDeterministicKeys(seed: string): {
|
|
|
87
73
|
publicKey: Uint8Array<ArrayBufferLike>;
|
|
88
74
|
};
|
|
89
75
|
|
|
90
|
-
export { BitcoinFaucet, createDeterministicKeys, createNewTree, createNewTreeWithoutDirectTx, getTestWalletConfig, getTestWalletConfigWithIdentityKey, signerTypes, walletTypes };
|
|
76
|
+
export { BitcoinFaucet, SparkWalletTesting, createDeterministicKeys, createNewTree, createNewTreeWithoutDirectTx, getTestWalletConfig, getTestWalletConfigWithIdentityKey, signerTypes, walletTypes };
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Q as QueryTransfersResponse, T as Transfer,
|
|
2
|
-
import { b as ConfigOptions
|
|
3
|
-
import { S as SparkSigner, D as DefaultSparkSigner } from '../client-
|
|
4
|
-
import { S as SparkWalletNodeJS } from '../spark-wallet.node-
|
|
1
|
+
import { Q as QueryTransfersResponse, T as Transfer, c as TreeNode } from '../spark-WA_4wcBr.js';
|
|
2
|
+
import { b as ConfigOptions } from '../spark-wallet-jwNvWvpK.js';
|
|
3
|
+
import { S as SparkSigner, D as DefaultSparkSigner } from '../client-GOlkXliC.js';
|
|
4
|
+
import { S as SparkWalletNodeJS } from '../spark-wallet.node-DB3ZqtJG.js';
|
|
5
5
|
import { Transaction } from '@scure/btc-signer';
|
|
6
6
|
import { TransactionInput, TransactionOutput } from '@scure/btc-signer/psbt';
|
|
7
7
|
import '@bufbuild/protobuf/wire';
|
|
8
8
|
import 'nice-grpc-common';
|
|
9
9
|
import '../proto/spark_token.js';
|
|
10
|
-
import 'bitcoinjs-lib';
|
|
11
10
|
import 'nice-grpc';
|
|
12
11
|
import 'nice-grpc-web';
|
|
13
12
|
import '@scure/base';
|
|
@@ -47,22 +46,9 @@ declare class BitcoinFaucet {
|
|
|
47
46
|
getRawTransaction(txid: string): Promise<any>;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
getSigner(): SparkSigner;
|
|
52
|
-
queryPendingTransfers(): Promise<QueryTransfersResponse>;
|
|
53
|
-
verifyPendingTransfer(transfer: Transfer): Promise<Map<string, Uint8Array>>;
|
|
54
|
-
}
|
|
55
|
-
declare class SparkWalletTesting extends SparkWalletNodeJS implements ISparkWalletTesting {
|
|
56
|
-
private disableEvents;
|
|
57
|
-
constructor(options?: ConfigOptions, signer?: SparkSigner, disableEvents?: boolean);
|
|
58
|
-
static initialize(props: SparkWalletProps, disableEvents?: boolean): Promise<{
|
|
59
|
-
wallet: SparkWalletTesting;
|
|
60
|
-
mnemonic?: undefined;
|
|
61
|
-
} | {
|
|
62
|
-
wallet: SparkWalletTesting;
|
|
63
|
-
mnemonic: string | undefined;
|
|
64
|
-
}>;
|
|
49
|
+
declare class SparkWalletTesting extends SparkWalletNodeJS {
|
|
65
50
|
protected setupBackgroundStream(): Promise<void>;
|
|
51
|
+
protected proxyParentSetupBackgroundStream(): Promise<void>;
|
|
66
52
|
getSigner(): SparkSigner;
|
|
67
53
|
queryPendingTransfers(): Promise<QueryTransfersResponse>;
|
|
68
54
|
verifyPendingTransfer(transfer: Transfer): Promise<Map<string, Uint8Array>>;
|
|
@@ -87,4 +73,4 @@ declare function createDeterministicKeys(seed: string): {
|
|
|
87
73
|
publicKey: Uint8Array<ArrayBufferLike>;
|
|
88
74
|
};
|
|
89
75
|
|
|
90
|
-
export { BitcoinFaucet, createDeterministicKeys, createNewTree, createNewTreeWithoutDirectTx, getTestWalletConfig, getTestWalletConfigWithIdentityKey, signerTypes, walletTypes };
|
|
76
|
+
export { BitcoinFaucet, SparkWalletTesting, createDeterministicKeys, createNewTree, createNewTreeWithoutDirectTx, getTestWalletConfig, getTestWalletConfigWithIdentityKey, signerTypes, walletTypes };
|
package/dist/tests/test-utils.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
ConnectionManagerNodeJS,
|
|
3
|
+
SparkWalletNodeJS
|
|
4
|
+
} from "../chunk-FJ7LTA2O.js";
|
|
5
|
+
import "../chunk-LIZFXQWK.js";
|
|
6
|
+
import "../chunk-EHKP3Y65.js";
|
|
2
7
|
import {
|
|
3
8
|
BitcoinFaucet,
|
|
4
|
-
ConnectionManager,
|
|
5
9
|
DefaultSparkSigner,
|
|
6
10
|
DepositService,
|
|
7
11
|
RPCError,
|
|
@@ -10,7 +14,7 @@ import {
|
|
|
10
14
|
WalletConfigService,
|
|
11
15
|
getNetwork,
|
|
12
16
|
getP2TRAddressFromPublicKey
|
|
13
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-XPHYQ2L6.js";
|
|
14
18
|
import "../chunk-NX5KPN5F.js";
|
|
15
19
|
import "../chunk-XWLR6G5C.js";
|
|
16
20
|
import "../chunk-J2P3KTQP.js";
|
|
@@ -21,6 +25,27 @@ import "../chunk-MVRQ5US7.js";
|
|
|
21
25
|
// src/tests/test-utils.ts
|
|
22
26
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
23
27
|
import { Address, OutScript, Transaction } from "@scure/btc-signer";
|
|
28
|
+
|
|
29
|
+
// src/tests/utils/spark-testing-wallet.ts
|
|
30
|
+
var SparkWalletTesting = class extends SparkWalletNodeJS {
|
|
31
|
+
async setupBackgroundStream() {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
async proxyParentSetupBackgroundStream() {
|
|
35
|
+
return super.setupBackgroundStream();
|
|
36
|
+
}
|
|
37
|
+
getSigner() {
|
|
38
|
+
return this.config.signer;
|
|
39
|
+
}
|
|
40
|
+
async queryPendingTransfers() {
|
|
41
|
+
return await this.transferService.queryPendingTransfers();
|
|
42
|
+
}
|
|
43
|
+
async verifyPendingTransfer(transfer) {
|
|
44
|
+
return await this.transferService.verifyPendingTransfer(transfer);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/tests/test-utils.ts
|
|
24
49
|
import { sha256 } from "@noble/hashes/sha2";
|
|
25
50
|
function getTestWalletConfig() {
|
|
26
51
|
const identityPrivateKey = secp256k1.utils.randomPrivateKey();
|
|
@@ -40,7 +65,7 @@ async function createDeposit(wallet, leafId, faucet, amountSats = 100000n, inclu
|
|
|
40
65
|
},
|
|
41
66
|
wallet.getSigner()
|
|
42
67
|
);
|
|
43
|
-
const connectionManager = new
|
|
68
|
+
const connectionManager = new ConnectionManagerNodeJS(configService);
|
|
44
69
|
const depositService = new DepositService(configService, connectionManager);
|
|
45
70
|
const pubKey = await wallet.getSigner().getPublicKeyFromDerivation({
|
|
46
71
|
type: "leaf" /* LEAF */,
|
|
@@ -134,6 +159,7 @@ function createDeterministicKeys(seed) {
|
|
|
134
159
|
}
|
|
135
160
|
export {
|
|
136
161
|
BitcoinFaucet,
|
|
162
|
+
SparkWalletTesting,
|
|
137
163
|
createDeterministicKeys,
|
|
138
164
|
createNewTree,
|
|
139
165
|
createNewTreeWithoutDirectTx,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { O as OutputWithPreviousTransactionData } from './spark-
|
|
1
|
+
import { O as OutputWithPreviousTransactionData } from './spark-WA_4wcBr.js';
|
|
2
2
|
import { TokenTransaction, QueryTokenTransactionsResponse } from './proto/spark_token.js';
|
|
3
|
-
import { W as WalletConfigService, C as ConnectionManager,
|
|
3
|
+
import { W as WalletConfigService, C as ConnectionManager, O as TokenOutputsMap, B as Bech32mTokenIdentifier, S as SparkAddressFormat } from './spark-wallet-jwNvWvpK.js';
|
|
4
4
|
|
|
5
5
|
declare class SparkSDKError extends Error {
|
|
6
6
|
readonly context: Record<string, unknown>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { O as OutputWithPreviousTransactionData } from './spark-
|
|
1
|
+
import { O as OutputWithPreviousTransactionData } from './spark-WA_4wcBr.cjs';
|
|
2
2
|
import { TokenTransaction, QueryTokenTransactionsResponse } from './proto/spark_token.cjs';
|
|
3
|
-
import { W as WalletConfigService, C as ConnectionManager,
|
|
3
|
+
import { W as WalletConfigService, C as ConnectionManager, O as TokenOutputsMap, B as Bech32mTokenIdentifier, S as SparkAddressFormat } from './spark-wallet-NxG55m7K.cjs';
|
|
4
4
|
|
|
5
5
|
declare class SparkSDKError extends Error {
|
|
6
6
|
readonly context: Record<string, unknown>;
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { B as BitcoinNetwork, O as ClaimStaticDeposit, C as ClaimStaticDepositOutput, Q as ClaimStaticDepositStatus, R as CompleteCoopExitInput, X as CompleteLeavesSwapInput, Y as CoopExitFeeEstimate, Z as CoopExitFeeEstimatesInput, _ as CoopExitFeeEstimatesOutput, F as CoopExitFeeQuote, a0 as CoopExitFeeQuoteInput, G as CoopExitRequest, a2 as CurrencyAmount, a3 as CurrencyUnit, E as ExitSpeed, a4 as GetChallengeOutput, a5 as Invoice, a6 as Leaf, L as LeavesSwapFeeEstimateOutput, a8 as LeavesSwapRequest, x as LightningReceiveRequest, aa as LightningReceiveRequestStatus, z as LightningSendFeeEstimateInput, ab as LightningSendFeeEstimateOutput, y as LightningSendRequest, ad as LightningSendRequestStatus, P as PageInfo, ae as RequestCoopExitInput, af as RequestLeavesSwapInput, ag as RequestLightningReceiveInput, ah as RequestLightningSendInput, ai as SparkCoopExitRequestStatus, aj as SparkLeavesSwapRequestStatus, ak as SparkTransferToLeavesConnection, al as StaticDepositQuoteInput, u as StaticDepositQuoteOutput, am as SwapLeaf, an as Transfer, ar as TransferDirection, ao as UserLeafInput, as as UserRequestType, ap as VerifyChallengeOutput, w as WalletLeaf, W as WalletTransfer, at as WalletTransferLeaf, N as getClaimStaticDepositQuery, $ as getCoopExitFeeQuoteQuery, a1 as getCoopExitRequestQuery, a7 as getLeavesSwapRequestQuery, a9 as getLightningReceiveRequestQuery, ac as getLightningSendRequestQuery, au as mapTransferLeafToWalletTransferLeaf, av as mapTransferToWalletTransfer, aq as mapTreeNodeToWalletLeaf } from '../client-
|
|
1
|
+
export { B as BitcoinNetwork, O as ClaimStaticDeposit, C as ClaimStaticDepositOutput, Q as ClaimStaticDepositStatus, R as CompleteCoopExitInput, X as CompleteLeavesSwapInput, Y as CoopExitFeeEstimate, Z as CoopExitFeeEstimatesInput, _ as CoopExitFeeEstimatesOutput, F as CoopExitFeeQuote, a0 as CoopExitFeeQuoteInput, G as CoopExitRequest, a2 as CurrencyAmount, a3 as CurrencyUnit, E as ExitSpeed, a4 as GetChallengeOutput, a5 as Invoice, a6 as Leaf, L as LeavesSwapFeeEstimateOutput, a8 as LeavesSwapRequest, x as LightningReceiveRequest, aa as LightningReceiveRequestStatus, z as LightningSendFeeEstimateInput, ab as LightningSendFeeEstimateOutput, y as LightningSendRequest, ad as LightningSendRequestStatus, P as PageInfo, ae as RequestCoopExitInput, af as RequestLeavesSwapInput, ag as RequestLightningReceiveInput, ah as RequestLightningSendInput, ai as SparkCoopExitRequestStatus, aj as SparkLeavesSwapRequestStatus, ak as SparkTransferToLeavesConnection, al as StaticDepositQuoteInput, u as StaticDepositQuoteOutput, am as SwapLeaf, an as Transfer, ar as TransferDirection, ao as UserLeafInput, as as UserRequestType, ap as VerifyChallengeOutput, w as WalletLeaf, W as WalletTransfer, at as WalletTransferLeaf, N as getClaimStaticDepositQuery, $ as getCoopExitFeeQuoteQuery, a1 as getCoopExitRequestQuery, a7 as getLeavesSwapRequestQuery, a9 as getLightningReceiveRequestQuery, ac as getLightningSendRequestQuery, au as mapTransferLeafToWalletTransferLeaf, av as mapTransferToWalletTransfer, aq as mapTreeNodeToWalletLeaf } from '../client-AHn11NHe.cjs';
|
|
2
2
|
export { ClaimStaticDepositInput, ClaimStaticDepositRequestType, CompleteCoopExitOutput, CompleteLeavesSwapOutput, CompleteSeedReleaseInput, CompleteSeedReleaseOutput, Connection, CoopExitFeeQuoteOutput, Entity, GetChallengeInput, LeavesSwapFeeEstimateInput, NotifyReceiverTransferInput, Provider, RequestCoopExitOutput, RequestLeavesSwapOutput, RequestLightningReceiveOutput, RequestLightningSendOutput, SparkUserRequestStatus, SparkUserRequestType, SparkWalletUser, SparkWalletUserToUserRequestsConnection, StartSeedReleaseInput, UserRequest, VerifyChallengeInput, WalletUserIdentityPublicKeyInput, WalletUserIdentityPublicKeyOutput, getUserRequestQuery } from '../graphql/objects/index.cjs';
|
|
3
|
-
export {
|
|
3
|
+
export { l as CommonProto, s as SparkProto } from '../spark-WA_4wcBr.cjs';
|
|
4
4
|
import '@lightsparkdev/core';
|
|
5
5
|
import '@scure/btc-signer';
|
|
6
6
|
import '@scure/bip32';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { B as BitcoinNetwork, O as ClaimStaticDeposit, C as ClaimStaticDepositOutput, Q as ClaimStaticDepositStatus, R as CompleteCoopExitInput, X as CompleteLeavesSwapInput, Y as CoopExitFeeEstimate, Z as CoopExitFeeEstimatesInput, _ as CoopExitFeeEstimatesOutput, F as CoopExitFeeQuote, a0 as CoopExitFeeQuoteInput, G as CoopExitRequest, a2 as CurrencyAmount, a3 as CurrencyUnit, E as ExitSpeed, a4 as GetChallengeOutput, a5 as Invoice, a6 as Leaf, L as LeavesSwapFeeEstimateOutput, a8 as LeavesSwapRequest, x as LightningReceiveRequest, aa as LightningReceiveRequestStatus, z as LightningSendFeeEstimateInput, ab as LightningSendFeeEstimateOutput, y as LightningSendRequest, ad as LightningSendRequestStatus, P as PageInfo, ae as RequestCoopExitInput, af as RequestLeavesSwapInput, ag as RequestLightningReceiveInput, ah as RequestLightningSendInput, ai as SparkCoopExitRequestStatus, aj as SparkLeavesSwapRequestStatus, ak as SparkTransferToLeavesConnection, al as StaticDepositQuoteInput, u as StaticDepositQuoteOutput, am as SwapLeaf, an as Transfer, ar as TransferDirection, ao as UserLeafInput, as as UserRequestType, ap as VerifyChallengeOutput, w as WalletLeaf, W as WalletTransfer, at as WalletTransferLeaf, N as getClaimStaticDepositQuery, $ as getCoopExitFeeQuoteQuery, a1 as getCoopExitRequestQuery, a7 as getLeavesSwapRequestQuery, a9 as getLightningReceiveRequestQuery, ac as getLightningSendRequestQuery, au as mapTransferLeafToWalletTransferLeaf, av as mapTransferToWalletTransfer, aq as mapTreeNodeToWalletLeaf } from '../client-
|
|
1
|
+
export { B as BitcoinNetwork, O as ClaimStaticDeposit, C as ClaimStaticDepositOutput, Q as ClaimStaticDepositStatus, R as CompleteCoopExitInput, X as CompleteLeavesSwapInput, Y as CoopExitFeeEstimate, Z as CoopExitFeeEstimatesInput, _ as CoopExitFeeEstimatesOutput, F as CoopExitFeeQuote, a0 as CoopExitFeeQuoteInput, G as CoopExitRequest, a2 as CurrencyAmount, a3 as CurrencyUnit, E as ExitSpeed, a4 as GetChallengeOutput, a5 as Invoice, a6 as Leaf, L as LeavesSwapFeeEstimateOutput, a8 as LeavesSwapRequest, x as LightningReceiveRequest, aa as LightningReceiveRequestStatus, z as LightningSendFeeEstimateInput, ab as LightningSendFeeEstimateOutput, y as LightningSendRequest, ad as LightningSendRequestStatus, P as PageInfo, ae as RequestCoopExitInput, af as RequestLeavesSwapInput, ag as RequestLightningReceiveInput, ah as RequestLightningSendInput, ai as SparkCoopExitRequestStatus, aj as SparkLeavesSwapRequestStatus, ak as SparkTransferToLeavesConnection, al as StaticDepositQuoteInput, u as StaticDepositQuoteOutput, am as SwapLeaf, an as Transfer, ar as TransferDirection, ao as UserLeafInput, as as UserRequestType, ap as VerifyChallengeOutput, w as WalletLeaf, W as WalletTransfer, at as WalletTransferLeaf, N as getClaimStaticDepositQuery, $ as getCoopExitFeeQuoteQuery, a1 as getCoopExitRequestQuery, a7 as getLeavesSwapRequestQuery, a9 as getLightningReceiveRequestQuery, ac as getLightningSendRequestQuery, au as mapTransferLeafToWalletTransferLeaf, av as mapTransferToWalletTransfer, aq as mapTreeNodeToWalletLeaf } from '../client-GOlkXliC.js';
|
|
2
2
|
export { ClaimStaticDepositInput, ClaimStaticDepositRequestType, CompleteCoopExitOutput, CompleteLeavesSwapOutput, CompleteSeedReleaseInput, CompleteSeedReleaseOutput, Connection, CoopExitFeeQuoteOutput, Entity, GetChallengeInput, LeavesSwapFeeEstimateInput, NotifyReceiverTransferInput, Provider, RequestCoopExitOutput, RequestLeavesSwapOutput, RequestLightningReceiveOutput, RequestLightningSendOutput, SparkUserRequestStatus, SparkUserRequestType, SparkWalletUser, SparkWalletUserToUserRequestsConnection, StartSeedReleaseInput, UserRequest, VerifyChallengeInput, WalletUserIdentityPublicKeyInput, WalletUserIdentityPublicKeyOutput, getUserRequestQuery } from '../graphql/objects/index.js';
|
|
3
|
-
export {
|
|
3
|
+
export { l as CommonProto, s as SparkProto } from '../spark-WA_4wcBr.js';
|
|
4
4
|
import '@lightsparkdev/core';
|
|
5
5
|
import '@scure/btc-signer';
|
|
6
6
|
import '@scure/bip32';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildonspark/spark-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"author": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
24
|
"import": {
|
|
25
|
+
"bun": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
25
29
|
"node": {
|
|
26
30
|
"types": "./dist/index.node.d.ts",
|
|
27
31
|
"default": "./dist/index.node.js"
|
|
@@ -79,22 +83,13 @@
|
|
|
79
83
|
"require": "./dist/bare/index.cjs"
|
|
80
84
|
}
|
|
81
85
|
},
|
|
82
|
-
"browser": {
|
|
83
|
-
"assert": false,
|
|
84
|
-
"crypto": false,
|
|
85
|
-
"fs": false,
|
|
86
|
-
"fs/promises": false,
|
|
87
|
-
"nice-grpc": "nice-grpc-web",
|
|
88
|
-
"path": false,
|
|
89
|
-
"url": false
|
|
90
|
-
},
|
|
91
86
|
"scripts": {
|
|
92
87
|
"build": "yarn tsc && rm -rf dist && tsup",
|
|
93
88
|
"build:watch": "yarn build --watch --clean=false",
|
|
94
89
|
"clean": "rm -rf dist",
|
|
95
90
|
"circular-deps": "madge --circular --extensions ts,tsx src",
|
|
96
91
|
"dev": "yarn build -- --watch",
|
|
97
|
-
"depcheck": "depcheck --ignores=buffer,ts-proto,jest,ts-jest
|
|
92
|
+
"depcheck": "depcheck --ignores=buffer,ts-proto,jest,ts-jest",
|
|
98
93
|
"docs": "typedoc src",
|
|
99
94
|
"format:fix": "prettier . --write",
|
|
100
95
|
"format": "prettier . --check",
|
|
@@ -102,7 +97,7 @@
|
|
|
102
97
|
"lint:fix:continue": "eslint --fix . || exit 0",
|
|
103
98
|
"lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
|
|
104
99
|
"lint": "eslint .",
|
|
105
|
-
"package:checks": "yarn depcheck && yarn attw --pack . && echo \"\nPackage checks passed successfully!\"",
|
|
100
|
+
"package:checks": "yarn depcheck && yarn publint && yarn attw --pack . && echo \"\nPackage checks passed successfully!\"",
|
|
106
101
|
"postversion": "yarn build",
|
|
107
102
|
"test-cmd": "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --detectOpenHandles --forceExit",
|
|
108
103
|
"test": "yarn test-cmd src/tests/*.test.ts",
|
|
@@ -155,7 +150,6 @@
|
|
|
155
150
|
"async-mutex": "^0.5.0",
|
|
156
151
|
"bare-crypto": "^1.9.2",
|
|
157
152
|
"bare-fetch": "^2.4.1",
|
|
158
|
-
"bitcoinjs-lib": "^6.1.5",
|
|
159
153
|
"buffer": "^6.0.3",
|
|
160
154
|
"eciesjs": "^0.4.13",
|
|
161
155
|
"eventemitter3": "^5.0.1",
|
package/src/bare/index.ts
CHANGED
|
@@ -35,7 +35,7 @@ setFetch(sparkBareFetch, Headers);
|
|
|
35
35
|
|
|
36
36
|
export * from "../errors/index.js";
|
|
37
37
|
/* Use Browser otel wrapper for now (more compatible with bare-fetch): */
|
|
38
|
-
export { SparkWallet } from "../spark-wallet/spark-wallet.
|
|
38
|
+
export { SparkWallet } from "../spark-wallet/spark-wallet.bare.js";
|
|
39
39
|
export { getLatestDepositTxId } from "../utils/mempool.js";
|
|
40
40
|
export * from "../utils/index.js";
|
|
41
41
|
export {
|
package/src/debug.ts
CHANGED
package/src/index.node.ts
CHANGED
|
@@ -28,7 +28,8 @@ export {
|
|
|
28
28
|
} from "./spark-wallet/spark-wallet.node.js";
|
|
29
29
|
export * from "./spark-wallet/types.js";
|
|
30
30
|
|
|
31
|
+
export { ConnectionManagerNodeJS as ConnectionManager } from "./services/connection/connection.node.js";
|
|
32
|
+
export { type ConnectionManager as BaseConnectionManager } from "./services/connection/connection.js";
|
|
31
33
|
export { type WalletConfigService } from "./services/config.js";
|
|
32
|
-
export { type ConnectionManager } from "./services/connection.js";
|
|
33
34
|
export { TokenTransactionService } from "./services/token-transactions.js";
|
|
34
35
|
export { WalletConfig, type ConfigOptions } from "./services/wallet-config.js";
|
package/src/index.ts
CHANGED
|
@@ -30,7 +30,8 @@ export {
|
|
|
30
30
|
} from "./spark-wallet/spark-wallet.browser.js";
|
|
31
31
|
export * from "./spark-wallet/types.js";
|
|
32
32
|
|
|
33
|
+
export { ConnectionManagerBrowser as ConnectionManager } from "./services/connection/connection.browser.js";
|
|
34
|
+
export { type ConnectionManager as BaseConnectionManager } from "./services/connection/connection.js";
|
|
33
35
|
export { type WalletConfigService } from "./services/config.js";
|
|
34
|
-
export { type ConnectionManager } from "./services/connection.js";
|
|
35
36
|
export { TokenTransactionService } from "./services/token-transactions.js";
|
|
36
37
|
export { WalletConfig, type ConfigOptions } from "./services/wallet-config.js";
|
package/src/native/index.ts
CHANGED
|
@@ -11,10 +11,11 @@ export { ReactNativeSparkSigner } from "../signer/signer.react-native.js";
|
|
|
11
11
|
/* Enable some consumers to use named import DefaultSparkSigner regardless of module, see LIG-7662 */
|
|
12
12
|
export { ReactNativeSparkSigner as DefaultSparkSigner } from "../signer/signer.react-native.js";
|
|
13
13
|
|
|
14
|
-
export { SparkWallet } from "../spark-wallet/spark-wallet.js";
|
|
14
|
+
export { SparkWallet } from "../spark-wallet/spark-wallet.react-native.js";
|
|
15
15
|
export * from "../spark-wallet/types.js";
|
|
16
16
|
|
|
17
17
|
export { type WalletConfigService } from "../services/config.js";
|
|
18
|
-
export {
|
|
18
|
+
export { ConnectionManagerBrowser as ConnectionManager } from "../services/connection/connection.browser.js";
|
|
19
|
+
export { type ConnectionManager as BaseConnectionManager } from "../services/connection/connection.js";
|
|
19
20
|
export { TokenTransactionService } from "../services/token-transactions.js";
|
|
20
21
|
export { WalletConfig, type ConfigOptions } from "../services/wallet-config.js";
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ConnectionManager } from "./connection.js";
|
|
2
|
+
import {
|
|
3
|
+
createChannel,
|
|
4
|
+
FetchTransport,
|
|
5
|
+
createClientFactory,
|
|
6
|
+
type Channel as ChannelWeb,
|
|
7
|
+
type ClientFactory as ClientFactoryWeb,
|
|
8
|
+
} from "nice-grpc-web";
|
|
9
|
+
import { ClientMiddlewareCall, Metadata } from "nice-grpc-common";
|
|
10
|
+
import { retryMiddleware } from "nice-grpc-client-middleware-retry";
|
|
11
|
+
import { RetryOptions, SparkCallOptions } from "../../types/grpc.js";
|
|
12
|
+
import { WalletConfigService } from "../config.js";
|
|
13
|
+
import { clientEnv } from "../../constants.js";
|
|
14
|
+
import { NetworkError } from "../../errors/types.js";
|
|
15
|
+
import type { SparkAuthnServiceDefinition } from "../../proto/spark_authn.js";
|
|
16
|
+
import type { SparkServiceDefinition } from "../../proto/spark.js";
|
|
17
|
+
import type { SparkTokenServiceDefinition } from "../../proto/spark_token.js";
|
|
18
|
+
|
|
19
|
+
export type Transport = NonNullable<Parameters<typeof createChannel>[1]>;
|
|
20
|
+
|
|
21
|
+
export class ConnectionManagerBrowser extends ConnectionManager {
|
|
22
|
+
protected transport: Transport;
|
|
23
|
+
|
|
24
|
+
constructor(config: WalletConfigService, transport = FetchTransport()) {
|
|
25
|
+
super(config);
|
|
26
|
+
this.transport = transport;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected async createChannelWithTLS(address: string, certPath?: string) {
|
|
30
|
+
try {
|
|
31
|
+
return createChannel(address, this.transport);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error("Channel creation error:", error);
|
|
34
|
+
throw new NetworkError(
|
|
35
|
+
"Failed to create channel",
|
|
36
|
+
{
|
|
37
|
+
url: address,
|
|
38
|
+
operation: "createChannel",
|
|
39
|
+
errorCount: 1,
|
|
40
|
+
errors: error instanceof Error ? error.message : String(error),
|
|
41
|
+
},
|
|
42
|
+
error as Error,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected createAuthnMiddleware() {
|
|
48
|
+
return async function* (
|
|
49
|
+
this: ConnectionManagerBrowser,
|
|
50
|
+
call: ClientMiddlewareCall<any, any>,
|
|
51
|
+
options: SparkCallOptions,
|
|
52
|
+
) {
|
|
53
|
+
const metadata = Metadata(options.metadata)
|
|
54
|
+
.set("X-Requested-With", "XMLHttpRequest")
|
|
55
|
+
.set("X-Grpc-Web", "1")
|
|
56
|
+
.set("X-Client-Env", clientEnv)
|
|
57
|
+
.set("Content-Type", "application/grpc-web+proto");
|
|
58
|
+
return yield* call.next(call.request, {
|
|
59
|
+
...options,
|
|
60
|
+
metadata,
|
|
61
|
+
});
|
|
62
|
+
}.bind(this);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected createMiddleware(address: string, initialAuthToken: string) {
|
|
66
|
+
return async function* (
|
|
67
|
+
this: ConnectionManagerBrowser,
|
|
68
|
+
call: ClientMiddlewareCall<any, any>,
|
|
69
|
+
options: SparkCallOptions,
|
|
70
|
+
) {
|
|
71
|
+
const metadata = Metadata(options.metadata)
|
|
72
|
+
.set("X-Requested-With", "XMLHttpRequest")
|
|
73
|
+
.set("X-Grpc-Web", "1")
|
|
74
|
+
.set("X-Client-Env", clientEnv)
|
|
75
|
+
.set("Content-Type", "application/grpc-web+proto");
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
return yield* call.next(call.request, {
|
|
79
|
+
...options,
|
|
80
|
+
metadata: metadata.set(
|
|
81
|
+
"Authorization",
|
|
82
|
+
`Bearer ${this.clients.get(address)?.authToken || initialAuthToken}`,
|
|
83
|
+
),
|
|
84
|
+
});
|
|
85
|
+
} catch (error: any) {
|
|
86
|
+
return yield* this.handleMiddlewareError(
|
|
87
|
+
error,
|
|
88
|
+
address,
|
|
89
|
+
call,
|
|
90
|
+
metadata,
|
|
91
|
+
options,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}.bind(this);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
protected async createGrpcClient<T>(
|
|
98
|
+
defintion:
|
|
99
|
+
| SparkAuthnServiceDefinition
|
|
100
|
+
| SparkServiceDefinition
|
|
101
|
+
| SparkTokenServiceDefinition,
|
|
102
|
+
channel: ChannelWeb,
|
|
103
|
+
withRetries: boolean,
|
|
104
|
+
middleware?: any,
|
|
105
|
+
) {
|
|
106
|
+
let clientFactory: ClientFactoryWeb;
|
|
107
|
+
|
|
108
|
+
const retryOptions = {
|
|
109
|
+
retry: true,
|
|
110
|
+
retryMaxAttempts: 3,
|
|
111
|
+
};
|
|
112
|
+
let options: RetryOptions = {};
|
|
113
|
+
|
|
114
|
+
clientFactory = createClientFactory();
|
|
115
|
+
if (withRetries) {
|
|
116
|
+
options = retryOptions;
|
|
117
|
+
clientFactory = clientFactory.use(retryMiddleware);
|
|
118
|
+
}
|
|
119
|
+
if (middleware) {
|
|
120
|
+
clientFactory = clientFactory.use(middleware);
|
|
121
|
+
}
|
|
122
|
+
const client = clientFactory.create(defintion, channel, {
|
|
123
|
+
"*": options,
|
|
124
|
+
}) as T;
|
|
125
|
+
return {
|
|
126
|
+
...client,
|
|
127
|
+
close: undefined,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { ConnectionManager } from "./connection.js";
|
|
2
|
+
import {
|
|
3
|
+
createClient,
|
|
4
|
+
createChannel,
|
|
5
|
+
createClientFactory,
|
|
6
|
+
ChannelCredentials,
|
|
7
|
+
type Channel,
|
|
8
|
+
} from "nice-grpc";
|
|
9
|
+
import { ClientMiddlewareCall, Metadata } from "nice-grpc-common";
|
|
10
|
+
import { RetryOptions, SparkCallOptions } from "../../types/grpc.js";
|
|
11
|
+
import { MockServiceClient, MockServiceDefinition } from "../../proto/mock.js";
|
|
12
|
+
import { SparkServiceDefinition } from "../../proto/spark.js";
|
|
13
|
+
import { SparkAuthnServiceDefinition } from "../../proto/spark_authn.js";
|
|
14
|
+
import { SparkTokenServiceDefinition } from "../../proto/spark_token.js";
|
|
15
|
+
import { openTelemetryClientMiddleware } from "nice-grpc-opentelemetry";
|
|
16
|
+
import { retryMiddleware } from "nice-grpc-client-middleware-retry";
|
|
17
|
+
import { WalletConfigService } from "../config.js";
|
|
18
|
+
import { NetworkError } from "../../errors/types.js";
|
|
19
|
+
import { clientEnv } from "../../constants.js";
|
|
20
|
+
import fs from "fs";
|
|
21
|
+
|
|
22
|
+
export class ConnectionManagerNodeJS extends ConnectionManager {
|
|
23
|
+
constructor(config: WalletConfigService) {
|
|
24
|
+
super(config);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async createMockClient(address: string): Promise<
|
|
28
|
+
MockServiceClient & {
|
|
29
|
+
close: () => void;
|
|
30
|
+
}
|
|
31
|
+
> {
|
|
32
|
+
const channel = await this.createChannelWithTLS(address);
|
|
33
|
+
|
|
34
|
+
const client = createClient(MockServiceDefinition, channel);
|
|
35
|
+
return { ...client, close: () => channel.close() };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected async createChannelWithTLS(address: string, certPath?: string) {
|
|
39
|
+
try {
|
|
40
|
+
if (certPath) {
|
|
41
|
+
try {
|
|
42
|
+
const cert = fs.readFileSync(certPath);
|
|
43
|
+
return createChannel(address, ChannelCredentials.createSsl(cert));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error("Error reading certificate:", error);
|
|
46
|
+
// Fallback to insecure for development
|
|
47
|
+
return createChannel(
|
|
48
|
+
address,
|
|
49
|
+
ChannelCredentials.createSsl(null, null, null, {
|
|
50
|
+
rejectUnauthorized: false,
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
// No cert provided, use insecure SSL for development
|
|
56
|
+
return createChannel(
|
|
57
|
+
address,
|
|
58
|
+
ChannelCredentials.createSsl(null, null, null, {
|
|
59
|
+
rejectUnauthorized: false,
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error("Channel creation error:", error);
|
|
65
|
+
throw new NetworkError(
|
|
66
|
+
"Failed to create channel",
|
|
67
|
+
{
|
|
68
|
+
url: address,
|
|
69
|
+
operation: "createChannel",
|
|
70
|
+
errorCount: 1,
|
|
71
|
+
errors: error instanceof Error ? error.message : String(error),
|
|
72
|
+
},
|
|
73
|
+
error as Error,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected createAuthnMiddleware() {
|
|
79
|
+
return async function* (
|
|
80
|
+
this: ConnectionManagerNodeJS,
|
|
81
|
+
call: ClientMiddlewareCall<any, any>,
|
|
82
|
+
options: SparkCallOptions,
|
|
83
|
+
) {
|
|
84
|
+
const metadata = Metadata(options.metadata).set(
|
|
85
|
+
"X-Client-Env",
|
|
86
|
+
clientEnv,
|
|
87
|
+
);
|
|
88
|
+
return yield* call.next(call.request, {
|
|
89
|
+
...options,
|
|
90
|
+
metadata,
|
|
91
|
+
});
|
|
92
|
+
}.bind(this);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
protected createMiddleware(address: string, initialAuthToken: string) {
|
|
96
|
+
return async function* (
|
|
97
|
+
this: ConnectionManagerNodeJS,
|
|
98
|
+
call: ClientMiddlewareCall<any, any>,
|
|
99
|
+
options: SparkCallOptions,
|
|
100
|
+
) {
|
|
101
|
+
const metadata = Metadata(options.metadata).set(
|
|
102
|
+
"X-Client-Env",
|
|
103
|
+
clientEnv,
|
|
104
|
+
);
|
|
105
|
+
try {
|
|
106
|
+
return yield* call.next(call.request, {
|
|
107
|
+
...options,
|
|
108
|
+
metadata: metadata.set(
|
|
109
|
+
"Authorization",
|
|
110
|
+
`Bearer ${this.clients.get(address)?.authToken || initialAuthToken}`,
|
|
111
|
+
),
|
|
112
|
+
});
|
|
113
|
+
} catch (error: unknown) {
|
|
114
|
+
return yield* this.handleMiddlewareError(
|
|
115
|
+
error,
|
|
116
|
+
address,
|
|
117
|
+
call,
|
|
118
|
+
metadata,
|
|
119
|
+
options,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}.bind(this);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
protected async createGrpcClient<T>(
|
|
126
|
+
defintion:
|
|
127
|
+
| SparkAuthnServiceDefinition
|
|
128
|
+
| SparkServiceDefinition
|
|
129
|
+
| SparkTokenServiceDefinition,
|
|
130
|
+
channel: Channel,
|
|
131
|
+
withRetries: boolean,
|
|
132
|
+
middleware?: any,
|
|
133
|
+
) {
|
|
134
|
+
const retryOptions = {
|
|
135
|
+
retry: true,
|
|
136
|
+
retryMaxAttempts: 3,
|
|
137
|
+
};
|
|
138
|
+
let options: RetryOptions = {};
|
|
139
|
+
|
|
140
|
+
let clientFactory = createClientFactory();
|
|
141
|
+
if (withRetries) {
|
|
142
|
+
options = retryOptions;
|
|
143
|
+
clientFactory = clientFactory
|
|
144
|
+
.use(openTelemetryClientMiddleware())
|
|
145
|
+
.use(retryMiddleware);
|
|
146
|
+
}
|
|
147
|
+
if (middleware) {
|
|
148
|
+
clientFactory = clientFactory.use(middleware);
|
|
149
|
+
}
|
|
150
|
+
const client = clientFactory.create(defintion, channel, {
|
|
151
|
+
"*": options,
|
|
152
|
+
}) as T;
|
|
153
|
+
return {
|
|
154
|
+
...client,
|
|
155
|
+
close: channel.close.bind(channel),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|