@lightsparkdev/core 1.0.9 → 1.0.11

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/dist/index.d.ts CHANGED
@@ -1,5 +1,27 @@
1
1
  import { Observable } from 'zen-observable-ts';
2
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, 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 } from './utils/index.js';
2
+ 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 } from './utils/index.js';
3
+
4
+ declare class LightsparkException extends Error {
5
+ code: string;
6
+ message: string;
7
+ extraInfo: Record<string, unknown> | undefined;
8
+ constructor(code: string, message: string, extraInfo?: Record<string, unknown>);
9
+ }
10
+
11
+ type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
12
+ declare class Logger {
13
+ context: string;
14
+ loggingEnabled: boolean;
15
+ constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
16
+ updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
17
+ info(message: string, ...rest: unknown[]): void;
18
+ }
19
+
20
+ declare enum ServerEnvironment {
21
+ PRODUCTION = "production",
22
+ DEV = "dev"
23
+ }
24
+ declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
3
25
 
4
26
  type Headers = Record<string, string>;
5
27
  type WsConnectionParams = Record<string, unknown>;
@@ -9,13 +31,6 @@ interface AuthProvider {
9
31
  addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
10
32
  }
11
33
 
12
- declare class LightsparkException extends Error {
13
- code: string;
14
- message: string;
15
- extraInfo: Record<string, unknown> | undefined;
16
- constructor(code: string, message: string, extraInfo?: Record<string, unknown>);
17
- }
18
-
19
34
  declare class LightsparkAuthException extends LightsparkException {
20
35
  constructor(message: string, extraInfo?: Record<string, unknown>);
21
36
  }
@@ -33,6 +48,20 @@ declare const ConfigKeys: {
33
48
  type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
34
49
  declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
35
50
 
51
+ type OnlyKey = {
52
+ key: string;
53
+ alias?: never;
54
+ };
55
+ type OnlyAlias = {
56
+ key?: never;
57
+ alias: string;
58
+ };
59
+ type KeyOrAliasType = OnlyKey | OnlyAlias;
60
+ declare const KeyOrAlias: {
61
+ key: (key: string) => OnlyKey;
62
+ alias: (alias: string) => OnlyAlias;
63
+ };
64
+
36
65
  declare class LightsparkSigningException extends LightsparkException {
37
66
  constructor(message: string, extraInfo?: Record<string, unknown>);
38
67
  }
@@ -60,20 +89,6 @@ declare const DefaultCrypto: {
60
89
  importPrivateSigningKey: (keyData: Uint8Array) => Promise<CryptoKey | string>;
61
90
  };
62
91
 
63
- type OnlyKey = {
64
- key: string;
65
- alias?: never;
66
- };
67
- type OnlyAlias = {
68
- key?: never;
69
- alias: string;
70
- };
71
- type KeyOrAliasType = OnlyKey | OnlyAlias;
72
- declare const KeyOrAlias: {
73
- key: (key: string) => OnlyKey;
74
- alias: (alias: string) => OnlyAlias;
75
- };
76
-
77
92
  interface Alias {
78
93
  alias: string;
79
94
  }
@@ -109,15 +124,6 @@ declare class NodeKeyCache {
109
124
  private stripPemTags;
110
125
  }
111
126
 
112
- type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
113
- declare class Logger {
114
- context: string;
115
- loggingEnabled: boolean;
116
- constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
117
- updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
118
- info(message: string, ...rest: unknown[]): void;
119
- }
120
-
121
127
  type Query<T> = {
122
128
  /** The string representation of the query payload for graphQL. **/
123
129
  queryPayload: string;
@@ -125,7 +131,10 @@ type Query<T> = {
125
131
  variables?: {
126
132
  [key: string]: unknown;
127
133
  };
128
- /** The function that will be called to construct the object from the response. **/
134
+ /**
135
+ * The function that will be called to construct the object from the
136
+ * response. *
137
+ */
129
138
  constructObject: (rawData: any) => T;
130
139
  /** The id of the node that will be used to sign the query. **/
131
140
  signingNodeId?: string;
@@ -150,16 +159,10 @@ declare class Requester {
150
159
  }>;
151
160
  makeRawRequest(queryPayload: string, variables?: {
152
161
  [key: string]: unknown;
153
- }, signingNodeId?: string | undefined, skipAuth?: boolean): Promise<any | null>;
162
+ }, signingNodeId?: string | undefined, skipAuth?: boolean): Promise<any>;
154
163
  private getSdkUserAgent;
155
164
  private stripProtocol;
156
165
  private addSigningDataIfNeeded;
157
166
  }
158
167
 
159
- declare enum ServerEnvironment {
160
- PRODUCTION = "production",
161
- DEV = "dev"
162
- }
163
- declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
164
-
165
168
  export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageConfigItem };
package/dist/index.js CHANGED
@@ -35,7 +35,56 @@ import {
35
35
  separateCurrencyStrParts,
36
36
  sleep,
37
37
  urlsafe_b64decode
38
- } from "./chunk-UU6SHVGX.js";
38
+ } from "./chunk-F3XHLUGC.js";
39
+
40
+ // src/Logger.ts
41
+ var Logger = class {
42
+ context;
43
+ loggingEnabled = false;
44
+ constructor(loggerContext, getLoggingEnabled) {
45
+ this.context = loggerContext;
46
+ void this.updateLoggingEnabled(getLoggingEnabled);
47
+ }
48
+ async updateLoggingEnabled(getLoggingEnabled) {
49
+ if (getLoggingEnabled) {
50
+ this.loggingEnabled = await getLoggingEnabled();
51
+ } else if (isTest) {
52
+ this.loggingEnabled = true;
53
+ } else if (isBrowser) {
54
+ try {
55
+ this.loggingEnabled = getLocalStorageConfigItem(
56
+ ConfigKeys.LoggingEnabled
57
+ );
58
+ } catch (e) {
59
+ }
60
+ }
61
+ if (this.loggingEnabled) {
62
+ console.log(`[${this.context}] Logging enabled`);
63
+ }
64
+ }
65
+ info(message, ...rest) {
66
+ if (this.loggingEnabled) {
67
+ console.log(`[${this.context}] ${message}`, ...rest);
68
+ }
69
+ }
70
+ };
71
+ var logger = new Logger("@lightsparkdev/core");
72
+
73
+ // src/ServerEnvironment.ts
74
+ var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
75
+ ServerEnvironment2["PRODUCTION"] = "production";
76
+ ServerEnvironment2["DEV"] = "dev";
77
+ return ServerEnvironment2;
78
+ })(ServerEnvironment || {});
79
+ var apiDomainForEnvironment = (environment) => {
80
+ switch (environment) {
81
+ case "dev" /* DEV */:
82
+ return "api.dev.dev.sparkinfra.net";
83
+ case "production" /* PRODUCTION */:
84
+ return "api.lightspark.com";
85
+ }
86
+ };
87
+ var ServerEnvironment_default = ServerEnvironment;
39
88
 
40
89
  // src/auth/LightsparkAuthException.ts
41
90
  var LightsparkAuthException = class extends LightsparkException_default {
@@ -47,14 +96,14 @@ var LightsparkAuthException_default = LightsparkAuthException;
47
96
 
48
97
  // src/auth/StubAuthProvider.ts
49
98
  var StubAuthProvider = class {
50
- async addAuthHeaders(headers) {
51
- return headers;
99
+ addAuthHeaders(headers) {
100
+ return Promise.resolve(headers);
52
101
  }
53
- async isAuthorized() {
54
- return false;
102
+ isAuthorized() {
103
+ return Promise.resolve(false);
55
104
  }
56
- async addWsConnectionParams(params) {
57
- return params;
105
+ addWsConnectionParams(params) {
106
+ return Promise.resolve(params);
58
107
  }
59
108
  };
60
109
 
@@ -71,6 +120,12 @@ var getLocalStorageConfigItem = (key) => {
71
120
  }
72
121
  };
73
122
 
123
+ // src/crypto/KeyOrAlias.ts
124
+ var KeyOrAlias = {
125
+ key: (key) => ({ key }),
126
+ alias: (alias) => ({ alias })
127
+ };
128
+
74
129
  // src/crypto/LightsparkSigningException.ts
75
130
  var LightsparkSigningException = class extends LightsparkException_default {
76
131
  constructor(message, extraInfo) {
@@ -79,6 +134,9 @@ var LightsparkSigningException = class extends LightsparkException_default {
79
134
  };
80
135
  var LightsparkSigningException_default = LightsparkSigningException;
81
136
 
137
+ // src/crypto/NodeKeyCache.ts
138
+ import autoBind from "auto-bind";
139
+
82
140
  // src/crypto/crypto.ts
83
141
  var getCrypto = () => {
84
142
  let cryptoImplPromise;
@@ -162,7 +220,7 @@ var decrypt = async (header_json, ciphertext, password) => {
162
220
  if (header.v < 0 || header.v > 4) {
163
221
  throw new LightsparkException_default(
164
222
  "DecryptionError",
165
- "Unknown version ".concat(header.v)
223
+ `Unknown version ${header.v}`
166
224
  );
167
225
  }
168
226
  const cryptoImpl = await getCrypto();
@@ -173,7 +231,10 @@ var decrypt = async (header_json, ciphertext, password) => {
173
231
  const salt = decoded.slice(decoded.length - 8, decoded.length);
174
232
  const nonce = decoded.slice(0, 12);
175
233
  const cipherText = decoded.slice(12, decoded.length - 8);
176
- const [key, _iv] = await deriveKey(
234
+ const [
235
+ key
236
+ /* , _iv */
237
+ ] = await deriveKey(
177
238
  password,
178
239
  salt,
179
240
  header.i,
@@ -283,15 +344,6 @@ var DefaultCrypto = {
283
344
  importPrivateSigningKey
284
345
  };
285
346
 
286
- // src/crypto/KeyOrAlias.ts
287
- var KeyOrAlias = {
288
- key: (key) => ({ key }),
289
- alias: (alias) => ({ alias })
290
- };
291
-
292
- // src/crypto/NodeKeyCache.ts
293
- import autoBind from "auto-bind";
294
-
295
347
  // src/crypto/SigningKey.ts
296
348
  import secp256k1 from "secp256k1";
297
349
  function isAlias(key) {
@@ -388,39 +440,6 @@ var NodeKeyCache = class {
388
440
  };
389
441
  var NodeKeyCache_default = NodeKeyCache;
390
442
 
391
- // src/Logger.ts
392
- var Logger = class {
393
- context;
394
- loggingEnabled = false;
395
- constructor(loggerContext, getLoggingEnabled) {
396
- this.context = loggerContext;
397
- this.updateLoggingEnabled(getLoggingEnabled);
398
- }
399
- async updateLoggingEnabled(getLoggingEnabled) {
400
- if (getLoggingEnabled) {
401
- this.loggingEnabled = await getLoggingEnabled();
402
- } else if (isTest) {
403
- this.loggingEnabled = true;
404
- } else if (isBrowser) {
405
- try {
406
- this.loggingEnabled = getLocalStorageConfigItem(
407
- ConfigKeys.LoggingEnabled
408
- );
409
- } catch (e) {
410
- }
411
- }
412
- if (this.loggingEnabled) {
413
- console.log(`[${this.context}] Logging enabled`);
414
- }
415
- }
416
- info(message, ...rest) {
417
- if (this.loggingEnabled) {
418
- console.log(`[${this.context}] ${message}`, ...rest);
419
- }
420
- }
421
- };
422
- var logger = new Logger("@lightsparkdev/core");
423
-
424
443
  // src/requester/Requester.ts
425
444
  import autoBind2 from "auto-bind";
426
445
  import dayjs from "dayjs";
@@ -545,6 +564,7 @@ var Requester = class {
545
564
  const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
546
565
  logger.info(`Requester.makeRawRequest`, {
547
566
  url,
567
+ operationName: operation,
548
568
  variables
549
569
  });
550
570
  const response = await fetch(url, {
@@ -592,7 +612,7 @@ var Requester = class {
592
612
  nonce,
593
613
  expires_at: expiration
594
614
  };
595
- const key = await this.nodeKeyCache.getKey(signingNodeId);
615
+ const key = this.nodeKeyCache.getKey(signingNodeId);
596
616
  if (!key) {
597
617
  throw new LightsparkSigningException_default(
598
618
  "Missing node of encrypted_signing_private_key"
@@ -615,22 +635,6 @@ var Requester = class {
615
635
  }
616
636
  };
617
637
  var Requester_default = Requester;
618
-
619
- // src/ServerEnvironment.ts
620
- var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
621
- ServerEnvironment2["PRODUCTION"] = "production";
622
- ServerEnvironment2["DEV"] = "dev";
623
- return ServerEnvironment2;
624
- })(ServerEnvironment || {});
625
- var apiDomainForEnvironment = (environment) => {
626
- switch (environment) {
627
- case "dev" /* DEV */:
628
- return "api.dev.dev.sparkinfra.net";
629
- case "production" /* PRODUCTION */:
630
- return "api.lightspark.com";
631
- }
632
- };
633
- var ServerEnvironment_default = ServerEnvironment;
634
638
  export {
635
639
  ConfigKeys,
636
640
  CurrencyUnit,
@@ -886,39 +886,38 @@ function sleep(ms) {
886
886
  function getDefaultMaxPollsError() {
887
887
  return new Error("pollUntil: Max polls reached");
888
888
  }
889
- function pollUntil(asyncFn, getValue, maxPolls = 60, pollIntervalMs = 500, ignoreErrors = false, getMaxPollsError = getDefaultMaxPollsError) {
890
- return new Promise((resolve, reject) => {
891
- let polls = 0;
892
- let stopPolling = false;
893
- (async function() {
894
- while (!stopPolling) {
895
- polls += 1;
896
- if (polls > maxPolls) {
897
- stopPolling = true;
898
- const maxPollsError = getMaxPollsError(maxPolls);
899
- reject(maxPollsError);
900
- break;
901
- }
902
- try {
903
- const asyncResult = await asyncFn();
904
- const result = getValue(asyncResult, {
905
- stopPolling: false,
906
- value: null
907
- });
908
- if (result.stopPolling) {
909
- stopPolling = true;
910
- resolve(result.value);
911
- }
912
- } catch (e) {
913
- if (!ignoreErrors || isFunction_default(ignoreErrors) && !ignoreErrors(e)) {
914
- stopPolling = true;
915
- reject(e);
916
- }
917
- }
918
- await sleep(pollIntervalMs);
889
+ async function pollUntil(asyncFn, getValue, maxPolls = 60, pollIntervalMs = 500, ignoreErrors = false, getMaxPollsError = getDefaultMaxPollsError) {
890
+ let polls = 0;
891
+ let stopPolling = false;
892
+ let result = {
893
+ stopPolling: false,
894
+ value: null
895
+ };
896
+ while (!stopPolling) {
897
+ polls += 1;
898
+ if (polls > maxPolls) {
899
+ stopPolling = true;
900
+ const maxPollsError = getMaxPollsError(maxPolls);
901
+ throw maxPollsError;
902
+ }
903
+ try {
904
+ const asyncResult = await asyncFn();
905
+ result = getValue(asyncResult, {
906
+ stopPolling: false,
907
+ value: null
908
+ });
909
+ if (result.stopPolling) {
910
+ stopPolling = true;
919
911
  }
920
- })();
921
- });
912
+ } catch (e) {
913
+ if (!ignoreErrors || isFunction_default(ignoreErrors) && !ignoreErrors(e)) {
914
+ stopPolling = true;
915
+ throw e;
916
+ }
917
+ }
918
+ await sleep(pollIntervalMs);
919
+ }
920
+ return result.value;
922
921
  }
923
922
 
924
923
  // src/utils/types.ts
@@ -0,0 +1,252 @@
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
+ 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 };