@lightsparkdev/lightspark-sdk 1.2.1 → 1.2.3
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 +14 -0
- package/dist/{BitcoinNetwork-a816c0be.d.ts → BitcoinNetwork-37e9f091.d.ts} +8 -3
- package/dist/{chunk-VTPDR6P4.js → chunk-NCPWHRFO.js} +353 -15
- package/dist/env.d.cts +1 -1
- package/dist/env.d.ts +1 -1
- package/dist/{index-5acc6526.d.ts → index-449c9f58.d.ts} +2089 -644
- package/dist/index.cjs +1082 -470
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +584 -302
- package/dist/objects/index.cjs +345 -5
- package/dist/objects/index.d.cts +2 -2
- package/dist/objects/index.d.ts +2 -2
- package/dist/objects/index.js +9 -1
- package/package.json +4 -4
- package/src/NodeKeyLoaderCache.ts +4 -3
- package/src/SigningKeyLoader.ts +12 -7
- package/src/client.ts +287 -60
- package/src/env.ts +3 -1
- package/src/graphql/ClaimUmaInvitation.ts +21 -0
- package/src/graphql/ClaimUmaInvitationWithIncentives.ts +25 -0
- package/src/graphql/CreateUmaInvitation.ts +19 -0
- package/src/graphql/CreateUmaInvitationWithIncentives.ts +23 -0
- package/src/graphql/FetchUmaInvitation.ts +15 -0
- package/src/objects/Account.ts +7 -3
- package/src/objects/AccountToApiTokensConnection.ts +7 -3
- package/src/objects/AccountToChannelsConnection.ts +3 -2
- package/src/objects/AccountToNodesConnection.ts +7 -3
- package/src/objects/AccountToPaymentRequestsConnection.ts +7 -3
- package/src/objects/AccountToTransactionsConnection.ts +13 -9
- package/src/objects/AccountToWalletsConnection.ts +7 -3
- package/src/objects/ApiToken.ts +13 -7
- package/src/objects/Balances.ts +22 -12
- package/src/objects/BitcoinNetwork.ts +8 -3
- package/src/objects/BlockchainBalance.ts +4 -1
- package/src/objects/Channel.ts +37 -14
- package/src/objects/ChannelClosingTransaction.ts +22 -11
- package/src/objects/ChannelFees.ts +4 -1
- package/src/objects/ChannelOpeningTransaction.ts +22 -11
- package/src/objects/ChannelStatus.ts +33 -8
- package/src/objects/ChannelToTransactionsConnection.ts +9 -8
- package/src/objects/ClaimUmaInvitationInput.ts +26 -0
- package/src/objects/ClaimUmaInvitationOutput.ts +30 -0
- package/src/objects/ClaimUmaInvitationWithIncentivesInput.ts +44 -0
- package/src/objects/ClaimUmaInvitationWithIncentivesOutput.ts +33 -0
- package/src/objects/ComplianceProvider.ts +3 -2
- package/src/objects/Connection.ts +7 -3
- package/src/objects/CreateApiTokenInput.ts +4 -1
- package/src/objects/CreateApiTokenOutput.ts +3 -3
- package/src/objects/CreateInvitationWithIncentivesInput.ts +37 -0
- package/src/objects/CreateInvitationWithIncentivesOutput.ts +32 -0
- package/src/objects/CreateLnurlInvoiceInput.ts +3 -2
- package/src/objects/CreateTestModePaymentInput.ts +2 -2
- package/src/objects/CreateTestModePaymentoutput.ts +5 -1
- package/src/objects/CreateUmaInvitationInput.ts +22 -0
- package/src/objects/CreateUmaInvitationOutput.ts +30 -0
- package/src/objects/CurrencyAmount.ts +6 -4
- package/src/objects/CurrencyUnit.ts +36 -9
- package/src/objects/Deposit.ts +22 -11
- package/src/objects/Entity.ts +21 -3
- package/src/objects/FeeEstimate.ts +5 -1
- package/src/objects/GraphNode.ts +30 -14
- package/src/objects/Hop.ts +12 -4
- package/src/objects/HtlcAttemptFailureCode.ts +7 -3
- package/src/objects/IncentivesIneligibilityReason.ts +48 -0
- package/src/objects/IncentivesStatus.ts +28 -0
- package/src/objects/IncomingPayment.ts +18 -7
- package/src/objects/IncomingPaymentAttempt.ts +8 -3
- package/src/objects/IncomingPaymentAttemptStatus.ts +7 -3
- package/src/objects/IncomingPaymentToAttemptsConnection.ts +7 -3
- package/src/objects/Invoice.ts +2 -2
- package/src/objects/InvoiceData.ts +7 -3
- package/src/objects/InvoiceType.ts +3 -2
- package/src/objects/LightningFeeEstimateForInvoiceInput.ts +2 -2
- package/src/objects/LightningTransaction.ts +12 -4
- package/src/objects/LightsparkNode.ts +33 -18
- package/src/objects/LightsparkNodeOwner.ts +2 -2
- package/src/objects/LightsparkNodeStatus.ts +3 -2
- package/src/objects/LightsparkNodeToChannelsConnection.ts +7 -3
- package/src/objects/LightsparkNodeWithOSK.ts +35 -19
- package/src/objects/LightsparkNodeWithRemoteSigning.ts +31 -18
- package/src/objects/Node.ts +28 -14
- package/src/objects/NodeAddressType.ts +7 -3
- package/src/objects/NodeToAddressesConnection.ts +7 -3
- package/src/objects/OnChainTransaction.ts +23 -11
- package/src/objects/OutgoingPayment.ts +25 -7
- package/src/objects/OutgoingPaymentAttempt.ts +34 -14
- package/src/objects/OutgoingPaymentAttemptStatus.ts +7 -3
- package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +12 -4
- package/src/objects/OutgoingPaymentToAttemptsConnection.ts +7 -3
- package/src/objects/PageInfo.ts +6 -1
- package/src/objects/PayInvoiceInput.ts +6 -3
- package/src/objects/PaymentDirection.ts +3 -2
- package/src/objects/PaymentFailureReason.ts +7 -3
- package/src/objects/PaymentRequest.ts +8 -3
- package/src/objects/PaymentRequestData.ts +5 -1
- package/src/objects/PaymentRequestStatus.ts +7 -3
- package/src/objects/Permission.ts +7 -3
- package/src/objects/PostTransactionData.ts +6 -3
- package/src/objects/RegionCode.ts +541 -0
- package/src/objects/RegisterPaymentInput.ts +12 -7
- package/src/objects/RemoteSigningSubEventType.ts +7 -3
- package/src/objects/RequestWithdrawalInput.ts +2 -2
- package/src/objects/RiskRating.ts +8 -3
- package/src/objects/RoutingTransaction.ts +20 -7
- package/src/objects/RoutingTransactionFailureReason.ts +8 -3
- package/src/objects/ScreenNodeInput.ts +3 -2
- package/src/objects/SendPaymentInput.ts +4 -1
- package/src/objects/SetInvoicePaymentHashInput.ts +3 -2
- package/src/objects/Signable.ts +2 -2
- package/src/objects/SignablePayload.ts +6 -3
- package/src/objects/SignablePayloadStatus.ts +3 -2
- package/src/objects/Transaction.ts +14 -4
- package/src/objects/TransactionFailures.ts +4 -1
- package/src/objects/TransactionStatus.ts +16 -5
- package/src/objects/TransactionType.ts +30 -8
- package/src/objects/TransactionUpdate.ts +6 -3
- package/src/objects/UmaInvitation.ts +119 -0
- package/src/objects/Wallet.ts +13 -4
- package/src/objects/WalletStatus.ts +36 -9
- package/src/objects/WalletToPaymentRequestsConnection.ts +7 -3
- package/src/objects/WalletToTransactionsConnection.ts +7 -3
- package/src/objects/WebhookEventType.ts +11 -3
- package/src/objects/Withdrawal.ts +22 -11
- package/src/objects/WithdrawalMode.ts +7 -3
- package/src/objects/WithdrawalRequest.ts +15 -6
- package/src/objects/WithdrawalRequestStatus.ts +3 -2
- package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +11 -4
- package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +11 -4
- package/src/objects/index.ts +21 -6
- package/src/tests/integration/constants.ts +0 -3
- package/src/tests/integration/general-regtest.test.ts +178 -197
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
FRAGMENT10,
|
|
17
17
|
FRAGMENT11,
|
|
18
18
|
FRAGMENT12,
|
|
19
|
+
FRAGMENT13,
|
|
19
20
|
FRAGMENT2,
|
|
20
21
|
FRAGMENT3,
|
|
21
22
|
FRAGMENT4,
|
|
@@ -27,6 +28,8 @@ import {
|
|
|
27
28
|
FeeEstimateFromJson,
|
|
28
29
|
GraphNode_default,
|
|
29
30
|
HtlcAttemptFailureCode_default,
|
|
31
|
+
IncentivesIneligibilityReason_default,
|
|
32
|
+
IncentivesStatus_default,
|
|
30
33
|
IncomingPaymentAttemptStatus_default,
|
|
31
34
|
IncomingPaymentFromJson,
|
|
32
35
|
IncomingPayment_default,
|
|
@@ -46,6 +49,7 @@ import {
|
|
|
46
49
|
PaymentRequestFromJson,
|
|
47
50
|
PaymentRequestStatus_default,
|
|
48
51
|
Permission_default,
|
|
52
|
+
RegionCode_default,
|
|
49
53
|
RemoteSigningSubEventType_default,
|
|
50
54
|
RiskRating_default,
|
|
51
55
|
RoutingTransactionFailureReason_default,
|
|
@@ -54,6 +58,7 @@ import {
|
|
|
54
58
|
TransactionStatus_default,
|
|
55
59
|
TransactionType_default,
|
|
56
60
|
TransactionUpdateFromJson,
|
|
61
|
+
UmaInvitationFromJson,
|
|
57
62
|
WalletStatus_default,
|
|
58
63
|
Wallet_default,
|
|
59
64
|
WebhookEventType,
|
|
@@ -79,8 +84,9 @@ import {
|
|
|
79
84
|
getSignablePayloadQuery,
|
|
80
85
|
getSignableQuery,
|
|
81
86
|
getTransactionQuery,
|
|
87
|
+
getUmaInvitationQuery,
|
|
82
88
|
getWithdrawalQuery
|
|
83
|
-
} from "./chunk-
|
|
89
|
+
} from "./chunk-NCPWHRFO.js";
|
|
84
90
|
import {
|
|
85
91
|
BitcoinNetwork_default
|
|
86
92
|
} from "./chunk-K6SAUSAX.js";
|
|
@@ -123,22 +129,22 @@ var AccountTokenAuthProvider_default = AccountTokenAuthProvider;
|
|
|
123
129
|
// src/client.ts
|
|
124
130
|
import autoBind2 from "auto-bind";
|
|
125
131
|
import {
|
|
126
|
-
createSha256Hash,
|
|
127
132
|
DefaultCrypto as DefaultCrypto2,
|
|
128
133
|
LightsparkAuthException,
|
|
129
134
|
LightsparkException,
|
|
130
135
|
LightsparkSigningException as LightsparkSigningException3,
|
|
131
136
|
NodeKeyCache,
|
|
132
|
-
pollUntil,
|
|
133
137
|
Requester,
|
|
134
138
|
SigningKeyType as SigningKeyType2,
|
|
135
|
-
StubAuthProvider
|
|
139
|
+
StubAuthProvider,
|
|
140
|
+
createSha256Hash,
|
|
141
|
+
pollUntil
|
|
136
142
|
} from "@lightsparkdev/core";
|
|
137
143
|
|
|
138
144
|
// package.json
|
|
139
145
|
var package_default = {
|
|
140
146
|
name: "@lightsparkdev/lightspark-sdk",
|
|
141
|
-
version: "1.2.
|
|
147
|
+
version: "1.2.3",
|
|
142
148
|
description: "Lightspark JS SDK",
|
|
143
149
|
author: "Lightspark Inc.",
|
|
144
150
|
keywords: [
|
|
@@ -207,7 +213,7 @@ var package_default = {
|
|
|
207
213
|
],
|
|
208
214
|
scripts: {
|
|
209
215
|
build: "yarn tsc && tsup",
|
|
210
|
-
"build:watch": "yarn build --watch",
|
|
216
|
+
"build:watch": "yarn build --watch --clean=false",
|
|
211
217
|
clean: "rm -rf .turbo && rm -rf dist",
|
|
212
218
|
dev: "yarn build -- --watch",
|
|
213
219
|
docs: "typedoc src",
|
|
@@ -226,7 +232,7 @@ var package_default = {
|
|
|
226
232
|
},
|
|
227
233
|
license: "Apache-2.0",
|
|
228
234
|
dependencies: {
|
|
229
|
-
"@lightsparkdev/core": "1.0.
|
|
235
|
+
"@lightsparkdev/core": "1.0.11",
|
|
230
236
|
"@lightsparkdev/crypto-wasm": "0.1.2",
|
|
231
237
|
"auto-bind": "^5.0.1",
|
|
232
238
|
"crypto-browserify": "^3.12.0",
|
|
@@ -253,7 +259,192 @@ var package_default = {
|
|
|
253
259
|
"tsc-absolute": "^1.0.1",
|
|
254
260
|
tsup: "^7.2.0",
|
|
255
261
|
typedoc: "^0.24.7",
|
|
256
|
-
typescript: "^
|
|
262
|
+
typescript: "^5.0.0"
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// src/NodeKeyLoaderCache.ts
|
|
267
|
+
import {
|
|
268
|
+
DefaultCrypto,
|
|
269
|
+
LightsparkSigningException as LightsparkSigningException2
|
|
270
|
+
} from "@lightsparkdev/core";
|
|
271
|
+
|
|
272
|
+
// src/SigningKeyLoader.ts
|
|
273
|
+
import {
|
|
274
|
+
LightsparkSigningException,
|
|
275
|
+
SigningKeyType,
|
|
276
|
+
b64encode as b64encode2,
|
|
277
|
+
isBrowser
|
|
278
|
+
} from "@lightsparkdev/core";
|
|
279
|
+
|
|
280
|
+
// src/graphql/RecoverNodeSigningKey.ts
|
|
281
|
+
var RecoverNodeSigningKey = `
|
|
282
|
+
query RecoverNodeSigningKey($nodeId: ID!) {
|
|
283
|
+
entity(id: $nodeId) {
|
|
284
|
+
__typename
|
|
285
|
+
... on LightsparkNodeWithOSK {
|
|
286
|
+
encrypted_signing_private_key {
|
|
287
|
+
encrypted_value
|
|
288
|
+
cipher
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
`;
|
|
294
|
+
|
|
295
|
+
// src/SigningKeyLoader.ts
|
|
296
|
+
var SIGNING_KEY_PATH = "m/5";
|
|
297
|
+
function isNodeIdAndPasswordSigningKeyLoaderArgs(args) {
|
|
298
|
+
return args.password !== void 0;
|
|
299
|
+
}
|
|
300
|
+
function isMasterSeedSigningKeyLoaderArgs(args) {
|
|
301
|
+
return args.masterSeed !== void 0;
|
|
302
|
+
}
|
|
303
|
+
var NodeIdAndPasswordSigningKeyLoader = class {
|
|
304
|
+
nodeId;
|
|
305
|
+
password;
|
|
306
|
+
requester;
|
|
307
|
+
cryptoImpl;
|
|
308
|
+
constructor(args, requester, cryptoImpl) {
|
|
309
|
+
this.nodeId = args.nodeId;
|
|
310
|
+
this.password = args.password;
|
|
311
|
+
this.requester = requester;
|
|
312
|
+
this.cryptoImpl = cryptoImpl;
|
|
313
|
+
}
|
|
314
|
+
async loadSigningKey() {
|
|
315
|
+
const encryptedKey = await this.recoverNodeSigningKey();
|
|
316
|
+
if (!encryptedKey) {
|
|
317
|
+
console.warn("No encrypted key found for node " + this.nodeId);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const signingPrivateKey = await this.cryptoImpl.decryptSecretWithNodePassword(
|
|
321
|
+
encryptedKey.cipher,
|
|
322
|
+
encryptedKey.encrypted_value,
|
|
323
|
+
this.password
|
|
324
|
+
);
|
|
325
|
+
if (!signingPrivateKey) {
|
|
326
|
+
throw new LightsparkSigningException(
|
|
327
|
+
"Unable to decrypt signing key with provided password. Please try again."
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
let signingPrivateKeyPEM = "";
|
|
331
|
+
if (new Uint8Array(signingPrivateKey)[0] === 48) {
|
|
332
|
+
signingPrivateKeyPEM = b64encode2(signingPrivateKey);
|
|
333
|
+
} else {
|
|
334
|
+
const dec = new TextDecoder();
|
|
335
|
+
signingPrivateKeyPEM = dec.decode(signingPrivateKey);
|
|
336
|
+
}
|
|
337
|
+
return { key: signingPrivateKeyPEM, type: SigningKeyType.RSASigningKey };
|
|
338
|
+
}
|
|
339
|
+
async recoverNodeSigningKey() {
|
|
340
|
+
const response = await this.requester.makeRawRequest(
|
|
341
|
+
RecoverNodeSigningKey,
|
|
342
|
+
{ nodeId: this.nodeId }
|
|
343
|
+
);
|
|
344
|
+
const nodeEntity = response.entity;
|
|
345
|
+
if (nodeEntity?.__typename === "LightsparkNodeWithOSK") {
|
|
346
|
+
return nodeEntity.encrypted_signing_private_key;
|
|
347
|
+
}
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
var MasterSeedSigningKeyLoader = class {
|
|
352
|
+
masterSeed;
|
|
353
|
+
network;
|
|
354
|
+
constructor(args) {
|
|
355
|
+
this.masterSeed = args.masterSeed;
|
|
356
|
+
this.network = args.network;
|
|
357
|
+
}
|
|
358
|
+
async loadSigningKey() {
|
|
359
|
+
if (isBrowser) {
|
|
360
|
+
throw new LightsparkSigningException(
|
|
361
|
+
"Browser environments not supported for master seed signing key loader."
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
const { LightsparkSigner, Network } = await import("@lightsparkdev/crypto-wasm");
|
|
365
|
+
let cryptoLibNetwork;
|
|
366
|
+
switch (this.network) {
|
|
367
|
+
case BitcoinNetwork_default.MAINNET:
|
|
368
|
+
cryptoLibNetwork = Network.Bitcoin;
|
|
369
|
+
break;
|
|
370
|
+
case BitcoinNetwork_default.TESTNET:
|
|
371
|
+
cryptoLibNetwork = Network.Testnet;
|
|
372
|
+
break;
|
|
373
|
+
case BitcoinNetwork_default.REGTEST:
|
|
374
|
+
cryptoLibNetwork = Network.Regtest;
|
|
375
|
+
break;
|
|
376
|
+
default:
|
|
377
|
+
throw new Error(
|
|
378
|
+
`Unsupported lightspark_crypto network ${this.network}.`
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
const lightsparkSigner = LightsparkSigner.from_bytes(
|
|
382
|
+
this.masterSeed,
|
|
383
|
+
cryptoLibNetwork
|
|
384
|
+
);
|
|
385
|
+
const privateKey = lightsparkSigner.derive_private_key(SIGNING_KEY_PATH);
|
|
386
|
+
return { key: privateKey, type: SigningKeyType.Secp256k1SigningKey };
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// src/NodeKeyLoaderCache.ts
|
|
391
|
+
var NodeKeyLoaderCache = class {
|
|
392
|
+
constructor(nodeKeyCache, cryptoImpl = DefaultCrypto) {
|
|
393
|
+
this.nodeKeyCache = nodeKeyCache;
|
|
394
|
+
this.cryptoImpl = cryptoImpl;
|
|
395
|
+
this.idToLoader = /* @__PURE__ */ new Map();
|
|
396
|
+
}
|
|
397
|
+
idToLoader;
|
|
398
|
+
/**
|
|
399
|
+
* Sets the signing key loader for a node.
|
|
400
|
+
* Instantiates a signing key loader based on the type of args passed in by
|
|
401
|
+
* the user.
|
|
402
|
+
*
|
|
403
|
+
* @param nodeId The ID of the node to get the key for
|
|
404
|
+
* @param loaderArgs Loader arguments for loading the key
|
|
405
|
+
* @param requester Requester used for loading the key
|
|
406
|
+
*/
|
|
407
|
+
setLoader(nodeId, loaderArgs, requester) {
|
|
408
|
+
let loader;
|
|
409
|
+
if (isNodeIdAndPasswordSigningKeyLoaderArgs(loaderArgs)) {
|
|
410
|
+
loader = new NodeIdAndPasswordSigningKeyLoader(
|
|
411
|
+
{ nodeId, ...loaderArgs },
|
|
412
|
+
requester,
|
|
413
|
+
this.cryptoImpl
|
|
414
|
+
);
|
|
415
|
+
} else if (isMasterSeedSigningKeyLoaderArgs(loaderArgs)) {
|
|
416
|
+
loader = new MasterSeedSigningKeyLoader({ ...loaderArgs });
|
|
417
|
+
} else {
|
|
418
|
+
throw new LightsparkSigningException2("Invalid signing key loader args");
|
|
419
|
+
}
|
|
420
|
+
this.idToLoader.set(nodeId, loader);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Gets the key for a node using the loader set by [setLoader]
|
|
424
|
+
*
|
|
425
|
+
* @param id The ID of the node to get the key for
|
|
426
|
+
* @returns The loaded key
|
|
427
|
+
*/
|
|
428
|
+
async getKeyWithLoader(id) {
|
|
429
|
+
if (this.nodeKeyCache.hasKey(id)) {
|
|
430
|
+
return this.nodeKeyCache.getKey(id);
|
|
431
|
+
}
|
|
432
|
+
const loader = this.idToLoader.get(id);
|
|
433
|
+
if (!loader) {
|
|
434
|
+
throw new LightsparkSigningException2(
|
|
435
|
+
"No signing key loader found for node " + id
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
const loaderResult = await loader.loadSigningKey();
|
|
439
|
+
if (!loaderResult) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const key = await this.nodeKeyCache.loadKey(
|
|
443
|
+
id,
|
|
444
|
+
{ key: loaderResult.key },
|
|
445
|
+
loaderResult.type
|
|
446
|
+
);
|
|
447
|
+
return key || void 0;
|
|
257
448
|
}
|
|
258
449
|
};
|
|
259
450
|
|
|
@@ -268,6 +459,48 @@ var BitcoinFeeEstimate = `
|
|
|
268
459
|
${FRAGMENT2}
|
|
269
460
|
`;
|
|
270
461
|
|
|
462
|
+
// src/graphql/ClaimUmaInvitation.ts
|
|
463
|
+
var ClaimUmaInvitation = `
|
|
464
|
+
mutation ClaimUmaInvitation(
|
|
465
|
+
$invitationCode: String!
|
|
466
|
+
$inviteeUma: String!
|
|
467
|
+
) {
|
|
468
|
+
claim_uma_invitation(input: {
|
|
469
|
+
invitation_code: $invitationCode
|
|
470
|
+
invitee_uma: $inviteeUma
|
|
471
|
+
}) {
|
|
472
|
+
invitation {
|
|
473
|
+
...UmaInvitationFragment
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
${FRAGMENT3}
|
|
479
|
+
`;
|
|
480
|
+
|
|
481
|
+
// src/graphql/ClaimUmaInvitationWithIncentives.ts
|
|
482
|
+
var ClaimUmaInvitationWithIncentives = `
|
|
483
|
+
mutation ClaimUmaInvitationWithIncentives(
|
|
484
|
+
$invitationCode: String!
|
|
485
|
+
$inviteeUma: String!
|
|
486
|
+
$inviteePhoneHash: String!
|
|
487
|
+
$inviteeRegion: RegionCode!
|
|
488
|
+
) {
|
|
489
|
+
claim_uma_invitation_with_incentives(input: {
|
|
490
|
+
invitation_code: $invitationCode
|
|
491
|
+
invitee_uma: $inviteeUma
|
|
492
|
+
invitee_phone_hash: $inviteePhoneHash
|
|
493
|
+
invitee_region: $inviteeRegion
|
|
494
|
+
}) {
|
|
495
|
+
invitation {
|
|
496
|
+
...UmaInvitationFragment
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
${FRAGMENT3}
|
|
502
|
+
`;
|
|
503
|
+
|
|
271
504
|
// src/graphql/CreateApiToken.ts
|
|
272
505
|
var CreateApiToken = `
|
|
273
506
|
mutation CreateApiToken(
|
|
@@ -285,7 +518,7 @@ var CreateApiToken = `
|
|
|
285
518
|
}
|
|
286
519
|
}
|
|
287
520
|
|
|
288
|
-
${
|
|
521
|
+
${FRAGMENT4}
|
|
289
522
|
`;
|
|
290
523
|
|
|
291
524
|
// src/graphql/CreateInvoice.ts
|
|
@@ -326,7 +559,7 @@ mutation CreateLnurlInvoice(
|
|
|
326
559
|
}
|
|
327
560
|
}
|
|
328
561
|
}
|
|
329
|
-
${
|
|
562
|
+
${FRAGMENT6}
|
|
330
563
|
`;
|
|
331
564
|
|
|
332
565
|
// src/graphql/CreateNodeWalletAddress.ts
|
|
@@ -379,7 +612,45 @@ mutation CreateTestModePayment(
|
|
|
379
612
|
}
|
|
380
613
|
}
|
|
381
614
|
|
|
382
|
-
${
|
|
615
|
+
${FRAGMENT7}
|
|
616
|
+
`;
|
|
617
|
+
|
|
618
|
+
// src/graphql/CreateUmaInvitation.ts
|
|
619
|
+
var CreateUmaInvitation = `
|
|
620
|
+
mutation CreateUmaInvitation(
|
|
621
|
+
$inviterUma: String!
|
|
622
|
+
) {
|
|
623
|
+
create_uma_invitation(input: {
|
|
624
|
+
inviter_uma: $inviterUma
|
|
625
|
+
}) {
|
|
626
|
+
invitation {
|
|
627
|
+
...UmaInvitationFragment
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
${FRAGMENT3}
|
|
633
|
+
`;
|
|
634
|
+
|
|
635
|
+
// src/graphql/CreateUmaInvitationWithIncentives.ts
|
|
636
|
+
var CreateUmaInvitationWithIncentives = `
|
|
637
|
+
mutation CreateUmaInvitationWithIncentives(
|
|
638
|
+
$inviterUma: String!
|
|
639
|
+
$inviterPhoneHash: String!
|
|
640
|
+
$inviterRegion: RegionCode!
|
|
641
|
+
) {
|
|
642
|
+
create_uma_invitation_with_incentives(input: {
|
|
643
|
+
inviter_uma: $inviterUma
|
|
644
|
+
inviter_phone_hash: $inviterPhoneHash
|
|
645
|
+
inviter_region: $inviterRegion
|
|
646
|
+
}) {
|
|
647
|
+
invitation {
|
|
648
|
+
...UmaInvitationFragment
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
${FRAGMENT3}
|
|
383
654
|
`;
|
|
384
655
|
|
|
385
656
|
// src/graphql/CreateUmaInvoice.ts
|
|
@@ -401,7 +672,7 @@ mutation CreateUmaInvoice(
|
|
|
401
672
|
}
|
|
402
673
|
}
|
|
403
674
|
}
|
|
404
|
-
${
|
|
675
|
+
${FRAGMENT6}
|
|
405
676
|
`;
|
|
406
677
|
|
|
407
678
|
// src/graphql/DecodeInvoice.ts
|
|
@@ -415,7 +686,7 @@ var DecodeInvoice = `
|
|
|
415
686
|
}
|
|
416
687
|
}
|
|
417
688
|
|
|
418
|
-
${
|
|
689
|
+
${FRAGMENT5}
|
|
419
690
|
`;
|
|
420
691
|
|
|
421
692
|
// src/graphql/DeleteApiToken.ts
|
|
@@ -431,6 +702,19 @@ var DeleteApiToken = `
|
|
|
431
702
|
}
|
|
432
703
|
`;
|
|
433
704
|
|
|
705
|
+
// src/graphql/FetchUmaInvitation.ts
|
|
706
|
+
var FetchUmaInvitation = `
|
|
707
|
+
query FetchUmaInvitation(
|
|
708
|
+
$invitationCode: String!
|
|
709
|
+
) {
|
|
710
|
+
uma_invitation_by_code(code: $invitationCode) {
|
|
711
|
+
...UmaInvitationFragment
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
${FRAGMENT3}
|
|
716
|
+
`;
|
|
717
|
+
|
|
434
718
|
// src/graphql/FundNode.ts
|
|
435
719
|
var FundNode = `
|
|
436
720
|
mutation FundNode(
|
|
@@ -463,7 +747,7 @@ var LightningFeeEstimateForInvoice = `
|
|
|
463
747
|
}
|
|
464
748
|
}
|
|
465
749
|
|
|
466
|
-
${
|
|
750
|
+
${FRAGMENT8}
|
|
467
751
|
`;
|
|
468
752
|
|
|
469
753
|
// src/graphql/LightningFeeEstimateForNode.ts
|
|
@@ -482,7 +766,7 @@ var LightningFeeEstimateForNode = `
|
|
|
482
766
|
}
|
|
483
767
|
}
|
|
484
768
|
|
|
485
|
-
${
|
|
769
|
+
${FRAGMENT8}
|
|
486
770
|
`;
|
|
487
771
|
|
|
488
772
|
// src/graphql/MultiNodeDashboard.ts
|
|
@@ -584,7 +868,34 @@ var PayInvoice = `
|
|
|
584
868
|
}
|
|
585
869
|
}
|
|
586
870
|
|
|
587
|
-
${
|
|
871
|
+
${FRAGMENT9}
|
|
872
|
+
`;
|
|
873
|
+
|
|
874
|
+
// src/graphql/PayUmaInvoice.ts
|
|
875
|
+
var PayUmaInvoice = `
|
|
876
|
+
mutation PayUmaInvoice(
|
|
877
|
+
$node_id: ID!
|
|
878
|
+
$encoded_invoice: String!
|
|
879
|
+
$timeout_secs: Int!
|
|
880
|
+
$maximum_fees_msats: Long!
|
|
881
|
+
$amount_msats: Long
|
|
882
|
+
) {
|
|
883
|
+
pay_uma_invoice(
|
|
884
|
+
input: {
|
|
885
|
+
node_id: $node_id
|
|
886
|
+
encoded_invoice: $encoded_invoice
|
|
887
|
+
timeout_secs: $timeout_secs
|
|
888
|
+
maximum_fees_msats: $maximum_fees_msats
|
|
889
|
+
amount_msats: $amount_msats
|
|
890
|
+
}
|
|
891
|
+
) {
|
|
892
|
+
payment {
|
|
893
|
+
...OutgoingPaymentFragment
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
${FRAGMENT9}
|
|
588
899
|
`;
|
|
589
900
|
|
|
590
901
|
// src/graphql/PaymentRequestsForNode.ts
|
|
@@ -615,34 +926,7 @@ query PaymentRequestsForNode(
|
|
|
615
926
|
}
|
|
616
927
|
}
|
|
617
928
|
|
|
618
|
-
${
|
|
619
|
-
`;
|
|
620
|
-
|
|
621
|
-
// src/graphql/PayUmaInvoice.ts
|
|
622
|
-
var PayUmaInvoice = `
|
|
623
|
-
mutation PayUmaInvoice(
|
|
624
|
-
$node_id: ID!
|
|
625
|
-
$encoded_invoice: String!
|
|
626
|
-
$timeout_secs: Int!
|
|
627
|
-
$maximum_fees_msats: Long!
|
|
628
|
-
$amount_msats: Long
|
|
629
|
-
) {
|
|
630
|
-
pay_uma_invoice(
|
|
631
|
-
input: {
|
|
632
|
-
node_id: $node_id
|
|
633
|
-
encoded_invoice: $encoded_invoice
|
|
634
|
-
timeout_secs: $timeout_secs
|
|
635
|
-
maximum_fees_msats: $maximum_fees_msats
|
|
636
|
-
amount_msats: $amount_msats
|
|
637
|
-
}
|
|
638
|
-
) {
|
|
639
|
-
payment {
|
|
640
|
-
...OutgoingPaymentFragment
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
${FRAGMENT8}
|
|
929
|
+
${FRAGMENT10}
|
|
646
930
|
`;
|
|
647
931
|
|
|
648
932
|
// src/graphql/RequestWithdrawal.ts
|
|
@@ -665,7 +949,7 @@ var RequestWithdrawal = `
|
|
|
665
949
|
}
|
|
666
950
|
}
|
|
667
951
|
|
|
668
|
-
${
|
|
952
|
+
${FRAGMENT11}
|
|
669
953
|
`;
|
|
670
954
|
|
|
671
955
|
// src/graphql/SendPayment.ts
|
|
@@ -692,7 +976,7 @@ var SendPayment = `
|
|
|
692
976
|
}
|
|
693
977
|
}
|
|
694
978
|
|
|
695
|
-
${
|
|
979
|
+
${FRAGMENT9}
|
|
696
980
|
`;
|
|
697
981
|
|
|
698
982
|
// src/graphql/SingleNodeDashboard.ts
|
|
@@ -803,10 +1087,24 @@ query SingleNodeDashboard(
|
|
|
803
1087
|
}
|
|
804
1088
|
}
|
|
805
1089
|
|
|
806
|
-
${
|
|
1090
|
+
${FRAGMENT12}
|
|
807
1091
|
${FRAGMENT}
|
|
808
1092
|
`;
|
|
809
1093
|
|
|
1094
|
+
// src/graphql/TransactionSubscription.ts
|
|
1095
|
+
var TransactionSubscription = `
|
|
1096
|
+
subscription TransactionSubscription(
|
|
1097
|
+
$nodeIds: [ID!]!
|
|
1098
|
+
) {
|
|
1099
|
+
transactions(node_ids: $nodeIds) {
|
|
1100
|
+
...TransactionUpdateFragment
|
|
1101
|
+
__typename
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
${FRAGMENT13}
|
|
1106
|
+
`;
|
|
1107
|
+
|
|
810
1108
|
// src/graphql/TransactionsForNode.ts
|
|
811
1109
|
var TransactionsForNode = `
|
|
812
1110
|
query TransactionsForNode(
|
|
@@ -834,216 +1132,18 @@ query TransactionsForNode(
|
|
|
834
1132
|
}
|
|
835
1133
|
entities {
|
|
836
1134
|
...TransactionFragment
|
|
837
|
-
__typename
|
|
838
|
-
}
|
|
839
|
-
__typename
|
|
840
|
-
}
|
|
841
|
-
__typename
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
${FRAGMENT11}
|
|
846
|
-
${FRAGMENT}
|
|
847
|
-
`;
|
|
848
|
-
|
|
849
|
-
// src/graphql/TransactionSubscription.ts
|
|
850
|
-
var TransactionSubscription = `
|
|
851
|
-
subscription TransactionSubscription(
|
|
852
|
-
$nodeIds: [ID!]!
|
|
853
|
-
) {
|
|
854
|
-
transactions(node_ids: $nodeIds) {
|
|
855
|
-
...TransactionUpdateFragment
|
|
1135
|
+
__typename
|
|
1136
|
+
}
|
|
1137
|
+
__typename
|
|
1138
|
+
}
|
|
856
1139
|
__typename
|
|
857
1140
|
}
|
|
858
1141
|
}
|
|
859
1142
|
|
|
860
1143
|
${FRAGMENT12}
|
|
1144
|
+
${FRAGMENT}
|
|
861
1145
|
`;
|
|
862
1146
|
|
|
863
|
-
// src/NodeKeyLoaderCache.ts
|
|
864
|
-
import {
|
|
865
|
-
DefaultCrypto,
|
|
866
|
-
LightsparkSigningException as LightsparkSigningException2
|
|
867
|
-
} from "@lightsparkdev/core";
|
|
868
|
-
|
|
869
|
-
// src/SigningKeyLoader.ts
|
|
870
|
-
import {
|
|
871
|
-
b64encode as b64encode2,
|
|
872
|
-
isBrowser,
|
|
873
|
-
LightsparkSigningException,
|
|
874
|
-
SigningKeyType
|
|
875
|
-
} from "@lightsparkdev/core";
|
|
876
|
-
|
|
877
|
-
// src/graphql/RecoverNodeSigningKey.ts
|
|
878
|
-
var RecoverNodeSigningKey = `
|
|
879
|
-
query RecoverNodeSigningKey($nodeId: ID!) {
|
|
880
|
-
entity(id: $nodeId) {
|
|
881
|
-
__typename
|
|
882
|
-
... on LightsparkNodeWithOSK {
|
|
883
|
-
encrypted_signing_private_key {
|
|
884
|
-
encrypted_value
|
|
885
|
-
cipher
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
`;
|
|
891
|
-
|
|
892
|
-
// src/SigningKeyLoader.ts
|
|
893
|
-
var SIGNING_KEY_PATH = "m/5";
|
|
894
|
-
function isNodeIdAndPasswordSigningKeyLoaderArgs(args) {
|
|
895
|
-
return args.password !== void 0;
|
|
896
|
-
}
|
|
897
|
-
function isMasterSeedSigningKeyLoaderArgs(args) {
|
|
898
|
-
return args.masterSeed !== void 0;
|
|
899
|
-
}
|
|
900
|
-
var NodeIdAndPasswordSigningKeyLoader = class {
|
|
901
|
-
nodeId;
|
|
902
|
-
password;
|
|
903
|
-
requester;
|
|
904
|
-
cryptoImpl;
|
|
905
|
-
constructor(args, requester, cryptoImpl) {
|
|
906
|
-
this.nodeId = args.nodeId;
|
|
907
|
-
this.password = args.password;
|
|
908
|
-
this.requester = requester;
|
|
909
|
-
this.cryptoImpl = cryptoImpl;
|
|
910
|
-
}
|
|
911
|
-
async loadSigningKey() {
|
|
912
|
-
const encryptedKey = await this.recoverNodeSigningKey();
|
|
913
|
-
if (!encryptedKey) {
|
|
914
|
-
console.warn("No encrypted key found for node " + this.nodeId);
|
|
915
|
-
return;
|
|
916
|
-
}
|
|
917
|
-
const signingPrivateKey = await this.cryptoImpl.decryptSecretWithNodePassword(
|
|
918
|
-
encryptedKey.cipher,
|
|
919
|
-
encryptedKey.encrypted_value,
|
|
920
|
-
this.password
|
|
921
|
-
);
|
|
922
|
-
if (!signingPrivateKey) {
|
|
923
|
-
throw new LightsparkSigningException(
|
|
924
|
-
"Unable to decrypt signing key with provided password. Please try again."
|
|
925
|
-
);
|
|
926
|
-
}
|
|
927
|
-
let signingPrivateKeyPEM = "";
|
|
928
|
-
if (new Uint8Array(signingPrivateKey)[0] === 48) {
|
|
929
|
-
signingPrivateKeyPEM = b64encode2(signingPrivateKey);
|
|
930
|
-
} else {
|
|
931
|
-
const dec = new TextDecoder();
|
|
932
|
-
signingPrivateKeyPEM = dec.decode(signingPrivateKey);
|
|
933
|
-
}
|
|
934
|
-
return { key: signingPrivateKeyPEM, type: SigningKeyType.RSASigningKey };
|
|
935
|
-
}
|
|
936
|
-
async recoverNodeSigningKey() {
|
|
937
|
-
const response = await this.requester.makeRawRequest(
|
|
938
|
-
RecoverNodeSigningKey,
|
|
939
|
-
{ nodeId: this.nodeId }
|
|
940
|
-
);
|
|
941
|
-
const nodeEntity = response.entity;
|
|
942
|
-
if (nodeEntity?.__typename === "LightsparkNodeWithOSK") {
|
|
943
|
-
return nodeEntity.encrypted_signing_private_key;
|
|
944
|
-
}
|
|
945
|
-
return null;
|
|
946
|
-
}
|
|
947
|
-
};
|
|
948
|
-
var MasterSeedSigningKeyLoader = class {
|
|
949
|
-
masterSeed;
|
|
950
|
-
network;
|
|
951
|
-
constructor(args) {
|
|
952
|
-
this.masterSeed = args.masterSeed;
|
|
953
|
-
this.network = args.network;
|
|
954
|
-
}
|
|
955
|
-
async loadSigningKey() {
|
|
956
|
-
if (isBrowser) {
|
|
957
|
-
throw new LightsparkSigningException(
|
|
958
|
-
"Browser environments not supported for master seed signing key loader."
|
|
959
|
-
);
|
|
960
|
-
}
|
|
961
|
-
const { LightsparkSigner, Network } = await import("@lightsparkdev/crypto-wasm");
|
|
962
|
-
let cryptoLibNetwork;
|
|
963
|
-
switch (this.network) {
|
|
964
|
-
case BitcoinNetwork_default.MAINNET:
|
|
965
|
-
cryptoLibNetwork = Network.Bitcoin;
|
|
966
|
-
break;
|
|
967
|
-
case BitcoinNetwork_default.TESTNET:
|
|
968
|
-
cryptoLibNetwork = Network.Testnet;
|
|
969
|
-
break;
|
|
970
|
-
case BitcoinNetwork_default.REGTEST:
|
|
971
|
-
cryptoLibNetwork = Network.Regtest;
|
|
972
|
-
break;
|
|
973
|
-
default:
|
|
974
|
-
throw new Error(
|
|
975
|
-
`Unsupported lightspark_crypto network ${this.network}.`
|
|
976
|
-
);
|
|
977
|
-
}
|
|
978
|
-
const lightsparkSigner = LightsparkSigner.from_bytes(
|
|
979
|
-
this.masterSeed,
|
|
980
|
-
cryptoLibNetwork
|
|
981
|
-
);
|
|
982
|
-
const privateKey = lightsparkSigner.derive_private_key(SIGNING_KEY_PATH);
|
|
983
|
-
return { key: privateKey, type: SigningKeyType.Secp256k1SigningKey };
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
|
|
987
|
-
// src/NodeKeyLoaderCache.ts
|
|
988
|
-
var NodeKeyLoaderCache = class {
|
|
989
|
-
constructor(nodeKeyCache, cryptoImpl = DefaultCrypto) {
|
|
990
|
-
this.nodeKeyCache = nodeKeyCache;
|
|
991
|
-
this.cryptoImpl = cryptoImpl;
|
|
992
|
-
this.idToLoader = /* @__PURE__ */ new Map();
|
|
993
|
-
}
|
|
994
|
-
idToLoader;
|
|
995
|
-
/**
|
|
996
|
-
* Sets the signing key loader for a node.
|
|
997
|
-
* Instantiates a signing key loader based on the type of args passed in by the user.
|
|
998
|
-
*
|
|
999
|
-
* @param nodeId The ID of the node to get the key for
|
|
1000
|
-
* @param loaderArgs Loader arguments for loading the key
|
|
1001
|
-
* @param requester Requester used for loading the key
|
|
1002
|
-
*/
|
|
1003
|
-
setLoader(nodeId, loaderArgs, requester) {
|
|
1004
|
-
let loader;
|
|
1005
|
-
if (isNodeIdAndPasswordSigningKeyLoaderArgs(loaderArgs)) {
|
|
1006
|
-
loader = new NodeIdAndPasswordSigningKeyLoader(
|
|
1007
|
-
{ nodeId, ...loaderArgs },
|
|
1008
|
-
requester,
|
|
1009
|
-
this.cryptoImpl
|
|
1010
|
-
);
|
|
1011
|
-
} else if (isMasterSeedSigningKeyLoaderArgs(loaderArgs)) {
|
|
1012
|
-
loader = new MasterSeedSigningKeyLoader({ ...loaderArgs });
|
|
1013
|
-
} else {
|
|
1014
|
-
throw new LightsparkSigningException2("Invalid signing key loader args");
|
|
1015
|
-
}
|
|
1016
|
-
this.idToLoader.set(nodeId, loader);
|
|
1017
|
-
}
|
|
1018
|
-
/**
|
|
1019
|
-
* Gets the key for a node using the loader set by [setLoader]
|
|
1020
|
-
*
|
|
1021
|
-
* @param id The ID of the node to get the key for
|
|
1022
|
-
* @returns The loaded key
|
|
1023
|
-
*/
|
|
1024
|
-
async getKeyWithLoader(id) {
|
|
1025
|
-
if (this.nodeKeyCache.hasKey(id)) {
|
|
1026
|
-
return this.nodeKeyCache.getKey(id);
|
|
1027
|
-
}
|
|
1028
|
-
const loader = this.idToLoader.get(id);
|
|
1029
|
-
if (!loader) {
|
|
1030
|
-
throw new LightsparkSigningException2(
|
|
1031
|
-
"No signing key loader found for node " + id
|
|
1032
|
-
);
|
|
1033
|
-
}
|
|
1034
|
-
const loaderResult = await loader.loadSigningKey();
|
|
1035
|
-
if (!loaderResult) {
|
|
1036
|
-
return;
|
|
1037
|
-
}
|
|
1038
|
-
const key = await this.nodeKeyCache.loadKey(
|
|
1039
|
-
id,
|
|
1040
|
-
{ key: loaderResult.key },
|
|
1041
|
-
loaderResult.type
|
|
1042
|
-
);
|
|
1043
|
-
return key || void 0;
|
|
1044
|
-
}
|
|
1045
|
-
};
|
|
1046
|
-
|
|
1047
1147
|
// src/client.ts
|
|
1048
1148
|
var sdkVersion = package_default.version;
|
|
1049
1149
|
var LightsparkClient = class {
|
|
@@ -1055,7 +1155,8 @@ var LightsparkClient = class {
|
|
|
1055
1155
|
* use, you should use the `AccountTokenAuthProvider`.
|
|
1056
1156
|
* @param serverUrl The base URL of the server to connect to. Defaults to lightspark production.
|
|
1057
1157
|
* @param cryptoImpl The crypto implementation to use. Defaults to web and node compatible crypto.
|
|
1058
|
-
* For React Native, you should use the `ReactNativeCrypto`
|
|
1158
|
+
* For React Native, you should use the `ReactNativeCrypto`
|
|
1159
|
+
* implementation from `@lightsparkdev/react-native`.
|
|
1059
1160
|
*/
|
|
1060
1161
|
constructor(authProvider = new StubAuthProvider(), serverUrl = "api.lightspark.com", cryptoImpl = DefaultCrypto2) {
|
|
1061
1162
|
this.authProvider = authProvider;
|
|
@@ -1081,9 +1182,11 @@ var LightsparkClient = class {
|
|
|
1081
1182
|
nodeKeyLoaderCache;
|
|
1082
1183
|
LIGHTSPARK_SDK_ENDPOINT = process.env.LIGHTSPARK_SDK_ENDPOINT || "graphql/server/2023-09-13";
|
|
1083
1184
|
/**
|
|
1084
|
-
* Sets the key loader for a node. This unlocks client operations that
|
|
1085
|
-
* Passing in [NodeIdAndPasswordSigningKeyLoaderArgs]
|
|
1086
|
-
*
|
|
1185
|
+
* Sets the key loader for a node. This unlocks client operations that
|
|
1186
|
+
* require a private key. Passing in [NodeIdAndPasswordSigningKeyLoaderArgs]
|
|
1187
|
+
* loads the RSA key for an OSK node.
|
|
1188
|
+
* Passing in [MasterSeedSigningKeyLoaderArgs] loads the Secp256k1 key for a
|
|
1189
|
+
* remote signing node.
|
|
1087
1190
|
*
|
|
1088
1191
|
* @param nodeId The ID of the node the key is for
|
|
1089
1192
|
* @param loader The loader for the key
|
|
@@ -1094,7 +1197,8 @@ var LightsparkClient = class {
|
|
|
1094
1197
|
return !!key;
|
|
1095
1198
|
}
|
|
1096
1199
|
/**
|
|
1097
|
-
* Gets the signing key for a node. Must have previously called
|
|
1200
|
+
* Gets the signing key for a node. Must have previously called
|
|
1201
|
+
* [loadNodeSigningKey].
|
|
1098
1202
|
*
|
|
1099
1203
|
* @param nodeId The ID of the node the key is for
|
|
1100
1204
|
* @returns The signing key for the node
|
|
@@ -1103,7 +1207,8 @@ var LightsparkClient = class {
|
|
|
1103
1207
|
return await this.nodeKeyLoaderCache.getKeyWithLoader(nodeId);
|
|
1104
1208
|
}
|
|
1105
1209
|
/**
|
|
1106
|
-
* Sets the auth provider for the client.
|
|
1210
|
+
* Sets the auth provider for the client.
|
|
1211
|
+
* This is useful for switching between auth providers if you are using
|
|
1107
1212
|
* multiple accounts or waiting for the user to log in.
|
|
1108
1213
|
*
|
|
1109
1214
|
* @param authProvider
|
|
@@ -1182,7 +1287,8 @@ var LightsparkClient = class {
|
|
|
1182
1287
|
) ?? [];
|
|
1183
1288
|
}
|
|
1184
1289
|
/**
|
|
1185
|
-
* Starts listening for new transactions or updates to existing transactions
|
|
1290
|
+
* Starts listening for new transactions or updates to existing transactions
|
|
1291
|
+
* for a list of nodes.
|
|
1186
1292
|
*
|
|
1187
1293
|
* @param nodeIds The node IDs for which to listen to transactions.
|
|
1188
1294
|
* @returns A zen-observable that emits transaction updates for the given node IDs.
|
|
@@ -1199,8 +1305,8 @@ var LightsparkClient = class {
|
|
|
1199
1305
|
);
|
|
1200
1306
|
}
|
|
1201
1307
|
/**
|
|
1202
|
-
* Retrieves a dashboard of basic info for the authenticated account.
|
|
1203
|
-
* included.
|
|
1308
|
+
* Retrieves a dashboard of basic info for the authenticated account.
|
|
1309
|
+
* See `AccountDashboard` for which info is included.
|
|
1204
1310
|
*
|
|
1205
1311
|
* @param nodeIds The node IDs to include in the dashboard. Defaults to undefined (all nodes).
|
|
1206
1312
|
* @param bitcoinNetwork The bitcoin network to include in the dashboard. Defaults to MAINNET.
|
|
@@ -1267,8 +1373,8 @@ var LightsparkClient = class {
|
|
|
1267
1373
|
};
|
|
1268
1374
|
}
|
|
1269
1375
|
/**
|
|
1270
|
-
* Gets a basic dashboard for a single node, including recent transactions.
|
|
1271
|
-
* included.
|
|
1376
|
+
* Gets a basic dashboard for a single node, including recent transactions.
|
|
1377
|
+
* See `SingleNodeDashboard` for which info is included.
|
|
1272
1378
|
*
|
|
1273
1379
|
* @param nodeId The node ID for which to get a dashboard.
|
|
1274
1380
|
* @param bitcoinNetwork The bitcoin network for which to get a dashboard. Defaults to MAINNET.
|
|
@@ -1339,7 +1445,8 @@ var LightsparkClient = class {
|
|
|
1339
1445
|
/**
|
|
1340
1446
|
* Creates an invoice for the given node.
|
|
1341
1447
|
*
|
|
1342
|
-
* Test mode note: You can simulate a payment of this invoice in test move
|
|
1448
|
+
* Test mode note: You can simulate a payment of this invoice in test move
|
|
1449
|
+
* using [createTestModePayment].
|
|
1343
1450
|
*
|
|
1344
1451
|
* @param nodeId The node ID for which to create an invoice.
|
|
1345
1452
|
* @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
|
|
@@ -1367,11 +1474,13 @@ var LightsparkClient = class {
|
|
|
1367
1474
|
return response.create_invoice?.invoice.data?.encoded_payment_request;
|
|
1368
1475
|
}
|
|
1369
1476
|
/**
|
|
1370
|
-
* Generates a Lightning Invoice (follows the Bolt 11 specification) to
|
|
1371
|
-
* from another Lightning Node.
|
|
1477
|
+
* Generates a Lightning Invoice (follows the Bolt 11 specification) to
|
|
1478
|
+
* request a payment from another Lightning Node.
|
|
1479
|
+
* This should only be used for generating invoices for LNURLs,
|
|
1372
1480
|
* with [createInvoice] preferred in the general case.
|
|
1373
1481
|
*
|
|
1374
|
-
* Test mode note: You can simulate a payment of this invoice in test move
|
|
1482
|
+
* Test mode note: You can simulate a payment of this invoice in test move
|
|
1483
|
+
* using [createTestModePayment].
|
|
1375
1484
|
*
|
|
1376
1485
|
* @param nodeId The node ID for which to create an invoice.
|
|
1377
1486
|
* @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
|
|
@@ -1402,10 +1511,12 @@ var LightsparkClient = class {
|
|
|
1402
1511
|
return InvoiceFromJson(invoiceJson);
|
|
1403
1512
|
}
|
|
1404
1513
|
/**
|
|
1405
|
-
* Creates a new invoice for the UMA protocol.
|
|
1406
|
-
*
|
|
1407
|
-
*
|
|
1408
|
-
*
|
|
1514
|
+
* Creates a new invoice for the UMA protocol.
|
|
1515
|
+
* The metadata is hashed and included in the invoice.
|
|
1516
|
+
* This API generates a Lightning Invoice (follows the Bolt 11 specification)
|
|
1517
|
+
* to request a payment from another Lightning Node.
|
|
1518
|
+
* This should only be used for generating invoices for UMA,
|
|
1519
|
+
* with `createInvoice` preferred in the general case.
|
|
1409
1520
|
*
|
|
1410
1521
|
* @param nodeId The node ID for which to create an invoice.
|
|
1411
1522
|
* @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
|
|
@@ -1446,7 +1557,8 @@ var LightsparkClient = class {
|
|
|
1446
1557
|
return InvoiceDataFromJson(response.decoded_payment_request);
|
|
1447
1558
|
}
|
|
1448
1559
|
/**
|
|
1449
|
-
* Gets an estimate of the fee for sending a payment over the given bitcoin
|
|
1560
|
+
* Gets an estimate of the fee for sending a payment over the given bitcoin
|
|
1561
|
+
* network.
|
|
1450
1562
|
*
|
|
1451
1563
|
* @param bitcoinNetwork The bitcoin network for which to get a fee estimate. Defaults to MAINNET.
|
|
1452
1564
|
* @returns A fee estimate for the given bitcoin network including a minimum fee rate, and a max-speed fee rate.
|
|
@@ -1483,7 +1595,8 @@ var LightsparkClient = class {
|
|
|
1483
1595
|
);
|
|
1484
1596
|
}
|
|
1485
1597
|
/**
|
|
1486
|
-
* Returns an estimate of the fees that will be paid to send a payment to
|
|
1598
|
+
* Returns an estimate of the fees that will be paid to send a payment to
|
|
1599
|
+
* another Lightning node.
|
|
1487
1600
|
*
|
|
1488
1601
|
* @param nodeId The node from where you want to send the payment.
|
|
1489
1602
|
* @param destinationNodePublicKey The public key of the node that you want to pay.
|
|
@@ -1519,17 +1632,20 @@ var LightsparkClient = class {
|
|
|
1519
1632
|
/**
|
|
1520
1633
|
* Sends a lightning payment for a given invoice.
|
|
1521
1634
|
*
|
|
1522
|
-
* Test mode note: For test mode, you can use the [createTestModeInvoice]
|
|
1523
|
-
* pay in test mode.
|
|
1635
|
+
* Test mode note: For test mode, you can use the [createTestModeInvoice]
|
|
1636
|
+
* function to create an invoice you can pay in test mode.
|
|
1524
1637
|
*
|
|
1525
1638
|
* @param payerNodeId The ID of the node that will pay the invoice.
|
|
1526
1639
|
* @param encodedInvoice The encoded invoice to pay.
|
|
1527
1640
|
* @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
|
|
1528
|
-
* As guidance, a maximum fee of 16 basis points should make almost all
|
|
1529
|
-
*
|
|
1641
|
+
* As guidance, a maximum fee of 16 basis points should make almost all
|
|
1642
|
+
* transactions succeed. For example,
|
|
1643
|
+
* for a transaction between 10k sats and 100k sats,
|
|
1644
|
+
* this would mean a fee limit of 16 to 160 sats.
|
|
1530
1645
|
* @param timeoutSecs A timeout for the payment in seconds. Defaults to 60 seconds.
|
|
1531
1646
|
* @param amountMsats The amount to pay in msats for a zero-amount invoice. Defaults to the full amount of the
|
|
1532
|
-
* invoice. NOTE: This parameter can only be passed for a zero-amount
|
|
1647
|
+
* invoice. NOTE: This parameter can only be passed for a zero-amount
|
|
1648
|
+
* invoice. Otherwise, the call will fail.
|
|
1533
1649
|
* @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
|
|
1534
1650
|
*/
|
|
1535
1651
|
async payInvoice(payerNodeId, encodedInvoice, maximumFeesMsats, timeoutSecs = 60, amountMsats = void 0) {
|
|
@@ -1559,18 +1675,23 @@ var LightsparkClient = class {
|
|
|
1559
1675
|
return response.pay_invoice && OutgoingPaymentFromJson(response.pay_invoice.payment);
|
|
1560
1676
|
}
|
|
1561
1677
|
/**
|
|
1562
|
-
* sends an UMA payment to a node on the Lightning Network,
|
|
1563
|
-
* (as defined by the BOLT11 specification) that you
|
|
1564
|
-
*
|
|
1678
|
+
* sends an UMA payment to a node on the Lightning Network,
|
|
1679
|
+
* based on the invoice (as defined by the BOLT11 specification) that you
|
|
1680
|
+
* provide.
|
|
1681
|
+
* This should only be used for paying UMA invoices,
|
|
1682
|
+
* with `payInvoice` preferred in the general case.
|
|
1565
1683
|
*
|
|
1566
1684
|
* @param payerNodeId The ID of the node that will pay the invoice.
|
|
1567
1685
|
* @param encodedInvoice The encoded invoice to pay.
|
|
1568
1686
|
* @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
|
|
1569
|
-
* As guidance, a maximum fee of 16 basis points should make almost all
|
|
1570
|
-
*
|
|
1687
|
+
* As guidance, a maximum fee of 16 basis points should make almost all
|
|
1688
|
+
* transactions succeed. For example,
|
|
1689
|
+
* for a transaction between 10k sats and 100k sats,
|
|
1690
|
+
* this would mean a fee limit of 16 to 160 sats.
|
|
1571
1691
|
* @param timeoutSecs A timeout for the payment in seconds. Defaults to 60 seconds.
|
|
1572
1692
|
* @param amountMsats The amount to pay in msats for a zero-amount invoice. Defaults to the full amount of the
|
|
1573
|
-
* invoice. NOTE: This parameter can only be passed for a zero-amount
|
|
1693
|
+
* invoice. NOTE: This parameter can only be passed for a zero-amount
|
|
1694
|
+
* invoice. Otherwise, the call will fail.
|
|
1574
1695
|
* @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
|
|
1575
1696
|
*/
|
|
1576
1697
|
async payUmaInvoice(payerNodeId, encodedInvoice, maximumFeesMsats, timeoutSecs = 60, amountMsats = void 0) {
|
|
@@ -1600,7 +1721,8 @@ var LightsparkClient = class {
|
|
|
1600
1721
|
return response.pay_uma_invoice && OutgoingPaymentFromJson(response.pay_invoice.payment);
|
|
1601
1722
|
}
|
|
1602
1723
|
/**
|
|
1603
|
-
* Waits for a transaction to have a completed status, and returns the
|
|
1724
|
+
* Waits for a transaction to have a completed status, and returns the
|
|
1725
|
+
* transaction.
|
|
1604
1726
|
*
|
|
1605
1727
|
* @param transactionId The ID of the transaction to wait for
|
|
1606
1728
|
* @param pollTimeoutSecs The timeout in seconds that we will wait before throwing an exception
|
|
@@ -1637,15 +1759,18 @@ var LightsparkClient = class {
|
|
|
1637
1759
|
return transaction;
|
|
1638
1760
|
}
|
|
1639
1761
|
/**
|
|
1640
|
-
* Sends a payment directly to a node on the Lightning Network through the
|
|
1762
|
+
* Sends a payment directly to a node on the Lightning Network through the
|
|
1763
|
+
* public key of the node without an invoice.
|
|
1641
1764
|
*
|
|
1642
1765
|
* @param payerNodeId The ID of the node that will send the payment.
|
|
1643
1766
|
* @param destinationPublicKey The public key of the destination node.
|
|
1644
1767
|
* @param timeoutSecs The timeout in seconds that we will try to make the payment.
|
|
1645
1768
|
* @param amountMsats The amount to pay in msats.
|
|
1646
1769
|
* @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
|
|
1647
|
-
* As guidance, a maximum fee of 15 basis points should make almost all
|
|
1648
|
-
*
|
|
1770
|
+
* As guidance, a maximum fee of 15 basis points should make almost all
|
|
1771
|
+
* transactions succeed. For example,
|
|
1772
|
+
* for a transaction between 10k sats and 100k sats,
|
|
1773
|
+
* this would mean a fee limit of 15 to 150 sats.
|
|
1649
1774
|
* @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
|
|
1650
1775
|
*/
|
|
1651
1776
|
async sendPayment(payerNodeId, destinationPublicKey, timeoutSecs = 60, amountMsats, maximumFeesMsats) {
|
|
@@ -1672,7 +1797,8 @@ var LightsparkClient = class {
|
|
|
1672
1797
|
return response.send_payment && OutgoingPaymentFromJson(response.send_payment.payment);
|
|
1673
1798
|
}
|
|
1674
1799
|
/**
|
|
1675
|
-
* Creates an L1 Bitcoin wallet address for a given node which can be used to
|
|
1800
|
+
* Creates an L1 Bitcoin wallet address for a given node which can be used to
|
|
1801
|
+
* deposit or withdraw funds.
|
|
1676
1802
|
*
|
|
1677
1803
|
* @param nodeId The ID of the node to create a wallet address for.
|
|
1678
1804
|
* @returns A string containing the wallet address for the given node.
|
|
@@ -1685,12 +1811,15 @@ var LightsparkClient = class {
|
|
|
1685
1811
|
return response.create_node_wallet_address.wallet_address;
|
|
1686
1812
|
}
|
|
1687
1813
|
/**
|
|
1688
|
-
* Withdraws funds from the account and sends it to the requested bitcoin
|
|
1814
|
+
* Withdraws funds from the account and sends it to the requested bitcoin
|
|
1815
|
+
* address.
|
|
1689
1816
|
*
|
|
1690
|
-
* Depending on the chosen mode, it will first take the funds from the
|
|
1691
|
-
*
|
|
1692
|
-
*
|
|
1693
|
-
*
|
|
1817
|
+
* Depending on the chosen mode, it will first take the funds from the
|
|
1818
|
+
* wallet, and if applicable, close channels appropriately to recover enough
|
|
1819
|
+
* funds and reopen channels with the remaining funds.
|
|
1820
|
+
* The process is asynchronous and may take up to a few minutes.
|
|
1821
|
+
* You can check the progress by polling the `WithdrawalRequest` that is
|
|
1822
|
+
* created, or by subscribing to a webhook.
|
|
1694
1823
|
*
|
|
1695
1824
|
* @param nodeId The ID of the node from which to withdraw funds.
|
|
1696
1825
|
* @param amountSats The amount of funds to withdraw in satoshis.
|
|
@@ -1711,9 +1840,10 @@ var LightsparkClient = class {
|
|
|
1711
1840
|
return WithdrawalRequestFromJson(response.request_withdrawal.request);
|
|
1712
1841
|
}
|
|
1713
1842
|
/**
|
|
1714
|
-
* Adds funds to a Lightspark node on the REGTEST network.
|
|
1715
|
-
*
|
|
1716
|
-
*
|
|
1843
|
+
* Adds funds to a Lightspark node on the REGTEST network.
|
|
1844
|
+
* If the amount is not specified, 10,000,000 SATOSHI will be added.
|
|
1845
|
+
* This API only functions for nodes created on the REGTEST network and will
|
|
1846
|
+
* return an error when called for any non-REGTEST node.
|
|
1717
1847
|
*
|
|
1718
1848
|
* @param nodeId The ID of the node to fund. Must be a REGTEST node.
|
|
1719
1849
|
* @param amountSats The amount of funds to add to the node in satoshis. Defaults to 10,000,000 SATOSHI.
|
|
@@ -1727,8 +1857,8 @@ var LightsparkClient = class {
|
|
|
1727
1857
|
return CurrencyAmountFromJson(response.fund_node.amount);
|
|
1728
1858
|
}
|
|
1729
1859
|
/**
|
|
1730
|
-
* Creates a new API token that can be used to authenticate requests for this
|
|
1731
|
-
* and SDKs.
|
|
1860
|
+
* Creates a new API token that can be used to authenticate requests for this
|
|
1861
|
+
* account when using the Lightspark APIs and SDKs.
|
|
1732
1862
|
*
|
|
1733
1863
|
* @param name Creates a new API token that can be used to authenticate requests for this account when using the
|
|
1734
1864
|
* Lightspark APIs and SDKs.
|
|
@@ -1765,8 +1895,9 @@ var LightsparkClient = class {
|
|
|
1765
1895
|
await this.requester.makeRawRequest(DeleteApiToken, { api_token_id: id });
|
|
1766
1896
|
}
|
|
1767
1897
|
/**
|
|
1768
|
-
* In test mode, generates a Lightning Invoice which can be paid by a local
|
|
1769
|
-
* This call is only valid in test mode.
|
|
1898
|
+
* In test mode, generates a Lightning Invoice which can be paid by a local
|
|
1899
|
+
* node. This call is only valid in test mode.
|
|
1900
|
+
* You can then pay the invoice using [payInvoice].
|
|
1770
1901
|
*
|
|
1771
1902
|
* @param localNodeId The ID of the node that will pay the invoice.
|
|
1772
1903
|
* @param amountMsats The amount to pay in milli-satoshis.
|
|
@@ -1795,8 +1926,9 @@ var LightsparkClient = class {
|
|
|
1795
1926
|
});
|
|
1796
1927
|
}
|
|
1797
1928
|
/**
|
|
1798
|
-
* In test mode, simulates a payment of a Lightning Invoice from another
|
|
1799
|
-
* This can only be used in test mode and should be used with invoices
|
|
1929
|
+
* In test mode, simulates a payment of a Lightning Invoice from another
|
|
1930
|
+
* node. This can only be used in test mode and should be used with invoices
|
|
1931
|
+
* generated by [createInvoice].
|
|
1800
1932
|
*
|
|
1801
1933
|
* @param localNodeId The ID of the node that will receive the payment.
|
|
1802
1934
|
* @param encodedInvoice The encoded invoice to pay.
|
|
@@ -1818,10 +1950,156 @@ var LightsparkClient = class {
|
|
|
1818
1950
|
}
|
|
1819
1951
|
});
|
|
1820
1952
|
}
|
|
1953
|
+
/**
|
|
1954
|
+
* Creates an UMA invitation. If you are part of the incentive program,
|
|
1955
|
+
* you should use [createUmaInvitationWithIncentives].
|
|
1956
|
+
*
|
|
1957
|
+
* @param inviterUma The UMA of the inviter.
|
|
1958
|
+
* @returns The invitation that was created.
|
|
1959
|
+
*/
|
|
1960
|
+
async createUmaInvitation(inviterUma) {
|
|
1961
|
+
return await this.executeRawQuery({
|
|
1962
|
+
queryPayload: CreateUmaInvitation,
|
|
1963
|
+
variables: {
|
|
1964
|
+
inviterUma
|
|
1965
|
+
},
|
|
1966
|
+
constructObject: (responseJson) => {
|
|
1967
|
+
if (!responseJson.create_uma_invitation?.invitation) {
|
|
1968
|
+
throw new LightsparkException(
|
|
1969
|
+
"CreateUmaInvitationError",
|
|
1970
|
+
"Unable to create UMA invitation"
|
|
1971
|
+
);
|
|
1972
|
+
}
|
|
1973
|
+
return UmaInvitationFromJson(
|
|
1974
|
+
responseJson.create_uma_invitation?.invitation
|
|
1975
|
+
);
|
|
1976
|
+
}
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* Creates an UMA invitation as part of the incentive program.
|
|
1981
|
+
* @param inviterUma The UMA of the inviter.
|
|
1982
|
+
* @param inviterPhoneNumber The phone number of the inviter in E164 format.
|
|
1983
|
+
* @param inviterRegion The region of the inviter.
|
|
1984
|
+
* @returns The invitation that was created.
|
|
1985
|
+
*/
|
|
1986
|
+
async createUmaInvitationWithIncentives(inviterUma, inviterPhoneNumber, inviterRegion) {
|
|
1987
|
+
const inviterPhoneHash = await this.hashPhoneNumber(inviterPhoneNumber);
|
|
1988
|
+
return await this.executeRawQuery({
|
|
1989
|
+
queryPayload: CreateUmaInvitationWithIncentives,
|
|
1990
|
+
variables: {
|
|
1991
|
+
inviterUma,
|
|
1992
|
+
inviterPhoneHash,
|
|
1993
|
+
inviterRegion
|
|
1994
|
+
},
|
|
1995
|
+
constructObject: (responseJson) => {
|
|
1996
|
+
if (!responseJson.create_uma_invitation_with_incentives?.invitation) {
|
|
1997
|
+
throw new LightsparkException(
|
|
1998
|
+
"CreateUmaInvitationError",
|
|
1999
|
+
"Unable to create UMA invitation"
|
|
2000
|
+
);
|
|
2001
|
+
}
|
|
2002
|
+
return UmaInvitationFromJson(
|
|
2003
|
+
responseJson.create_uma_invitation_with_incentives?.invitation
|
|
2004
|
+
);
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
/**
|
|
2009
|
+
* Claims an UMA invitation. If you are part of the incentive program,
|
|
2010
|
+
* you should use [claimUmaInvitationWithIncentives].
|
|
2011
|
+
*
|
|
2012
|
+
* @param invitationCode The invitation code to claim.
|
|
2013
|
+
* @param inviteeUma The UMA of the invitee.
|
|
2014
|
+
* @returns The invitation that was claimed.
|
|
2015
|
+
*/
|
|
2016
|
+
async claimUmaInvitation(invitationCode, inviteeUma) {
|
|
2017
|
+
return await this.executeRawQuery({
|
|
2018
|
+
queryPayload: ClaimUmaInvitation,
|
|
2019
|
+
variables: {
|
|
2020
|
+
invitationCode,
|
|
2021
|
+
inviteeUma
|
|
2022
|
+
},
|
|
2023
|
+
constructObject: (responseJson) => {
|
|
2024
|
+
if (!responseJson.claim_uma_invitation?.invitation) {
|
|
2025
|
+
throw new LightsparkException(
|
|
2026
|
+
"ClaimUmaInvitationError",
|
|
2027
|
+
"Unable to claim UMA invitation"
|
|
2028
|
+
);
|
|
2029
|
+
}
|
|
2030
|
+
return UmaInvitationFromJson(
|
|
2031
|
+
responseJson.claim_uma_invitation?.invitation
|
|
2032
|
+
);
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Claims an UMA invitation as part of the incentive program.
|
|
2038
|
+
*
|
|
2039
|
+
* @param invitationCode The invitation code to claim.
|
|
2040
|
+
* @param inviteeUma The UMA of the invitee.
|
|
2041
|
+
* @param inviteePhoneNumber The phone number of the invitee in E164 format.
|
|
2042
|
+
* @param inviteeRegion The region of the invitee.
|
|
2043
|
+
* @returns The invitation that was claimed.
|
|
2044
|
+
*/
|
|
2045
|
+
async claimUmaInvitationWithIncentives(invitationCode, inviteeUma, inviteePhoneNumber, inviteeRegion) {
|
|
2046
|
+
const inviteePhoneHash = await this.hashPhoneNumber(inviteePhoneNumber);
|
|
2047
|
+
return await this.executeRawQuery({
|
|
2048
|
+
queryPayload: ClaimUmaInvitationWithIncentives,
|
|
2049
|
+
variables: {
|
|
2050
|
+
invitationCode,
|
|
2051
|
+
inviteeUma,
|
|
2052
|
+
inviteePhoneHash,
|
|
2053
|
+
inviteeRegion
|
|
2054
|
+
},
|
|
2055
|
+
constructObject: (responseJson) => {
|
|
2056
|
+
if (!responseJson.claim_uma_invitation_with_incentives?.invitation) {
|
|
2057
|
+
throw new LightsparkException(
|
|
2058
|
+
"ClaimUmaInvitationError",
|
|
2059
|
+
"Unable to claim UMA invitation"
|
|
2060
|
+
);
|
|
2061
|
+
}
|
|
2062
|
+
return UmaInvitationFromJson(
|
|
2063
|
+
responseJson.claim_uma_invitation_with_incentives?.invitation
|
|
2064
|
+
);
|
|
2065
|
+
}
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
/**
|
|
2069
|
+
* Fetches an UMA invitation by its invitation code.
|
|
2070
|
+
*
|
|
2071
|
+
* @param invitationCode The code of the invitation to fetch.
|
|
2072
|
+
* @returns The invitation with the given code, or null if no invitation exists with that code.
|
|
2073
|
+
*/
|
|
2074
|
+
async fetchUmaInvitation(invitationCode) {
|
|
2075
|
+
return await this.executeRawQuery({
|
|
2076
|
+
queryPayload: FetchUmaInvitation,
|
|
2077
|
+
variables: {
|
|
2078
|
+
invitationCode
|
|
2079
|
+
},
|
|
2080
|
+
constructObject: (responseJson) => {
|
|
2081
|
+
if (!responseJson.uma_invitation_by_code) {
|
|
2082
|
+
return null;
|
|
2083
|
+
}
|
|
2084
|
+
return UmaInvitationFromJson(responseJson.uma_invitation_by_code);
|
|
2085
|
+
}
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
async hashPhoneNumber(e164PhoneNumber) {
|
|
2089
|
+
const e164PhoneRegex = /^\+[1-9]\d{1,14}$/;
|
|
2090
|
+
if (!e164PhoneRegex.test(e164PhoneNumber)) {
|
|
2091
|
+
throw new LightsparkException(
|
|
2092
|
+
"InvalidPhoneNumber",
|
|
2093
|
+
"Invalid phone number. Phone number must be in E164 format."
|
|
2094
|
+
);
|
|
2095
|
+
}
|
|
2096
|
+
return await createSha256Hash(e164PhoneNumber, true);
|
|
2097
|
+
}
|
|
1821
2098
|
/**
|
|
1822
2099
|
* Executes a raw `Query` against the Lightspark API.
|
|
1823
2100
|
*
|
|
1824
|
-
* This generally should not be used directly,
|
|
2101
|
+
* This generally should not be used directly,
|
|
2102
|
+
* but is exposed for advanced use cases and for internal use to retrieve
|
|
1825
2103
|
* complex fields from objects.
|
|
1826
2104
|
*
|
|
1827
2105
|
* @param query The `Query` to execute.
|
|
@@ -1896,6 +2174,8 @@ export {
|
|
|
1896
2174
|
CurrencyUnit_default as CurrencyUnit,
|
|
1897
2175
|
GraphNode_default as GraphNode,
|
|
1898
2176
|
HtlcAttemptFailureCode_default as HtlcAttemptFailureCode,
|
|
2177
|
+
IncentivesIneligibilityReason_default as IncentivesIneligibilityReason,
|
|
2178
|
+
IncentivesStatus_default as IncentivesStatus,
|
|
1899
2179
|
IncomingPayment_default as IncomingPayment,
|
|
1900
2180
|
IncomingPaymentAttemptStatus_default as IncomingPaymentAttemptStatus,
|
|
1901
2181
|
InvoiceType_default as InvoiceType,
|
|
@@ -1911,6 +2191,7 @@ export {
|
|
|
1911
2191
|
PaymentFailureReason_default as PaymentFailureReason,
|
|
1912
2192
|
PaymentRequestStatus_default as PaymentRequestStatus,
|
|
1913
2193
|
Permission_default as Permission,
|
|
2194
|
+
RegionCode_default as RegionCode,
|
|
1914
2195
|
RemoteSigningSubEventType_default as RemoteSigningSubEventType,
|
|
1915
2196
|
RemoteSigningWebhookHandler,
|
|
1916
2197
|
RiskRating_default as RiskRating,
|
|
@@ -1944,6 +2225,7 @@ export {
|
|
|
1944
2225
|
getSignablePayloadQuery,
|
|
1945
2226
|
getSignableQuery,
|
|
1946
2227
|
getTransactionQuery,
|
|
2228
|
+
getUmaInvitationQuery,
|
|
1947
2229
|
getWithdrawalQuery,
|
|
1948
2230
|
isBitcoinNetwork,
|
|
1949
2231
|
verifyAndParseWebhook
|