@lightsparkdev/core 1.0.12 → 1.0.13

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - da1e0b2: - export secp256k1 signatures to DER format
8
+
3
9
  ## 1.0.12
4
10
 
5
11
  ### Patch Changes
@@ -737,6 +737,30 @@ function errorToJSON(err) {
737
737
  );
738
738
  }
739
739
 
740
+ // src/utils/localStorage.ts
741
+ function getLocalStorageConfigItem(key) {
742
+ return getLocalStorageBoolean(key);
743
+ }
744
+ function getLocalStorageBoolean(key) {
745
+ try {
746
+ return localStorage.getItem(key) === "1";
747
+ } catch (e) {
748
+ return false;
749
+ }
750
+ }
751
+ function setLocalStorageBoolean(key, value) {
752
+ try {
753
+ localStorage.setItem(key, value ? "1" : "0");
754
+ } catch (e) {
755
+ }
756
+ }
757
+ var deleteLocalStorageItem = (key) => {
758
+ try {
759
+ localStorage.removeItem(key);
760
+ } catch (e) {
761
+ }
762
+ };
763
+
740
764
  // ../../node_modules/lodash-es/_freeGlobal.js
741
765
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
742
766
  var freeGlobal_default = freeGlobal;
@@ -898,6 +922,10 @@ export {
898
922
  getErrorMsg,
899
923
  isErrorMsg,
900
924
  errorToJSON,
925
+ getLocalStorageConfigItem,
926
+ getLocalStorageBoolean,
927
+ setLocalStorageBoolean,
928
+ deleteLocalStorageItem,
901
929
  sleep,
902
930
  pollUntil,
903
931
  isType
@@ -0,0 +1,271 @@
1
+ declare const ConfigKeys: {
2
+ readonly LoggingEnabled: "lightspark-logging-enabled";
3
+ readonly ConsoleToolsEnabled: "lightspark-console-tools-enabled";
4
+ };
5
+ type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
6
+
7
+ declare const b64decode: (encoded: string) => Uint8Array;
8
+ declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
9
+ declare const b64encode: (data: ArrayBuffer) => string;
10
+
11
+ type SourceData = Uint8Array | string;
12
+ declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
13
+ declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
14
+
15
+ declare const defaultCurrencyCode = "USD";
16
+ /**
17
+ * This enum identifies the unit of currency associated with a CurrencyAmount.
18
+ * *
19
+ */
20
+ declare enum CurrencyUnit {
21
+ /**
22
+ * This is an enum value that represents values that could be added in the
23
+ * future. Clients should support unknown values as more of them could be
24
+ * added without notice.
25
+ */
26
+ FUTURE_VALUE = "FUTURE_VALUE",
27
+ /**
28
+ * Bitcoin is the cryptocurrency native to the Bitcoin network.
29
+ * It is used as the native medium for value transfer for the Lightning
30
+ * Network. *
31
+ */
32
+ BITCOIN = "BITCOIN",
33
+ /**
34
+ * 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin.
35
+ * This is the unit most commonly used in Lightning transactions.
36
+ * *
37
+ */
38
+ SATOSHI = "SATOSHI",
39
+ /**
40
+ * 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit
41
+ * instead when possible. *
42
+ */
43
+ MILLISATOSHI = "MILLISATOSHI",
44
+ /** United States Dollar. **/
45
+ USD = "USD",
46
+ /**
47
+ * 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin.
48
+ * We recommend using the Satoshi unit instead when possible.
49
+ * *
50
+ */
51
+ NANOBITCOIN = "NANOBITCOIN",
52
+ /**
53
+ * 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin.
54
+ * We recommend using the Satoshi unit instead when possible.
55
+ * *
56
+ */
57
+ MICROBITCOIN = "MICROBITCOIN",
58
+ /**
59
+ * 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin.
60
+ * We recommend using the Satoshi unit instead when possible.
61
+ * *
62
+ */
63
+ MILLIBITCOIN = "MILLIBITCOIN"
64
+ }
65
+ /** This object represents the value and unit for an amount of currency. **/
66
+ type CurrencyAmountType = {
67
+ /** The original numeric value for this CurrencyAmount. **/
68
+ originalValue: number;
69
+ /** The original unit of currency for this CurrencyAmount. **/
70
+ originalUnit: CurrencyUnit;
71
+ /** The unit of user's preferred currency. **/
72
+ preferredCurrencyUnit: CurrencyUnit;
73
+ /**
74
+ * The rounded numeric value for this CurrencyAmount in the very base level
75
+ * of user's preferred currency. For example, for USD, the value will be in
76
+ * cents.
77
+ **/
78
+ preferredCurrencyValueRounded: number;
79
+ /**
80
+ * The approximate float value for this CurrencyAmount in the very base level
81
+ * of user's preferred currency. For example, for USD, the value will be in
82
+ * cents.
83
+ **/
84
+ preferredCurrencyValueApprox: number;
85
+ };
86
+ declare function convertCurrencyAmountValue(fromUnit: CurrencyUnit, toUnit: CurrencyUnit, amount: number, centsPerBtc?: number): number;
87
+ declare const convertCurrencyAmount: (from: CurrencyAmountType, toUnit: CurrencyUnit) => CurrencyAmountType;
88
+ type CurrencyMap = {
89
+ sats: number;
90
+ msats: number;
91
+ btc: number;
92
+ [CurrencyUnit.BITCOIN]: number;
93
+ [CurrencyUnit.SATOSHI]: number;
94
+ [CurrencyUnit.MILLISATOSHI]: number;
95
+ [CurrencyUnit.MICROBITCOIN]: number;
96
+ [CurrencyUnit.MILLIBITCOIN]: number;
97
+ [CurrencyUnit.NANOBITCOIN]: number;
98
+ [CurrencyUnit.USD]: number;
99
+ [CurrencyUnit.FUTURE_VALUE]: number;
100
+ formatted: {
101
+ sats: string;
102
+ msats: string;
103
+ btc: string;
104
+ [CurrencyUnit.BITCOIN]: string;
105
+ [CurrencyUnit.SATOSHI]: string;
106
+ [CurrencyUnit.MILLISATOSHI]: string;
107
+ [CurrencyUnit.MILLIBITCOIN]: string;
108
+ [CurrencyUnit.MICROBITCOIN]: string;
109
+ [CurrencyUnit.NANOBITCOIN]: string;
110
+ [CurrencyUnit.USD]: string;
111
+ [CurrencyUnit.FUTURE_VALUE]: string;
112
+ };
113
+ isZero: boolean;
114
+ isLessThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
115
+ isGreaterThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
116
+ isEqualTo: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
117
+ type: "CurrencyMap";
118
+ };
119
+ type CurrencyAmountObj = {
120
+ value?: number | string | null;
121
+ unit?: CurrencyUnit;
122
+ __typename?: "CurrencyAmount";
123
+ };
124
+ type CurrencyAmountArg = CurrencyAmountObj | CurrencyAmountType | undefined | null;
125
+ declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
126
+ declare function isCurrencyAmount(arg: unknown): arg is CurrencyAmountType;
127
+ declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
128
+ declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
129
+ declare const abbrCurrencyUnit: (unit: CurrencyUnit) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
130
+ declare function formatCurrencyStr(amount: CurrencyAmountArg, maxFractionDigits?: number, compact?: boolean, showBtcSymbol?: boolean, options?: Intl.NumberFormatOptions): string;
131
+ declare function separateCurrencyStrParts(currencyStr: string): {
132
+ symbol: string;
133
+ amount: string;
134
+ };
135
+ declare function localeToCurrencySymbol(locale: string): string;
136
+
137
+ declare const isBrowser: boolean;
138
+ declare const isNode: boolean;
139
+ declare const isTest: boolean;
140
+
141
+ type Maybe<T> = T | null | undefined;
142
+ type ExpandRecursively<T> = T extends object ? T extends infer O ? {
143
+ [K in keyof O]: ExpandRecursively<O[K]>;
144
+ } : never : T;
145
+ type ById<T> = {
146
+ [id: string]: T;
147
+ };
148
+ type OmitTypename<T> = Omit<T, "__typename">;
149
+ declare const isType: <T extends string>(typename: T) => <N extends {
150
+ __typename: string;
151
+ }>(node: N | null | undefined) => node is Extract<N, {
152
+ __typename: T;
153
+ }>;
154
+ type DeepPartial<T> = T extends object ? {
155
+ [P in keyof T]?: DeepPartial<T[P]>;
156
+ } : T;
157
+ type JSONLiteral = string | number | boolean | null;
158
+ type JSONType = JSONLiteral | JSONType[] | {
159
+ [key: string]: JSONType;
160
+ };
161
+ type JSONObject = {
162
+ [key: string]: JSONType;
163
+ };
164
+
165
+ declare const isError: (e: unknown) => e is Error;
166
+ type ErrorWithMessage = {
167
+ message: string;
168
+ };
169
+ declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
170
+ declare const getErrorMsg: (e: unknown) => string;
171
+ declare const isErrorMsg: (e: unknown, msg: string) => boolean;
172
+ declare function errorToJSON(err: unknown): JSONType;
173
+
174
+ declare const bytesToHex: (bytes: Uint8Array) => string;
175
+ declare const hexToBytes: (hex: string) => Uint8Array;
176
+
177
+ declare function getLocalStorageConfigItem(key: ConfigKeys): boolean;
178
+ declare function getLocalStorageBoolean(key: string): boolean;
179
+ declare function setLocalStorageBoolean(key: string, value: boolean): void;
180
+ declare const deleteLocalStorageItem: (key: string) => void;
181
+
182
+ declare function getCurrentLocale(): string;
183
+
184
+ declare const countryCodesToCurrencyCodes: {
185
+ readonly AD: "EUR";
186
+ readonly AR: "ARS";
187
+ readonly AS: "USD";
188
+ readonly AT: "EUR";
189
+ readonly AU: "AUD";
190
+ readonly AX: "EUR";
191
+ readonly BE: "EUR";
192
+ readonly BL: "EUR";
193
+ readonly BQ: "USD";
194
+ readonly BR: "BRL";
195
+ readonly CA: "CAD";
196
+ readonly CO: "COP";
197
+ readonly CY: "EUR";
198
+ readonly DE: "EUR";
199
+ readonly EC: "USD";
200
+ readonly EE: "EUR";
201
+ readonly ES: "EUR";
202
+ readonly FI: "EUR";
203
+ readonly FM: "USD";
204
+ readonly FR: "EUR";
205
+ readonly GB: "GBP";
206
+ readonly GF: "EUR";
207
+ readonly GG: "GBP";
208
+ readonly GP: "EUR";
209
+ readonly GR: "EUR";
210
+ readonly GS: "GBP";
211
+ readonly GU: "USD";
212
+ readonly IE: "EUR";
213
+ readonly IM: "GBP";
214
+ readonly IN: "INR";
215
+ readonly IO: "USD";
216
+ readonly IT: "EUR";
217
+ readonly JE: "GBP";
218
+ readonly LT: "EUR";
219
+ readonly LU: "EUR";
220
+ readonly LV: "EUR";
221
+ readonly MC: "EUR";
222
+ readonly ME: "EUR";
223
+ readonly MF: "EUR";
224
+ readonly MH: "USD";
225
+ readonly MP: "USD";
226
+ readonly MQ: "EUR";
227
+ readonly MT: "EUR";
228
+ readonly MX: "MXN";
229
+ readonly NF: "AUD";
230
+ readonly NL: "EUR";
231
+ readonly NR: "AUD";
232
+ readonly PM: "EUR";
233
+ readonly PR: "USD";
234
+ readonly PT: "EUR";
235
+ readonly PW: "USD";
236
+ readonly RE: "EUR";
237
+ readonly SI: "EUR";
238
+ readonly SK: "EUR";
239
+ readonly SM: "EUR";
240
+ readonly TC: "USD";
241
+ readonly TF: "EUR";
242
+ readonly TL: "USD";
243
+ readonly TV: "AUD";
244
+ readonly UM: "USD";
245
+ readonly US: "USD";
246
+ readonly VA: "EUR";
247
+ readonly VG: "USD";
248
+ readonly VI: "USD";
249
+ readonly YT: "EUR";
250
+ };
251
+ type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
252
+ type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
253
+ declare function localeToCurrencyCode(locale: string): CurrencyCodes;
254
+
255
+ declare function clamp(val: number, min: number, max: number): number;
256
+ declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
257
+ declare function round(num: number, decimalPlaces?: number): number;
258
+ declare function isNumber(value: unknown): value is number;
259
+
260
+ type GetValueResult<T> = {
261
+ stopPolling: boolean;
262
+ value: null | T;
263
+ };
264
+ declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getValue: (data: Awaited<ReturnType<D>>, response: {
265
+ stopPolling: boolean;
266
+ value: null | T;
267
+ }) => GetValueResult<T>, maxPolls?: number, pollIntervalMs?: number, ignoreErrors?: boolean | ((e: unknown) => boolean), getMaxPollsError?: (maxPolls: number) => Error): Promise<T>;
268
+
269
+ declare function sleep(ms: number): Promise<unknown>;
270
+
271
+ export { JSONType as $, isErrorMsg as A, errorToJSON as B, ConfigKeys as C, bytesToHex as D, hexToBytes as E, getLocalStorageConfigItem as F, getLocalStorageBoolean as G, setLocalStorageBoolean as H, deleteLocalStorageItem as I, getCurrentLocale as J, countryCodesToCurrencyCodes as K, CurrencyLocales as L, CurrencyCodes as M, localeToCurrencyCode as N, clamp as O, linearInterpolate as P, round as Q, isNumber as R, pollUntil as S, sleep as T, Maybe as U, ExpandRecursively as V, ById as W, OmitTypename as X, isType as Y, DeepPartial as Z, JSONLiteral as _, b64encode as a, JSONObject as a0, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, CurrencyUnit as e, CurrencyAmountType as f, convertCurrencyAmountValue as g, convertCurrencyAmount as h, CurrencyMap as i, CurrencyAmountObj as j, CurrencyAmountArg as k, isCurrencyAmountObj as l, isCurrencyAmount as m, mapCurrencyAmount as n, isCurrencyMap as o, abbrCurrencyUnit as p, formatCurrencyStr as q, localeToCurrencySymbol as r, separateCurrencyStrParts as s, isBrowser as t, urlsafe_b64decode as u, isNode as v, isTest as w, isError as x, isErrorWithMessage as y, getErrorMsg as z };
package/dist/index.cjs CHANGED
@@ -57,6 +57,7 @@ __export(src_exports, {
57
57
  countryCodesToCurrencyCodes: () => countryCodesToCurrencyCodes,
58
58
  createSha256Hash: () => createSha256Hash,
59
59
  defaultCurrencyCode: () => defaultCurrencyCode,
60
+ deleteLocalStorageItem: () => deleteLocalStorageItem,
60
61
  errorToJSON: () => errorToJSON,
61
62
  formatCurrencyStr: () => formatCurrencyStr,
62
63
  getCurrentLocale: () => getCurrentLocale,
@@ -82,6 +83,7 @@ __export(src_exports, {
82
83
  pollUntil: () => pollUntil,
83
84
  round: () => round,
84
85
  separateCurrencyStrParts: () => separateCurrencyStrParts,
86
+ setLocalStorageBoolean: () => setLocalStorageBoolean,
85
87
  sleep: () => sleep,
86
88
  urlsafe_b64decode: () => urlsafe_b64decode
87
89
  });
@@ -176,21 +178,11 @@ var StubAuthProvider = class {
176
178
  }
177
179
  };
178
180
 
179
- // src/constants/localStorage.ts
181
+ // src/constants/index.ts
180
182
  var ConfigKeys = {
181
183
  LoggingEnabled: "lightspark-logging-enabled",
182
184
  ConsoleToolsEnabled: "lightspark-console-tools-enabled"
183
185
  };
184
- var getLocalStorageConfigItem = (key) => {
185
- return getLocalStorageBoolean(key);
186
- };
187
- var getLocalStorageBoolean = (key) => {
188
- try {
189
- return localStorage.getItem(key) === "1";
190
- } catch (e) {
191
- return false;
192
- }
193
- };
194
186
 
195
187
  // src/crypto/KeyOrAlias.ts
196
188
  var KeyOrAlias = {
@@ -1139,6 +1131,30 @@ function errorToJSON(err) {
1139
1131
  );
1140
1132
  }
1141
1133
 
1134
+ // src/utils/localStorage.ts
1135
+ function getLocalStorageConfigItem(key) {
1136
+ return getLocalStorageBoolean(key);
1137
+ }
1138
+ function getLocalStorageBoolean(key) {
1139
+ try {
1140
+ return localStorage.getItem(key) === "1";
1141
+ } catch (e) {
1142
+ return false;
1143
+ }
1144
+ }
1145
+ function setLocalStorageBoolean(key, value) {
1146
+ try {
1147
+ localStorage.setItem(key, value ? "1" : "0");
1148
+ } catch (e) {
1149
+ }
1150
+ }
1151
+ var deleteLocalStorageItem = (key) => {
1152
+ try {
1153
+ localStorage.removeItem(key);
1154
+ } catch (e) {
1155
+ }
1156
+ };
1157
+
1142
1158
  // ../../node_modules/lodash-es/_freeGlobal.js
1143
1159
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
1144
1160
  var freeGlobal_default = freeGlobal;
@@ -1295,7 +1311,7 @@ var Secp256k1SigningKey = class extends SigningKey {
1295
1311
  const keyBytes = new Uint8Array(hexToBytes(this.privateKey));
1296
1312
  const hash = await createSha256Hash(data);
1297
1313
  const signResult = import_secp256k1.default.ecdsaSign(hash, keyBytes);
1298
- return signResult.signature;
1314
+ return import_secp256k1.default.signatureExport(signResult.signature);
1299
1315
  }
1300
1316
  };
1301
1317
 
@@ -1538,9 +1554,11 @@ var Requester = class {
1538
1554
  "Missing node of encrypted_signing_private_key"
1539
1555
  );
1540
1556
  }
1541
- let TextEncoderImpl = TextEncoder;
1557
+ let TextEncoderImpl;
1542
1558
  if (typeof TextEncoder === "undefined") {
1543
1559
  TextEncoderImpl = (await import("text-encoding")).TextEncoder;
1560
+ } else {
1561
+ TextEncoderImpl = TextEncoder;
1544
1562
  }
1545
1563
  const encodedPayload = new TextEncoderImpl().encode(
1546
1564
  JSON.stringify(payload)
@@ -1584,6 +1602,7 @@ var Requester_default = Requester;
1584
1602
  countryCodesToCurrencyCodes,
1585
1603
  createSha256Hash,
1586
1604
  defaultCurrencyCode,
1605
+ deleteLocalStorageItem,
1587
1606
  errorToJSON,
1588
1607
  formatCurrencyStr,
1589
1608
  getCurrentLocale,
@@ -1609,6 +1628,7 @@ var Requester_default = Requester;
1609
1628
  pollUntil,
1610
1629
  round,
1611
1630
  separateCurrencyStrParts,
1631
+ setLocalStorageBoolean,
1612
1632
  sleep,
1613
1633
  urlsafe_b64decode
1614
1634
  });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
+ export { W as ById, C as ConfigKeys, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from './index-d0c72658.js';
1
2
  import { Observable } from 'zen-observable-ts';
2
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, JSONLiteral, JSONObject, JSONType, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, errorToJSON, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode } from './utils/index.cjs';
3
3
 
4
4
  declare class LightsparkException extends Error {
5
5
  code: string;
@@ -41,14 +41,6 @@ declare class StubAuthProvider implements AuthProvider {
41
41
  addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
42
42
  }
43
43
 
44
- declare const ConfigKeys: {
45
- readonly LoggingEnabled: "lightspark-logging-enabled";
46
- readonly ConsoleToolsEnabled: "lightspark-console-tools-enabled";
47
- };
48
- type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
49
- declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
50
- declare const getLocalStorageBoolean: (key: string) => boolean;
51
-
52
44
  type OnlyKey = {
53
45
  key: string;
54
46
  alias?: never;
@@ -166,4 +158,4 @@ declare class Requester {
166
158
  private addSigningDataIfNeeded;
167
159
  }
168
160
 
169
- export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageBoolean, getLocalStorageConfigItem };
161
+ export { AuthProvider, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ export { W as ById, C as ConfigKeys, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from './index-d0c72658.js';
1
2
  import { Observable } from 'zen-observable-ts';
2
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, JSONLiteral, JSONObject, JSONType, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, errorToJSON, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode } from './utils/index.js';
3
3
 
4
4
  declare class LightsparkException extends Error {
5
5
  code: string;
@@ -41,14 +41,6 @@ declare class StubAuthProvider implements AuthProvider {
41
41
  addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
42
42
  }
43
43
 
44
- declare const ConfigKeys: {
45
- readonly LoggingEnabled: "lightspark-logging-enabled";
46
- readonly ConsoleToolsEnabled: "lightspark-console-tools-enabled";
47
- };
48
- type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
49
- declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
50
- declare const getLocalStorageBoolean: (key: string) => boolean;
51
-
52
44
  type OnlyKey = {
53
45
  key: string;
54
46
  alias?: never;
@@ -166,4 +158,4 @@ declare class Requester {
166
158
  private addSigningDataIfNeeded;
167
159
  }
168
160
 
169
- export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageBoolean, getLocalStorageConfigItem };
161
+ export { AuthProvider, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment };
package/dist/index.js CHANGED
@@ -11,10 +11,13 @@ import {
11
11
  countryCodesToCurrencyCodes,
12
12
  createSha256Hash,
13
13
  defaultCurrencyCode,
14
+ deleteLocalStorageItem,
14
15
  errorToJSON,
15
16
  formatCurrencyStr,
16
17
  getCurrentLocale,
17
18
  getErrorMsg,
19
+ getLocalStorageBoolean,
20
+ getLocalStorageConfigItem,
18
21
  hexToBytes,
19
22
  isBrowser,
20
23
  isCurrencyAmount,
@@ -34,9 +37,10 @@ import {
34
37
  pollUntil,
35
38
  round,
36
39
  separateCurrencyStrParts,
40
+ setLocalStorageBoolean,
37
41
  sleep,
38
42
  urlsafe_b64decode
39
- } from "./chunk-BYCLLNFL.js";
43
+ } from "./chunk-ADJSE2YZ.js";
40
44
 
41
45
  // src/Logger.ts
42
46
  var Logger = class {
@@ -108,21 +112,11 @@ var StubAuthProvider = class {
108
112
  }
109
113
  };
110
114
 
111
- // src/constants/localStorage.ts
115
+ // src/constants/index.ts
112
116
  var ConfigKeys = {
113
117
  LoggingEnabled: "lightspark-logging-enabled",
114
118
  ConsoleToolsEnabled: "lightspark-console-tools-enabled"
115
119
  };
116
- var getLocalStorageConfigItem = (key) => {
117
- return getLocalStorageBoolean(key);
118
- };
119
- var getLocalStorageBoolean = (key) => {
120
- try {
121
- return localStorage.getItem(key) === "1";
122
- } catch (e) {
123
- return false;
124
- }
125
- };
126
120
 
127
121
  // src/crypto/KeyOrAlias.ts
128
122
  var KeyOrAlias = {
@@ -379,7 +373,7 @@ var Secp256k1SigningKey = class extends SigningKey {
379
373
  const keyBytes = new Uint8Array(hexToBytes(this.privateKey));
380
374
  const hash = await createSha256Hash(data);
381
375
  const signResult = secp256k1.ecdsaSign(hash, keyBytes);
382
- return signResult.signature;
376
+ return secp256k1.signatureExport(signResult.signature);
383
377
  }
384
378
  };
385
379
 
@@ -622,9 +616,11 @@ var Requester = class {
622
616
  "Missing node of encrypted_signing_private_key"
623
617
  );
624
618
  }
625
- let TextEncoderImpl = TextEncoder;
619
+ let TextEncoderImpl;
626
620
  if (typeof TextEncoder === "undefined") {
627
621
  TextEncoderImpl = (await import("text-encoding")).TextEncoder;
622
+ } else {
623
+ TextEncoderImpl = TextEncoder;
628
624
  }
629
625
  const encodedPayload = new TextEncoderImpl().encode(
630
626
  JSON.stringify(payload)
@@ -667,6 +663,7 @@ export {
667
663
  countryCodesToCurrencyCodes,
668
664
  createSha256Hash,
669
665
  defaultCurrencyCode,
666
+ deleteLocalStorageItem,
670
667
  errorToJSON,
671
668
  formatCurrencyStr,
672
669
  getCurrentLocale,
@@ -692,6 +689,7 @@ export {
692
689
  pollUntil,
693
690
  round,
694
691
  separateCurrencyStrParts,
692
+ setLocalStorageBoolean,
695
693
  sleep,
696
694
  urlsafe_b64decode
697
695
  };
@@ -41,10 +41,13 @@ __export(utils_exports, {
41
41
  countryCodesToCurrencyCodes: () => countryCodesToCurrencyCodes,
42
42
  createSha256Hash: () => createSha256Hash,
43
43
  defaultCurrencyCode: () => defaultCurrencyCode,
44
+ deleteLocalStorageItem: () => deleteLocalStorageItem,
44
45
  errorToJSON: () => errorToJSON,
45
46
  formatCurrencyStr: () => formatCurrencyStr,
46
47
  getCurrentLocale: () => getCurrentLocale,
47
48
  getErrorMsg: () => getErrorMsg,
49
+ getLocalStorageBoolean: () => getLocalStorageBoolean,
50
+ getLocalStorageConfigItem: () => getLocalStorageConfigItem,
48
51
  hexToBytes: () => hexToBytes,
49
52
  isBrowser: () => isBrowser,
50
53
  isCurrencyAmount: () => isCurrencyAmount,
@@ -64,6 +67,7 @@ __export(utils_exports, {
64
67
  pollUntil: () => pollUntil,
65
68
  round: () => round,
66
69
  separateCurrencyStrParts: () => separateCurrencyStrParts,
70
+ setLocalStorageBoolean: () => setLocalStorageBoolean,
67
71
  sleep: () => sleep,
68
72
  urlsafe_b64decode: () => urlsafe_b64decode
69
73
  });
@@ -808,6 +812,30 @@ function errorToJSON(err) {
808
812
  );
809
813
  }
810
814
 
815
+ // src/utils/localStorage.ts
816
+ function getLocalStorageConfigItem(key) {
817
+ return getLocalStorageBoolean(key);
818
+ }
819
+ function getLocalStorageBoolean(key) {
820
+ try {
821
+ return localStorage.getItem(key) === "1";
822
+ } catch (e) {
823
+ return false;
824
+ }
825
+ }
826
+ function setLocalStorageBoolean(key, value) {
827
+ try {
828
+ localStorage.setItem(key, value ? "1" : "0");
829
+ } catch (e) {
830
+ }
831
+ }
832
+ var deleteLocalStorageItem = (key) => {
833
+ try {
834
+ localStorage.removeItem(key);
835
+ } catch (e) {
836
+ }
837
+ };
838
+
811
839
  // ../../node_modules/lodash-es/_freeGlobal.js
812
840
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
813
841
  var freeGlobal_default = freeGlobal;
@@ -946,10 +974,13 @@ var isType = (typename) => (node) => {
946
974
  countryCodesToCurrencyCodes,
947
975
  createSha256Hash,
948
976
  defaultCurrencyCode,
977
+ deleteLocalStorageItem,
949
978
  errorToJSON,
950
979
  formatCurrencyStr,
951
980
  getCurrentLocale,
952
981
  getErrorMsg,
982
+ getLocalStorageBoolean,
983
+ getLocalStorageConfigItem,
953
984
  hexToBytes,
954
985
  isBrowser,
955
986
  isCurrencyAmount,
@@ -969,6 +1000,7 @@ var isType = (typename) => (node) => {
969
1000
  pollUntil,
970
1001
  round,
971
1002
  separateCurrencyStrParts,
1003
+ setLocalStorageBoolean,
972
1004
  sleep,
973
1005
  urlsafe_b64decode
974
1006
  });
@@ -1,260 +1 @@
1
- declare const b64decode: (encoded: string) => Uint8Array;
2
- declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
3
- declare const b64encode: (data: ArrayBuffer) => string;
4
-
5
- type SourceData = Uint8Array | string;
6
- declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
7
- declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
8
-
9
- declare const defaultCurrencyCode = "USD";
10
- /**
11
- * This enum identifies the unit of currency associated with a CurrencyAmount.
12
- * *
13
- */
14
- declare enum CurrencyUnit {
15
- /**
16
- * This is an enum value that represents values that could be added in the
17
- * future. Clients should support unknown values as more of them could be
18
- * added without notice.
19
- */
20
- FUTURE_VALUE = "FUTURE_VALUE",
21
- /**
22
- * Bitcoin is the cryptocurrency native to the Bitcoin network.
23
- * It is used as the native medium for value transfer for the Lightning
24
- * Network. *
25
- */
26
- BITCOIN = "BITCOIN",
27
- /**
28
- * 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin.
29
- * This is the unit most commonly used in Lightning transactions.
30
- * *
31
- */
32
- SATOSHI = "SATOSHI",
33
- /**
34
- * 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit
35
- * instead when possible. *
36
- */
37
- MILLISATOSHI = "MILLISATOSHI",
38
- /** United States Dollar. **/
39
- USD = "USD",
40
- /**
41
- * 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin.
42
- * We recommend using the Satoshi unit instead when possible.
43
- * *
44
- */
45
- NANOBITCOIN = "NANOBITCOIN",
46
- /**
47
- * 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin.
48
- * We recommend using the Satoshi unit instead when possible.
49
- * *
50
- */
51
- MICROBITCOIN = "MICROBITCOIN",
52
- /**
53
- * 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin.
54
- * We recommend using the Satoshi unit instead when possible.
55
- * *
56
- */
57
- MILLIBITCOIN = "MILLIBITCOIN"
58
- }
59
- /** This object represents the value and unit for an amount of currency. **/
60
- type CurrencyAmountType = {
61
- /** The original numeric value for this CurrencyAmount. **/
62
- originalValue: number;
63
- /** The original unit of currency for this CurrencyAmount. **/
64
- originalUnit: CurrencyUnit;
65
- /** The unit of user's preferred currency. **/
66
- preferredCurrencyUnit: CurrencyUnit;
67
- /**
68
- * The rounded numeric value for this CurrencyAmount in the very base level
69
- * of user's preferred currency. For example, for USD, the value will be in
70
- * cents.
71
- **/
72
- preferredCurrencyValueRounded: number;
73
- /**
74
- * The approximate float value for this CurrencyAmount in the very base level
75
- * of user's preferred currency. For example, for USD, the value will be in
76
- * cents.
77
- **/
78
- preferredCurrencyValueApprox: number;
79
- };
80
- declare function convertCurrencyAmountValue(fromUnit: CurrencyUnit, toUnit: CurrencyUnit, amount: number, centsPerBtc?: number): number;
81
- declare const convertCurrencyAmount: (from: CurrencyAmountType, toUnit: CurrencyUnit) => CurrencyAmountType;
82
- type CurrencyMap = {
83
- sats: number;
84
- msats: number;
85
- btc: number;
86
- [CurrencyUnit.BITCOIN]: number;
87
- [CurrencyUnit.SATOSHI]: number;
88
- [CurrencyUnit.MILLISATOSHI]: number;
89
- [CurrencyUnit.MICROBITCOIN]: number;
90
- [CurrencyUnit.MILLIBITCOIN]: number;
91
- [CurrencyUnit.NANOBITCOIN]: number;
92
- [CurrencyUnit.USD]: number;
93
- [CurrencyUnit.FUTURE_VALUE]: number;
94
- formatted: {
95
- sats: string;
96
- msats: string;
97
- btc: string;
98
- [CurrencyUnit.BITCOIN]: string;
99
- [CurrencyUnit.SATOSHI]: string;
100
- [CurrencyUnit.MILLISATOSHI]: string;
101
- [CurrencyUnit.MILLIBITCOIN]: string;
102
- [CurrencyUnit.MICROBITCOIN]: string;
103
- [CurrencyUnit.NANOBITCOIN]: string;
104
- [CurrencyUnit.USD]: string;
105
- [CurrencyUnit.FUTURE_VALUE]: string;
106
- };
107
- isZero: boolean;
108
- isLessThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
109
- isGreaterThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
110
- isEqualTo: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
111
- type: "CurrencyMap";
112
- };
113
- type CurrencyAmountObj = {
114
- value?: number | string | null;
115
- unit?: CurrencyUnit;
116
- __typename?: "CurrencyAmount";
117
- };
118
- type CurrencyAmountArg = CurrencyAmountObj | CurrencyAmountType | undefined | null;
119
- declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
120
- declare function isCurrencyAmount(arg: unknown): arg is CurrencyAmountType;
121
- declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
122
- declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
123
- declare const abbrCurrencyUnit: (unit: CurrencyUnit) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
124
- declare function formatCurrencyStr(amount: CurrencyAmountArg, maxFractionDigits?: number, compact?: boolean, showBtcSymbol?: boolean, options?: Intl.NumberFormatOptions): string;
125
- declare function separateCurrencyStrParts(currencyStr: string): {
126
- symbol: string;
127
- amount: string;
128
- };
129
- declare function localeToCurrencySymbol(locale: string): string;
130
-
131
- declare const isBrowser: boolean;
132
- declare const isNode: boolean;
133
- declare const isTest: boolean;
134
-
135
- type Maybe<T> = T | null | undefined;
136
- type ExpandRecursively<T> = T extends object ? T extends infer O ? {
137
- [K in keyof O]: ExpandRecursively<O[K]>;
138
- } : never : T;
139
- type ById<T> = {
140
- [id: string]: T;
141
- };
142
- type OmitTypename<T> = Omit<T, "__typename">;
143
- declare const isType: <T extends string>(typename: T) => <N extends {
144
- __typename: string;
145
- }>(node: N | null | undefined) => node is Extract<N, {
146
- __typename: T;
147
- }>;
148
- type DeepPartial<T> = T extends object ? {
149
- [P in keyof T]?: DeepPartial<T[P]>;
150
- } : T;
151
- type JSONLiteral = string | number | boolean | null;
152
- type JSONType = JSONLiteral | JSONType[] | {
153
- [key: string]: JSONType;
154
- };
155
- type JSONObject = {
156
- [key: string]: JSONType;
157
- };
158
-
159
- declare const isError: (e: unknown) => e is Error;
160
- type ErrorWithMessage = {
161
- message: string;
162
- };
163
- declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
164
- declare const getErrorMsg: (e: unknown) => string;
165
- declare const isErrorMsg: (e: unknown, msg: string) => boolean;
166
- declare function errorToJSON(err: unknown): JSONType;
167
-
168
- declare const bytesToHex: (bytes: Uint8Array) => string;
169
- declare const hexToBytes: (hex: string) => Uint8Array;
170
-
171
- declare function getCurrentLocale(): string;
172
-
173
- declare const countryCodesToCurrencyCodes: {
174
- readonly AD: "EUR";
175
- readonly AR: "ARS";
176
- readonly AS: "USD";
177
- readonly AT: "EUR";
178
- readonly AU: "AUD";
179
- readonly AX: "EUR";
180
- readonly BE: "EUR";
181
- readonly BL: "EUR";
182
- readonly BQ: "USD";
183
- readonly BR: "BRL";
184
- readonly CA: "CAD";
185
- readonly CO: "COP";
186
- readonly CY: "EUR";
187
- readonly DE: "EUR";
188
- readonly EC: "USD";
189
- readonly EE: "EUR";
190
- readonly ES: "EUR";
191
- readonly FI: "EUR";
192
- readonly FM: "USD";
193
- readonly FR: "EUR";
194
- readonly GB: "GBP";
195
- readonly GF: "EUR";
196
- readonly GG: "GBP";
197
- readonly GP: "EUR";
198
- readonly GR: "EUR";
199
- readonly GS: "GBP";
200
- readonly GU: "USD";
201
- readonly IE: "EUR";
202
- readonly IM: "GBP";
203
- readonly IN: "INR";
204
- readonly IO: "USD";
205
- readonly IT: "EUR";
206
- readonly JE: "GBP";
207
- readonly LT: "EUR";
208
- readonly LU: "EUR";
209
- readonly LV: "EUR";
210
- readonly MC: "EUR";
211
- readonly ME: "EUR";
212
- readonly MF: "EUR";
213
- readonly MH: "USD";
214
- readonly MP: "USD";
215
- readonly MQ: "EUR";
216
- readonly MT: "EUR";
217
- readonly MX: "MXN";
218
- readonly NF: "AUD";
219
- readonly NL: "EUR";
220
- readonly NR: "AUD";
221
- readonly PM: "EUR";
222
- readonly PR: "USD";
223
- readonly PT: "EUR";
224
- readonly PW: "USD";
225
- readonly RE: "EUR";
226
- readonly SI: "EUR";
227
- readonly SK: "EUR";
228
- readonly SM: "EUR";
229
- readonly TC: "USD";
230
- readonly TF: "EUR";
231
- readonly TL: "USD";
232
- readonly TV: "AUD";
233
- readonly UM: "USD";
234
- readonly US: "USD";
235
- readonly VA: "EUR";
236
- readonly VG: "USD";
237
- readonly VI: "USD";
238
- readonly YT: "EUR";
239
- };
240
- type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
241
- type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
242
- declare function localeToCurrencyCode(locale: string): CurrencyCodes;
243
-
244
- declare function clamp(val: number, min: number, max: number): number;
245
- declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
246
- declare function round(num: number, decimalPlaces?: number): number;
247
- declare function isNumber(value: unknown): value is number;
248
-
249
- type GetValueResult<T> = {
250
- stopPolling: boolean;
251
- value: null | T;
252
- };
253
- declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getValue: (data: Awaited<ReturnType<D>>, response: {
254
- stopPolling: boolean;
255
- value: null | T;
256
- }) => GetValueResult<T>, maxPolls?: number, pollIntervalMs?: number, ignoreErrors?: boolean | ((e: unknown) => boolean), getMaxPollsError?: (maxPolls: number) => Error): Promise<T>;
257
-
258
- declare function sleep(ms: number): Promise<unknown>;
259
-
260
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, JSONLiteral, JSONObject, JSONType, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, errorToJSON, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode };
1
+ export { W as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from '../index-d0c72658.js';
@@ -1,260 +1 @@
1
- declare const b64decode: (encoded: string) => Uint8Array;
2
- declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
3
- declare const b64encode: (data: ArrayBuffer) => string;
4
-
5
- type SourceData = Uint8Array | string;
6
- declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
7
- declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
8
-
9
- declare const defaultCurrencyCode = "USD";
10
- /**
11
- * This enum identifies the unit of currency associated with a CurrencyAmount.
12
- * *
13
- */
14
- declare enum CurrencyUnit {
15
- /**
16
- * This is an enum value that represents values that could be added in the
17
- * future. Clients should support unknown values as more of them could be
18
- * added without notice.
19
- */
20
- FUTURE_VALUE = "FUTURE_VALUE",
21
- /**
22
- * Bitcoin is the cryptocurrency native to the Bitcoin network.
23
- * It is used as the native medium for value transfer for the Lightning
24
- * Network. *
25
- */
26
- BITCOIN = "BITCOIN",
27
- /**
28
- * 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin.
29
- * This is the unit most commonly used in Lightning transactions.
30
- * *
31
- */
32
- SATOSHI = "SATOSHI",
33
- /**
34
- * 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit
35
- * instead when possible. *
36
- */
37
- MILLISATOSHI = "MILLISATOSHI",
38
- /** United States Dollar. **/
39
- USD = "USD",
40
- /**
41
- * 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin.
42
- * We recommend using the Satoshi unit instead when possible.
43
- * *
44
- */
45
- NANOBITCOIN = "NANOBITCOIN",
46
- /**
47
- * 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin.
48
- * We recommend using the Satoshi unit instead when possible.
49
- * *
50
- */
51
- MICROBITCOIN = "MICROBITCOIN",
52
- /**
53
- * 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin.
54
- * We recommend using the Satoshi unit instead when possible.
55
- * *
56
- */
57
- MILLIBITCOIN = "MILLIBITCOIN"
58
- }
59
- /** This object represents the value and unit for an amount of currency. **/
60
- type CurrencyAmountType = {
61
- /** The original numeric value for this CurrencyAmount. **/
62
- originalValue: number;
63
- /** The original unit of currency for this CurrencyAmount. **/
64
- originalUnit: CurrencyUnit;
65
- /** The unit of user's preferred currency. **/
66
- preferredCurrencyUnit: CurrencyUnit;
67
- /**
68
- * The rounded numeric value for this CurrencyAmount in the very base level
69
- * of user's preferred currency. For example, for USD, the value will be in
70
- * cents.
71
- **/
72
- preferredCurrencyValueRounded: number;
73
- /**
74
- * The approximate float value for this CurrencyAmount in the very base level
75
- * of user's preferred currency. For example, for USD, the value will be in
76
- * cents.
77
- **/
78
- preferredCurrencyValueApprox: number;
79
- };
80
- declare function convertCurrencyAmountValue(fromUnit: CurrencyUnit, toUnit: CurrencyUnit, amount: number, centsPerBtc?: number): number;
81
- declare const convertCurrencyAmount: (from: CurrencyAmountType, toUnit: CurrencyUnit) => CurrencyAmountType;
82
- type CurrencyMap = {
83
- sats: number;
84
- msats: number;
85
- btc: number;
86
- [CurrencyUnit.BITCOIN]: number;
87
- [CurrencyUnit.SATOSHI]: number;
88
- [CurrencyUnit.MILLISATOSHI]: number;
89
- [CurrencyUnit.MICROBITCOIN]: number;
90
- [CurrencyUnit.MILLIBITCOIN]: number;
91
- [CurrencyUnit.NANOBITCOIN]: number;
92
- [CurrencyUnit.USD]: number;
93
- [CurrencyUnit.FUTURE_VALUE]: number;
94
- formatted: {
95
- sats: string;
96
- msats: string;
97
- btc: string;
98
- [CurrencyUnit.BITCOIN]: string;
99
- [CurrencyUnit.SATOSHI]: string;
100
- [CurrencyUnit.MILLISATOSHI]: string;
101
- [CurrencyUnit.MILLIBITCOIN]: string;
102
- [CurrencyUnit.MICROBITCOIN]: string;
103
- [CurrencyUnit.NANOBITCOIN]: string;
104
- [CurrencyUnit.USD]: string;
105
- [CurrencyUnit.FUTURE_VALUE]: string;
106
- };
107
- isZero: boolean;
108
- isLessThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
109
- isGreaterThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
110
- isEqualTo: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
111
- type: "CurrencyMap";
112
- };
113
- type CurrencyAmountObj = {
114
- value?: number | string | null;
115
- unit?: CurrencyUnit;
116
- __typename?: "CurrencyAmount";
117
- };
118
- type CurrencyAmountArg = CurrencyAmountObj | CurrencyAmountType | undefined | null;
119
- declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
120
- declare function isCurrencyAmount(arg: unknown): arg is CurrencyAmountType;
121
- declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
122
- declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
123
- declare const abbrCurrencyUnit: (unit: CurrencyUnit) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
124
- declare function formatCurrencyStr(amount: CurrencyAmountArg, maxFractionDigits?: number, compact?: boolean, showBtcSymbol?: boolean, options?: Intl.NumberFormatOptions): string;
125
- declare function separateCurrencyStrParts(currencyStr: string): {
126
- symbol: string;
127
- amount: string;
128
- };
129
- declare function localeToCurrencySymbol(locale: string): string;
130
-
131
- declare const isBrowser: boolean;
132
- declare const isNode: boolean;
133
- declare const isTest: boolean;
134
-
135
- type Maybe<T> = T | null | undefined;
136
- type ExpandRecursively<T> = T extends object ? T extends infer O ? {
137
- [K in keyof O]: ExpandRecursively<O[K]>;
138
- } : never : T;
139
- type ById<T> = {
140
- [id: string]: T;
141
- };
142
- type OmitTypename<T> = Omit<T, "__typename">;
143
- declare const isType: <T extends string>(typename: T) => <N extends {
144
- __typename: string;
145
- }>(node: N | null | undefined) => node is Extract<N, {
146
- __typename: T;
147
- }>;
148
- type DeepPartial<T> = T extends object ? {
149
- [P in keyof T]?: DeepPartial<T[P]>;
150
- } : T;
151
- type JSONLiteral = string | number | boolean | null;
152
- type JSONType = JSONLiteral | JSONType[] | {
153
- [key: string]: JSONType;
154
- };
155
- type JSONObject = {
156
- [key: string]: JSONType;
157
- };
158
-
159
- declare const isError: (e: unknown) => e is Error;
160
- type ErrorWithMessage = {
161
- message: string;
162
- };
163
- declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
164
- declare const getErrorMsg: (e: unknown) => string;
165
- declare const isErrorMsg: (e: unknown, msg: string) => boolean;
166
- declare function errorToJSON(err: unknown): JSONType;
167
-
168
- declare const bytesToHex: (bytes: Uint8Array) => string;
169
- declare const hexToBytes: (hex: string) => Uint8Array;
170
-
171
- declare function getCurrentLocale(): string;
172
-
173
- declare const countryCodesToCurrencyCodes: {
174
- readonly AD: "EUR";
175
- readonly AR: "ARS";
176
- readonly AS: "USD";
177
- readonly AT: "EUR";
178
- readonly AU: "AUD";
179
- readonly AX: "EUR";
180
- readonly BE: "EUR";
181
- readonly BL: "EUR";
182
- readonly BQ: "USD";
183
- readonly BR: "BRL";
184
- readonly CA: "CAD";
185
- readonly CO: "COP";
186
- readonly CY: "EUR";
187
- readonly DE: "EUR";
188
- readonly EC: "USD";
189
- readonly EE: "EUR";
190
- readonly ES: "EUR";
191
- readonly FI: "EUR";
192
- readonly FM: "USD";
193
- readonly FR: "EUR";
194
- readonly GB: "GBP";
195
- readonly GF: "EUR";
196
- readonly GG: "GBP";
197
- readonly GP: "EUR";
198
- readonly GR: "EUR";
199
- readonly GS: "GBP";
200
- readonly GU: "USD";
201
- readonly IE: "EUR";
202
- readonly IM: "GBP";
203
- readonly IN: "INR";
204
- readonly IO: "USD";
205
- readonly IT: "EUR";
206
- readonly JE: "GBP";
207
- readonly LT: "EUR";
208
- readonly LU: "EUR";
209
- readonly LV: "EUR";
210
- readonly MC: "EUR";
211
- readonly ME: "EUR";
212
- readonly MF: "EUR";
213
- readonly MH: "USD";
214
- readonly MP: "USD";
215
- readonly MQ: "EUR";
216
- readonly MT: "EUR";
217
- readonly MX: "MXN";
218
- readonly NF: "AUD";
219
- readonly NL: "EUR";
220
- readonly NR: "AUD";
221
- readonly PM: "EUR";
222
- readonly PR: "USD";
223
- readonly PT: "EUR";
224
- readonly PW: "USD";
225
- readonly RE: "EUR";
226
- readonly SI: "EUR";
227
- readonly SK: "EUR";
228
- readonly SM: "EUR";
229
- readonly TC: "USD";
230
- readonly TF: "EUR";
231
- readonly TL: "USD";
232
- readonly TV: "AUD";
233
- readonly UM: "USD";
234
- readonly US: "USD";
235
- readonly VA: "EUR";
236
- readonly VG: "USD";
237
- readonly VI: "USD";
238
- readonly YT: "EUR";
239
- };
240
- type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
241
- type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
242
- declare function localeToCurrencyCode(locale: string): CurrencyCodes;
243
-
244
- declare function clamp(val: number, min: number, max: number): number;
245
- declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
246
- declare function round(num: number, decimalPlaces?: number): number;
247
- declare function isNumber(value: unknown): value is number;
248
-
249
- type GetValueResult<T> = {
250
- stopPolling: boolean;
251
- value: null | T;
252
- };
253
- declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getValue: (data: Awaited<ReturnType<D>>, response: {
254
- stopPolling: boolean;
255
- value: null | T;
256
- }) => GetValueResult<T>, maxPolls?: number, pollIntervalMs?: number, ignoreErrors?: boolean | ((e: unknown) => boolean), getMaxPollsError?: (maxPolls: number) => Error): Promise<T>;
257
-
258
- declare function sleep(ms: number): Promise<unknown>;
259
-
260
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, JSONLiteral, JSONObject, JSONType, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, errorToJSON, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode };
1
+ export { W as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from '../index-d0c72658.js';
@@ -10,10 +10,13 @@ import {
10
10
  countryCodesToCurrencyCodes,
11
11
  createSha256Hash,
12
12
  defaultCurrencyCode,
13
+ deleteLocalStorageItem,
13
14
  errorToJSON,
14
15
  formatCurrencyStr,
15
16
  getCurrentLocale,
16
17
  getErrorMsg,
18
+ getLocalStorageBoolean,
19
+ getLocalStorageConfigItem,
17
20
  hexToBytes,
18
21
  isBrowser,
19
22
  isCurrencyAmount,
@@ -33,9 +36,10 @@ import {
33
36
  pollUntil,
34
37
  round,
35
38
  separateCurrencyStrParts,
39
+ setLocalStorageBoolean,
36
40
  sleep,
37
41
  urlsafe_b64decode
38
- } from "../chunk-BYCLLNFL.js";
42
+ } from "../chunk-ADJSE2YZ.js";
39
43
  export {
40
44
  CurrencyUnit,
41
45
  abbrCurrencyUnit,
@@ -48,10 +52,13 @@ export {
48
52
  countryCodesToCurrencyCodes,
49
53
  createSha256Hash,
50
54
  defaultCurrencyCode,
55
+ deleteLocalStorageItem,
51
56
  errorToJSON,
52
57
  formatCurrencyStr,
53
58
  getCurrentLocale,
54
59
  getErrorMsg,
60
+ getLocalStorageBoolean,
61
+ getLocalStorageConfigItem,
55
62
  hexToBytes,
56
63
  isBrowser,
57
64
  isCurrencyAmount,
@@ -71,6 +78,7 @@ export {
71
78
  pollUntil,
72
79
  round,
73
80
  separateCurrencyStrParts,
81
+ setLocalStorageBoolean,
74
82
  sleep,
75
83
  urlsafe_b64decode
76
84
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/core",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -1 +1,5 @@
1
- export * from "./localStorage.js";
1
+ export const ConfigKeys = {
2
+ LoggingEnabled: "lightspark-logging-enabled",
3
+ ConsoleToolsEnabled: "lightspark-console-tools-enabled",
4
+ } as const;
5
+ export type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
@@ -45,6 +45,6 @@ export class Secp256k1SigningKey extends SigningKey {
45
45
  const keyBytes = new Uint8Array(hexToBytes(this.privateKey));
46
46
  const hash = await createSha256Hash(data);
47
47
  const signResult = secp256k1.ecdsaSign(hash, keyBytes);
48
- return signResult.signature;
48
+ return secp256k1.signatureExport(signResult.signature);
49
49
  }
50
50
  }
@@ -245,9 +245,11 @@ class Requester {
245
245
  );
246
246
  }
247
247
 
248
- let TextEncoderImpl = TextEncoder;
248
+ let TextEncoderImpl;
249
249
  if (typeof TextEncoder === "undefined") {
250
250
  TextEncoderImpl = (await import("text-encoding")).TextEncoder;
251
+ } else {
252
+ TextEncoderImpl = TextEncoder;
251
253
  }
252
254
  const encodedPayload = new TextEncoderImpl().encode(
253
255
  JSON.stringify(payload),
@@ -6,6 +6,7 @@ export * from "./currency.js";
6
6
  export * from "./environment.js";
7
7
  export * from "./errors.js";
8
8
  export * from "./hex.js";
9
+ export * from "./localStorage.js";
9
10
  export * from "./locale.js";
10
11
  export * from "./localeToCurrencyCodes.js";
11
12
  export * from "./numbers.js";
@@ -0,0 +1,32 @@
1
+ import { type ConfigKeys } from "../constants/index.js";
2
+
3
+ export function getLocalStorageConfigItem(key: ConfigKeys) {
4
+ return getLocalStorageBoolean(key);
5
+ }
6
+
7
+ export function getLocalStorageBoolean(key: string) {
8
+ /* localStorage is not available in all contexts, use try/catch: */
9
+ try {
10
+ return localStorage.getItem(key) === "1";
11
+ } catch (e) {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ export function setLocalStorageBoolean(key: string, value: boolean) {
17
+ /* localStorage is not available in all contexts, use try/catch: */
18
+ try {
19
+ localStorage.setItem(key, value ? "1" : "0");
20
+ } catch (e) {
21
+ // ignore
22
+ }
23
+ }
24
+
25
+ export const deleteLocalStorageItem = (key: string) => {
26
+ /* localStorage is not available in all contexts, use try/catch: */
27
+ try {
28
+ localStorage.removeItem(key);
29
+ } catch (e) {
30
+ // ignore
31
+ }
32
+ };
@@ -1,18 +0,0 @@
1
- export const ConfigKeys = {
2
- LoggingEnabled: "lightspark-logging-enabled",
3
- ConsoleToolsEnabled: "lightspark-console-tools-enabled",
4
- } as const;
5
- export type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
6
-
7
- export const getLocalStorageConfigItem = (key: ConfigKeys) => {
8
- return getLocalStorageBoolean(key);
9
- };
10
-
11
- export const getLocalStorageBoolean = (key: string) => {
12
- /* localStorage is not available in all contexts, use try/catch: */
13
- try {
14
- return localStorage.getItem(key) === "1";
15
- } catch (e) {
16
- return false;
17
- }
18
- };