@invisible-labs/sdk 0.6.0-devnet.3 → 0.6.0-devnet.5
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/README.md +129 -15
- package/dist/.invisible-sdk-build-target.json +7 -0
- package/dist/{chunk-QQSI3ZD7.js → chunk-3MDHAS4D.js} +109 -17
- package/dist/chunk-3MDHAS4D.js.map +1 -0
- package/dist/{chunk-NKRVQXRP.js → chunk-3TGQ4CZ3.js} +297 -11
- package/dist/chunk-3TGQ4CZ3.js.map +1 -0
- package/dist/chunk-DCTYBUY3.js +258 -0
- package/dist/chunk-DCTYBUY3.js.map +1 -0
- package/dist/{chunk-NHEHCUS5.js → chunk-EBWTAXNT.js} +3 -3
- package/dist/{chunk-NHEHCUS5.js.map → chunk-EBWTAXNT.js.map} +1 -1
- package/dist/{chunk-V5HXJRBW.js → chunk-HJFMDMPY.js} +3 -3
- package/dist/chunk-HJFMDMPY.js.map +1 -0
- package/dist/{chunk-GHBQF3A7.js → chunk-QRN46R3F.js} +5 -2
- package/dist/chunk-QRN46R3F.js.map +1 -0
- package/dist/chunk-Y7AK6RBV.js +4189 -0
- package/dist/chunk-Y7AK6RBV.js.map +1 -0
- package/dist/{coordinator-VVJ33WF2.js → coordinator-PEWHNZ7I.js} +3 -3
- package/dist/{coordinator-VVJ33WF2.js.map → coordinator-PEWHNZ7I.js.map} +1 -1
- package/dist/events.js +3 -3
- package/dist/index.d.ts +69 -353
- package/dist/index.js +161 -43
- package/dist/index.js.map +1 -1
- package/dist/lp.d.ts +76 -18
- package/dist/lp.js +511 -111
- package/dist/lp.js.map +1 -1
- package/dist/presets.d.ts +7 -40
- package/dist/presets.js +10 -68
- package/dist/presets.js.map +1 -1
- package/dist/stats.js +1 -1
- package/dist/storage.js +2 -243
- package/dist/storage.js.map +1 -1
- package/dist/{errors-N2touVm4.d.ts → types.generated-YhFu9ZBR.d.ts} +65 -4
- package/dist/user.d.ts +134 -8
- package/dist/user.js +991 -250
- package/dist/user.js.map +1 -1
- package/package.json +5 -31
- package/dist/chunk-BWCGNTN5.js +0 -1153
- package/dist/chunk-BWCGNTN5.js.map +0 -1
- package/dist/chunk-DIA6U2CV.js +0 -1927
- package/dist/chunk-DIA6U2CV.js.map +0 -1
- package/dist/chunk-GHBQF3A7.js.map +0 -1
- package/dist/chunk-NKRVQXRP.js.map +0 -1
- package/dist/chunk-QQSI3ZD7.js.map +0 -1
- package/dist/chunk-V5HXJRBW.js.map +0 -1
- package/dist/types.generated-BSEBz4jR.d.ts +0 -68
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/coordinator/protocolClient.ts"],"names":[],"mappings":";;;;AAWA,IAAM,sBAAA,GAAyB,CAAA;AAExB,IAAM,YAAA,GAAe;AAAA,EAC1B,OAAA,EAAS,SAAA;AAAA,EACT,QAAA,EAAU,UAAA;AAAA,EACV,IAAA,EAAM,MAAA;AAAA,EACN,KAAA,EAAO;AACT;AAIO,IAAM,sBAAA,GAAyB;AAAA,EACpC,eAAA,EAAiB,iBAAA;AAAA,EACjB,OAAA,EAAS,SAAA;AAAA,EACT,SAAA,EAAW,WAAA;AAAA,EACX,SAAA,EAAW,WAAA;AAAA,EACX,WAAA,EAAa,aAAA;AAAA,EACb,aAAA,EAAe,eAAA;AAAA,EACf,WAAA,EAAa,aAAA;AAAA,EACb,gBAAA,EAAkB,kBAAA;AAAA,EAClB,IAAA,EAAM,MAAA;AAAA,EACN,YAAA,EAAc,cAAA;AAAA,EACd,MAAA,EAAQ,QAAA;AAAA,EACR,cAAA,EAAgB,gBAAA;AAAA,EAChB,eAAA,EAAiB,iBAAA;AAAA,EACjB,gBAAA,EAAkB,kBAAA;AAAA,EAClB,gBAAA,EAAkB,kBAAA;AAAA,EAClB,SAAA,EAAW,WAAA;AAAA,EACX,KAAA,EAAO;AACT;AA4BA,IAAI,eAAA,GAAkD,IAAA;AAEtD,SAAS,YAAA,GAAwC;AAC/C,EAAA,eAAA,KAA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K,yBAAA;AAAA,IACL,KAAK,iBAAA;AAAA,IACL,KAAK,cAAA;AAAA,IACL,KAAK,qBAAA;AAAA,IACL,KAAK,uBAAA;AACH,MAAA,OAAO,IAAA;AAAA,IACT;AACE,MAAA,OAAO,cAAA;AAAA;AAEb;AAcA,SAAS,SAAA,CAAU,SAA0B,KAAA,EAAoB;AAC/D,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,OAAO,KAAK,OAAA,CAAQ,OAAA,CAAQ,SAAQ,EAAG;AACxD,IAAA,OAAA,CAAQ,OAAA,CAAQ,OAAO,KAAK,CAAA;AAC5B,IAAA,IAAI,OAAA,CAAQ,KAAA,EAAO,YAAA,CAAa,OAAA,CAAQ,KAAK,CAAA;AAC7C,IAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,EACtB;AACA,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,OAAO,KAAK,OAAA,CAAQ,WAAA,CAAY,SAAQ,EAAG;AAC3D,IAAA,OAAA,CAAQ,WAAA,CAAY,OAAO,IAAI,CAAA;AAC/B,IAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,MAAA,IAAI,MAAA,CAAO,KAAA,EAAO,YAAA,CAAa,MAAA,CAAO,KAAK,CAAA;AAC3C,MAAA,MAAA,CAAO,OAAO,KAAK,CAAA;AAAA,IACrB;AAAA,EACF;AACF","file":"chunk-QQSI3ZD7.js","sourcesContent":["import {\n CommandError,\n TransportError,\n type CommandErrorCode,\n type CoordinatorWireErrorCode,\n} from \"../core/errors.js\";\nimport type { Session } from \"../core/session.js\";\nimport { getSessionState, type SessionState } from \"../session/state.js\";\nimport type { Unsubscribe } from \"../transport/types.js\";\n\nconst COORDINATOR_ENVELOPE_VERSION = 2;\nconst OUT_OF_BAND_REQUEST_ID = 0;\n\nexport const EnvelopeKind = {\n REQUEST: \"request\",\n RESPONSE: \"response\",\n PUSH: \"push\",\n ERROR: \"error\",\n} as const;\n\nexport type EnvelopeKind = (typeof EnvelopeKind)[keyof typeof EnvelopeKind];\n\nexport const CoordinatorMessageType = {\n ContractRequest: \"ContractRequest\",\n DkgInit: \"DkgInit\",\n DkgRound1: \"DkgRound1\",\n DkgRound2: \"DkgRound2\",\n DkgComplete: \"DkgComplete\",\n DelegateShare: \"DelegateShare\",\n DelegateAck: \"DelegateAck\",\n DepositConfirmed: \"DepositConfirmed\",\n Sync: \"Sync\",\n SyncRequired: \"SyncRequired\",\n Refill: \"Refill\",\n PayoutExecuted: \"PayoutExecuted\",\n WithdrawRequest: \"WithdrawRequest\",\n WithdrawAccepted: \"WithdrawAccepted\",\n WithdrawExecuted: \"WithdrawExecuted\",\n LpCommand: \"LpCommand\",\n Error: \"Error\",\n} as const;\n\nexport type CoordinatorMessageType =\n (typeof CoordinatorMessageType)[keyof typeof CoordinatorMessageType];\n\nexport type Envelope = {\n readonly version: typeof COORDINATOR_ENVELOPE_VERSION;\n readonly kind: EnvelopeKind;\n readonly type: CoordinatorMessageType;\n readonly swap_id: string | null;\n readonly req_id: number;\n readonly timestamp_ms: number;\n readonly payload: unknown;\n};\n\ntype ProtocolModule = {\n readonly ENVELOPE_VERSION: typeof COORDINATOR_ENVELOPE_VERSION;\n readonly EnvelopeKind: typeof EnvelopeKind;\n readonly CoordinatorMessageType: typeof CoordinatorMessageType;\n readonly encodeValidated: (envelope: Envelope) => Uint8Array;\n readonly decode: (raw: Uint8Array) => { ok: true; value: Envelope } | { ok: false; error: Error };\n readonly asErrorPayload: (envelope: Envelope) => {\n readonly code: string;\n readonly failed_req_id?: number;\n readonly message: string;\n };\n};\n\nlet protocolPromise: Promise<ProtocolModule> | null = null;\n\nfunction loadProtocol(): Promise<ProtocolModule> {\n protocolPromise ??= import(\"protocol/coordinator\") as Promise<ProtocolModule>;\n return protocolPromise;\n}\n\nexport type ProtocolLogDirection = \"in\" | \"out\" | \"info\";\nexport type ProtocolLogHandler = (message: string, direction: ProtocolLogDirection) => void;\nexport type ProtocolEnvelopeHandler = (envelope: Envelope) => void;\n\nexport interface RequestEnvelopeOptions {\n readonly swapId?: string | null;\n readonly timeoutMs?: number;\n readonly onLog?: ProtocolLogHandler;\n /** Reject this request when the coordinator reports a swap-scoped error without a request id. */\n readonly rejectMatchingOutOfBandErrors?: boolean;\n}\n\nexport interface AwaitPushOptions {\n readonly timeoutMs?: number | null;\n}\n\ntype PendingRequest = {\n readonly resolve: (envelope: Envelope) => void;\n readonly reject: (error: Error) => void;\n readonly timer: ReturnType<typeof setTimeout> | null;\n readonly swapId: string | null;\n readonly rejectMatchingOutOfBandErrors: boolean;\n};\n\ntype PushWaiter = {\n readonly resolve: (envelope: Envelope) => void;\n readonly reject: (error: Error) => void;\n readonly timer: ReturnType<typeof setTimeout> | null;\n};\n\ntype ProtocolRuntime = {\n reqCounter: number;\n readonly pending: Map<number, PendingRequest>;\n readonly pushWaiters: Map<CoordinatorMessageType, PushWaiter[]>;\n readonly envelopeHandlers: Set<ProtocolEnvelopeHandler>;\n unsubscribeChannel: Unsubscribe | null;\n unsubscribeTransport: Unsubscribe | null;\n};\n\nconst runtimes = new WeakMap<SessionState, ProtocolRuntime>();\n\nexport async function requestEnvelope(\n session: Session,\n type: CoordinatorMessageType,\n payload: unknown,\n options: RequestEnvelopeOptions = {},\n): Promise<Envelope> {\n const protocol = await loadProtocol();\n const state = getSessionState(session);\n const runtime = ensureProtocolRuntime(state);\n const channel = state.channel;\n if (!state.attested || channel === null) {\n throw new TransportError(\"CONNECTION_LOST\", \"coordinator request requires an attested channel\");\n }\n\n const reqId = ++runtime.reqCounter;\n const envelope: Envelope = {\n version: protocol.ENVELOPE_VERSION,\n kind: protocol.EnvelopeKind.REQUEST,\n type,\n swap_id: options.swapId ?? null,\n req_id: reqId,\n timestamp_ms: Date.now(),\n payload,\n };\n const frame = protocol.encodeValidated(envelope);\n\n return new Promise((resolve, reject) => {\n const timer =\n options.timeoutMs === undefined\n ? null\n : setTimeout(() => {\n runtime.pending.delete(reqId);\n reject(\n new CommandError(\n \"REJECTED_STALE_JOB\",\n `coordinator request timed out for ${type} after ${options.timeoutMs}ms`,\n ),\n );\n }, options.timeoutMs);\n\n runtime.pending.set(reqId, {\n resolve,\n reject,\n timer,\n swapId: envelope.swap_id,\n rejectMatchingOutOfBandErrors: options.rejectMatchingOutOfBandErrors === true,\n });\n options.onLog?.(`-> ${type} req_id=${reqId}`, \"out\");\n try {\n channel.send(frame);\n } catch (error) {\n runtime.pending.delete(reqId);\n if (timer) clearTimeout(timer);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n}\n\nexport function awaitPush(\n session: Session,\n type: CoordinatorMessageType,\n options: AwaitPushOptions = {},\n): Promise<Envelope> {\n const state = getSessionState(session);\n const runtime = ensureProtocolRuntime(state);\n const timeoutMs = options.timeoutMs === undefined ? 30_000 : options.timeoutMs;\n\n return new Promise((resolve, reject) => {\n const timer =\n timeoutMs === null\n ? null\n : setTimeout(() => {\n removePushWaiter(runtime, type, waiter);\n reject(new CommandError(\"REJECTED_STALE_JOB\", `timed out waiting for ${type} push`));\n }, timeoutMs);\n const waiter: PushWaiter = { resolve, reject, timer };\n const waiters = runtime.pushWaiters.get(type) ?? [];\n waiters.push(waiter);\n runtime.pushWaiters.set(type, waiters);\n });\n}\n\nexport function onEnvelope(session: Session, handler: ProtocolEnvelopeHandler): Unsubscribe {\n const runtime = ensureProtocolRuntime(getSessionState(session));\n runtime.envelopeHandlers.add(handler);\n return () => runtime.envelopeHandlers.delete(handler);\n}\n\nexport function closeProtocolRuntime(session: Session): void {\n const state = getSessionState(session);\n const runtime = runtimes.get(state);\n if (!runtime) return;\n const error = new TransportError(\"CONNECTION_LOST\", \"coordinator protocol runtime closed\");\n rejectAll(runtime, error);\n runtime.unsubscribeChannel?.();\n runtime.unsubscribeTransport?.();\n runtimes.delete(state);\n}\n\nfunction ensureProtocolRuntime(state: SessionState): ProtocolRuntime {\n const existing = runtimes.get(state);\n if (existing) return existing;\n\n const runtime: ProtocolRuntime = {\n reqCounter: 0,\n pending: new Map(),\n pushWaiters: new Map(),\n envelopeHandlers: new Set(),\n unsubscribeChannel: null,\n unsubscribeTransport: null,\n };\n\n if (state.channel === null) {\n throw new TransportError(\"CONNECTION_LOST\", \"coordinator protocol requires a live channel\");\n }\n runtime.unsubscribeChannel = state.channel.onMessage((frame) => handleFrame(runtime, frame));\n runtime.unsubscribeTransport = state.transport.onStateChange((transportState) => {\n if (transportState === \"closing\" || transportState === \"closed\") {\n rejectAll(runtime, new TransportError(\"CONNECTION_LOST\", \"coordinator transport closed\"));\n }\n });\n\n runtimes.set(state, runtime);\n return runtime;\n}\n\nfunction handleFrame(runtime: ProtocolRuntime, frame: Uint8Array): void {\n void handleFrameAsync(runtime, frame);\n}\n\nasync function handleFrameAsync(runtime: ProtocolRuntime, frame: Uint8Array): Promise<void> {\n const protocol = await loadProtocol();\n const decoded = protocol.decode(frame);\n if (!decoded.ok) {\n rejectAll(runtime, decoded.error);\n return;\n }\n\n const envelope = decoded.value;\n for (const handler of runtime.envelopeHandlers) handler(envelope);\n\n if (envelope.kind === protocol.EnvelopeKind.ERROR) {\n const payload = protocol.asErrorPayload(envelope);\n const error = commandErrorFromCoordinatorError(payload);\n if (payload.failed_req_id === undefined || payload.failed_req_id === OUT_OF_BAND_REQUEST_ID) {\n if (envelope.swap_id !== null) {\n rejectMatchingOutOfBandErrors(runtime, envelope.swap_id, error);\n }\n return;\n }\n rejectPending(runtime, payload.failed_req_id, error);\n return;\n }\n\n if (envelope.kind === protocol.EnvelopeKind.PUSH) {\n resolvePushWaiter(runtime, envelope);\n return;\n }\n\n if (envelope.kind !== protocol.EnvelopeKind.RESPONSE) return;\n const pending = runtime.pending.get(envelope.req_id);\n if (!pending) return;\n runtime.pending.delete(envelope.req_id);\n if (pending.timer) clearTimeout(pending.timer);\n pending.resolve(envelope);\n}\n\nfunction resolvePushWaiter(runtime: ProtocolRuntime, envelope: Envelope): void {\n const waiters = runtime.pushWaiters.get(envelope.type);\n const waiter = waiters?.shift();\n if (!waiter || !waiters) return;\n if (waiters.length === 0) {\n runtime.pushWaiters.delete(envelope.type);\n }\n if (waiter.timer) clearTimeout(waiter.timer);\n waiter.resolve(envelope);\n}\n\nfunction rejectPending(runtime: ProtocolRuntime, reqId: number, error: Error): void {\n const pending = runtime.pending.get(reqId);\n if (!pending) return;\n runtime.pending.delete(reqId);\n if (pending.timer) clearTimeout(pending.timer);\n pending.reject(error);\n}\n\nfunction rejectMatchingOutOfBandErrors(\n runtime: ProtocolRuntime,\n swapId: string,\n error: Error,\n): void {\n for (const [reqId, pending] of runtime.pending) {\n if (!pending.rejectMatchingOutOfBandErrors || pending.swapId !== swapId) continue;\n rejectPending(runtime, reqId, error);\n }\n}\n\nfunction commandErrorFromCoordinatorError(payload: {\n readonly code: string;\n readonly failed_req_id?: number;\n readonly message: string;\n}): CommandError {\n const coordinatorCode = toCoordinatorWireErrorCode(payload.code);\n return new CommandError(commandCodeFromCoordinatorCode(coordinatorCode), payload.message, {\n coordinatorCode,\n ...(payload.failed_req_id !== undefined ? { failedReqId: payload.failed_req_id } : {}),\n });\n}\n\nfunction commandCodeFromCoordinatorCode(code: CoordinatorWireErrorCode): CommandErrorCode {\n switch (code) {\n case \"ERR_UNEXPECTED_TYPE\":\n case \"ERR_UNKNOWN_SWAP\":\n case \"ERR_SWAP_NOT_REFUNDABLE\":\n return \"REJECTED_STATE\";\n case \"ERR_INTERNAL\":\n case \"ERR_SETTLEMENT_FAILED\":\n return \"REJECTED_STALE_JOB\";\n case \"ERR_INVALID_PAYLOAD\":\n case \"ERR_POLICY_VIOLATION\":\n case \"ERR_INVALID_RECOVERY_CODE\":\n case \"ERR_DKG_FAILURE\":\n case \"ERR_INVALID_DEPOSIT\":\n return \"REJECTED_GUARD\";\n }\n}\n\nfunction toCoordinatorWireErrorCode(code: string): CoordinatorWireErrorCode {\n switch (code) {\n case \"ERR_INVALID_PAYLOAD\":\n case \"ERR_UNEXPECTED_TYPE\":\n case \"ERR_UNKNOWN_SWAP\":\n case \"ERR_POLICY_VIOLATION\":\n case \"ERR_INVALID_RECOVERY_CODE\":\n case \"ERR_SWAP_NOT_REFUNDABLE\":\n case \"ERR_DKG_FAILURE\":\n case \"ERR_INTERNAL\":\n case \"ERR_INVALID_DEPOSIT\":\n case \"ERR_SETTLEMENT_FAILED\":\n return code;\n default:\n return \"ERR_INTERNAL\";\n }\n}\n\nfunction removePushWaiter(\n runtime: ProtocolRuntime,\n type: CoordinatorMessageType,\n waiter: PushWaiter,\n): void {\n const waiters = runtime.pushWaiters.get(type);\n if (!waiters) return;\n const index = waiters.indexOf(waiter);\n if (index >= 0) waiters.splice(index, 1);\n if (waiters.length === 0) runtime.pushWaiters.delete(type);\n}\n\nfunction rejectAll(runtime: ProtocolRuntime, error: Error): void {\n for (const [reqId, pending] of runtime.pending.entries()) {\n runtime.pending.delete(reqId);\n if (pending.timer) clearTimeout(pending.timer);\n pending.reject(error);\n }\n for (const [type, waiters] of runtime.pushWaiters.entries()) {\n runtime.pushWaiters.delete(type);\n for (const waiter of waiters) {\n if (waiter.timer) clearTimeout(waiter.timer);\n waiter.reject(error);\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/session/state.ts"],"names":[],"mappings":";;;AAiDA,IAAM,QAAA,uBAAe,OAAA,EAA+B;AAG7C,SAAS,oBAAoB,KAAA,EAA8B;AAChE,EAAA,MAAM,MAAA,GAAS;AAAA,IACb,IAAI,QAAA,GAAW;AACb,MAAA,OAAO,KAAA,CAAM,QAAA;AAAA,IACf;AAAA,GACF;AACA,EAAA,QAAA,CAAS,GAAA,CAAI,QAAQ,KAAK,CAAA;AAC1B,EAAA,OAAO,MAAA;AACT;AAOO,SAAS,gBAAgB,OAAA,EAAgC;AAC9D,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,GAAA,CAAI,OAAO,CAAA;AAClC,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,MAAM,IAAI,MAAM,+DAA+D,CAAA;AAAA,EACjF;AACA,EAAA,OAAO,KAAA;AACT;AAEO,SAAS,kBAAkB,KAAA,EAA2B;AAC3D,EAAA,iBAAA,CAAkB,KAAA,EAAO,IAAI,cAAA,CAAe,iBAAA,EAAmB,gBAAgB,CAAA,EAAG;AAAA,IAChF,qBAAA,EAAuB;AAAA,GACxB,CAAA;AACH;AAEO,SAAS,iBAAA,CACd,KAAA,EACA,KAAA,EACA,OAAA,GAAwD,EAAC,EACnD;AACN,EAAA,MAAM,qBAAA,GAAwB,QAAQ,qBAAA,IAAyB,IAAA;AAC/D,EAAA,MAAM,YAAA,GACJ,0BACC,KAAA,CAAM,QAAA,IAAY,MAAM,WAAA,KAAgB,IAAA,IAAQ,MAAM,OAAA,KAAY,IAAA,CAAA;AAErE,EAAA,IAAI,KAAA,CAAM,kBAAkB,IAAA,EAAM;AAChC,IAAA,YAAA,CAAa,MAAM,aAAa,CAAA;AAChC,IAAA,KAAA,CAAM,aAAA,GAAgB,IAAA;AAAA,EACxB;AACA,EAAA,KAAA,CAAM,eAAA,GAAkB,IAAA;AACxB,EAAA,KAAA,CAAM,cAAA,GAAiB,KAAA;AAEvB,EAAA,MAAM,UAAU,KAAA,CAAM,OAAA;AACtB,EAAA,KAAA,CAAM,QAAA,GAAW,KAAA;AACjB,EAAA,KAAA,CAAM,WAAA,GAAc,IAAA;AACpB,EAAA,KAAA,CAAM,OAAA,GAAU,IAAA;AAChB,EAAA,KAAA,CAAM,KAAA,GAAQ,IAAA;AACd,EAAA,KAAA,CAAM,qBAAA,GAAwB,IAAA;AAE9B,EAAA,OAAA,EAAS,KAAA,EAAM;AACf,EAAA,KAAA,CAAM,UAAU,KAAA,EAAM;AAEtB,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,KAAA,MAAW,OAAA,IAAW,KAAA,CAAM,uBAAA,EAAyB,OAAA,CAAQ,KAAK,CAAA;AAAA,EACpE;AACF","file":"chunk-V5HXJRBW.js","sourcesContent":["/**\n * Internal session state and the opaque-handle registry.\n *\n * The public {@link Session} is opaque: consumers only read `session.attested`.\n * The real state (transport, endpoint pool, attestation result) is held here\n * and reached through {@link getSessionState}, keyed off the handle in a\n * `WeakMap` so it is never reachable from the public surface.\n */\n\nimport type { Session } from \"../core/session.js\";\nimport type { Transport } from \"../transport/types.js\";\nimport type { AttestationResult } from \"../transport/handshake.js\";\nimport type { SecureChannel } from \"./secureChannel.js\";\nimport type { CoordinatorPoolConfig } from \"../schemas/types.generated.js\";\nimport { TransportError } from \"../core/errors.js\";\n\nexport interface SessionState {\n /** Flipped to `true` once attestation passes. */\n attested: boolean;\n /** The byte channel this session runs over. */\n readonly transport: Transport;\n /** The endpoint pool the session was created with. */\n readonly pool: CoordinatorPoolConfig;\n /** The last verified attestation result, or `null` before first attestation. */\n attestation: AttestationResult | null;\n /**\n * The live attested Noise channel, or `null` before/after attestation. All\n * application I/O Noise-encrypts through this.\n */\n channel: SecureChannel | null;\n /**\n * The per-connection 32-byte CSPRNG nonce bound into the attestation request.\n * Retained for re-attestation over the same channel.\n */\n nonce: Uint8Array | null;\n /** The coordinator's pinned Noise static public key, or `null` if unattested. */\n remoteStaticPublicKey: Uint8Array | null;\n /** Pending re-attestation timer, cleared on close. */\n reattestTimer: ReturnType<typeof setTimeout> | null;\n /** In-flight re-attestation shared by explicit and periodic checks. */\n reattestPromise: Promise<AttestationResult> | null;\n /** Fatal secure-channel cause preserved across transport close notifications. */\n lastFatalError: Error | null;\n /** Handlers invoked when an out-of-band re-attestation fails. */\n readonly policyViolationHandlers: Set<(error: Error) => void>;\n /** Tear down the session: clear the re-attest timer and close the channel. */\n close(): void;\n}\n\nconst registry = new WeakMap<Session, SessionState>();\n\n/** Build an opaque {@link Session} handle backed by `state`. */\nexport function createSessionHandle(state: SessionState): Session {\n const handle = {\n get attested() {\n return state.attested;\n },\n } as unknown as Session;\n registry.set(handle, state);\n return handle;\n}\n\n/**\n * Resolve the internal state for a session.\n *\n * @throws Error if the handle was not produced by `createSession`.\n */\nexport function getSessionState(session: Session): SessionState {\n const state = registry.get(session);\n if (!state) {\n throw new Error(\"invalid Session: this handle was not created by createSession\");\n }\n return state;\n}\n\nexport function closeSessionState(state: SessionState): void {\n failSessionClosed(state, new TransportError(\"CONNECTION_LOST\", \"session closed\"), {\n notifyPolicyViolation: false,\n });\n}\n\nexport function failSessionClosed(\n state: SessionState,\n cause: Error,\n options: { readonly notifyPolicyViolation?: boolean } = {},\n): void {\n const notifyPolicyViolation = options.notifyPolicyViolation ?? true;\n const shouldNotify =\n notifyPolicyViolation &&\n (state.attested || state.attestation !== null || state.channel !== null);\n\n if (state.reattestTimer !== null) {\n clearTimeout(state.reattestTimer);\n state.reattestTimer = null;\n }\n state.reattestPromise = null;\n state.lastFatalError = cause;\n\n const channel = state.channel;\n state.attested = false;\n state.attestation = null;\n state.channel = null;\n state.nonce = null;\n state.remoteStaticPublicKey = null;\n\n channel?.close();\n state.transport.close();\n\n if (shouldNotify) {\n for (const handler of state.policyViolationHandlers) handler(cause);\n }\n}\n"]}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
type CoordinatorEndpoint = {
|
|
2
|
-
readonly wsUrl: string;
|
|
3
|
-
readonly expectedHostname: string;
|
|
4
|
-
readonly releasePin: CoordinatorReleasePin;
|
|
5
|
-
readonly requiredMode: "prod" | "dev" | "auto";
|
|
6
|
-
readonly allowLocalAttestation?: boolean;
|
|
7
|
-
readonly roleHint?: "leader" | "watcher";
|
|
8
|
-
readonly weight?: number;
|
|
9
|
-
};
|
|
10
|
-
type CoordinatorReleasePin = {
|
|
11
|
-
readonly mrtd: string;
|
|
12
|
-
readonly binaryHash?: string;
|
|
13
|
-
readonly runtimeProfile?: "prod-hardened" | "prod-devnet-simplified";
|
|
14
|
-
readonly intelRootFingerprint?: string;
|
|
15
|
-
readonly allowMissingDcapCollateral?: boolean;
|
|
16
|
-
readonly azureMaa?: AzureMaaPin;
|
|
17
|
-
};
|
|
18
|
-
type AzureMaaPin = {
|
|
19
|
-
readonly issuer: string;
|
|
20
|
-
readonly jwksUrl: string;
|
|
21
|
-
readonly policyHash: string;
|
|
22
|
-
};
|
|
23
|
-
type CoordinatorPoolConfig = {
|
|
24
|
-
readonly endpoints: readonly CoordinatorEndpoint[];
|
|
25
|
-
readonly reattestEveryMs?: number;
|
|
26
|
-
readonly failoverDebounceMs?: number;
|
|
27
|
-
readonly maxReconnectAttempts?: number;
|
|
28
|
-
readonly noiseTransportTimeoutMs?: number;
|
|
29
|
-
readonly preferLeader?: boolean;
|
|
30
|
-
readonly allowedRoles?: readonly ("leader" | "watcher")[];
|
|
31
|
-
};
|
|
32
|
-
type LpPositionView = {
|
|
33
|
-
readonly id: string;
|
|
34
|
-
readonly status: "dkg_pending" | "active" | "withdrawing" | "closed";
|
|
35
|
-
readonly targetShardCount: number;
|
|
36
|
-
readonly authPublicKey: string;
|
|
37
|
-
readonly refillPublicKey: string;
|
|
38
|
-
readonly withdrawalCommitment: string;
|
|
39
|
-
readonly committedLamports: number;
|
|
40
|
-
readonly earnedLamports: number;
|
|
41
|
-
readonly refillThreshold: number;
|
|
42
|
-
readonly shards: readonly {
|
|
43
|
-
readonly [key: string]: unknown;
|
|
44
|
-
}[];
|
|
45
|
-
readonly createdAt: number;
|
|
46
|
-
};
|
|
47
|
-
type PayoutDestination = {
|
|
48
|
-
readonly address: string;
|
|
49
|
-
readonly sharePercent: number;
|
|
50
|
-
readonly minDelayMs?: number;
|
|
51
|
-
readonly maxDelayMs?: number;
|
|
52
|
-
readonly minLamports?: number;
|
|
53
|
-
};
|
|
54
|
-
type PayoutPolicy = {
|
|
55
|
-
readonly destinations: readonly PayoutDestination[];
|
|
56
|
-
readonly totalDeadlineMs?: number;
|
|
57
|
-
readonly batchExclusionId?: string;
|
|
58
|
-
};
|
|
59
|
-
type StorageEnvelope = {
|
|
60
|
-
readonly namespace: string;
|
|
61
|
-
readonly key: string;
|
|
62
|
-
readonly alg: "AES-GCM" | "none";
|
|
63
|
-
readonly ciphertext: string;
|
|
64
|
-
readonly iv?: string;
|
|
65
|
-
readonly createdAtMs: number;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type { AzureMaaPin as A, CoordinatorEndpoint as C, LpPositionView as L, PayoutPolicy as P, StorageEnvelope as S, CoordinatorPoolConfig as a, CoordinatorReleasePin as b, PayoutDestination as c };
|