@lightninglabs/wavelength-core 0.1.0

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.
Files changed (93) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +31 -0
  3. package/dist/activity-options.d.ts +15 -0
  4. package/dist/activity-options.d.ts.map +1 -0
  5. package/dist/activity-options.js +7 -0
  6. package/dist/base-client.d.ts +59 -0
  7. package/dist/base-client.d.ts.map +1 -0
  8. package/dist/base-client.js +144 -0
  9. package/dist/casing.d.ts +4 -0
  10. package/dist/casing.d.ts.map +1 -0
  11. package/dist/casing.js +42 -0
  12. package/dist/client.d.ts +90 -0
  13. package/dist/client.d.ts.map +1 -0
  14. package/dist/client.js +1 -0
  15. package/dist/config.d.ts +128 -0
  16. package/dist/config.d.ts.map +1 -0
  17. package/dist/config.js +142 -0
  18. package/dist/destination.d.ts +56 -0
  19. package/dist/destination.d.ts.map +1 -0
  20. package/dist/destination.js +90 -0
  21. package/dist/engine/activity.d.ts +25 -0
  22. package/dist/engine/activity.d.ts.map +1 -0
  23. package/dist/engine/activity.js +119 -0
  24. package/dist/engine/constants.d.ts +29 -0
  25. package/dist/engine/constants.d.ts.map +1 -0
  26. package/dist/engine/constants.js +29 -0
  27. package/dist/engine/engine.d.ts +115 -0
  28. package/dist/engine/engine.d.ts.map +1 -0
  29. package/dist/engine/engine.js +548 -0
  30. package/dist/engine/machine.d.ts +50 -0
  31. package/dist/engine/machine.d.ts.map +1 -0
  32. package/dist/engine/machine.js +55 -0
  33. package/dist/engine/optionsAssertions.d.ts +2 -0
  34. package/dist/engine/optionsAssertions.d.ts.map +1 -0
  35. package/dist/engine/optionsAssertions.js +20 -0
  36. package/dist/engine/poller.d.ts +20 -0
  37. package/dist/engine/poller.d.ts.map +1 -0
  38. package/dist/engine/poller.js +51 -0
  39. package/dist/engine/reconcile.d.ts +36 -0
  40. package/dist/engine/reconcile.d.ts.map +1 -0
  41. package/dist/engine/reconcile.js +81 -0
  42. package/dist/engine/snapshot.d.ts +58 -0
  43. package/dist/engine/snapshot.d.ts.map +1 -0
  44. package/dist/engine/snapshot.js +10 -0
  45. package/dist/engine/stabilize.d.ts +8 -0
  46. package/dist/engine/stabilize.d.ts.map +1 -0
  47. package/dist/engine/stabilize.js +17 -0
  48. package/dist/engine/store.d.ts +21 -0
  49. package/dist/engine/store.d.ts.map +1 -0
  50. package/dist/engine/store.js +46 -0
  51. package/dist/errors.d.ts +55 -0
  52. package/dist/errors.d.ts.map +1 -0
  53. package/dist/errors.js +80 -0
  54. package/dist/events.d.ts +62 -0
  55. package/dist/events.d.ts.map +1 -0
  56. package/dist/events.js +1 -0
  57. package/dist/exit.d.ts +93 -0
  58. package/dist/exit.d.ts.map +1 -0
  59. package/dist/exit.js +86 -0
  60. package/dist/facade.d.ts +88 -0
  61. package/dist/facade.d.ts.map +1 -0
  62. package/dist/facade.js +150 -0
  63. package/dist/generated.d.ts +1197 -0
  64. package/dist/generated.d.ts.map +1 -0
  65. package/dist/generated.js +206 -0
  66. package/dist/index.d.ts +28 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +36 -0
  69. package/dist/passkey.d.ts +46 -0
  70. package/dist/passkey.d.ts.map +1 -0
  71. package/dist/passkey.js +16 -0
  72. package/dist/public-api-assertions.d.ts +2 -0
  73. package/dist/public-api-assertions.d.ts.map +1 -0
  74. package/dist/public-api-assertions.js +42 -0
  75. package/dist/request-assertions.d.ts +2 -0
  76. package/dist/request-assertions.d.ts.map +1 -0
  77. package/dist/request-assertions.js +12 -0
  78. package/dist/requests.d.ts +186 -0
  79. package/dist/requests.d.ts.map +1 -0
  80. package/dist/requests.js +5 -0
  81. package/dist/response-normalization.d.ts +5 -0
  82. package/dist/response-normalization.d.ts.map +1 -0
  83. package/dist/response-normalization.js +101 -0
  84. package/dist/results.d.ts +49 -0
  85. package/dist/results.d.ts.map +1 -0
  86. package/dist/results.js +4 -0
  87. package/dist/state.d.ts +87 -0
  88. package/dist/state.d.ts.map +1 -0
  89. package/dist/state.js +87 -0
  90. package/dist/version.d.ts +18 -0
  91. package/dist/version.d.ts.map +1 -0
  92. package/dist/version.js +17 -0
  93. package/package.json +42 -0
@@ -0,0 +1,5 @@
1
+ // Request types stay hand-authored: they carry semantics the wire shape does not
2
+ // (e.g. a plain password the client base64-encodes into the Go []byte field), so
3
+ // core's facade module keeps explicit request mappers for them.
4
+ /** Exact acknowledgement required to start a unilateral unroll. */
5
+ export const FORCE_UNROLL_ACK = 'I_KNOW_WHAT_I_AM_DOING';
@@ -0,0 +1,5 @@
1
+ import type { FacadeMethod } from './facade.ts';
2
+ import type { Entry } from './generated.ts';
3
+ export declare function normalizeEntry(raw: unknown): Entry;
4
+ export declare function normalizeFacadeResult<T = unknown>(method: FacadeMethod, raw: unknown): T;
5
+ //# sourceMappingURL=response-normalization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-normalization.d.ts","sourceRoot":"","sources":["../src/response-normalization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAiC5C,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CASlD;AAED,wBAAgB,qBAAqB,CAAC,CAAC,GAAG,OAAO,EAC/C,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,OAAO,GACX,CAAC,CAiEH"}
@@ -0,0 +1,101 @@
1
+ import { camelizeKeys } from "./casing.js";
2
+ import { normalizeInfo } from "./state.js";
3
+ function object(value) {
4
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
5
+ ? value
6
+ : undefined;
7
+ }
8
+ function nilPointer(value) {
9
+ return value === null ? undefined : value;
10
+ }
11
+ function nilSlice(value) {
12
+ return value === null ? [] : value;
13
+ }
14
+ function mapEntries(value) {
15
+ const entries = nilSlice(value);
16
+ return Array.isArray(entries) ? entries.map(normalizeEntry) : entries;
17
+ }
18
+ function normalizeOptionalObject(value, transform) {
19
+ if (value === null)
20
+ return undefined;
21
+ const record = object(value);
22
+ return record ? transform(record) : value;
23
+ }
24
+ export function normalizeEntry(raw) {
25
+ const camel = camelizeKeys(raw);
26
+ const entry = object(camel);
27
+ if (!entry)
28
+ return camel;
29
+ return {
30
+ ...entry,
31
+ progress: nilPointer(entry.progress),
32
+ request: nilPointer(entry.request),
33
+ };
34
+ }
35
+ export function normalizeFacadeResult(method, raw) {
36
+ const camel = camelizeKeys(raw);
37
+ if (method === 'getInfo')
38
+ return normalizeInfo(camel);
39
+ const result = object(camel);
40
+ if (!result)
41
+ return camel;
42
+ switch (method) {
43
+ case 'createWallet':
44
+ case 'openWalletFromPasskey':
45
+ return { ...result, mnemonic: nilSlice(result.mnemonic) };
46
+ case 'prepareSend':
47
+ return {
48
+ ...result,
49
+ selectedOutpoints: nilSlice(result.selectedOutpoints),
50
+ creditPreview: nilPointer(result.creditPreview),
51
+ };
52
+ case 'list': {
53
+ const normalized = { ...result };
54
+ if (Object.hasOwn(result, 'activity')) {
55
+ normalized.activity = normalizeOptionalObject(result.activity, (activity) => ({
56
+ ...activity,
57
+ entries: mapEntries(activity.entries),
58
+ }));
59
+ }
60
+ if (Object.hasOwn(result, 'vtxos')) {
61
+ normalized.vtxos = normalizeOptionalObject(result.vtxos, (inventory) => ({
62
+ ...inventory,
63
+ vtxos: nilSlice(inventory.vtxos),
64
+ }));
65
+ }
66
+ if (Object.hasOwn(result, 'onchain')) {
67
+ normalized.onchain = normalizeOptionalObject(result.onchain, (history) => ({
68
+ ...history,
69
+ txs: nilSlice(history.txs),
70
+ }));
71
+ }
72
+ return normalized;
73
+ }
74
+ case 'exit':
75
+ return { ...result, queuedOutpoints: nilSlice(result.queuedOutpoints) };
76
+ case 'exitStatus':
77
+ return {
78
+ ...result,
79
+ progress: nilPointer(result.progress),
80
+ cSV: nilPointer(result.cSV),
81
+ fees: nilPointer(result.fees),
82
+ };
83
+ case 'exitSummary':
84
+ return { ...result, exits: nilSlice(result.exits) };
85
+ case 'getExitPlan':
86
+ return { ...result, plans: nilSlice(result.plans) };
87
+ case 'sweepWallet':
88
+ return { ...result, inputs: nilSlice(result.inputs) };
89
+ case 'deposit':
90
+ case 'receive':
91
+ case 'sendPrepared':
92
+ return {
93
+ ...result,
94
+ entry: result.entry === undefined
95
+ ? undefined
96
+ : normalizeEntry(result.entry),
97
+ };
98
+ default:
99
+ return result;
100
+ }
101
+ }
@@ -0,0 +1,49 @@
1
+ import type { OpenWalletResult, SendResult as SendResultWire } from './generated.ts';
2
+ /**
3
+ * The result of opening a wallet from a passkey, re-exported verbatim under the
4
+ * SDK's public name.
5
+ */
6
+ export type OpenWalletFromPasskeyResult = OpenWalletResult;
7
+ /**
8
+ * Augments the wire send shape with `paymentHash`, the canonical place to read
9
+ * a Lightning payment hash for a send. The daemon returns it from prepareSend
10
+ * (not sendPrepared), so the client folds it into `send()`'s result. Prefer this
11
+ * field over digging into `entry.progress` / `entry.request`, and note that
12
+ * `entry.id` is an activity id, not a payment hash.
13
+ */
14
+ export type SendResult = SendResultWire & {
15
+ /** The Lightning payment hash, when the send produced one. */
16
+ paymentHash?: string;
17
+ };
18
+ /**
19
+ * Result types re-exported verbatim from the generated daemon facade types. They
20
+ * keep their generated names as part of the SDK's public surface.
21
+ */
22
+ export type { Balance, CreateWalletResult, DepositResult, ExitResult, ExitStatusResult, GetExitPlanResult, ListResult, ReceiveResult, SweepWalletResult, UnlockWalletResult, } from './generated.ts';
23
+ /**
24
+ * Detailed exit-status sub-shapes re-exported verbatim from the generated
25
+ * daemon facade types. They populate {@link ExitStatusResult} when its request
26
+ * sets `detailed`.
27
+ */
28
+ export type { ExitProgress, ExitCSV, ExitFees } from './generated.ts';
29
+ /**
30
+ * Exit portfolio types re-exported verbatim from the generated daemon facade
31
+ * types: the wallet-wide summary and its per-exit entry.
32
+ */
33
+ export type { ExitSummaryResult, ExitSummaryEntry } from './generated.ts';
34
+ /**
35
+ * Plan- and sweep-input types re-exported verbatim from the generated daemon
36
+ * facade types. `ExitInfeasibilityReason` explains why an {@link ExitPlanEntry}
37
+ * cannot start.
38
+ */
39
+ export type { ExitPlanEntry, ExitInfeasibilityReason, WalletSweepInput, } from './generated.ts';
40
+ /**
41
+ * Activity and entry types re-exported verbatim from the generated daemon facade
42
+ * types. These describe the wallet activity stream and its list/preview shapes.
43
+ */
44
+ export type { ActivityList, CreditPreview, Entry, EntryFailureCode, EntryKind, EntryPhase, EntryProgress, EntryRequest, EntryRequestType, EntryStatus, ExitJobStatus, ExitPath, ListView, OnchainHistory, OnchainTx, PrepareSendResult, SendRail, SendQuoteStatus, VTXOInventory, WalletVTXO, } from './generated.ts';
45
+ /**
46
+ * Generated string-enum constants for public result and activity shapes.
47
+ */
48
+ export { SendRailUnspecified, SendRailOffchainUnknown, SendRailInArk, SendRailLightning, SendRailOnchain, SendRailCredit, SendRailMixed, SendQuoteStatusUnspecified, SendQuoteStatusComplete, SendQuoteStatusLocalOnly, ListViewActivity, ListViewVTXOs, ListViewOnchain, ExitPathCooperative, ExitPathUnilateral, ExitPathUnilateralFallback, ExitJobStatusUnspecified, ExitJobStatusPending, ExitJobStatusMaterializing, ExitJobStatusCSVPending, ExitJobStatusSweeping, ExitJobStatusCompleted, ExitJobStatusFailed, ExitInfeasibilityReasonUnspecified, ExitInfeasibilityReasonSweepBelowDust, ExitInfeasibilityReasonUneconomical, ExitInfeasibilityReasonWalletUnderfunded, ExitInfeasibilityReasonWalletTooFewInputs, EntryKindSend, EntryKindReceive, EntryKindDeposit, EntryKindExit, EntryStatusPending, EntryStatusComplete, EntryStatusFailed, EntryPhaseUnspecified, EntryPhaseRequestCreated, EntryPhaseWaitingForPayment, EntryPhasePaymentDetected, EntryPhaseSettling, EntryPhaseConfirmed, EntryPhaseRefunding, EntryPhaseRefunded, EntryPhaseFailed, EntryPhaseWaitingForConfirmation, EntryRequestTypeLightning, EntryRequestTypeOnchain, EntryRequestTypeArk, EntryFailureCodeTimedOut, EntryFailureCodeExpired, EntryFailureCodeRefunded, EntryFailureCodeNeedsIntervention, EntryFailureCodeFailed, } from './generated.ts';
49
+ //# sourceMappingURL=results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,IAAI,cAAc,EAC7B,MAAM,gBAAgB,CAAC;AAExB;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,gBAAgB,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG;IACxC,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;GAGG;AACH,YAAY,EACV,OAAO,EACP,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtE;;;GAGG;AACH,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE1E;;;;GAIG;AACH,YAAY,EACV,aAAa,EACb,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAExB;;;GAGG;AACH,YAAY,EACV,YAAY,EACZ,aAAa,EACb,KAAK,EACL,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,eAAe,EACf,aAAa,EACb,UAAU,GACX,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,aAAa,EACb,0BAA0B,EAC1B,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,EAC1B,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,kCAAkC,EAClC,qCAAqC,EACrC,mCAAmC,EACnC,wCAAwC,EACxC,yCAAyC,EACzC,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,EACxB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,gCAAgC,EAChC,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,iCAAiC,EACjC,sBAAsB,GACvB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Generated string-enum constants for public result and activity shapes.
3
+ */
4
+ export { SendRailUnspecified, SendRailOffchainUnknown, SendRailInArk, SendRailLightning, SendRailOnchain, SendRailCredit, SendRailMixed, SendQuoteStatusUnspecified, SendQuoteStatusComplete, SendQuoteStatusLocalOnly, ListViewActivity, ListViewVTXOs, ListViewOnchain, ExitPathCooperative, ExitPathUnilateral, ExitPathUnilateralFallback, ExitJobStatusUnspecified, ExitJobStatusPending, ExitJobStatusMaterializing, ExitJobStatusCSVPending, ExitJobStatusSweeping, ExitJobStatusCompleted, ExitJobStatusFailed, ExitInfeasibilityReasonUnspecified, ExitInfeasibilityReasonSweepBelowDust, ExitInfeasibilityReasonUneconomical, ExitInfeasibilityReasonWalletUnderfunded, ExitInfeasibilityReasonWalletTooFewInputs, EntryKindSend, EntryKindReceive, EntryKindDeposit, EntryKindExit, EntryStatusPending, EntryStatusComplete, EntryStatusFailed, EntryPhaseUnspecified, EntryPhaseRequestCreated, EntryPhaseWaitingForPayment, EntryPhasePaymentDetected, EntryPhaseSettling, EntryPhaseConfirmed, EntryPhaseRefunding, EntryPhaseRefunded, EntryPhaseFailed, EntryPhaseWaitingForConfirmation, EntryRequestTypeLightning, EntryRequestTypeOnchain, EntryRequestTypeArk, EntryFailureCodeTimedOut, EntryFailureCodeExpired, EntryFailureCodeRefunded, EntryFailureCodeNeedsIntervention, EntryFailureCodeFailed, } from "./generated.js";
@@ -0,0 +1,87 @@
1
+ import type { Info, Status } from './generated.ts';
2
+ /**
3
+ * The wallet lifecycle, exposed as a lowercase string union to match the SDK's
4
+ * other enums (EntryKind, SendRail, ...). The daemon sends the proto's numeric
5
+ * enum; the client maps it to these strings at the response boundary via
6
+ * {@link walletStateFromProto}.
7
+ */
8
+ export declare const WalletState: {
9
+ /** No wallet exists yet; one must be created. */
10
+ readonly None: "none";
11
+ /** A wallet exists but is locked and must be unlocked. */
12
+ readonly Locked: "locked";
13
+ /** The wallet is unlocked and ready to use. */
14
+ readonly Ready: "ready";
15
+ /** The wallet is unlocked and catching up with the chain. */
16
+ readonly Syncing: "syncing";
17
+ };
18
+ /**
19
+ * The wallet lifecycle value type: one of the {@link WalletState} string values.
20
+ */
21
+ export type WalletState = (typeof WalletState)[keyof typeof WalletState];
22
+ /**
23
+ * Normalizes a raw daemon walletState (a proto number) to the SDK string union.
24
+ * Already-string values pass through unchanged.
25
+ *
26
+ * @param value - The raw walletState as a proto number, an SDK string, or undefined.
27
+ * @returns The normalized {@link WalletState} string.
28
+ */
29
+ export declare function walletStateFromProto(value: number | WalletState | undefined): WalletState;
30
+ export type { ServerInfo } from './generated.ts';
31
+ /**
32
+ * The daemon's Info with walletState normalized to the string union and the
33
+ * walletReady predicate backfilled (the facade exposes it as a Go method, so it
34
+ * is absent from the JSON). The client always returns this complete shape from
35
+ * `getInfo()`/`start()`; the engine snapshot holds it as `WalletInfo | null`.
36
+ */
37
+ export type WalletInfo = Omit<Info, 'walletState'> & {
38
+ /** The wallet lifecycle as the SDK string union. */
39
+ walletState: WalletState;
40
+ /** True iff the wallet is unlocked and ready (mirrors the Go Info.WalletReady() method). */
41
+ walletReady: boolean;
42
+ };
43
+ /**
44
+ * Maps a raw daemon Info (numeric walletState, no walletReady) onto the public
45
+ * {@link WalletInfo}: it converts walletState to the string union and backfills
46
+ * walletReady (ready iff walletState === 'ready'), mirroring the Go
47
+ * Info.WalletReady() method. Shared facade normalization applies this after
48
+ * the transport returns getInfo.
49
+ *
50
+ * @param raw - The raw daemon Info payload (untrusted shape).
51
+ * @returns The normalized {@link WalletInfo}.
52
+ */
53
+ export declare function normalizeInfo(raw: unknown): WalletInfo;
54
+ /**
55
+ * The lifecycle a UI renders. The runtime phases
56
+ * (loading/runtimeReady/starting/stopping/stopped/error) are owned by the host's
57
+ * start/stop flow; the wallet phases (needsWallet/locked/syncing/ready) are
58
+ * derived from {@link WalletInfo} by {@link phaseFromInfo}. It lives in core so
59
+ * non-React and React Native consumers share one vocabulary. 'restoring'
60
+ * means a background restore is bringing a fresh wallet up; the engine owns it
61
+ * (like 'starting'), it is never returned by phaseFromInfo.
62
+ */
63
+ export type RuntimePhase = 'loading' | 'runtimeReady' | 'starting' | 'needsWallet' | 'locked' | 'syncing' | 'restoring' | 'ready' | 'stopping' | 'stopped' | 'error';
64
+ /**
65
+ * The subset of {@link RuntimePhase} derivable from wallet info: the phases
66
+ * {@link phaseFromInfo} can return. The runtime-owned phases (loading,
67
+ * runtimeReady, starting, restoring, stopping, stopped, error) are not
68
+ * representable here.
69
+ */
70
+ export type WalletPhase = 'needsWallet' | 'locked' | 'syncing' | 'ready';
71
+ /**
72
+ * Derives the wallet-state phase from a {@link WalletInfo}. Runtime phases are
73
+ * not represented here; the caller owns those.
74
+ *
75
+ * @param info - The wallet state and readiness to derive the phase from.
76
+ * @returns The wallet-state {@link WalletPhase}.
77
+ */
78
+ export declare function phaseFromInfo(info: {
79
+ walletState?: WalletState;
80
+ walletReady?: boolean;
81
+ }): WalletPhase;
82
+ /**
83
+ * The daemon's runtime status snapshot, re-exported verbatim under the SDK's
84
+ * public name.
85
+ */
86
+ export type WalletStatus = Status;
87
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,WAAW;IACtB,iDAAiD;;IAEjD,0DAA0D;;IAE1D,+CAA+C;;IAE/C,6DAA6D;;CAErD,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAczE;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,GACtC,WAAW,CAcb;AAQD,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG;IACnD,oDAAoD;IACpD,WAAW,EAAE,WAAW,CAAC;IACzB,4FAA4F;IAC5F,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAWtD;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,cAAc,GACd,UAAU,GACV,aAAa,GACb,QAAQ,GACR,SAAS,GACT,WAAW,GACX,OAAO,GACP,UAAU,GACV,SAAS,GACT,OAAO,CAAC;AAEZ;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;AAEzE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE;IAClC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GAAG,WAAW,CAgBd;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC"}
package/dist/state.js ADDED
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The wallet lifecycle, exposed as a lowercase string union to match the SDK's
3
+ * other enums (EntryKind, SendRail, ...). The daemon sends the proto's numeric
4
+ * enum; the client maps it to these strings at the response boundary via
5
+ * {@link walletStateFromProto}.
6
+ */
7
+ export const WalletState = {
8
+ /** No wallet exists yet; one must be created. */
9
+ None: 'none',
10
+ /** A wallet exists but is locked and must be unlocked. */
11
+ Locked: 'locked',
12
+ /** The wallet is unlocked and ready to use. */
13
+ Ready: 'ready',
14
+ /** The wallet is unlocked and catching up with the chain. */
15
+ Syncing: 'syncing',
16
+ };
17
+ /**
18
+ * Maps the daemon's numeric WalletState enum to the SDK string. The daemon never
19
+ * emits 0 (Unspecified); a missing/unknown value maps to 'none', the safe
20
+ * non-ready state.
21
+ */
22
+ const PROTO_WALLET_STATE = {
23
+ 1: WalletState.None,
24
+ 2: WalletState.Locked,
25
+ 3: WalletState.Ready,
26
+ 4: WalletState.Syncing,
27
+ };
28
+ /**
29
+ * Normalizes a raw daemon walletState (a proto number) to the SDK string union.
30
+ * Already-string values pass through unchanged.
31
+ *
32
+ * @param value - The raw walletState as a proto number, an SDK string, or undefined.
33
+ * @returns The normalized {@link WalletState} string.
34
+ */
35
+ export function walletStateFromProto(value) {
36
+ if (typeof value === 'string') {
37
+ return value;
38
+ }
39
+ // An absent value or the proto's 0 (Unspecified) means no wallet yet.
40
+ if (value === undefined || value === 0) {
41
+ return WalletState.None;
42
+ }
43
+ // A recognized enum maps directly. An unrecognized non-zero value (a future
44
+ // or garbled daemon state) maps to the conservative 'locked', not 'none', so
45
+ // it never drives the UI into creating a wallet over an existing one.
46
+ return PROTO_WALLET_STATE[value] ?? WalletState.Locked;
47
+ }
48
+ /**
49
+ * Maps a raw daemon Info (numeric walletState, no walletReady) onto the public
50
+ * {@link WalletInfo}: it converts walletState to the string union and backfills
51
+ * walletReady (ready iff walletState === 'ready'), mirroring the Go
52
+ * Info.WalletReady() method. Shared facade normalization applies this after
53
+ * the transport returns getInfo.
54
+ *
55
+ * @param raw - The raw daemon Info payload (untrusted shape).
56
+ * @returns The normalized {@link WalletInfo}.
57
+ */
58
+ export function normalizeInfo(raw) {
59
+ const info = (raw ?? {});
60
+ const walletState = walletStateFromProto(info.walletState);
61
+ return {
62
+ ...info,
63
+ walletState,
64
+ walletReady: info.walletReady ?? walletState === WalletState.Ready,
65
+ };
66
+ }
67
+ /**
68
+ * Derives the wallet-state phase from a {@link WalletInfo}. Runtime phases are
69
+ * not represented here; the caller owns those.
70
+ *
71
+ * @param info - The wallet state and readiness to derive the phase from.
72
+ * @returns The wallet-state {@link WalletPhase}.
73
+ */
74
+ export function phaseFromInfo(info) {
75
+ if (info.walletReady || info.walletState === WalletState.Ready) {
76
+ return 'ready';
77
+ }
78
+ switch (info.walletState) {
79
+ case WalletState.Locked:
80
+ return 'locked';
81
+ case WalletState.Syncing:
82
+ return 'syncing';
83
+ case WalletState.None:
84
+ default:
85
+ return 'needsWallet';
86
+ }
87
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * RUNTIME_MANIFEST_VERSION pins the daemon build this SDK release is paired
3
+ * with: the generated types, the client methods, and the wasm runtime asset
4
+ * set (RUNTIME_ASSET_FILES in the web transport) are all produced from this
5
+ * one daemon revision.
6
+ *
7
+ * Hosted runtime assets live in a directory named after this value
8
+ * (`<assets root>/<RUNTIME_MANIFEST_VERSION>/<file>`), so every asset set gets
9
+ * a unique URL and a browser can never serve a stale cached runtime. Bump it
10
+ * together with regenerating the daemon types and publishing the matching
11
+ * asset set.
12
+ *
13
+ * Build tooling reads this value from the source text via
14
+ * scripts/runtime-version.mjs, so keep the declaration in this exact
15
+ * single-quoted literal form.
16
+ */
17
+ export declare const RUNTIME_MANIFEST_VERSION = "v0.1.0";
18
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,wBAAwB,WAAW,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * RUNTIME_MANIFEST_VERSION pins the daemon build this SDK release is paired
3
+ * with: the generated types, the client methods, and the wasm runtime asset
4
+ * set (RUNTIME_ASSET_FILES in the web transport) are all produced from this
5
+ * one daemon revision.
6
+ *
7
+ * Hosted runtime assets live in a directory named after this value
8
+ * (`<assets root>/<RUNTIME_MANIFEST_VERSION>/<file>`), so every asset set gets
9
+ * a unique URL and a browser can never serve a stale cached runtime. Bump it
10
+ * together with regenerating the daemon types and publishing the matching
11
+ * asset set.
12
+ *
13
+ * Build tooling reads this value from the source text via
14
+ * scripts/runtime-version.mjs, so keep the declaration in this exact
15
+ * single-quoted literal form.
16
+ */
17
+ export const RUNTIME_MANIFEST_VERSION = 'v0.1.0';
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@lightninglabs/wavelength-core",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "Transport- and framework-agnostic contract for the Wavelength self-custodial Lightning wallet SDK.",
6
+ "license": "MIT",
7
+ "homepage": "https://wavelength.lightning.engineering",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/lightninglabs/wavelength-sdk.git",
11
+ "directory": "packages/core"
12
+ },
13
+ "bugs": "https://github.com/lightninglabs/wavelength-sdk/issues",
14
+ "keywords": [
15
+ "lightning",
16
+ "bitcoin",
17
+ "wallet",
18
+ "self-custodial",
19
+ "payments"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "type": "module",
25
+ "main": "dist/index.js",
26
+ "types": "dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ }
32
+ },
33
+ "sideEffects": false,
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.json",
39
+ "typecheck": "tsc -p tsconfig.json --noEmit",
40
+ "test": "node --test"
41
+ }
42
+ }