@lightsparkdev/core 1.0.11 → 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 +12 -0
- package/dist/{chunk-F3XHLUGC.js → chunk-ADJSE2YZ.js} +37 -0
- package/dist/index-d0c72658.d.ts +271 -0
- package/dist/index.cjs +45 -10
- package/dist/index.d.cts +2 -9
- package/dist/index.d.ts +2 -9
- package/dist/index.js +15 -11
- package/dist/utils/index.cjs +42 -0
- package/dist/utils/index.d.cts +1 -252
- package/dist/utils/index.d.ts +1 -252
- package/dist/utils/index.js +11 -1
- package/package.json +1 -1
- package/src/constants/index.ts +5 -1
- package/src/crypto/SigningKey.ts +1 -1
- package/src/requester/Requester.ts +3 -1
- package/src/utils/errors.ts +16 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/localStorage.ts +32 -0
- package/src/utils/types.ts +4 -0
- package/src/constants/localStorage.ts +0 -13
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,252 +1 @@
|
|
|
1
|
-
|
|
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
|
-
declare const isError: (e: unknown) => e is Error;
|
|
136
|
-
type ErrorWithMessage = {
|
|
137
|
-
message: string;
|
|
138
|
-
};
|
|
139
|
-
declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
|
|
140
|
-
declare const getErrorMsg: (e: unknown) => string;
|
|
141
|
-
declare const isErrorMsg: (e: unknown, msg: string) => boolean;
|
|
142
|
-
|
|
143
|
-
declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
144
|
-
declare const hexToBytes: (hex: string) => Uint8Array;
|
|
145
|
-
|
|
146
|
-
declare function getCurrentLocale(): string;
|
|
147
|
-
|
|
148
|
-
declare const countryCodesToCurrencyCodes: {
|
|
149
|
-
readonly AD: "EUR";
|
|
150
|
-
readonly AR: "ARS";
|
|
151
|
-
readonly AS: "USD";
|
|
152
|
-
readonly AT: "EUR";
|
|
153
|
-
readonly AU: "AUD";
|
|
154
|
-
readonly AX: "EUR";
|
|
155
|
-
readonly BE: "EUR";
|
|
156
|
-
readonly BL: "EUR";
|
|
157
|
-
readonly BQ: "USD";
|
|
158
|
-
readonly BR: "BRL";
|
|
159
|
-
readonly CA: "CAD";
|
|
160
|
-
readonly CO: "COP";
|
|
161
|
-
readonly CY: "EUR";
|
|
162
|
-
readonly DE: "EUR";
|
|
163
|
-
readonly EC: "USD";
|
|
164
|
-
readonly EE: "EUR";
|
|
165
|
-
readonly ES: "EUR";
|
|
166
|
-
readonly FI: "EUR";
|
|
167
|
-
readonly FM: "USD";
|
|
168
|
-
readonly FR: "EUR";
|
|
169
|
-
readonly GB: "GBP";
|
|
170
|
-
readonly GF: "EUR";
|
|
171
|
-
readonly GG: "GBP";
|
|
172
|
-
readonly GP: "EUR";
|
|
173
|
-
readonly GR: "EUR";
|
|
174
|
-
readonly GS: "GBP";
|
|
175
|
-
readonly GU: "USD";
|
|
176
|
-
readonly IE: "EUR";
|
|
177
|
-
readonly IM: "GBP";
|
|
178
|
-
readonly IN: "INR";
|
|
179
|
-
readonly IO: "USD";
|
|
180
|
-
readonly IT: "EUR";
|
|
181
|
-
readonly JE: "GBP";
|
|
182
|
-
readonly LT: "EUR";
|
|
183
|
-
readonly LU: "EUR";
|
|
184
|
-
readonly LV: "EUR";
|
|
185
|
-
readonly MC: "EUR";
|
|
186
|
-
readonly ME: "EUR";
|
|
187
|
-
readonly MF: "EUR";
|
|
188
|
-
readonly MH: "USD";
|
|
189
|
-
readonly MP: "USD";
|
|
190
|
-
readonly MQ: "EUR";
|
|
191
|
-
readonly MT: "EUR";
|
|
192
|
-
readonly MX: "MXN";
|
|
193
|
-
readonly NF: "AUD";
|
|
194
|
-
readonly NL: "EUR";
|
|
195
|
-
readonly NR: "AUD";
|
|
196
|
-
readonly PM: "EUR";
|
|
197
|
-
readonly PR: "USD";
|
|
198
|
-
readonly PT: "EUR";
|
|
199
|
-
readonly PW: "USD";
|
|
200
|
-
readonly RE: "EUR";
|
|
201
|
-
readonly SI: "EUR";
|
|
202
|
-
readonly SK: "EUR";
|
|
203
|
-
readonly SM: "EUR";
|
|
204
|
-
readonly TC: "USD";
|
|
205
|
-
readonly TF: "EUR";
|
|
206
|
-
readonly TL: "USD";
|
|
207
|
-
readonly TV: "AUD";
|
|
208
|
-
readonly UM: "USD";
|
|
209
|
-
readonly US: "USD";
|
|
210
|
-
readonly VA: "EUR";
|
|
211
|
-
readonly VG: "USD";
|
|
212
|
-
readonly VI: "USD";
|
|
213
|
-
readonly YT: "EUR";
|
|
214
|
-
};
|
|
215
|
-
type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
|
|
216
|
-
type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
|
|
217
|
-
declare function localeToCurrencyCode(locale: string): CurrencyCodes;
|
|
218
|
-
|
|
219
|
-
declare function clamp(val: number, min: number, max: number): number;
|
|
220
|
-
declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
|
|
221
|
-
declare function round(num: number, decimalPlaces?: number): number;
|
|
222
|
-
declare function isNumber(value: unknown): value is number;
|
|
223
|
-
|
|
224
|
-
type GetValueResult<T> = {
|
|
225
|
-
stopPolling: boolean;
|
|
226
|
-
value: null | T;
|
|
227
|
-
};
|
|
228
|
-
declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getValue: (data: Awaited<ReturnType<D>>, response: {
|
|
229
|
-
stopPolling: boolean;
|
|
230
|
-
value: null | T;
|
|
231
|
-
}) => GetValueResult<T>, maxPolls?: number, pollIntervalMs?: number, ignoreErrors?: boolean | ((e: unknown) => boolean), getMaxPollsError?: (maxPolls: number) => Error): Promise<T>;
|
|
232
|
-
|
|
233
|
-
declare function sleep(ms: number): Promise<unknown>;
|
|
234
|
-
|
|
235
|
-
type Maybe<T> = T | null | undefined;
|
|
236
|
-
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
237
|
-
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
238
|
-
} : never : T;
|
|
239
|
-
type ById<T> = {
|
|
240
|
-
[id: string]: T;
|
|
241
|
-
};
|
|
242
|
-
type OmitTypename<T> = Omit<T, "__typename">;
|
|
243
|
-
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
244
|
-
__typename: string;
|
|
245
|
-
}>(node: N | null | undefined) => node is Extract<N, {
|
|
246
|
-
__typename: T;
|
|
247
|
-
}>;
|
|
248
|
-
type DeepPartial<T> = T extends object ? {
|
|
249
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
250
|
-
} : T;
|
|
251
|
-
|
|
252
|
-
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, 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';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,252 +1 @@
|
|
|
1
|
-
|
|
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
|
-
declare const isError: (e: unknown) => e is Error;
|
|
136
|
-
type ErrorWithMessage = {
|
|
137
|
-
message: string;
|
|
138
|
-
};
|
|
139
|
-
declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
|
|
140
|
-
declare const getErrorMsg: (e: unknown) => string;
|
|
141
|
-
declare const isErrorMsg: (e: unknown, msg: string) => boolean;
|
|
142
|
-
|
|
143
|
-
declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
144
|
-
declare const hexToBytes: (hex: string) => Uint8Array;
|
|
145
|
-
|
|
146
|
-
declare function getCurrentLocale(): string;
|
|
147
|
-
|
|
148
|
-
declare const countryCodesToCurrencyCodes: {
|
|
149
|
-
readonly AD: "EUR";
|
|
150
|
-
readonly AR: "ARS";
|
|
151
|
-
readonly AS: "USD";
|
|
152
|
-
readonly AT: "EUR";
|
|
153
|
-
readonly AU: "AUD";
|
|
154
|
-
readonly AX: "EUR";
|
|
155
|
-
readonly BE: "EUR";
|
|
156
|
-
readonly BL: "EUR";
|
|
157
|
-
readonly BQ: "USD";
|
|
158
|
-
readonly BR: "BRL";
|
|
159
|
-
readonly CA: "CAD";
|
|
160
|
-
readonly CO: "COP";
|
|
161
|
-
readonly CY: "EUR";
|
|
162
|
-
readonly DE: "EUR";
|
|
163
|
-
readonly EC: "USD";
|
|
164
|
-
readonly EE: "EUR";
|
|
165
|
-
readonly ES: "EUR";
|
|
166
|
-
readonly FI: "EUR";
|
|
167
|
-
readonly FM: "USD";
|
|
168
|
-
readonly FR: "EUR";
|
|
169
|
-
readonly GB: "GBP";
|
|
170
|
-
readonly GF: "EUR";
|
|
171
|
-
readonly GG: "GBP";
|
|
172
|
-
readonly GP: "EUR";
|
|
173
|
-
readonly GR: "EUR";
|
|
174
|
-
readonly GS: "GBP";
|
|
175
|
-
readonly GU: "USD";
|
|
176
|
-
readonly IE: "EUR";
|
|
177
|
-
readonly IM: "GBP";
|
|
178
|
-
readonly IN: "INR";
|
|
179
|
-
readonly IO: "USD";
|
|
180
|
-
readonly IT: "EUR";
|
|
181
|
-
readonly JE: "GBP";
|
|
182
|
-
readonly LT: "EUR";
|
|
183
|
-
readonly LU: "EUR";
|
|
184
|
-
readonly LV: "EUR";
|
|
185
|
-
readonly MC: "EUR";
|
|
186
|
-
readonly ME: "EUR";
|
|
187
|
-
readonly MF: "EUR";
|
|
188
|
-
readonly MH: "USD";
|
|
189
|
-
readonly MP: "USD";
|
|
190
|
-
readonly MQ: "EUR";
|
|
191
|
-
readonly MT: "EUR";
|
|
192
|
-
readonly MX: "MXN";
|
|
193
|
-
readonly NF: "AUD";
|
|
194
|
-
readonly NL: "EUR";
|
|
195
|
-
readonly NR: "AUD";
|
|
196
|
-
readonly PM: "EUR";
|
|
197
|
-
readonly PR: "USD";
|
|
198
|
-
readonly PT: "EUR";
|
|
199
|
-
readonly PW: "USD";
|
|
200
|
-
readonly RE: "EUR";
|
|
201
|
-
readonly SI: "EUR";
|
|
202
|
-
readonly SK: "EUR";
|
|
203
|
-
readonly SM: "EUR";
|
|
204
|
-
readonly TC: "USD";
|
|
205
|
-
readonly TF: "EUR";
|
|
206
|
-
readonly TL: "USD";
|
|
207
|
-
readonly TV: "AUD";
|
|
208
|
-
readonly UM: "USD";
|
|
209
|
-
readonly US: "USD";
|
|
210
|
-
readonly VA: "EUR";
|
|
211
|
-
readonly VG: "USD";
|
|
212
|
-
readonly VI: "USD";
|
|
213
|
-
readonly YT: "EUR";
|
|
214
|
-
};
|
|
215
|
-
type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
|
|
216
|
-
type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
|
|
217
|
-
declare function localeToCurrencyCode(locale: string): CurrencyCodes;
|
|
218
|
-
|
|
219
|
-
declare function clamp(val: number, min: number, max: number): number;
|
|
220
|
-
declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
|
|
221
|
-
declare function round(num: number, decimalPlaces?: number): number;
|
|
222
|
-
declare function isNumber(value: unknown): value is number;
|
|
223
|
-
|
|
224
|
-
type GetValueResult<T> = {
|
|
225
|
-
stopPolling: boolean;
|
|
226
|
-
value: null | T;
|
|
227
|
-
};
|
|
228
|
-
declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getValue: (data: Awaited<ReturnType<D>>, response: {
|
|
229
|
-
stopPolling: boolean;
|
|
230
|
-
value: null | T;
|
|
231
|
-
}) => GetValueResult<T>, maxPolls?: number, pollIntervalMs?: number, ignoreErrors?: boolean | ((e: unknown) => boolean), getMaxPollsError?: (maxPolls: number) => Error): Promise<T>;
|
|
232
|
-
|
|
233
|
-
declare function sleep(ms: number): Promise<unknown>;
|
|
234
|
-
|
|
235
|
-
type Maybe<T> = T | null | undefined;
|
|
236
|
-
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
237
|
-
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
238
|
-
} : never : T;
|
|
239
|
-
type ById<T> = {
|
|
240
|
-
[id: string]: T;
|
|
241
|
-
};
|
|
242
|
-
type OmitTypename<T> = Omit<T, "__typename">;
|
|
243
|
-
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
244
|
-
__typename: string;
|
|
245
|
-
}>(node: N | null | undefined) => node is Extract<N, {
|
|
246
|
-
__typename: T;
|
|
247
|
-
}>;
|
|
248
|
-
type DeepPartial<T> = T extends object ? {
|
|
249
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
250
|
-
} : T;
|
|
251
|
-
|
|
252
|
-
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, 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';
|
package/dist/utils/index.js
CHANGED
|
@@ -10,9 +10,13 @@ import {
|
|
|
10
10
|
countryCodesToCurrencyCodes,
|
|
11
11
|
createSha256Hash,
|
|
12
12
|
defaultCurrencyCode,
|
|
13
|
+
deleteLocalStorageItem,
|
|
14
|
+
errorToJSON,
|
|
13
15
|
formatCurrencyStr,
|
|
14
16
|
getCurrentLocale,
|
|
15
17
|
getErrorMsg,
|
|
18
|
+
getLocalStorageBoolean,
|
|
19
|
+
getLocalStorageConfigItem,
|
|
16
20
|
hexToBytes,
|
|
17
21
|
isBrowser,
|
|
18
22
|
isCurrencyAmount,
|
|
@@ -32,9 +36,10 @@ import {
|
|
|
32
36
|
pollUntil,
|
|
33
37
|
round,
|
|
34
38
|
separateCurrencyStrParts,
|
|
39
|
+
setLocalStorageBoolean,
|
|
35
40
|
sleep,
|
|
36
41
|
urlsafe_b64decode
|
|
37
|
-
} from "../chunk-
|
|
42
|
+
} from "../chunk-ADJSE2YZ.js";
|
|
38
43
|
export {
|
|
39
44
|
CurrencyUnit,
|
|
40
45
|
abbrCurrencyUnit,
|
|
@@ -47,9 +52,13 @@ export {
|
|
|
47
52
|
countryCodesToCurrencyCodes,
|
|
48
53
|
createSha256Hash,
|
|
49
54
|
defaultCurrencyCode,
|
|
55
|
+
deleteLocalStorageItem,
|
|
56
|
+
errorToJSON,
|
|
50
57
|
formatCurrencyStr,
|
|
51
58
|
getCurrentLocale,
|
|
52
59
|
getErrorMsg,
|
|
60
|
+
getLocalStorageBoolean,
|
|
61
|
+
getLocalStorageConfigItem,
|
|
53
62
|
hexToBytes,
|
|
54
63
|
isBrowser,
|
|
55
64
|
isCurrencyAmount,
|
|
@@ -69,6 +78,7 @@ export {
|
|
|
69
78
|
pollUntil,
|
|
70
79
|
round,
|
|
71
80
|
separateCurrencyStrParts,
|
|
81
|
+
setLocalStorageBoolean,
|
|
72
82
|
sleep,
|
|
73
83
|
urlsafe_b64decode
|
|
74
84
|
};
|
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
package/src/crypto/SigningKey.ts
CHANGED
|
@@ -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
|
|
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),
|
package/src/utils/errors.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type JSONType } from "./types.js";
|
|
2
|
+
|
|
1
3
|
export const isError = (e: unknown): e is Error => {
|
|
2
4
|
return Boolean(
|
|
3
5
|
typeof e === "object" &&
|
|
@@ -34,3 +36,17 @@ export const isErrorMsg = (e: unknown, msg: string) => {
|
|
|
34
36
|
}
|
|
35
37
|
return false;
|
|
36
38
|
};
|
|
39
|
+
|
|
40
|
+
export function errorToJSON(err: unknown) {
|
|
41
|
+
if (
|
|
42
|
+
typeof err === "object" &&
|
|
43
|
+
err !== null &&
|
|
44
|
+
"toJSON" in err &&
|
|
45
|
+
typeof err.toJSON === "function"
|
|
46
|
+
) {
|
|
47
|
+
return err.toJSON() as JSONType;
|
|
48
|
+
}
|
|
49
|
+
return JSON.parse(
|
|
50
|
+
JSON.stringify(err, Object.getOwnPropertyNames(err)),
|
|
51
|
+
) as JSONType;
|
|
52
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -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
|
+
};
|
package/src/utils/types.ts
CHANGED
|
@@ -27,3 +27,7 @@ export type DeepPartial<T> = T extends object
|
|
|
27
27
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
28
28
|
}
|
|
29
29
|
: T;
|
|
30
|
+
|
|
31
|
+
export type JSONLiteral = string | number | boolean | null;
|
|
32
|
+
export type JSONType = JSONLiteral | JSONType[] | { [key: string]: JSONType };
|
|
33
|
+
export type JSONObject = { [key: string]: JSONType };
|
|
@@ -1,13 +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
|
-
try {
|
|
9
|
-
return localStorage.getItem(key) === "1";
|
|
10
|
-
} catch (e) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
};
|