@lightsparkdev/lightspark-sdk 1.0.0 → 1.0.2
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 +19 -0
- package/dist/BitcoinNetwork-a816c0be.d.ts +18 -0
- package/dist/chunk-5RDIWPBE.js +27 -0
- package/dist/{chunk-LZC5C5NI.js → chunk-K2ZU5YQL.js} +4 -12
- package/dist/chunk-K6SAUSAX.js +14 -0
- package/dist/env.cjs +101 -0
- package/dist/env.d.ts +17 -0
- package/dist/env.js +47 -0
- package/dist/{index-09d4ac20.d.ts → index-dbf06298.d.ts} +2 -18
- package/dist/index.cjs +70 -22
- package/dist/index.d.ts +8 -3
- package/dist/index.js +54 -25
- package/dist/objects/index.d.ts +2 -1
- package/dist/objects/index.js +4 -2
- package/package.json +15 -3
- package/src/NodeKeyLoaderCache.ts +3 -1
- package/src/SigningKeyLoader.ts +28 -20
- package/src/env.ts +54 -0
- package/src/helpers.ts +31 -0
- package/src/index.ts +1 -0
- package/src/lightspark_crypto/lightspark_crypto.d.ts +0 -157
- package/src/lightspark_crypto/lightspark_crypto.js +0 -1010
- package/src/lightspark_crypto/lightspark_crypto_bg.wasm +0 -0
- package/src/lightspark_crypto/lightspark_crypto_bg.wasm.d.ts +0 -120
- package/src/lightspark_crypto/package.json +0 -11
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertValidBitcoinNetwork,
|
|
3
|
+
getBitcoinNetworkOrThrow,
|
|
4
|
+
isBitcoinNetwork
|
|
5
|
+
} from "./chunk-5RDIWPBE.js";
|
|
1
6
|
import {
|
|
2
7
|
AccountToChannelsConnection_default,
|
|
3
8
|
Account_default,
|
|
4
9
|
ApiTokenFromJson,
|
|
5
|
-
BitcoinNetwork_default,
|
|
6
10
|
ChannelStatus_default,
|
|
7
11
|
Channel_default,
|
|
8
12
|
ComplianceProvider_default,
|
|
@@ -72,7 +76,10 @@ import {
|
|
|
72
76
|
getSignableQuery,
|
|
73
77
|
getTransactionQuery,
|
|
74
78
|
getWithdrawalQuery
|
|
75
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-K2ZU5YQL.js";
|
|
80
|
+
import {
|
|
81
|
+
BitcoinNetwork_default
|
|
82
|
+
} from "./chunk-K6SAUSAX.js";
|
|
76
83
|
import "./chunk-NIMBE7W3.js";
|
|
77
84
|
|
|
78
85
|
// src/auth/AccountTokenAuthProvider.ts
|
|
@@ -122,7 +129,7 @@ import { createHash } from "crypto";
|
|
|
122
129
|
// package.json
|
|
123
130
|
var package_default = {
|
|
124
131
|
name: "@lightsparkdev/lightspark-sdk",
|
|
125
|
-
version: "1.0.
|
|
132
|
+
version: "1.0.2",
|
|
126
133
|
description: "Lightspark JS SDK",
|
|
127
134
|
author: "Lightspark Inc.",
|
|
128
135
|
keywords: [
|
|
@@ -163,6 +170,16 @@ var package_default = {
|
|
|
163
170
|
module: "./dist/objects/index.js",
|
|
164
171
|
require: "./dist/objects/index.cjs",
|
|
165
172
|
default: "./dist/objects/index.cjs"
|
|
173
|
+
},
|
|
174
|
+
"./env": {
|
|
175
|
+
types: "./dist/env.d.ts",
|
|
176
|
+
import: {
|
|
177
|
+
types: "./dist/env.d.ts",
|
|
178
|
+
default: "./dist/env.js"
|
|
179
|
+
},
|
|
180
|
+
module: "./dist/env.js",
|
|
181
|
+
require: "./dist/env.cjs",
|
|
182
|
+
default: "./dist/env.cjs"
|
|
166
183
|
}
|
|
167
184
|
},
|
|
168
185
|
type: "module",
|
|
@@ -180,7 +197,7 @@ var package_default = {
|
|
|
180
197
|
"CHANGELOG.md"
|
|
181
198
|
],
|
|
182
199
|
scripts: {
|
|
183
|
-
build: "tsup",
|
|
200
|
+
build: "yarn tsc && tsup",
|
|
184
201
|
clean: "rm -rf .turbo && rm -rf dist",
|
|
185
202
|
dev: "yarn build -- --watch",
|
|
186
203
|
docs: "typedoc src",
|
|
@@ -197,11 +214,13 @@ var package_default = {
|
|
|
197
214
|
},
|
|
198
215
|
license: "Apache-2.0",
|
|
199
216
|
dependencies: {
|
|
200
|
-
"@lightsparkdev/core": "1.0.
|
|
217
|
+
"@lightsparkdev/core": "1.0.1",
|
|
218
|
+
"@lightsparkdev/crypto-wasm": "0.1.0",
|
|
201
219
|
"auto-bind": "^5.0.1",
|
|
202
220
|
crypto: "^1.0.1",
|
|
203
221
|
"crypto-browserify": "^3.12.0",
|
|
204
222
|
dayjs: "^1.11.7",
|
|
223
|
+
dotenv: "^16.3.1",
|
|
205
224
|
graphql: "^16.6.0",
|
|
206
225
|
"graphql-ws": "^5.11.3",
|
|
207
226
|
ws: "^8.12.1",
|
|
@@ -801,12 +820,14 @@ ${FRAGMENT10}
|
|
|
801
820
|
|
|
802
821
|
// src/NodeKeyLoaderCache.ts
|
|
803
822
|
import {
|
|
823
|
+
DefaultCrypto,
|
|
804
824
|
LightsparkSigningException as LightsparkSigningException2
|
|
805
825
|
} from "@lightsparkdev/core";
|
|
806
826
|
|
|
807
827
|
// src/SigningKeyLoader.ts
|
|
808
828
|
import {
|
|
809
829
|
b64encode as b64encode2,
|
|
830
|
+
isBrowser,
|
|
810
831
|
LightsparkSigningException,
|
|
811
832
|
SigningKeyType
|
|
812
833
|
} from "@lightsparkdev/core";
|
|
@@ -827,25 +848,7 @@ var RecoverNodeSigningKey = `
|
|
|
827
848
|
`;
|
|
828
849
|
|
|
829
850
|
// src/SigningKeyLoader.ts
|
|
830
|
-
import {
|
|
831
|
-
LightsparkSigner,
|
|
832
|
-
Network
|
|
833
|
-
} from "../src/lightspark_crypto/lightspark_crypto.js";
|
|
834
851
|
var SIGNING_KEY_PATH = "m/5";
|
|
835
|
-
var getCryptoLibNetwork = (bitcoinNetwork) => {
|
|
836
|
-
switch (bitcoinNetwork) {
|
|
837
|
-
case BitcoinNetwork_default.MAINNET:
|
|
838
|
-
return Network.Bitcoin;
|
|
839
|
-
case BitcoinNetwork_default.TESTNET:
|
|
840
|
-
return Network.Testnet;
|
|
841
|
-
case BitcoinNetwork_default.REGTEST:
|
|
842
|
-
return Network.Regtest;
|
|
843
|
-
default:
|
|
844
|
-
throw new Error(
|
|
845
|
-
`Unsupported lightspark_crypto network ${bitcoinNetwork}.`
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
852
|
function isNodeIdAndPasswordSigningKeyLoaderArgs(args) {
|
|
850
853
|
return args.password !== void 0;
|
|
851
854
|
}
|
|
@@ -908,9 +911,31 @@ var MasterSeedSigningKeyLoader = class {
|
|
|
908
911
|
this.network = args.network;
|
|
909
912
|
}
|
|
910
913
|
async loadSigningKey() {
|
|
914
|
+
if (isBrowser) {
|
|
915
|
+
throw new LightsparkSigningException(
|
|
916
|
+
"Browser environments not supported for master seed signing key loader."
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
const { LightsparkSigner, Network } = await import("@lightsparkdev/crypto-wasm");
|
|
920
|
+
let cryptoLibNetwork;
|
|
921
|
+
switch (this.network) {
|
|
922
|
+
case BitcoinNetwork_default.MAINNET:
|
|
923
|
+
cryptoLibNetwork = Network.Bitcoin;
|
|
924
|
+
break;
|
|
925
|
+
case BitcoinNetwork_default.TESTNET:
|
|
926
|
+
cryptoLibNetwork = Network.Testnet;
|
|
927
|
+
break;
|
|
928
|
+
case BitcoinNetwork_default.REGTEST:
|
|
929
|
+
cryptoLibNetwork = Network.Regtest;
|
|
930
|
+
break;
|
|
931
|
+
default:
|
|
932
|
+
throw new Error(
|
|
933
|
+
`Unsupported lightspark_crypto network ${this.network}.`
|
|
934
|
+
);
|
|
935
|
+
}
|
|
911
936
|
const lightsparkSigner = LightsparkSigner.from_bytes(
|
|
912
937
|
this.masterSeed,
|
|
913
|
-
|
|
938
|
+
cryptoLibNetwork
|
|
914
939
|
);
|
|
915
940
|
const privateKey = lightsparkSigner.derive_private_key(SIGNING_KEY_PATH);
|
|
916
941
|
return { key: privateKey, type: SigningKeyType.Secp256k1SigningKey };
|
|
@@ -968,11 +993,12 @@ var NodeKeyLoaderCache = class {
|
|
|
968
993
|
if (!loaderResult) {
|
|
969
994
|
return;
|
|
970
995
|
}
|
|
971
|
-
|
|
996
|
+
const key = await this.nodeKeyCache.loadKey(
|
|
972
997
|
id,
|
|
973
998
|
{ key: loaderResult.key },
|
|
974
999
|
loaderResult.type
|
|
975
1000
|
);
|
|
1001
|
+
return key || void 0;
|
|
976
1002
|
}
|
|
977
1003
|
};
|
|
978
1004
|
|
|
@@ -1764,7 +1790,9 @@ export {
|
|
|
1764
1790
|
WithdrawalMode_default as WithdrawalMode,
|
|
1765
1791
|
WithdrawalRequest_default as WithdrawalRequest,
|
|
1766
1792
|
WithdrawalRequestStatus_default as WithdrawalRequestStatus,
|
|
1793
|
+
assertValidBitcoinNetwork,
|
|
1767
1794
|
getApiTokenQuery,
|
|
1795
|
+
getBitcoinNetworkOrThrow,
|
|
1768
1796
|
getChannelClosingTransactionQuery,
|
|
1769
1797
|
getChannelOpeningTransactionQuery,
|
|
1770
1798
|
getDepositQuery,
|
|
@@ -1780,5 +1808,6 @@ export {
|
|
|
1780
1808
|
getSignableQuery,
|
|
1781
1809
|
getTransactionQuery,
|
|
1782
1810
|
getWithdrawalQuery,
|
|
1811
|
+
isBitcoinNetwork,
|
|
1783
1812
|
verifyAndParseWebhook
|
|
1784
1813
|
};
|
package/dist/objects/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as
|
|
1
|
+
export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BlockchainBalance, C as Channel, j as ChannelClosingTransaction, l as ChannelFees, m as ChannelOpeningTransaction, o as ChannelStatus, p as ChannelToTransactionsConnection, q as ComplianceProvider, r as Connection, s as CreateApiTokenInput, t as CreateApiTokenOutput, u as CreateInvoiceInput, v as CreateInvoiceOutput, w as CreateLnurlInvoiceInput, x as CreateNodeWalletAddressInput, y as CreateNodeWalletAddressOutput, z as CreateTestModeInvoiceInput, D as CreateTestModeInvoiceOutput, E as CreateTestModePaymentInput, F as CreateTestModePaymentoutput, G as CreateUmaInvoiceInput, H as CurrencyAmount, I as CurrencyUnit, J as DeclineToSignMessagesInput, K as DeclineToSignMessagesOutput, M as DeleteApiTokenInput, N as DeleteApiTokenOutput, O as Deposit, Q as Entity, R as FeeEstimate, S as FundNodeInput, T as FundNodeOutput, U as GraphNode, V as Hop, Y as HtlcAttemptFailureCode, Z as IdAndSignature, _ as IncomingPayment, $ as IncomingPaymentAttempt, a1 as IncomingPaymentAttemptStatus, a2 as IncomingPaymentToAttemptsConnection, a3 as Invoice, a5 as InvoiceData, a6 as InvoiceType, a7 as LightningFeeEstimateForInvoiceInput, a8 as LightningFeeEstimateForNodeInput, a9 as LightningFeeEstimateOutput, aa as LightningTransaction, ac as LightsparkNode, ad as LightsparkNodeOwner, af as LightsparkNodeStatus, ag as LightsparkNodeToChannelsConnection, ah as LightsparkNodeWithOSK, ai as LightsparkNodeWithRemoteSigning, aj as Node, ak as NodeAddress, al as NodeAddressType, am as NodeToAddressesConnection, an as OnChainTransaction, ap as OutgoingPayment, aq as OutgoingPaymentAttempt, ar as OutgoingPaymentAttemptStatus, as as OutgoingPaymentAttemptToHopsConnection, av as OutgoingPaymentToAttemptsConnection, at as OutgoingPaymentsForInvoiceQueryInput, au as OutgoingPaymentsForInvoiceQueryOutput, aw as PageInfo, ax as PayInvoiceInput, ay as PayInvoiceOutput, aF as PayUmaInvoiceInput, az as PaymentDirection, aA as PaymentFailureReason, aB as PaymentRequest, aD as PaymentRequestData, aE as PaymentRequestStatus, aG as Permission, aH as PostTransactionData, aI as RegisterPaymentInput, aJ as RegisterPaymentOutput, aK as ReleaseChannelPerCommitmentSecretInput, aL as ReleaseChannelPerCommitmentSecretOutput, aM as ReleasePaymentPreimageInput, aN as ReleasePaymentPreimageOutput, aO as RemoteSigningSubEventType, aP as RequestWithdrawalInput, aQ as RequestWithdrawalOutput, aR as RichText, aS as RiskRating, aT as RoutingTransaction, aV as RoutingTransactionFailureReason, aW as ScreenNodeInput, aX as ScreenNodeOutput, aY as Secret, aZ as SendPaymentInput, a_ as SendPaymentOutput, a$ as SetInvoicePaymentHashInput, b0 as SetInvoicePaymentHashOutput, b6 as SignInvoiceInput, b7 as SignInvoiceOutput, b8 as SignMessagesInput, b9 as SignMessagesOutput, b1 as Signable, b3 as SignablePayload, b5 as SignablePayloadStatus, ba as SingleNodeDashboard, bb as Transaction, bd as TransactionFailures, be as TransactionStatus, bf as TransactionType, bg as TransactionUpdate, bh as UpdateChannelPerCommitmentPointInput, bi as UpdateChannelPerCommitmentPointOutput, bj as UpdateNodeSharedSecretInput, bk as UpdateNodeSharedSecretOutput, bl as Wallet, bm as WalletStatus, bn as WalletToPaymentRequestsConnection, bo as WalletToTransactionsConnection, W as WebhookEventType, bp as Withdrawal, br as WithdrawalMode, bs as WithdrawalRequest, bt as WithdrawalRequestStatus, bu as WithdrawalRequestToChannelClosingTransactionsConnection, bv as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, k as getChannelClosingTransactionQuery, n as getChannelOpeningTransactionQuery, P as getDepositQuery, X as getHopQuery, a0 as getIncomingPaymentAttemptQuery, a4 as getInvoiceQuery, ab as getLightningTransactionQuery, ae as getLightsparkNodeOwnerQuery, ao as getOnChainTransactionQuery, aC as getPaymentRequestQuery, aU as getRoutingTransactionQuery, b4 as getSignablePayloadQuery, b2 as getSignableQuery, bc as getTransactionQuery, bq as getWithdrawalQuery } from '../index-dbf06298.js';
|
|
2
|
+
export { B as BitcoinNetwork } from '../BitcoinNetwork-a816c0be.js';
|
|
2
3
|
import '@lightsparkdev/core';
|
|
3
4
|
import 'zen-observable';
|
package/dist/objects/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AccountToChannelsConnection_default,
|
|
3
3
|
Account_default,
|
|
4
|
-
BitcoinNetwork_default,
|
|
5
4
|
ChannelStatus_default,
|
|
6
5
|
Channel_default,
|
|
7
6
|
ComplianceProvider_default,
|
|
@@ -52,7 +51,10 @@ import {
|
|
|
52
51
|
getSignableQuery,
|
|
53
52
|
getTransactionQuery,
|
|
54
53
|
getWithdrawalQuery
|
|
55
|
-
} from "../chunk-
|
|
54
|
+
} from "../chunk-K2ZU5YQL.js";
|
|
55
|
+
import {
|
|
56
|
+
BitcoinNetwork_default
|
|
57
|
+
} from "../chunk-K6SAUSAX.js";
|
|
56
58
|
import "../chunk-NIMBE7W3.js";
|
|
57
59
|
export {
|
|
58
60
|
Account_default as Account,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightsparkdev/lightspark-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Lightspark JS SDK",
|
|
5
5
|
"author": "Lightspark Inc.",
|
|
6
6
|
"keywords": [
|
|
@@ -41,6 +41,16 @@
|
|
|
41
41
|
"module": "./dist/objects/index.js",
|
|
42
42
|
"require": "./dist/objects/index.cjs",
|
|
43
43
|
"default": "./dist/objects/index.cjs"
|
|
44
|
+
},
|
|
45
|
+
"./env": {
|
|
46
|
+
"types": "./dist/env.d.ts",
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/env.d.ts",
|
|
49
|
+
"default": "./dist/env.js"
|
|
50
|
+
},
|
|
51
|
+
"module": "./dist/env.js",
|
|
52
|
+
"require": "./dist/env.cjs",
|
|
53
|
+
"default": "./dist/env.cjs"
|
|
44
54
|
}
|
|
45
55
|
},
|
|
46
56
|
"type": "module",
|
|
@@ -58,7 +68,7 @@
|
|
|
58
68
|
"CHANGELOG.md"
|
|
59
69
|
],
|
|
60
70
|
"scripts": {
|
|
61
|
-
"build": "tsup",
|
|
71
|
+
"build": "yarn tsc && tsup",
|
|
62
72
|
"clean": "rm -rf .turbo && rm -rf dist",
|
|
63
73
|
"dev": "yarn build -- --watch",
|
|
64
74
|
"docs": "typedoc src",
|
|
@@ -75,11 +85,13 @@
|
|
|
75
85
|
},
|
|
76
86
|
"license": "Apache-2.0",
|
|
77
87
|
"dependencies": {
|
|
78
|
-
"@lightsparkdev/core": "1.0.
|
|
88
|
+
"@lightsparkdev/core": "1.0.1",
|
|
89
|
+
"@lightsparkdev/crypto-wasm": "0.1.0",
|
|
79
90
|
"auto-bind": "^5.0.1",
|
|
80
91
|
"crypto": "^1.0.1",
|
|
81
92
|
"crypto-browserify": "^3.12.0",
|
|
82
93
|
"dayjs": "^1.11.7",
|
|
94
|
+
"dotenv": "^16.3.1",
|
|
83
95
|
"graphql": "^16.6.0",
|
|
84
96
|
"graphql-ws": "^5.11.3",
|
|
85
97
|
"ws": "^8.12.1",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DefaultCrypto,
|
|
2
3
|
LightsparkSigningException,
|
|
3
4
|
type CryptoInterface,
|
|
4
5
|
type NodeKeyCache,
|
|
@@ -78,10 +79,11 @@ export default class NodeKeyLoaderCache {
|
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
const key = await this.nodeKeyCache.loadKey(
|
|
82
83
|
id,
|
|
83
84
|
{ key: loaderResult.key },
|
|
84
85
|
loaderResult.type,
|
|
85
86
|
);
|
|
87
|
+
return key || undefined;
|
|
86
88
|
}
|
|
87
89
|
}
|
package/src/SigningKeyLoader.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
b64encode,
|
|
3
|
+
isBrowser,
|
|
3
4
|
LightsparkSigningException,
|
|
4
5
|
SigningKeyType,
|
|
5
6
|
type CryptoInterface,
|
|
@@ -8,28 +9,9 @@ import {
|
|
|
8
9
|
} from "@lightsparkdev/core";
|
|
9
10
|
import { RecoverNodeSigningKey } from "./graphql/RecoverNodeSigningKey.js";
|
|
10
11
|
import { BitcoinNetwork } from "./index.js";
|
|
11
|
-
import {
|
|
12
|
-
LightsparkSigner,
|
|
13
|
-
Network,
|
|
14
|
-
} from "./lightspark_crypto/lightspark_crypto.js";
|
|
15
12
|
|
|
16
13
|
const SIGNING_KEY_PATH = "m/5";
|
|
17
14
|
|
|
18
|
-
const getCryptoLibNetwork = (bitcoinNetwork: BitcoinNetwork): Network => {
|
|
19
|
-
switch (bitcoinNetwork) {
|
|
20
|
-
case BitcoinNetwork.MAINNET:
|
|
21
|
-
return Network.Bitcoin;
|
|
22
|
-
case BitcoinNetwork.TESTNET:
|
|
23
|
-
return Network.Testnet;
|
|
24
|
-
case BitcoinNetwork.REGTEST:
|
|
25
|
-
return Network.Regtest;
|
|
26
|
-
default:
|
|
27
|
-
throw new Error(
|
|
28
|
-
`Unsupported lightspark_crypto network ${bitcoinNetwork}.`,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
15
|
/**
|
|
34
16
|
* Args for creating a new SigningKeyLoader. Must be one of the sub types.
|
|
35
17
|
*/
|
|
@@ -167,9 +149,35 @@ export class MasterSeedSigningKeyLoader implements SigningKeyLoader {
|
|
|
167
149
|
}
|
|
168
150
|
|
|
169
151
|
async loadSigningKey() {
|
|
152
|
+
if (isBrowser) {
|
|
153
|
+
throw new LightsparkSigningException(
|
|
154
|
+
"Browser environments not supported for master seed signing key loader.",
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const { LightsparkSigner, Network } = await import(
|
|
159
|
+
"@lightsparkdev/crypto-wasm"
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
let cryptoLibNetwork;
|
|
163
|
+
switch (this.network) {
|
|
164
|
+
case BitcoinNetwork.MAINNET:
|
|
165
|
+
cryptoLibNetwork = Network.Bitcoin;
|
|
166
|
+
break;
|
|
167
|
+
case BitcoinNetwork.TESTNET:
|
|
168
|
+
cryptoLibNetwork = Network.Testnet;
|
|
169
|
+
break;
|
|
170
|
+
case BitcoinNetwork.REGTEST:
|
|
171
|
+
cryptoLibNetwork = Network.Regtest;
|
|
172
|
+
break;
|
|
173
|
+
default:
|
|
174
|
+
throw new Error(
|
|
175
|
+
`Unsupported lightspark_crypto network ${this.network}.`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
170
178
|
const lightsparkSigner = LightsparkSigner.from_bytes(
|
|
171
179
|
this.masterSeed,
|
|
172
|
-
|
|
180
|
+
cryptoLibNetwork,
|
|
173
181
|
);
|
|
174
182
|
const privateKey = lightsparkSigner.derive_private_key(SIGNING_KEY_PATH);
|
|
175
183
|
return { key: privateKey, type: SigningKeyType.Secp256k1SigningKey };
|
package/src/env.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
/* These utils are only needed in NodeJS contexts and so the file is exported separately
|
|
4
|
+
in the package to avoid eg unnecessary browser bundling */
|
|
5
|
+
import dotenv from "dotenv";
|
|
6
|
+
import { getBitcoinNetworkOrThrow } from "./helpers.js";
|
|
7
|
+
import { type BitcoinNetwork } from "./objects/BitcoinNetwork.js";
|
|
8
|
+
|
|
9
|
+
export type EnvCredentials = {
|
|
10
|
+
apiTokenClientId: string;
|
|
11
|
+
apiTokenClientSecret: string;
|
|
12
|
+
bitcoinNetwork: BitcoinNetwork;
|
|
13
|
+
testNodePassword: string;
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export enum RequiredCredentials {
|
|
18
|
+
ClientId = "LIGHTSPARK_API_TOKEN_CLIENT_ID",
|
|
19
|
+
ClientSecret = "LIGHTSPARK_API_TOKEN_CLIENT_SECRET",
|
|
20
|
+
BitcoinNetwork = "BITCOIN_NETWORK",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const getCredentialsFromEnvOrThrow = (): EnvCredentials => {
|
|
24
|
+
const env =
|
|
25
|
+
dotenv.config({
|
|
26
|
+
path: process.env.HOME + "/.lightsparkapienv",
|
|
27
|
+
}).parsed || {};
|
|
28
|
+
|
|
29
|
+
const missingTestCredentials = Object.values(RequiredCredentials).filter(
|
|
30
|
+
(cred) => !env[cred],
|
|
31
|
+
);
|
|
32
|
+
if (missingTestCredentials.length) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Missing test credentials. Please set ${missingTestCredentials.join(
|
|
35
|
+
", ",
|
|
36
|
+
)} environment variables.`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const apiTokenClientId = env[RequiredCredentials.ClientId]!;
|
|
41
|
+
const apiTokenClientSecret = env[RequiredCredentials.ClientSecret]!;
|
|
42
|
+
const bitcoinNetwork = getBitcoinNetworkOrThrow(
|
|
43
|
+
env[RequiredCredentials.BitcoinNetwork]! as BitcoinNetwork,
|
|
44
|
+
);
|
|
45
|
+
const testNodePassword = "1234!@#$";
|
|
46
|
+
const baseUrl = env["LIGHTSPARK_BASE_URL"] || "api.lightspark.com";
|
|
47
|
+
return {
|
|
48
|
+
apiTokenClientId,
|
|
49
|
+
apiTokenClientSecret,
|
|
50
|
+
bitcoinNetwork,
|
|
51
|
+
testNodePassword,
|
|
52
|
+
baseUrl,
|
|
53
|
+
};
|
|
54
|
+
};
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
import { BitcoinNetwork } from "./objects/BitcoinNetwork.js";
|
|
4
|
+
|
|
5
|
+
const BITCOIN_NETWORKS = [
|
|
6
|
+
BitcoinNetwork.MAINNET,
|
|
7
|
+
BitcoinNetwork.TESTNET,
|
|
8
|
+
BitcoinNetwork.SIGNET,
|
|
9
|
+
BitcoinNetwork.REGTEST,
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export const isBitcoinNetwork = (bitcoinNetwork: BitcoinNetwork) => {
|
|
13
|
+
return BITCOIN_NETWORKS.includes(bitcoinNetwork);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const assertValidBitcoinNetwork = (
|
|
17
|
+
bitcoinNetwork: BitcoinNetwork,
|
|
18
|
+
): void => {
|
|
19
|
+
if (!isBitcoinNetwork(bitcoinNetwork)) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Invalid bitcoin network ${bitcoinNetwork}. Valid networks: ${BITCOIN_NETWORKS}`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const getBitcoinNetworkOrThrow = (
|
|
27
|
+
bitcoinNetwork: BitcoinNetwork,
|
|
28
|
+
): BitcoinNetwork => {
|
|
29
|
+
assertValidBitcoinNetwork(bitcoinNetwork.toUpperCase() as BitcoinNetwork);
|
|
30
|
+
return bitcoinNetwork;
|
|
31
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
/**
|
|
4
|
-
*/
|
|
5
|
-
export enum Network {
|
|
6
|
-
Bitcoin = 0,
|
|
7
|
-
Testnet = 1,
|
|
8
|
-
Regtest = 2,
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
*/
|
|
12
|
-
export class InvoiceSignature {
|
|
13
|
-
free(): void;
|
|
14
|
-
/**
|
|
15
|
-
* @returns {Uint8Array}
|
|
16
|
-
*/
|
|
17
|
-
get_signature(): Uint8Array;
|
|
18
|
-
/**
|
|
19
|
-
* @returns {number}
|
|
20
|
-
*/
|
|
21
|
-
get_recovery_id(): number;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
*/
|
|
25
|
-
export class LightsparkSigner {
|
|
26
|
-
free(): void;
|
|
27
|
-
/**
|
|
28
|
-
* @param {Seed} seed
|
|
29
|
-
* @param {number} network
|
|
30
|
-
* @returns {LightsparkSigner}
|
|
31
|
-
*/
|
|
32
|
-
static new(seed: Seed, network: number): LightsparkSigner;
|
|
33
|
-
/**
|
|
34
|
-
* @param {Uint8Array} seed
|
|
35
|
-
* @param {number} network
|
|
36
|
-
* @returns {LightsparkSigner}
|
|
37
|
-
*/
|
|
38
|
-
static from_bytes(seed: Uint8Array, network: number): LightsparkSigner;
|
|
39
|
-
/**
|
|
40
|
-
* @returns {string}
|
|
41
|
-
*/
|
|
42
|
-
get_master_public_key(): string;
|
|
43
|
-
/**
|
|
44
|
-
* @param {string} derivation_path
|
|
45
|
-
* @returns {string}
|
|
46
|
-
*/
|
|
47
|
-
derive_public_key(derivation_path: string): string;
|
|
48
|
-
/**
|
|
49
|
-
* @param {Uint8Array} message
|
|
50
|
-
* @param {string} derivation_path
|
|
51
|
-
* @param {boolean} is_raw
|
|
52
|
-
* @param {Uint8Array | undefined} add_tweak
|
|
53
|
-
* @param {Uint8Array | undefined} mul_tweak
|
|
54
|
-
* @returns {Uint8Array}
|
|
55
|
-
*/
|
|
56
|
-
derive_key_and_sign(
|
|
57
|
-
message: Uint8Array,
|
|
58
|
-
derivation_path: string,
|
|
59
|
-
is_raw: boolean,
|
|
60
|
-
add_tweak?: Uint8Array,
|
|
61
|
-
mul_tweak?: Uint8Array,
|
|
62
|
-
): Uint8Array;
|
|
63
|
-
/**
|
|
64
|
-
* @param {Uint8Array} public_key
|
|
65
|
-
* @returns {Uint8Array}
|
|
66
|
-
*/
|
|
67
|
-
ecdh(public_key: Uint8Array): Uint8Array;
|
|
68
|
-
/**
|
|
69
|
-
* @param {string} derivation_path
|
|
70
|
-
* @param {bigint} per_commitment_point_idx
|
|
71
|
-
* @returns {Uint8Array}
|
|
72
|
-
*/
|
|
73
|
-
get_per_commitment_point(
|
|
74
|
-
derivation_path: string,
|
|
75
|
-
per_commitment_point_idx: bigint,
|
|
76
|
-
): Uint8Array;
|
|
77
|
-
/**
|
|
78
|
-
* @param {string} derivation_path
|
|
79
|
-
* @param {bigint} per_commitment_point_idx
|
|
80
|
-
* @returns {Uint8Array}
|
|
81
|
-
*/
|
|
82
|
-
release_per_commitment_secret(
|
|
83
|
-
derivation_path: string,
|
|
84
|
-
per_commitment_point_idx: bigint,
|
|
85
|
-
): Uint8Array;
|
|
86
|
-
/**
|
|
87
|
-
* @returns {Uint8Array}
|
|
88
|
-
*/
|
|
89
|
-
generate_preimage_nonce(): Uint8Array;
|
|
90
|
-
/**
|
|
91
|
-
* @param {Uint8Array} nonce
|
|
92
|
-
* @returns {Uint8Array}
|
|
93
|
-
*/
|
|
94
|
-
generate_preimage(nonce: Uint8Array): Uint8Array;
|
|
95
|
-
/**
|
|
96
|
-
* @param {Uint8Array} nonce
|
|
97
|
-
* @returns {Uint8Array}
|
|
98
|
-
*/
|
|
99
|
-
generate_preimage_hash(nonce: Uint8Array): Uint8Array;
|
|
100
|
-
/**
|
|
101
|
-
* @param {string} derivation_path
|
|
102
|
-
* @returns {string}
|
|
103
|
-
*/
|
|
104
|
-
derive_private_key(derivation_path: string): string;
|
|
105
|
-
/**
|
|
106
|
-
* @param {string} unsigned_invoice
|
|
107
|
-
* @returns {InvoiceSignature}
|
|
108
|
-
*/
|
|
109
|
-
sign_invoice_wasm(unsigned_invoice: string): InvoiceSignature;
|
|
110
|
-
/**
|
|
111
|
-
* @param {Uint8Array} invoice_hash
|
|
112
|
-
* @returns {InvoiceSignature}
|
|
113
|
-
*/
|
|
114
|
-
sign_invoice_hash_wasm(invoice_hash: Uint8Array): InvoiceSignature;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
*/
|
|
118
|
-
export class Mnemonic {
|
|
119
|
-
free(): void;
|
|
120
|
-
/**
|
|
121
|
-
* @returns {Mnemonic}
|
|
122
|
-
*/
|
|
123
|
-
static random(): Mnemonic;
|
|
124
|
-
/**
|
|
125
|
-
* @param {Uint8Array} entropy
|
|
126
|
-
* @returns {Mnemonic}
|
|
127
|
-
*/
|
|
128
|
-
static from_entropy(entropy: Uint8Array): Mnemonic;
|
|
129
|
-
/**
|
|
130
|
-
* @param {string} phrase
|
|
131
|
-
* @returns {Mnemonic}
|
|
132
|
-
*/
|
|
133
|
-
static from_phrase(phrase: string): Mnemonic;
|
|
134
|
-
/**
|
|
135
|
-
* @returns {string}
|
|
136
|
-
*/
|
|
137
|
-
as_string(): string;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
*/
|
|
141
|
-
export class Seed {
|
|
142
|
-
free(): void;
|
|
143
|
-
/**
|
|
144
|
-
* @param {Mnemonic} mnemonic
|
|
145
|
-
* @returns {Seed}
|
|
146
|
-
*/
|
|
147
|
-
static from_mnemonic(mnemonic: Mnemonic): Seed;
|
|
148
|
-
/**
|
|
149
|
-
* @param {Uint8Array} seed
|
|
150
|
-
* @returns {Seed}
|
|
151
|
-
*/
|
|
152
|
-
static new(seed: Uint8Array): Seed;
|
|
153
|
-
/**
|
|
154
|
-
* @returns {Uint8Array}
|
|
155
|
-
*/
|
|
156
|
-
as_bytes(): Uint8Array;
|
|
157
|
-
}
|