@totemsdk/omnia-lsp-provider 0.0.0-stage → 0.2.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.
package/dist/host.js ADDED
@@ -0,0 +1,132 @@
1
+ function handlerFor(methods, name) {
2
+ return typeof methods.get === 'function'
3
+ ? methods.get(name)
4
+ : undefined;
5
+ }
6
+ function isRecord(value) {
7
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
8
+ }
9
+ function text(value) {
10
+ return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
11
+ }
12
+ /**
13
+ * Adapt an `omnia-host` method registry (`createHostMethods(context)`) to the
14
+ * LSP provider host port.
15
+ *
16
+ * The quote is written from the consumer's perspective: `localAmount` is the
17
+ * consumer side and `remoteAmount` is the provider side. The host is the provider,
18
+ * so those sides are swapped when calling `totem_omniaOpenChannel`.
19
+ */
20
+ export function createOmniaHostProviderHost(options) {
21
+ const openMethod = options.openMethod ?? 'totem_omniaOpenChannel';
22
+ const closeMethod = options.closeMethod ?? 'totem_omniaCloseChannel';
23
+ const prefix = options.operationIdPrefix ?? 'omnia-lsp';
24
+ return {
25
+ async openChannel({ quote, fundingAddress, fundingCoinId, fundingPubkey, fundingScript, fundingCoinProofsHex, fundingWitnessHex, contestDelayBlocks, }) {
26
+ const handler = handlerFor(options.methods, openMethod);
27
+ if (!handler) {
28
+ return {
29
+ success: false,
30
+ error: `${openMethod} is not registered on this omnia-host`,
31
+ errorCode: 'UNSUPPORTED',
32
+ };
33
+ }
34
+ try {
35
+ const result = (await handler({
36
+ remotePartyId: quote.consumerPartyId,
37
+ remotePublicKeyDigest: quote.consumerPublicKeyDigest,
38
+ ...(quote.consumerSettlementAddress
39
+ ? { remoteSettlementAddress: quote.consumerSettlementAddress }
40
+ : {}),
41
+ ...(quote.consumerTransportPubkey
42
+ ? { remoteTransportPubkey: quote.consumerTransportPubkey }
43
+ : {}),
44
+ localAmount: quote.remoteAmount,
45
+ remoteAmount: quote.localAmount,
46
+ tokenId: quote.tokenId,
47
+ ...(fundingAddress ? { fundingAddress } : {}),
48
+ ...(fundingCoinId ? { fundingCoinId } : {}),
49
+ ...(fundingPubkey ? { fundingPubkey } : {}),
50
+ ...(fundingScript ? { fundingScript } : {}),
51
+ ...(fundingCoinProofsHex !== undefined ? { fundingCoinProofsHex } : {}),
52
+ ...(fundingWitnessHex ? { fundingWitnessHex } : {}),
53
+ ...(contestDelayBlocks !== undefined ? { contestDelayBlocks } : {}),
54
+ operationId: `${prefix}-open-${quote.quoteId}`,
55
+ }));
56
+ // OMN-070: require explicit, operation-specific evidence. An undefined,
57
+ // non-object, `{}` or error-only response is a failure, and success
58
+ // without a channelId is not a successful open.
59
+ if (!isRecord(result)) {
60
+ return {
61
+ success: false,
62
+ error: `${openMethod} returned no structured result`,
63
+ errorCode: 'HOST_PROTOCOL_ERROR',
64
+ };
65
+ }
66
+ const channelId = text(result.channelId);
67
+ if (result.success !== true) {
68
+ return {
69
+ success: false,
70
+ error: text(result.error) ?? `${openMethod} reported failure`,
71
+ errorCode: text(result.errorCode) ?? 'HOST_OPEN_FAILED',
72
+ };
73
+ }
74
+ if (!channelId) {
75
+ return {
76
+ success: false,
77
+ error: `${openMethod} reported success without a channelId`,
78
+ errorCode: 'HOST_PROTOCOL_ERROR',
79
+ };
80
+ }
81
+ return {
82
+ success: true,
83
+ channelId,
84
+ ...(text(result.fundingTxId) ? { fundingTxId: text(result.fundingTxId) } : {}),
85
+ };
86
+ }
87
+ catch (error) {
88
+ return {
89
+ success: false,
90
+ error: error instanceof Error ? error.message : String(error),
91
+ errorCode: 'HOST_OPEN_FAILED',
92
+ };
93
+ }
94
+ },
95
+ async closeChannel(channelId) {
96
+ const handler = handlerFor(options.methods, closeMethod);
97
+ if (!handler) {
98
+ return {
99
+ success: false,
100
+ error: `${closeMethod} is not registered on this omnia-host`,
101
+ errorCode: 'UNSUPPORTED',
102
+ };
103
+ }
104
+ try {
105
+ const result = (await handler({
106
+ channelId,
107
+ operationId: `${prefix}-close-${channelId}`,
108
+ }));
109
+ // OMN-070: an undefined or malformed close response is not a success.
110
+ if (!isRecord(result) || result.success !== true) {
111
+ return {
112
+ success: false,
113
+ error: isRecord(result) && text(result.error)
114
+ ? text(result.error)
115
+ : `${closeMethod} did not confirm the close`,
116
+ errorCode: isRecord(result) && text(result.errorCode)
117
+ ? text(result.errorCode)
118
+ : 'HOST_CLOSE_FAILED',
119
+ };
120
+ }
121
+ return { success: true };
122
+ }
123
+ catch (error) {
124
+ return {
125
+ success: false,
126
+ error: error instanceof Error ? error.message : String(error),
127
+ errorCode: 'HOST_CLOSE_FAILED',
128
+ };
129
+ }
130
+ },
131
+ };
132
+ }
@@ -0,0 +1,10 @@
1
+ export { evaluateOpenRequest, } from './policy.js';
2
+ export type { OmniaLspOpenDecision, OmniaLspOpenRequest, OmniaLspProviderPolicy, } from './policy.js';
3
+ export { createUnsignedOpenQuote, signOpenQuote, } from './quote.js';
4
+ export type { CreateQuoteOptions, UnsignedOmniaLspOpenQuote, } from './quote.js';
5
+ export { createOmniaLspProvider, } from './provider.js';
6
+ export type { OmniaLspConsumerIdentity, OmniaLspHostCloseResult, OmniaLspHostOpenInput, OmniaLspHostOpenResult, OmniaLspOpenQuoteOptions, OmniaLspProvider, OmniaLspProviderConfig, OmniaLspProviderHost, } from './provider.js';
7
+ export { createMemoryQuoteLedger } from './ledger.js';
8
+ export type { ConsumeReservationResult, OmniaLspQuoteLedger, OmniaLspQuoteReservation, QuoteReservationState, } from './ledger.js';
9
+ export { createOmniaHostProviderHost } from './host.js';
10
+ export type { CreateOmniaHostProviderHostOptions, OmniaHostHandler, OmniaHostMethodMap, } from './host.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { evaluateOpenRequest, } from './policy.js';
2
+ export { createUnsignedOpenQuote, signOpenQuote, } from './quote.js';
3
+ export { createOmniaLspProvider, } from './provider.js';
4
+ export { createMemoryQuoteLedger } from './ledger.js';
5
+ export { createOmniaHostProviderHost } from './host.js';
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Quote reservations (OMN-068).
3
+ *
4
+ * Admission validates a request against the manifest's advertised capacity, but
5
+ * the manifest is static: without a ledger, N concurrent quotes each fit inside
6
+ * capacity while their sum does not. The facade now reserves the provider-side
7
+ * amount when it issues a quote, releases it on expiry or a failed open, and
8
+ * consumes it atomically when a quote is redeemed.
9
+ *
10
+ * The in-memory ledger is the default. A production provider injects an
11
+ * implementation backed by durable storage; the interface is intentionally
12
+ * small so that the durable version can make `consume` a single transaction.
13
+ */
14
+ export type QuoteReservationState = 'reserved' | 'consumed' | 'released';
15
+ export interface OmniaLspQuoteReservation {
16
+ quoteId: string;
17
+ providerId: string;
18
+ tokenId: string;
19
+ /** Provider-side amount as quoted, decimal units. */
20
+ amount: string;
21
+ /** Provider-side amount in integer units (18 decimal places). */
22
+ amountUnits: bigint;
23
+ expiresAt: number;
24
+ state: QuoteReservationState;
25
+ updatedAt: number;
26
+ }
27
+ export type ConsumeReservationResult =
28
+ /** The reservation existed, was live, and is now consumed. */
29
+ 'consumed'
30
+ /** No reservation with this id was ever recorded. */
31
+ | 'unknown'
32
+ /** The reservation exists but its TTL has passed. */
33
+ | 'expired'
34
+ /** The reservation was already consumed or released. */
35
+ | 'already-consumed';
36
+ export interface OmniaLspQuoteLedger {
37
+ /** Record a reservation. Throws if the quoteId is already known. */
38
+ reserve(entry: OmniaLspQuoteReservation): Promise<void> | void;
39
+ /**
40
+ * Atomically move a live reservation to consumed. `unknown` must be returned
41
+ * when this ledger has no record, never an implicit success.
42
+ */
43
+ consume(quoteId: string, now?: number): Promise<ConsumeReservationResult> | ConsumeReservationResult;
44
+ /** Free a reservation. No-op when unknown or already final. */
45
+ release(quoteId: string, now?: number): Promise<void> | void;
46
+ /** Sum of live reservations for a token and provider, in integer units. */
47
+ outstanding(tokenId: string, providerId: string, now?: number): Promise<bigint> | bigint;
48
+ /** Optional: drop final or expired entries. */
49
+ prune?(now?: number): Promise<void> | void;
50
+ }
51
+ /**
52
+ * Default in-process ledger.
53
+ *
54
+ * Single-threaded JS makes the check-and-set inside `consume` atomic for one
55
+ * process. It does not survive a restart — inject a durable ledger for that.
56
+ */
57
+ export declare function createMemoryQuoteLedger(): OmniaLspQuoteLedger;
package/dist/ledger.js ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Quote reservations (OMN-068).
3
+ *
4
+ * Admission validates a request against the manifest's advertised capacity, but
5
+ * the manifest is static: without a ledger, N concurrent quotes each fit inside
6
+ * capacity while their sum does not. The facade now reserves the provider-side
7
+ * amount when it issues a quote, releases it on expiry or a failed open, and
8
+ * consumes it atomically when a quote is redeemed.
9
+ *
10
+ * The in-memory ledger is the default. A production provider injects an
11
+ * implementation backed by durable storage; the interface is intentionally
12
+ * small so that the durable version can make `consume` a single transaction.
13
+ */
14
+ /**
15
+ * Default in-process ledger.
16
+ *
17
+ * Single-threaded JS makes the check-and-set inside `consume` atomic for one
18
+ * process. It does not survive a restart — inject a durable ledger for that.
19
+ */
20
+ export function createMemoryQuoteLedger() {
21
+ const entries = new Map();
22
+ return {
23
+ reserve(entry) {
24
+ if (entries.has(entry.quoteId)) {
25
+ throw new Error(`quote ${entry.quoteId} is already reserved`);
26
+ }
27
+ entries.set(entry.quoteId, { ...entry });
28
+ },
29
+ consume(quoteId, now = Date.now()) {
30
+ const entry = entries.get(quoteId);
31
+ if (!entry)
32
+ return 'unknown';
33
+ if (entry.state !== 'reserved')
34
+ return 'already-consumed';
35
+ if (entry.expiresAt <= now)
36
+ return 'expired';
37
+ entry.state = 'consumed';
38
+ entry.updatedAt = now;
39
+ return 'consumed';
40
+ },
41
+ release(quoteId, now = Date.now()) {
42
+ const entry = entries.get(quoteId);
43
+ if (!entry || entry.state !== 'reserved')
44
+ return;
45
+ entry.state = 'released';
46
+ entry.updatedAt = now;
47
+ },
48
+ outstanding(tokenId, providerId, now = Date.now()) {
49
+ let total = 0n;
50
+ for (const entry of entries.values()) {
51
+ if (entry.state !== 'reserved')
52
+ continue;
53
+ if (entry.expiresAt <= now)
54
+ continue;
55
+ if (entry.tokenId !== tokenId)
56
+ continue;
57
+ if (entry.providerId !== providerId)
58
+ continue;
59
+ total += entry.amountUnits;
60
+ }
61
+ return total;
62
+ },
63
+ prune(now = Date.now()) {
64
+ for (const [id, entry] of entries) {
65
+ if (entry.state !== 'reserved' || entry.expiresAt <= now)
66
+ entries.delete(id);
67
+ }
68
+ },
69
+ };
70
+ }
@@ -0,0 +1,56 @@
1
+ import type { OmniaLspAsset, OmniaLspDirection, OmniaLspManifest } from '@totemsdk/omnia-lsp';
2
+ export interface OmniaLspOpenRequest {
3
+ providerId: string;
4
+ consumerAddress: string;
5
+ /** Consumer Omnia party id (identity id or channel party id). */
6
+ consumerPartyId: string;
7
+ /** Consumer channel key digest (32-byte hex). */
8
+ consumerPublicKeyDigest: string;
9
+ consumerSettlementAddress?: string;
10
+ consumerTransportPubkey?: string;
11
+ tokenId: string;
12
+ /** Consumer side of the initial channel balance, decimal units. */
13
+ localAmount: string;
14
+ /** Provider side of the initial channel balance, decimal units. */
15
+ remoteAmount: string;
16
+ direction: OmniaLspDirection;
17
+ lease?: boolean;
18
+ jit?: boolean;
19
+ /** Reject when the total open fee exceeds this decimal amount. */
20
+ maxOpenFee?: string;
21
+ /**
22
+ * Legacy ceiling for the percentage component. Also bounds a flat fee by
23
+ * converting it to the equivalent basis points on the fee basis (OMN-072).
24
+ */
25
+ maxOpenFeeBps?: number;
26
+ }
27
+ export interface OmniaLspOpenDecision {
28
+ allowed: boolean;
29
+ errors: string[];
30
+ asset?: OmniaLspAsset;
31
+ }
32
+ export interface OmniaLspProviderPolicy {
33
+ /** Reject hosted-custody manifests. Default true for a non-custodial LSP. */
34
+ requireNonCustodial?: boolean;
35
+ /** Minimum provider-bond score accepted by this provider. Informational only. */
36
+ minProviderScore?: number;
37
+ /**
38
+ * Spendable provider funds for the requested asset, decimal units. When set,
39
+ * the provider-side contribution must fit inside it (OMN-067).
40
+ */
41
+ availableProviderFunds?: string;
42
+ }
43
+ declare function hasCapacity(asset: OmniaLspAsset, direction: OmniaLspDirection, amount: bigint): boolean;
44
+ /**
45
+ * Evaluate an open request against a provider manifest.
46
+ *
47
+ * This is the provider's admission policy. It does not reserve capacity; the
48
+ * provider MUST do that through the quote ledger (OMN-068).
49
+ *
50
+ * Both sides of the channel are validated independently (OMN-067): the
51
+ * consumer's `localAmount` and the provider's own `remoteAmount`, because the
52
+ * provider is the party that funds the latter. `now` is the provider's trusted
53
+ * clock — never the requester's (OMN-069).
54
+ */
55
+ export declare function evaluateOpenRequest(manifest: OmniaLspManifest, request: OmniaLspOpenRequest, policy?: OmniaLspProviderPolicy, now?: number): OmniaLspOpenDecision;
56
+ export { hasCapacity };
package/dist/policy.js ADDED
@@ -0,0 +1,131 @@
1
+ import { applyBpsUnits, computeOpenFees, DEFAULT_FEE_BASIS, parseDecimalUnits, } from '@totemsdk/omnia-lsp';
2
+ function hasCapacity(asset, direction, amount) {
3
+ if (direction === 'send')
4
+ return parseUnitsAtLeast(asset.outboundCapacity, amount);
5
+ if (direction === 'receive')
6
+ return parseUnitsAtLeast(asset.inboundCapacity, amount);
7
+ return parseUnitsAtLeast(asset.inboundCapacity, amount) && parseUnitsAtLeast(asset.outboundCapacity, amount);
8
+ }
9
+ /** True when `capacity` (decimal) is at least `amount` (units). */
10
+ function parseUnitsAtLeast(capacity, amount) {
11
+ const parsed = parseDecimalUnits(capacity, { allowZero: true });
12
+ return parsed.ok && parsed.units >= amount;
13
+ }
14
+ /** The capacity side the provider itself draws on for a direction. */
15
+ function providerCapacitySide(direction) {
16
+ return direction === 'send' ? 'outbound' : direction === 'receive' ? 'inbound' : 'both';
17
+ }
18
+ /** The capacity side the consumer's contribution lands on. */
19
+ function consumerCapacitySide(direction) {
20
+ return direction === 'send' ? 'inbound' : direction === 'receive' ? 'outbound' : 'both';
21
+ }
22
+ function withinCapacity(asset, side, amount) {
23
+ if (side === 'both') {
24
+ return parseUnitsAtLeast(asset.inboundCapacity, amount) && parseUnitsAtLeast(asset.outboundCapacity, amount);
25
+ }
26
+ return parseUnitsAtLeast(side === 'inbound' ? asset.inboundCapacity : asset.outboundCapacity, amount);
27
+ }
28
+ /**
29
+ * Evaluate an open request against a provider manifest.
30
+ *
31
+ * This is the provider's admission policy. It does not reserve capacity; the
32
+ * provider MUST do that through the quote ledger (OMN-068).
33
+ *
34
+ * Both sides of the channel are validated independently (OMN-067): the
35
+ * consumer's `localAmount` and the provider's own `remoteAmount`, because the
36
+ * provider is the party that funds the latter. `now` is the provider's trusted
37
+ * clock — never the requester's (OMN-069).
38
+ */
39
+ export function evaluateOpenRequest(manifest, request, policy = {}, now = Date.now()) {
40
+ const errors = [];
41
+ if (request.providerId !== manifest.providerId) {
42
+ errors.push('request.providerId does not match the manifest');
43
+ }
44
+ if (manifest.expiresAt <= now) {
45
+ errors.push('manifest is expired');
46
+ }
47
+ if (policy.requireNonCustodial !== false && (manifest.custody.mode === 'hosted' || manifest.custody.canMoveFunds)) {
48
+ errors.push('hosted custody is not accepted by this provider policy');
49
+ }
50
+ const asset = manifest.assets.find((entry) => entry.tokenId === request.tokenId);
51
+ if (!asset) {
52
+ errors.push('asset is not offered by the provider');
53
+ }
54
+ else {
55
+ const local = parseDecimalUnits(request.localAmount);
56
+ const remote = parseDecimalUnits(request.remoteAmount);
57
+ const minChannel = parseDecimalUnits(asset.minChannel, { allowZero: true });
58
+ const maxChannel = parseDecimalUnits(asset.maxChannel, { allowZero: true });
59
+ if (!local.ok)
60
+ errors.push(`localAmount: ${local.error}`);
61
+ if (!remote.ok)
62
+ errors.push(`remoteAmount: ${remote.error}`);
63
+ if (!minChannel.ok)
64
+ errors.push(`manifest asset minChannel: ${minChannel.error}`);
65
+ if (!maxChannel.ok)
66
+ errors.push(`manifest asset maxChannel: ${maxChannel.error}`);
67
+ if (local.ok && minChannel.ok && maxChannel.ok) {
68
+ if (local.units < minChannel.units)
69
+ errors.push('localAmount is below the provider minimum');
70
+ if (local.units > maxChannel.units)
71
+ errors.push('localAmount is above the provider maximum');
72
+ }
73
+ if (remote.ok && minChannel.ok && maxChannel.ok) {
74
+ // OMN-067: the provider's own contribution is a channel limit too.
75
+ if (remote.units < minChannel.units)
76
+ errors.push('remoteAmount is below the provider minimum');
77
+ if (remote.units > maxChannel.units)
78
+ errors.push('remoteAmount is above the provider maximum');
79
+ }
80
+ if (local.ok && !withinCapacity(asset, consumerCapacitySide(request.direction), local.units)) {
81
+ errors.push('insufficient capacity for the consumer contribution in the requested direction');
82
+ }
83
+ if (remote.ok && !withinCapacity(asset, providerCapacitySide(request.direction), remote.units)) {
84
+ errors.push('insufficient capacity for the provider contribution in the requested direction');
85
+ }
86
+ if (remote.ok && policy.availableProviderFunds !== undefined) {
87
+ const available = parseDecimalUnits(policy.availableProviderFunds, { allowZero: true });
88
+ if (!available.ok) {
89
+ errors.push(`availableProviderFunds: ${available.error}`);
90
+ }
91
+ else if (remote.units > available.units) {
92
+ errors.push('provider-side amount exceeds the provider available funds');
93
+ }
94
+ }
95
+ if (local.ok && remote.ok) {
96
+ const fees = computeOpenFees(manifest, request, DEFAULT_FEE_BASIS);
97
+ if (!fees.ok) {
98
+ errors.push(`fee schedule: ${fees.error}`);
99
+ }
100
+ else {
101
+ const schedule = fees.schedule;
102
+ if (request.maxOpenFee !== undefined) {
103
+ const ceiling = parseDecimalUnits(request.maxOpenFee, { allowZero: true });
104
+ if (!ceiling.ok) {
105
+ errors.push(`maxOpenFee: ${ceiling.error}`);
106
+ }
107
+ else if (schedule.totalFeeUnits > ceiling.units) {
108
+ errors.push('provider total open fee exceeds the request maximum');
109
+ }
110
+ }
111
+ if (request.maxOpenFeeBps !== undefined) {
112
+ // A flat fee is bounded by converting the ceiling onto the fee basis,
113
+ // so a manifest with openFlat can no longer bypass the check (OMN-072).
114
+ const basis = parseDecimalUnits(schedule.basisAmount, { allowZero: true });
115
+ const bpsCeiling = basis.ok ? applyBpsUnits(basis.units, request.maxOpenFeeBps) : 0n;
116
+ if (schedule.openFeeUnits > bpsCeiling) {
117
+ errors.push('provider open fee exceeds the request maximum rate');
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ if (request.lease === true && manifest.terms.lease !== true) {
124
+ errors.push('lease is not offered by the provider');
125
+ }
126
+ if (request.jit === true && manifest.terms.jit !== true) {
127
+ errors.push('JIT is not offered by the provider');
128
+ }
129
+ return { allowed: errors.length === 0, errors, ...(asset ? { asset } : {}) };
130
+ }
131
+ export { hasCapacity };
@@ -0,0 +1,108 @@
1
+ import { type OmniaLspManifest, type OmniaLspOpenQuote, type OpenQuoteSigningPayload } from '@totemsdk/omnia-lsp';
2
+ import { type OmniaLspOpenDecision, type OmniaLspOpenRequest, type OmniaLspProviderPolicy } from './policy.js';
3
+ import { type UnsignedOmniaLspOpenQuote } from './quote.js';
4
+ import { type OmniaLspQuoteLedger } from './ledger.js';
5
+ /**
6
+ * Optional funding inputs for a provider-hosted open.
7
+ *
8
+ * A provider that already selected its funding coin can pass the coin id plus
9
+ * the node proof material. A provider that wants the host to select a coin can
10
+ * omit all of these; `omnia-host` then selects a sendable coin and builds the
11
+ * funding witness from its own wallet/node.
12
+ */
13
+ export interface OmniaLspHostFunding {
14
+ /** Address to select the provider funding coin from (simple wallet address). */
15
+ fundingAddress?: string;
16
+ fundingCoinId?: string;
17
+ fundingPubkey?: string;
18
+ fundingScript?: string;
19
+ fundingCoinProofsHex?: string | string[];
20
+ /** Provider-wallet-built witness. The consumer/dApp witness is still forbidden. */
21
+ fundingWitnessHex?: string;
22
+ /**
23
+ * Channel contest delay. Omit for the host/program default (normally 256).
24
+ * Test/dev hosts may pass a shorter value when OMNIA_ALLOW_SHORT_CONTEST_DELAY=1.
25
+ */
26
+ contestDelayBlocks?: number;
27
+ }
28
+ export interface OmniaLspHostOpenInput extends OmniaLspHostFunding {
29
+ quote: OmniaLspOpenQuote;
30
+ }
31
+ export interface OmniaLspHostOpenResult {
32
+ success: boolean;
33
+ channelId?: string;
34
+ fundingTxId?: string;
35
+ error?: string;
36
+ errorCode?: string;
37
+ }
38
+ export interface OmniaLspHostCloseResult {
39
+ success: boolean;
40
+ error?: string;
41
+ errorCode?: string;
42
+ }
43
+ /**
44
+ * Host port implemented by the provider runtime (for example an `omnia-host`
45
+ * wrapper). The LSP package owns policy and quotes; the host owns channel
46
+ * construction, signing and broadcast.
47
+ */
48
+ export interface OmniaLspProviderHost {
49
+ openChannel(input: OmniaLspHostOpenInput): Promise<OmniaLspHostOpenResult>;
50
+ closeChannel?(channelId: string): Promise<OmniaLspHostCloseResult>;
51
+ }
52
+ /** The authenticated caller's identity, supplied by the API layer. */
53
+ export interface OmniaLspConsumerIdentity {
54
+ address?: string;
55
+ partyId?: string;
56
+ publicKeyDigest?: string;
57
+ }
58
+ export interface OmniaLspProviderConfig {
59
+ manifest: OmniaLspManifest;
60
+ host: OmniaLspProviderHost;
61
+ policy?: OmniaLspProviderPolicy;
62
+ /** Provider identity signer for quotes. Required for quote issuance. */
63
+ signQuote: (quote: UnsignedOmniaLspOpenQuote, payload: OpenQuoteSigningPayload) => Promise<string> | string;
64
+ /**
65
+ * Verify a provider quote signature over `domain|termsHash` (OMN-066).
66
+ * Required to redeem a quote with `openQuote`; when absent, redemption fails
67
+ * closed rather than trusting an unverified quote.
68
+ */
69
+ verifyQuoteSignature?: (input: OpenQuoteSigningPayload & {
70
+ signature: string;
71
+ quote: OmniaLspOpenQuote;
72
+ }) => boolean | Promise<boolean>;
73
+ /**
74
+ * Durable reservation ledger (OMN-068). Defaults to an in-process ledger,
75
+ * which enforces concurrency limits but does not survive a restart.
76
+ */
77
+ quoteLedger?: OmniaLspQuoteLedger;
78
+ /**
79
+ * Require `openQuote` to be given the authenticated consumer so the quote can
80
+ * be bound to it. Default true — pass false only for a caller that has
81
+ * already authenticated the quote's consumer outside this facade.
82
+ */
83
+ requireConsumerBinding?: boolean;
84
+ /** Default quote TTL. Default 60s. */
85
+ quoteTtlMs?: number;
86
+ /** Clock injection for deterministic tests. The provider clock is authoritative. */
87
+ now?: () => number;
88
+ }
89
+ export interface OmniaLspOpenQuoteOptions {
90
+ /** Identity of the already-authenticated caller redeeming this quote. */
91
+ consumer?: OmniaLspConsumerIdentity;
92
+ }
93
+ export interface OmniaLspProvider {
94
+ manifest(): OmniaLspManifest;
95
+ evaluate(request: OmniaLspOpenRequest): OmniaLspOpenDecision;
96
+ quote(request: OmniaLspOpenRequest): Promise<OmniaLspOpenQuote>;
97
+ open(request: OmniaLspOpenRequest, funding?: OmniaLspHostFunding | string): Promise<OmniaLspHostOpenResult>;
98
+ openQuote(quote: OmniaLspOpenQuote, funding?: OmniaLspHostFunding | string, options?: OmniaLspOpenQuoteOptions): Promise<OmniaLspHostOpenResult>;
99
+ close(channelId: string): Promise<OmniaLspHostCloseResult>;
100
+ }
101
+ /**
102
+ * Reference provider facade.
103
+ *
104
+ * It does not hold keys, open channels or broadcast. It applies policy, issues
105
+ * signed quotes, reserves provider capacity and delegates the channel operation
106
+ * to the injected host.
107
+ */
108
+ export declare function createOmniaLspProvider(config: OmniaLspProviderConfig): OmniaLspProvider;