@lightsparkdev/core 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +1 -0
- package/.turbo/turbo-build.log +14 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE +201 -0
- package/README.md +11 -0
- package/dist/index.cjs +663 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +602 -0
- package/package.json +63 -0
- package/src/LightsparkException.ts +16 -0
- package/src/ServerEnvironment.ts +17 -0
- package/src/auth/AuthProvider.ts +7 -0
- package/src/auth/LightsparkAuthException.ts +11 -0
- package/src/auth/StubAuthProvider.ts +16 -0
- package/src/auth/index.ts +5 -0
- package/src/crypto/LightsparkSigningException.ts +11 -0
- package/src/crypto/NodeKeyCache.ts +46 -0
- package/src/crypto/crypto.ts +258 -0
- package/src/crypto/index.ts +5 -0
- package/src/index.ts +11 -0
- package/src/requester/Query.ts +17 -0
- package/src/requester/Requester.ts +226 -0
- package/src/requester/index.ts +4 -0
- package/src/utils/base64.ts +15 -0
- package/src/utils/currency.ts +119 -0
- package/src/utils/environment.ts +7 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/types.ts +23 -0
- package/tsconfig.json +35 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Observable } from 'zen-observable-ts';
|
|
2
|
+
|
|
3
|
+
interface AuthProvider {
|
|
4
|
+
addAuthHeaders(headers: any): Promise<any>;
|
|
5
|
+
isAuthorized(): Promise<boolean>;
|
|
6
|
+
addWsConnectionParams(params: any): any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare class LightsparkException extends Error {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
extraInfo: any;
|
|
13
|
+
constructor(code: string, message: string, extraInfo?: any);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class LightsparkAuthException extends LightsparkException {
|
|
17
|
+
constructor(message: string, extraInfo?: any);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare class StubAuthProvider implements AuthProvider {
|
|
21
|
+
addAuthHeaders(headers: any): Promise<any>;
|
|
22
|
+
isAuthorized(): Promise<boolean>;
|
|
23
|
+
addWsConnectionParams(params: any): any;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare class LightsparkSigningException extends LightsparkException {
|
|
27
|
+
constructor(message: string, extraInfo?: any);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare function getCrypto(): Promise<Crypto>;
|
|
31
|
+
declare const encrypt: (plaintext: ArrayBuffer, password: string, salt?: Uint8Array) => Promise<[
|
|
32
|
+
string,
|
|
33
|
+
string
|
|
34
|
+
]>;
|
|
35
|
+
declare const decrypt: (header_json: string, ciphertext: string, password: string) => Promise<ArrayBuffer>;
|
|
36
|
+
declare function decryptSecretWithNodePassword(cipher: string, encryptedSecret: string, nodePassword: string): Promise<ArrayBuffer | null>;
|
|
37
|
+
declare function decode(arrBuff: ArrayBuffer): string;
|
|
38
|
+
declare const generateSigningKeyPair: () => Promise<CryptoKeyPair>;
|
|
39
|
+
declare const serializeSigningKey: (key: CryptoKey, format: "pkcs8" | "spki") => Promise<ArrayBuffer>;
|
|
40
|
+
declare const encryptWithNodeKey: (key: CryptoKey, data: string) => Promise<string>;
|
|
41
|
+
declare const loadNodeEncryptionKey: (rawPublicKey: string) => Promise<CryptoKey>;
|
|
42
|
+
declare const getNonce: () => Promise<number>;
|
|
43
|
+
|
|
44
|
+
declare class NodeKeyCache {
|
|
45
|
+
private idToKey;
|
|
46
|
+
constructor();
|
|
47
|
+
loadKey(id: string, rawKey: string): Promise<CryptoKey | null>;
|
|
48
|
+
getKey(id: string): CryptoKey | undefined;
|
|
49
|
+
hasKey(id: string): boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type Query<T> = {
|
|
53
|
+
/** The string representation of the query payload for graphQL. **/
|
|
54
|
+
queryPayload: string;
|
|
55
|
+
/** The variables that will be passed to the query. **/
|
|
56
|
+
variables?: {
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
};
|
|
59
|
+
/** The function that will be called to construct the object from the response. **/
|
|
60
|
+
constructObject: (rawData: any) => T;
|
|
61
|
+
/** The id of the node that will be used to sign the query. **/
|
|
62
|
+
signingNodeId?: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
declare class Requester {
|
|
66
|
+
private readonly nodeKeyCache;
|
|
67
|
+
private readonly schemaEndpoint;
|
|
68
|
+
private readonly authProvider;
|
|
69
|
+
private readonly baseUrl;
|
|
70
|
+
private readonly wsClient;
|
|
71
|
+
constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, authProvider?: AuthProvider, baseUrl?: string);
|
|
72
|
+
executeQuery<T>(query: Query<T>): Promise<T | null>;
|
|
73
|
+
subscribe(queryPayload: string, variables?: {
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
}): Observable<any>;
|
|
76
|
+
makeRawRequest(queryPayload: string, variables?: {
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
}, signingNodeId?: string | undefined): Promise<any | null>;
|
|
79
|
+
private getSdkUserAgent;
|
|
80
|
+
private addSigningDataIfNeeded;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare enum ServerEnvironment {
|
|
84
|
+
PRODUCTION = "production",
|
|
85
|
+
DEV = "dev"
|
|
86
|
+
}
|
|
87
|
+
declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
|
|
88
|
+
|
|
89
|
+
declare const b64decode: (encoded: string) => Uint8Array;
|
|
90
|
+
declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
|
|
91
|
+
declare const b64encode: (data: ArrayBuffer) => string;
|
|
92
|
+
|
|
93
|
+
/** Represents the value and unit for an amount of currency. **/
|
|
94
|
+
type CurrencyAmount = {
|
|
95
|
+
/** The original numeric value for this CurrencyAmount. **/
|
|
96
|
+
originalValue: number;
|
|
97
|
+
/** The original unit of currency for this CurrencyAmount. **/
|
|
98
|
+
originalUnit: CurrencyUnit;
|
|
99
|
+
/** The unit of user's preferred currency. **/
|
|
100
|
+
preferredCurrencyUnit: CurrencyUnit;
|
|
101
|
+
/**
|
|
102
|
+
* The rounded numeric value for this CurrencyAmount in the very base level of user's preferred
|
|
103
|
+
* currency. For example, for USD, the value will be in cents.
|
|
104
|
+
**/
|
|
105
|
+
preferredCurrencyValueRounded: number;
|
|
106
|
+
/**
|
|
107
|
+
* The approximate float value for this CurrencyAmount in the very base level of user's preferred
|
|
108
|
+
* currency. For example, for USD, the value will be in cents.
|
|
109
|
+
**/
|
|
110
|
+
preferredCurrencyValueApprox: number;
|
|
111
|
+
};
|
|
112
|
+
declare enum CurrencyUnit {
|
|
113
|
+
/**
|
|
114
|
+
* This is an enum value that represents values that could be added in the future.
|
|
115
|
+
* Clients should support unknown values as more of them could be added without notice.
|
|
116
|
+
*/
|
|
117
|
+
FUTURE_VALUE = "FUTURE_VALUE",
|
|
118
|
+
/** Bitcoin is the cryptocurrency native to the Bitcoin network. It is used as the native medium for value transfer for the Lightning Network. **/
|
|
119
|
+
BITCOIN = "BITCOIN",
|
|
120
|
+
/** 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin. This is the unit most commonly used in Lightning transactions. **/
|
|
121
|
+
SATOSHI = "SATOSHI",
|
|
122
|
+
/** 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
123
|
+
MILLISATOSHI = "MILLISATOSHI",
|
|
124
|
+
/** United States Dollar. **/
|
|
125
|
+
USD = "USD",
|
|
126
|
+
/** 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
127
|
+
NANOBITCOIN = "NANOBITCOIN",
|
|
128
|
+
/** 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
129
|
+
MICROBITCOIN = "MICROBITCOIN",
|
|
130
|
+
/** 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
131
|
+
MILLIBITCOIN = "MILLIBITCOIN"
|
|
132
|
+
}
|
|
133
|
+
declare const convertCurrencyAmount: (from: CurrencyAmount, toUnit: CurrencyUnit) => CurrencyAmount;
|
|
134
|
+
|
|
135
|
+
declare const isBrowser: boolean;
|
|
136
|
+
declare const isNode: boolean;
|
|
137
|
+
|
|
138
|
+
type Maybe<T> = T | null | undefined;
|
|
139
|
+
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
140
|
+
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
141
|
+
} : never : T;
|
|
142
|
+
type ById<T> = {
|
|
143
|
+
[id: string]: T;
|
|
144
|
+
};
|
|
145
|
+
type OmitTypename<T> = Omit<T, "__typename">;
|
|
146
|
+
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
147
|
+
__typename: string;
|
|
148
|
+
}>(node: N | null | undefined) => node is Extract<N, {
|
|
149
|
+
__typename: T;
|
|
150
|
+
}>;
|
|
151
|
+
|
|
152
|
+
export { AuthProvider, ById, ExpandRecursively, LightsparkAuthException, LightsparkException, LightsparkSigningException, Maybe, NodeKeyCache, OmitTypename, Query, Requester, ServerEnvironment, StubAuthProvider, apiDomainForEnvironment, b64decode, b64encode, convertCurrencyAmount, decode, decrypt, decryptSecretWithNodePassword, encrypt, encryptWithNodeKey, generateSigningKeyPair, getCrypto, getNonce, isBrowser, isNode, isType, loadNodeEncryptionKey, serializeSigningKey, urlsafe_b64decode };
|