@tinycloud/share-sdk 1.2.0-beta.3 → 1.2.0-beta.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/dist/index.d.cts CHANGED
@@ -1,7 +1,10 @@
1
- import { ShareEnvelopeV3, ShareEnvelopeV2 } from '@tinycloud/share-envelope';
1
+ import { ShareEnvelopeV3, ShareEnvelopeV2, ArtifactPin, UnsignedShareEnvelopeV3 } from '@tinycloud/share-envelope';
2
2
  export { CheckBearerDelegationOptions, DelegationCheckResult, canonicalize, checkBearerDelegation, fromBase64Url, requiredResourceUri, resourceUriCovers, toBase64Url } from '@tinycloud/share-envelope';
3
- import { S as ShareAuthorizationMethod, O as OwnerShareAction, a as OwnerShareMatcher, P as PublishedShareDeliveryMaterial, b as OwnerSharePolicyRegistrationReceipt, D as DelegatedShareKey, c as PublishedShare, d as ShareAuthorizedContent, e as ShareAuthorizationAdapter, T as TargetPublishOutcome, f as TargetPublishInput, g as ShareAuthorizationResult, h as ShareTarget } from './addressed-publish-CsUS7-SI.cjs';
4
- export { A as AddressedOwnerRootInput, i as AddressedOwnerRootReceipt, j as AddressedPolicyRegistrationInput, k as AddressedPolicyRegistrationReceipt, l as AddressedPublishAuthority, m as AddressedSharePublishOptions, n as AddressedShareRequest, C as CreateOwnerDelegationParams, o as DEFAULT_SHARE_LIFETIME_MS, M as MAX_CONTENT_BYTES, p as OWNER_SHARE_REGISTRATION_DOMAIN, q as OwnerDelegationPermission, r as OwnerDelegationReceipt, s as OwnerShareDecryption, t as OwnerSharePolicyRegistration, u as OwnerSharePolicyV2, v as PreparedAddressedShare, w as PublishedShareMetadata, R as RegisterOwnerSharePolicyParams, x as SHARE_CONTENT_LIMIT, y as SHARE_PUBLISH_RESULT_VERSION, z as ShareAuthorizationDenied, B as ShareAuthorizationReady, E as ShareAuthorizationRequired, F as SharePublishError, G as SharePublishErrorCode, H as SharePublishOptions, I as SharePublishTarget, J as SignedDelegation, K as TargetPublishAdapter, L as addressedCredentialRequirement, N as authorizationMethodForTarget, Q as authorizeShare, U as canonicalOwnerSharePolicy, V as computeOwnerShareRegistrationCid, W as createDelegatedShareKey, X as createPolicyEnforcementDelegation, Y as normalizeShareTarget, Z as prepareAddressedShare, _ as publishAddressedShare, $ as publishTargetShare, a0 as redactPublishedShare, a1 as restoreDelegatedShareKey, a2 as targetAuthorizationMethod, a3 as validateOwnerSharePolicyRegistration, a4 as validateOwnerSharePolicyRegistrationBytes } from './addressed-publish-CsUS7-SI.cjs';
3
+ import { S as ShareAuthorizationMethod, a as ShareAuthorizedContent, b as ShareAuthorizationAdapter, T as TargetPublishOutcome, c as TargetPublishInput, d as ShareAuthorizationResult, e as ShareTarget } from './addressed-publish-DtcLNG2m.cjs';
4
+ export { A as AddressedOwnerRootInput, f as AddressedOwnerRootReceipt, g as AddressedPolicyRegistrationInput, h as AddressedPolicyRegistrationReceipt, i as AddressedPublishAuthority, j as AddressedSharePublishOptions, k as AddressedShareRequest, P as PreparedAddressedShare, l as ShareAuthorizationDenied, m as ShareAuthorizationReady, n as ShareAuthorizationRequired, o as TargetPublishAdapter, p as addressedCredentialRequirement, q as authorizationMethodForTarget, r as authorizeShare, s as normalizeShareTarget, t as prepareAddressedShare, u as publishAddressedShare, v as publishTargetShare, w as targetAuthorizationMethod } from './addressed-publish-DtcLNG2m.cjs';
5
+ export { C as CreateOwnerDelegationParams, D as DEFAULT_SHARE_LIFETIME_MS, a as DelegatedShareKey, M as MAX_CONTENT_BYTES, O as OWNER_SHARE_REGISTRATION_DOMAIN, b as OwnerDelegationPermission, c as OwnerDelegationReceipt, d as OwnerShareAction, e as OwnerShareDecryption, f as OwnerShareMatcher, g as OwnerSharePolicyRegistration, h as OwnerSharePolicyRegistrationReceipt, i as OwnerSharePolicyV2, P as PublishedShare, j as PublishedShareDeliveryMaterial, k as PublishedShareMetadata, R as RegisterOwnerSharePolicyParams, S as SHARE_CONTENT_LIMIT, l as SHARE_PUBLISH_RESULT_VERSION, m as SharePublishError, n as SharePublishErrorCode, o as SharePublishOptions, p as SharePublishTarget, q as SignedDelegation, r as canonicalOwnerSharePolicy, s as computeOwnerShareRegistrationCid, t as createDelegatedShareKey, u as createPolicyEnforcementDelegation, v as redactPublishedShare, w as restoreDelegatedShareKey, x as validateOwnerSharePolicyRegistration, y as validateOwnerSharePolicyRegistrationBytes } from './owner-policy-BqzRlkb6.cjs';
6
+ import { S as SenderShareRecord, a as SenderShareRecordStorage } from './history-CUWDK0lE.cjs';
7
+ export { E as EncryptedSenderShareHistory, b as EncryptedShareHistoryStorage, M as MemoryEncryptedShareHistoryStorage, c as MemorySenderShareKeyStorage, d as MemorySenderShareRecordStorage, e as SenderShareKeyStorage, f as SenderShareRecordProofs, g as SenderShareRevocationScope, h as SenderShareStore, i as historyRecordForPublishedShare } from './history-CUWDK0lE.cjs';
5
8
 
6
9
  declare function hasUnsafeFilenameCodePoint(value: string): boolean;
7
10
  /** A single display/download filename, never a path. Returns the NFC form. */
@@ -64,6 +67,11 @@ interface ShareMetadata {
64
67
  readonly filename?: string;
65
68
  readonly mode?: string;
66
69
  };
70
+ /** Set when the share is pinned to one artifact version; the owner's signature covers it (TC-1428). */
71
+ readonly artifact?: {
72
+ readonly id: string;
73
+ readonly version: number;
74
+ };
67
75
  }
68
76
  interface ShareInspection {
69
77
  readonly metadata: ShareMetadata;
@@ -139,156 +147,6 @@ declare class MemoryShareCache implements ShareCache {
139
147
  clear(): Promise<void>;
140
148
  }
141
149
 
142
- interface EncryptedShareHistoryStorage {
143
- put(value: Uint8Array): Promise<void>;
144
- list(): Promise<readonly Uint8Array[]>;
145
- clear(): Promise<void>;
146
- }
147
- declare class MemoryEncryptedShareHistoryStorage implements EncryptedShareHistoryStorage {
148
- private readonly values;
149
- put(value: Uint8Array): Promise<void>;
150
- list(): Promise<readonly Uint8Array[]>;
151
- clear(): Promise<void>;
152
- }
153
- /**
154
- * The durable record a sender needs, after a reload, to display and manage
155
- * a share it created. Every identity/CID here comes verbatim from the
156
- * Node-verified {@link OwnerSharePolicyRegistrationReceipt}; nothing is
157
- * re-derived or guessed.
158
- */
159
- interface SenderShareRecord {
160
- readonly shareId: string;
161
- readonly registrationCid?: string;
162
- readonly policyCid?: string;
163
- readonly ownerDelegationCid?: string;
164
- readonly enforcementDelegationCid?: string;
165
- readonly shareKeyDid?: string;
166
- readonly ownerDid?: string;
167
- readonly enforcerDid?: string;
168
- readonly target: {
169
- readonly origin: string;
170
- readonly nodeAudience: string;
171
- readonly spaceId: string;
172
- };
173
- readonly resource: {
174
- readonly kind: "exact" | "prefix";
175
- readonly path: string;
176
- };
177
- readonly actions: readonly OwnerShareAction[];
178
- readonly recipientMatcher: OwnerShareMatcher;
179
- /** The signed target discriminator, retained separately from the email matcher. */
180
- readonly targetKind?: "bearer" | "recipientDid" | "email" | "emailDomain";
181
- readonly registeredAt: string;
182
- readonly expiresAt: string;
183
- readonly revokedAt?: string;
184
- readonly envelopeCid?: string;
185
- readonly shareCid?: string;
186
- /** Complete bearer links are encrypted at rest and only revealed explicitly. */
187
- readonly link?: string;
188
- readonly filename?: string;
189
- /** Policy/v3 delivery material. The containing history record must remain encrypted at rest. */
190
- readonly deliveryMaterial?: PublishedShareDeliveryMaterial;
191
- /** Canonical mailboxes whose invitation delivery was confirmed; history is encrypted at rest. */
192
- readonly deliveredRecipients?: readonly string[];
193
- }
194
- /** Create the durable encrypted-history shape from canonical publication receipts. */
195
- declare function historyRecordForPublishedShare(result: PublishedShare, now?: Date): SenderShareRecord;
196
- /**
197
- * "direct" selects the Policy/v3 enforcement root; "ancestor" selects its
198
- * policy-authority sibling. Addressed shares revoke that signed root through
199
- * the Node Policy/v3 endpoint, which cuts off existing sessions as well as
200
- * fresh admission and delivery. Bearer shares retain ordinary delegation
201
- * revocation.
202
- */
203
- type SenderShareRevocationScope = "direct" | "ancestor";
204
- interface SenderShareRecordStorage {
205
- put(record: SenderShareRecord): Promise<void>;
206
- /** Atomically transform the latest record, if present. Implementations that
207
- * provide this must serialize the read and write with every other writer. */
208
- update?(shareId: string, change: (record: SenderShareRecord) => SenderShareRecord | Promise<SenderShareRecord>): Promise<SenderShareRecord | undefined>;
209
- list(): Promise<readonly SenderShareRecord[]>;
210
- get(shareId: string): Promise<SenderShareRecord | undefined>;
211
- delete(shareId: string): Promise<void>;
212
- }
213
- interface StoredSenderShareKey {
214
- readonly cryptoKey: CryptoKey;
215
- readonly publicKey: Uint8Array;
216
- readonly extractable: boolean;
217
- }
218
- interface SenderShareKeyStorage {
219
- put(shareId: string, key: StoredSenderShareKey): Promise<void>;
220
- get(shareId: string): Promise<StoredSenderShareKey | undefined>;
221
- delete(shareId: string): Promise<void>;
222
- }
223
- /** In-memory reference implementation. Real deployments back these with IndexedDB so the non-extractable `CryptoKey` survives a reload via structured clone. */
224
- declare class MemorySenderShareRecordStorage implements SenderShareRecordStorage {
225
- private readonly records;
226
- private operation;
227
- private serialize;
228
- put(record: SenderShareRecord): Promise<void>;
229
- update(shareId: string, change: (record: SenderShareRecord) => SenderShareRecord | Promise<SenderShareRecord>): Promise<SenderShareRecord | undefined>;
230
- list(): Promise<readonly SenderShareRecord[]>;
231
- get(shareId: string): Promise<SenderShareRecord | undefined>;
232
- delete(shareId: string): Promise<void>;
233
- }
234
- declare class MemorySenderShareKeyStorage implements SenderShareKeyStorage {
235
- private readonly keys;
236
- put(shareId: string, key: StoredSenderShareKey): Promise<void>;
237
- get(shareId: string): Promise<StoredSenderShareKey | undefined>;
238
- delete(shareId: string): Promise<void>;
239
- }
240
- interface SenderShareStoreOptions {
241
- readonly records: SenderShareRecordStorage;
242
- readonly keys: SenderShareKeyStorage;
243
- readonly now?: () => Date;
244
- }
245
- /**
246
- * Reload-safe sender-side management for shares created through
247
- * {@link canonicalOwnerSharePolicy} / `registerOwnerSharePolicy`. Persists
248
- * the registration receipt's canonical identity tuple plus the ephemeral
249
- * share key's non-extractable `CryptoKey` handle, so a sender can list,
250
- * inspect, and revoke shares it created in an earlier session -- without
251
- * ever re-exporting private key material.
252
- */
253
- declare class SenderShareStore {
254
- private readonly records;
255
- private readonly keys;
256
- private readonly now;
257
- constructor(options: SenderShareStoreOptions);
258
- /** Persist a Node-verified registration receipt and its share key handle. */
259
- save(receipt: OwnerSharePolicyRegistrationReceipt, key: DelegatedShareKey): Promise<SenderShareRecord>;
260
- /** List shares created in any session, most recent first. */
261
- list(options?: {
262
- readonly includeRevoked?: boolean;
263
- readonly includeExpired?: boolean;
264
- }): Promise<readonly SenderShareRecord[]>;
265
- get(shareId: string): Promise<SenderShareRecord | undefined>;
266
- /** Recover a signer for the persisted share key after a reload. */
267
- loadKey(shareId: string): Promise<DelegatedShareKey | undefined>;
268
- /**
269
- * The delegation CID to pass to the node's existing generic
270
- * `tinycloud.delegation/revoke` invocation to revoke this share at the
271
- * requested scope. Does not itself call the node -- callers invoke
272
- * their own `revokeDelegation`/`DelegationManager.revoke` with the
273
- * returned CID, then call {@link markRevoked} once that succeeds.
274
- */
275
- revocationTarget(shareId: string, scope: SenderShareRevocationScope): Promise<string>;
276
- /** Mark a share revoked locally after the caller's node-side revoke call succeeds. */
277
- markRevoked(shareId: string, revokedAt?: string): Promise<SenderShareRecord>;
278
- /** Forget a share and clear its persisted key handle. */
279
- remove(shareId: string): Promise<void>;
280
- }
281
- /** WebCrypto-backed persistence adapter; links and private material are absent. */
282
- declare class EncryptedSenderShareHistory {
283
- private readonly storage;
284
- private readonly key;
285
- private readonly now;
286
- constructor(storage: EncryptedShareHistoryStorage, key: CryptoKey, now?: () => Date);
287
- put(record: SenderShareRecord): Promise<void>;
288
- list(): Promise<readonly SenderShareRecord[]>;
289
- clear(): Promise<void>;
290
- }
291
-
292
150
  type ShareNotifyState = "delivered" | "already-delivered" | "partial-failure";
293
151
  interface ShareNotifyResult {
294
152
  readonly protocol: "tinycloud-share";
@@ -632,4 +490,85 @@ declare function parseNativeShareUrl(value: string): string;
632
490
  /** Receive through the public SDK without creating another transport protocol. */
633
491
  declare function openNativeShare(sharing: NativeSharingService, link: string): Promise<unknown>;
634
492
 
635
- export { CredentialInvitationError, type CredentialInvitationErrorCode, type CredentialInvitationReceipt, type CredentialInvitationResult, DEFAULT_MAX_CONTENT_BLOB_BYTES, DEFAULT_MAX_SEALED_BLOB_BYTES, DelegatedShareKey, EncryptedSenderShareHistory, type EncryptedShareHistoryStorage, MemoryEncryptedShareHistoryStorage, MemorySenderShareKeyStorage, MemorySenderShareRecordStorage, MemoryShareCache, NATIVE_SHARE_FRAGMENT_PARAMETER, type NativeShareResult, type NativeSharingService, OwnerShareAction, OwnerShareMatcher, OwnerSharePolicyRegistrationReceipt, type ParsedAddressedEnvelope, PublishedShare, PublishedShareDeliveryMaterial, SHARE_RESULT_VERSION, SHARE_V2_PROTOCOL, type SenderShareKeyStorage, type SenderShareRecord, type SenderShareRecordStorage, type SenderShareRevocationScope, SenderShareStore, ShareAuthorizationAdapter, ShareAuthorizationMethod, ShareAuthorizationResult, ShareAuthorizedContent, type ShareCache, type ShareCacheEntry, type ShareCacheKey, type ShareCacheMetadata, type ShareDeliveryAdapter, type ShareErrorCode, type ShareErrorInfo, type ShareFetchOptions, type ShareHistoryView, type ShareInspection, type ShareMetadata, type ShareNodeTrust, ShareNotifyError, type ShareNotifyInput, type ShareNotifyResult, type ShareNotifyState, type SharePolicyChallenge, type SharePolicyDelegationLink, type SharePolicyPublishAdapter, type SharePolicyRootRevocation, type SharePolicySession, type SharePresentationMaterial, type ShareReceiveAuthorizationRequired, ShareReceiveError, type ShareReceiveOutcome, type ShareReceiveResult, ShareRecipientClient, type ShareRecipientClientOptions, type ShareRevocationAdapter, type ShareRevocationResult, ShareTarget, TargetPublishInput, TargetPublishOutcome, canonicalShareFilename, claimShare, createAddressedAuthorization, createNativeShare, createShareV2HolderBindingArtifact, deliverCredentialInvitation, hasUnsafeFilenameCodePoint, historyRecordForPublishedShare, inspectShare, listShares, notifyShare, openNativeShare, parseAddressedEnvelope, parseNativeShareUrl, publishPolicyShare, receiveShare, recipientMatchesShareRecord, resumeShareAuthorization, revokeShare, shareDeliveryWindowExpiresAt, showShare, toShareErrorInfo };
493
+ /**
494
+ * Artifact pin verification (TC-1428). Small on purpose: this is the one place that decides whether an addressed
495
+ * share that reads an artifact version may be trusted.
496
+ *
497
+ * What is signed. The owner signs the whole Policy/v3 envelope (Ed25519, `verifyEnvelopeV3SignatureOnly`). `artifactPin` is a
498
+ * field of that envelope, so the signature covers it: artifact id, version, the sha256 of the version's
499
+ * `manifest.json`, and the sha256 and size of the one stored file the share reads. The manifest stays an owner-side
500
+ * record; a recipient never needs to fetch it. Policy/v3 already binds the file's ciphertext digest
501
+ * (`contentSource.initialCiphertextDigestHex`); the pin binds that digest to an artifact identity and a version, so a
502
+ * share cannot be re-pointed at another version or another artifact's path without breaking the signature.
503
+ *
504
+ * Trust model (accepted, TC-1428 finding 3): the owner is the trusted signer. The node has no write-once ACL, so the
505
+ * owner (or whoever holds the owner's session) can overwrite `versions/<n>/<file>` afterwards. A recipient then
506
+ * detects the substitution through the pin digest and fails closed; it cannot tell a malicious owner from a node
507
+ * serving stale or altered bytes, and does not try to.
508
+ *
509
+ * Fails closed: any addressed share whose content source lies under `artifacts/` must carry a valid pin that matches
510
+ * that source. A pin on any other path is refused. `artifacts/<id>/current/...` has no pin form in v1 and is refused.
511
+ */
512
+
513
+ type ArtifactPinErrorCode = "missing-pin" | "unsupported-artifact-path" | "wrong-signer" | "bad-signature" | "pin-source-mismatch" | "pinned-share-writable" | "expectation-mismatch" | "file-digest-mismatch" | "manifest-mismatch";
514
+ declare class ArtifactPinError extends Error {
515
+ readonly code: ArtifactPinErrorCode;
516
+ /** The code is the message: stable, short, and what callers and tests match on. */
517
+ constructor(code: ArtifactPinErrorCode);
518
+ }
519
+ /**
520
+ * What the caller already knows about the share it is opening, from outside the envelope. Optional: a v1 pinned share
521
+ * names its version in its own signed pin and nothing outside the link says which one to expect, so no production
522
+ * caller passes it. A caller that does learn a version out of band (a listing, a "newer version" link) uses it to
523
+ * refuse an older or different pin.
524
+ */
525
+ interface ExpectedArtifact {
526
+ readonly artifactId?: string;
527
+ readonly version?: number;
528
+ }
529
+ interface VerifyArtifactShareOptions {
530
+ /** The did:key the caller trusts as the sender. `signature.signerDid` is self-asserted and proves nothing alone. */
531
+ readonly expectedOwnerDid: string;
532
+ readonly expected?: ExpectedArtifact;
533
+ }
534
+ /**
535
+ * The fields of an envelope (or of a share about to be built) that the pin binds. Taking a view lets the publisher run
536
+ * the identical check before it registers anything, and the recipient run it again where it reads.
537
+ */
538
+ interface ArtifactBindingView {
539
+ readonly artifactPin?: ArtifactPin;
540
+ readonly target: {
541
+ readonly spaceId: string;
542
+ };
543
+ readonly contentSource: {
544
+ readonly kvResource: string;
545
+ readonly selector: "exact" | "prefix";
546
+ readonly mode: "mutable" | "immutable";
547
+ readonly initialCiphertextDigestHex?: string | undefined;
548
+ };
549
+ readonly resource: {
550
+ readonly kind: "exact" | "prefix";
551
+ readonly path: string;
552
+ };
553
+ /** Share actions (`read` | `list` | `edit`). */
554
+ readonly actions: readonly string[];
555
+ /** KV abilities the signed policy grants on the content source. */
556
+ readonly policyKvActions: readonly string[];
557
+ }
558
+ declare function artifactBindingView(envelope: UnsignedShareEnvelopeV3 | ShareEnvelopeV3): ArtifactBindingView;
559
+ /**
560
+ * The pin and the content source must say the same thing, and a pinned share must be read-only. Synchronous and
561
+ * signature-free, so the publisher can run it before registering anything and the recipient can re-run it at the
562
+ * point of reading. Returns the pin for an artifact share and `undefined` for any other share.
563
+ */
564
+ declare function assertArtifactBinding(view: ArtifactBindingView, expected?: ExpectedArtifact): ArtifactPin | undefined;
565
+ /**
566
+ * Check that the trusted owner signed this envelope (and so its pin), then the pin binding. Throws `ArtifactPinError`;
567
+ * never returns a partial answer. Only the owner's Ed25519 signature over the envelope is checked here, because that
568
+ * is what authenticates the pin. The rest of the envelope (policy signature, owner roots, enforcer binding) is
569
+ * `verifyEnvelopeV3`'s job, and `resolvePolicyShare` runs both before it trusts a link. (Folding the two into one
570
+ * call was measured: +911 gzip bytes in the canonical ESM bundle, for a saved ed25519 verify.)
571
+ */
572
+ declare function verifyArtifactShare(envelope: ShareEnvelopeV3, options: VerifyArtifactShareOptions): ArtifactPin | undefined;
573
+
574
+ export { type ArtifactBindingView, ArtifactPinError, type ArtifactPinErrorCode, CredentialInvitationError, type CredentialInvitationErrorCode, type CredentialInvitationReceipt, type CredentialInvitationResult, DEFAULT_MAX_CONTENT_BLOB_BYTES, DEFAULT_MAX_SEALED_BLOB_BYTES, type ExpectedArtifact, MemoryShareCache, NATIVE_SHARE_FRAGMENT_PARAMETER, type NativeShareResult, type NativeSharingService, type ParsedAddressedEnvelope, SHARE_RESULT_VERSION, SHARE_V2_PROTOCOL, SenderShareRecord, SenderShareRecordStorage, ShareAuthorizationAdapter, ShareAuthorizationMethod, ShareAuthorizationResult, ShareAuthorizedContent, type ShareCache, type ShareCacheEntry, type ShareCacheKey, type ShareCacheMetadata, type ShareDeliveryAdapter, type ShareErrorCode, type ShareErrorInfo, type ShareFetchOptions, type ShareHistoryView, type ShareInspection, type ShareMetadata, type ShareNodeTrust, ShareNotifyError, type ShareNotifyInput, type ShareNotifyResult, type ShareNotifyState, type SharePolicyChallenge, type SharePolicyDelegationLink, type SharePolicyPublishAdapter, type SharePolicyRootRevocation, type SharePolicySession, type SharePresentationMaterial, type ShareReceiveAuthorizationRequired, ShareReceiveError, type ShareReceiveOutcome, type ShareReceiveResult, ShareRecipientClient, type ShareRecipientClientOptions, type ShareRevocationAdapter, type ShareRevocationResult, ShareTarget, TargetPublishInput, TargetPublishOutcome, type VerifyArtifactShareOptions, artifactBindingView, assertArtifactBinding, canonicalShareFilename, claimShare, createAddressedAuthorization, createNativeShare, createShareV2HolderBindingArtifact, deliverCredentialInvitation, hasUnsafeFilenameCodePoint, inspectShare, listShares, notifyShare, openNativeShare, parseAddressedEnvelope, parseNativeShareUrl, publishPolicyShare, receiveShare, recipientMatchesShareRecord, resumeShareAuthorization, revokeShare, shareDeliveryWindowExpiresAt, showShare, toShareErrorInfo, verifyArtifactShare };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- import { ShareEnvelopeV3, ShareEnvelopeV2 } from '@tinycloud/share-envelope';
1
+ import { ShareEnvelopeV3, ShareEnvelopeV2, ArtifactPin, UnsignedShareEnvelopeV3 } from '@tinycloud/share-envelope';
2
2
  export { CheckBearerDelegationOptions, DelegationCheckResult, canonicalize, checkBearerDelegation, fromBase64Url, requiredResourceUri, resourceUriCovers, toBase64Url } from '@tinycloud/share-envelope';
3
- import { S as ShareAuthorizationMethod, O as OwnerShareAction, a as OwnerShareMatcher, P as PublishedShareDeliveryMaterial, b as OwnerSharePolicyRegistrationReceipt, D as DelegatedShareKey, c as PublishedShare, d as ShareAuthorizedContent, e as ShareAuthorizationAdapter, T as TargetPublishOutcome, f as TargetPublishInput, g as ShareAuthorizationResult, h as ShareTarget } from './addressed-publish-CsUS7-SI.js';
4
- export { A as AddressedOwnerRootInput, i as AddressedOwnerRootReceipt, j as AddressedPolicyRegistrationInput, k as AddressedPolicyRegistrationReceipt, l as AddressedPublishAuthority, m as AddressedSharePublishOptions, n as AddressedShareRequest, C as CreateOwnerDelegationParams, o as DEFAULT_SHARE_LIFETIME_MS, M as MAX_CONTENT_BYTES, p as OWNER_SHARE_REGISTRATION_DOMAIN, q as OwnerDelegationPermission, r as OwnerDelegationReceipt, s as OwnerShareDecryption, t as OwnerSharePolicyRegistration, u as OwnerSharePolicyV2, v as PreparedAddressedShare, w as PublishedShareMetadata, R as RegisterOwnerSharePolicyParams, x as SHARE_CONTENT_LIMIT, y as SHARE_PUBLISH_RESULT_VERSION, z as ShareAuthorizationDenied, B as ShareAuthorizationReady, E as ShareAuthorizationRequired, F as SharePublishError, G as SharePublishErrorCode, H as SharePublishOptions, I as SharePublishTarget, J as SignedDelegation, K as TargetPublishAdapter, L as addressedCredentialRequirement, N as authorizationMethodForTarget, Q as authorizeShare, U as canonicalOwnerSharePolicy, V as computeOwnerShareRegistrationCid, W as createDelegatedShareKey, X as createPolicyEnforcementDelegation, Y as normalizeShareTarget, Z as prepareAddressedShare, _ as publishAddressedShare, $ as publishTargetShare, a0 as redactPublishedShare, a1 as restoreDelegatedShareKey, a2 as targetAuthorizationMethod, a3 as validateOwnerSharePolicyRegistration, a4 as validateOwnerSharePolicyRegistrationBytes } from './addressed-publish-CsUS7-SI.js';
3
+ import { S as ShareAuthorizationMethod, a as ShareAuthorizedContent, b as ShareAuthorizationAdapter, T as TargetPublishOutcome, c as TargetPublishInput, d as ShareAuthorizationResult, e as ShareTarget } from './addressed-publish-BnSBJ-MX.js';
4
+ export { A as AddressedOwnerRootInput, f as AddressedOwnerRootReceipt, g as AddressedPolicyRegistrationInput, h as AddressedPolicyRegistrationReceipt, i as AddressedPublishAuthority, j as AddressedSharePublishOptions, k as AddressedShareRequest, P as PreparedAddressedShare, l as ShareAuthorizationDenied, m as ShareAuthorizationReady, n as ShareAuthorizationRequired, o as TargetPublishAdapter, p as addressedCredentialRequirement, q as authorizationMethodForTarget, r as authorizeShare, s as normalizeShareTarget, t as prepareAddressedShare, u as publishAddressedShare, v as publishTargetShare, w as targetAuthorizationMethod } from './addressed-publish-BnSBJ-MX.js';
5
+ export { C as CreateOwnerDelegationParams, D as DEFAULT_SHARE_LIFETIME_MS, a as DelegatedShareKey, M as MAX_CONTENT_BYTES, O as OWNER_SHARE_REGISTRATION_DOMAIN, b as OwnerDelegationPermission, c as OwnerDelegationReceipt, d as OwnerShareAction, e as OwnerShareDecryption, f as OwnerShareMatcher, g as OwnerSharePolicyRegistration, h as OwnerSharePolicyRegistrationReceipt, i as OwnerSharePolicyV2, P as PublishedShare, j as PublishedShareDeliveryMaterial, k as PublishedShareMetadata, R as RegisterOwnerSharePolicyParams, S as SHARE_CONTENT_LIMIT, l as SHARE_PUBLISH_RESULT_VERSION, m as SharePublishError, n as SharePublishErrorCode, o as SharePublishOptions, p as SharePublishTarget, q as SignedDelegation, r as canonicalOwnerSharePolicy, s as computeOwnerShareRegistrationCid, t as createDelegatedShareKey, u as createPolicyEnforcementDelegation, v as redactPublishedShare, w as restoreDelegatedShareKey, x as validateOwnerSharePolicyRegistration, y as validateOwnerSharePolicyRegistrationBytes } from './owner-policy-BqzRlkb6.js';
6
+ import { S as SenderShareRecord, a as SenderShareRecordStorage } from './history-CyT6x8h4.js';
7
+ export { E as EncryptedSenderShareHistory, b as EncryptedShareHistoryStorage, M as MemoryEncryptedShareHistoryStorage, c as MemorySenderShareKeyStorage, d as MemorySenderShareRecordStorage, e as SenderShareKeyStorage, f as SenderShareRecordProofs, g as SenderShareRevocationScope, h as SenderShareStore, i as historyRecordForPublishedShare } from './history-CyT6x8h4.js';
5
8
 
6
9
  declare function hasUnsafeFilenameCodePoint(value: string): boolean;
7
10
  /** A single display/download filename, never a path. Returns the NFC form. */
@@ -64,6 +67,11 @@ interface ShareMetadata {
64
67
  readonly filename?: string;
65
68
  readonly mode?: string;
66
69
  };
70
+ /** Set when the share is pinned to one artifact version; the owner's signature covers it (TC-1428). */
71
+ readonly artifact?: {
72
+ readonly id: string;
73
+ readonly version: number;
74
+ };
67
75
  }
68
76
  interface ShareInspection {
69
77
  readonly metadata: ShareMetadata;
@@ -139,156 +147,6 @@ declare class MemoryShareCache implements ShareCache {
139
147
  clear(): Promise<void>;
140
148
  }
141
149
 
142
- interface EncryptedShareHistoryStorage {
143
- put(value: Uint8Array): Promise<void>;
144
- list(): Promise<readonly Uint8Array[]>;
145
- clear(): Promise<void>;
146
- }
147
- declare class MemoryEncryptedShareHistoryStorage implements EncryptedShareHistoryStorage {
148
- private readonly values;
149
- put(value: Uint8Array): Promise<void>;
150
- list(): Promise<readonly Uint8Array[]>;
151
- clear(): Promise<void>;
152
- }
153
- /**
154
- * The durable record a sender needs, after a reload, to display and manage
155
- * a share it created. Every identity/CID here comes verbatim from the
156
- * Node-verified {@link OwnerSharePolicyRegistrationReceipt}; nothing is
157
- * re-derived or guessed.
158
- */
159
- interface SenderShareRecord {
160
- readonly shareId: string;
161
- readonly registrationCid?: string;
162
- readonly policyCid?: string;
163
- readonly ownerDelegationCid?: string;
164
- readonly enforcementDelegationCid?: string;
165
- readonly shareKeyDid?: string;
166
- readonly ownerDid?: string;
167
- readonly enforcerDid?: string;
168
- readonly target: {
169
- readonly origin: string;
170
- readonly nodeAudience: string;
171
- readonly spaceId: string;
172
- };
173
- readonly resource: {
174
- readonly kind: "exact" | "prefix";
175
- readonly path: string;
176
- };
177
- readonly actions: readonly OwnerShareAction[];
178
- readonly recipientMatcher: OwnerShareMatcher;
179
- /** The signed target discriminator, retained separately from the email matcher. */
180
- readonly targetKind?: "bearer" | "recipientDid" | "email" | "emailDomain";
181
- readonly registeredAt: string;
182
- readonly expiresAt: string;
183
- readonly revokedAt?: string;
184
- readonly envelopeCid?: string;
185
- readonly shareCid?: string;
186
- /** Complete bearer links are encrypted at rest and only revealed explicitly. */
187
- readonly link?: string;
188
- readonly filename?: string;
189
- /** Policy/v3 delivery material. The containing history record must remain encrypted at rest. */
190
- readonly deliveryMaterial?: PublishedShareDeliveryMaterial;
191
- /** Canonical mailboxes whose invitation delivery was confirmed; history is encrypted at rest. */
192
- readonly deliveredRecipients?: readonly string[];
193
- }
194
- /** Create the durable encrypted-history shape from canonical publication receipts. */
195
- declare function historyRecordForPublishedShare(result: PublishedShare, now?: Date): SenderShareRecord;
196
- /**
197
- * "direct" selects the Policy/v3 enforcement root; "ancestor" selects its
198
- * policy-authority sibling. Addressed shares revoke that signed root through
199
- * the Node Policy/v3 endpoint, which cuts off existing sessions as well as
200
- * fresh admission and delivery. Bearer shares retain ordinary delegation
201
- * revocation.
202
- */
203
- type SenderShareRevocationScope = "direct" | "ancestor";
204
- interface SenderShareRecordStorage {
205
- put(record: SenderShareRecord): Promise<void>;
206
- /** Atomically transform the latest record, if present. Implementations that
207
- * provide this must serialize the read and write with every other writer. */
208
- update?(shareId: string, change: (record: SenderShareRecord) => SenderShareRecord | Promise<SenderShareRecord>): Promise<SenderShareRecord | undefined>;
209
- list(): Promise<readonly SenderShareRecord[]>;
210
- get(shareId: string): Promise<SenderShareRecord | undefined>;
211
- delete(shareId: string): Promise<void>;
212
- }
213
- interface StoredSenderShareKey {
214
- readonly cryptoKey: CryptoKey;
215
- readonly publicKey: Uint8Array;
216
- readonly extractable: boolean;
217
- }
218
- interface SenderShareKeyStorage {
219
- put(shareId: string, key: StoredSenderShareKey): Promise<void>;
220
- get(shareId: string): Promise<StoredSenderShareKey | undefined>;
221
- delete(shareId: string): Promise<void>;
222
- }
223
- /** In-memory reference implementation. Real deployments back these with IndexedDB so the non-extractable `CryptoKey` survives a reload via structured clone. */
224
- declare class MemorySenderShareRecordStorage implements SenderShareRecordStorage {
225
- private readonly records;
226
- private operation;
227
- private serialize;
228
- put(record: SenderShareRecord): Promise<void>;
229
- update(shareId: string, change: (record: SenderShareRecord) => SenderShareRecord | Promise<SenderShareRecord>): Promise<SenderShareRecord | undefined>;
230
- list(): Promise<readonly SenderShareRecord[]>;
231
- get(shareId: string): Promise<SenderShareRecord | undefined>;
232
- delete(shareId: string): Promise<void>;
233
- }
234
- declare class MemorySenderShareKeyStorage implements SenderShareKeyStorage {
235
- private readonly keys;
236
- put(shareId: string, key: StoredSenderShareKey): Promise<void>;
237
- get(shareId: string): Promise<StoredSenderShareKey | undefined>;
238
- delete(shareId: string): Promise<void>;
239
- }
240
- interface SenderShareStoreOptions {
241
- readonly records: SenderShareRecordStorage;
242
- readonly keys: SenderShareKeyStorage;
243
- readonly now?: () => Date;
244
- }
245
- /**
246
- * Reload-safe sender-side management for shares created through
247
- * {@link canonicalOwnerSharePolicy} / `registerOwnerSharePolicy`. Persists
248
- * the registration receipt's canonical identity tuple plus the ephemeral
249
- * share key's non-extractable `CryptoKey` handle, so a sender can list,
250
- * inspect, and revoke shares it created in an earlier session -- without
251
- * ever re-exporting private key material.
252
- */
253
- declare class SenderShareStore {
254
- private readonly records;
255
- private readonly keys;
256
- private readonly now;
257
- constructor(options: SenderShareStoreOptions);
258
- /** Persist a Node-verified registration receipt and its share key handle. */
259
- save(receipt: OwnerSharePolicyRegistrationReceipt, key: DelegatedShareKey): Promise<SenderShareRecord>;
260
- /** List shares created in any session, most recent first. */
261
- list(options?: {
262
- readonly includeRevoked?: boolean;
263
- readonly includeExpired?: boolean;
264
- }): Promise<readonly SenderShareRecord[]>;
265
- get(shareId: string): Promise<SenderShareRecord | undefined>;
266
- /** Recover a signer for the persisted share key after a reload. */
267
- loadKey(shareId: string): Promise<DelegatedShareKey | undefined>;
268
- /**
269
- * The delegation CID to pass to the node's existing generic
270
- * `tinycloud.delegation/revoke` invocation to revoke this share at the
271
- * requested scope. Does not itself call the node -- callers invoke
272
- * their own `revokeDelegation`/`DelegationManager.revoke` with the
273
- * returned CID, then call {@link markRevoked} once that succeeds.
274
- */
275
- revocationTarget(shareId: string, scope: SenderShareRevocationScope): Promise<string>;
276
- /** Mark a share revoked locally after the caller's node-side revoke call succeeds. */
277
- markRevoked(shareId: string, revokedAt?: string): Promise<SenderShareRecord>;
278
- /** Forget a share and clear its persisted key handle. */
279
- remove(shareId: string): Promise<void>;
280
- }
281
- /** WebCrypto-backed persistence adapter; links and private material are absent. */
282
- declare class EncryptedSenderShareHistory {
283
- private readonly storage;
284
- private readonly key;
285
- private readonly now;
286
- constructor(storage: EncryptedShareHistoryStorage, key: CryptoKey, now?: () => Date);
287
- put(record: SenderShareRecord): Promise<void>;
288
- list(): Promise<readonly SenderShareRecord[]>;
289
- clear(): Promise<void>;
290
- }
291
-
292
150
  type ShareNotifyState = "delivered" | "already-delivered" | "partial-failure";
293
151
  interface ShareNotifyResult {
294
152
  readonly protocol: "tinycloud-share";
@@ -632,4 +490,85 @@ declare function parseNativeShareUrl(value: string): string;
632
490
  /** Receive through the public SDK without creating another transport protocol. */
633
491
  declare function openNativeShare(sharing: NativeSharingService, link: string): Promise<unknown>;
634
492
 
635
- export { CredentialInvitationError, type CredentialInvitationErrorCode, type CredentialInvitationReceipt, type CredentialInvitationResult, DEFAULT_MAX_CONTENT_BLOB_BYTES, DEFAULT_MAX_SEALED_BLOB_BYTES, DelegatedShareKey, EncryptedSenderShareHistory, type EncryptedShareHistoryStorage, MemoryEncryptedShareHistoryStorage, MemorySenderShareKeyStorage, MemorySenderShareRecordStorage, MemoryShareCache, NATIVE_SHARE_FRAGMENT_PARAMETER, type NativeShareResult, type NativeSharingService, OwnerShareAction, OwnerShareMatcher, OwnerSharePolicyRegistrationReceipt, type ParsedAddressedEnvelope, PublishedShare, PublishedShareDeliveryMaterial, SHARE_RESULT_VERSION, SHARE_V2_PROTOCOL, type SenderShareKeyStorage, type SenderShareRecord, type SenderShareRecordStorage, type SenderShareRevocationScope, SenderShareStore, ShareAuthorizationAdapter, ShareAuthorizationMethod, ShareAuthorizationResult, ShareAuthorizedContent, type ShareCache, type ShareCacheEntry, type ShareCacheKey, type ShareCacheMetadata, type ShareDeliveryAdapter, type ShareErrorCode, type ShareErrorInfo, type ShareFetchOptions, type ShareHistoryView, type ShareInspection, type ShareMetadata, type ShareNodeTrust, ShareNotifyError, type ShareNotifyInput, type ShareNotifyResult, type ShareNotifyState, type SharePolicyChallenge, type SharePolicyDelegationLink, type SharePolicyPublishAdapter, type SharePolicyRootRevocation, type SharePolicySession, type SharePresentationMaterial, type ShareReceiveAuthorizationRequired, ShareReceiveError, type ShareReceiveOutcome, type ShareReceiveResult, ShareRecipientClient, type ShareRecipientClientOptions, type ShareRevocationAdapter, type ShareRevocationResult, ShareTarget, TargetPublishInput, TargetPublishOutcome, canonicalShareFilename, claimShare, createAddressedAuthorization, createNativeShare, createShareV2HolderBindingArtifact, deliverCredentialInvitation, hasUnsafeFilenameCodePoint, historyRecordForPublishedShare, inspectShare, listShares, notifyShare, openNativeShare, parseAddressedEnvelope, parseNativeShareUrl, publishPolicyShare, receiveShare, recipientMatchesShareRecord, resumeShareAuthorization, revokeShare, shareDeliveryWindowExpiresAt, showShare, toShareErrorInfo };
493
+ /**
494
+ * Artifact pin verification (TC-1428). Small on purpose: this is the one place that decides whether an addressed
495
+ * share that reads an artifact version may be trusted.
496
+ *
497
+ * What is signed. The owner signs the whole Policy/v3 envelope (Ed25519, `verifyEnvelopeV3SignatureOnly`). `artifactPin` is a
498
+ * field of that envelope, so the signature covers it: artifact id, version, the sha256 of the version's
499
+ * `manifest.json`, and the sha256 and size of the one stored file the share reads. The manifest stays an owner-side
500
+ * record; a recipient never needs to fetch it. Policy/v3 already binds the file's ciphertext digest
501
+ * (`contentSource.initialCiphertextDigestHex`); the pin binds that digest to an artifact identity and a version, so a
502
+ * share cannot be re-pointed at another version or another artifact's path without breaking the signature.
503
+ *
504
+ * Trust model (accepted, TC-1428 finding 3): the owner is the trusted signer. The node has no write-once ACL, so the
505
+ * owner (or whoever holds the owner's session) can overwrite `versions/<n>/<file>` afterwards. A recipient then
506
+ * detects the substitution through the pin digest and fails closed; it cannot tell a malicious owner from a node
507
+ * serving stale or altered bytes, and does not try to.
508
+ *
509
+ * Fails closed: any addressed share whose content source lies under `artifacts/` must carry a valid pin that matches
510
+ * that source. A pin on any other path is refused. `artifacts/<id>/current/...` has no pin form in v1 and is refused.
511
+ */
512
+
513
+ type ArtifactPinErrorCode = "missing-pin" | "unsupported-artifact-path" | "wrong-signer" | "bad-signature" | "pin-source-mismatch" | "pinned-share-writable" | "expectation-mismatch" | "file-digest-mismatch" | "manifest-mismatch";
514
+ declare class ArtifactPinError extends Error {
515
+ readonly code: ArtifactPinErrorCode;
516
+ /** The code is the message: stable, short, and what callers and tests match on. */
517
+ constructor(code: ArtifactPinErrorCode);
518
+ }
519
+ /**
520
+ * What the caller already knows about the share it is opening, from outside the envelope. Optional: a v1 pinned share
521
+ * names its version in its own signed pin and nothing outside the link says which one to expect, so no production
522
+ * caller passes it. A caller that does learn a version out of band (a listing, a "newer version" link) uses it to
523
+ * refuse an older or different pin.
524
+ */
525
+ interface ExpectedArtifact {
526
+ readonly artifactId?: string;
527
+ readonly version?: number;
528
+ }
529
+ interface VerifyArtifactShareOptions {
530
+ /** The did:key the caller trusts as the sender. `signature.signerDid` is self-asserted and proves nothing alone. */
531
+ readonly expectedOwnerDid: string;
532
+ readonly expected?: ExpectedArtifact;
533
+ }
534
+ /**
535
+ * The fields of an envelope (or of a share about to be built) that the pin binds. Taking a view lets the publisher run
536
+ * the identical check before it registers anything, and the recipient run it again where it reads.
537
+ */
538
+ interface ArtifactBindingView {
539
+ readonly artifactPin?: ArtifactPin;
540
+ readonly target: {
541
+ readonly spaceId: string;
542
+ };
543
+ readonly contentSource: {
544
+ readonly kvResource: string;
545
+ readonly selector: "exact" | "prefix";
546
+ readonly mode: "mutable" | "immutable";
547
+ readonly initialCiphertextDigestHex?: string | undefined;
548
+ };
549
+ readonly resource: {
550
+ readonly kind: "exact" | "prefix";
551
+ readonly path: string;
552
+ };
553
+ /** Share actions (`read` | `list` | `edit`). */
554
+ readonly actions: readonly string[];
555
+ /** KV abilities the signed policy grants on the content source. */
556
+ readonly policyKvActions: readonly string[];
557
+ }
558
+ declare function artifactBindingView(envelope: UnsignedShareEnvelopeV3 | ShareEnvelopeV3): ArtifactBindingView;
559
+ /**
560
+ * The pin and the content source must say the same thing, and a pinned share must be read-only. Synchronous and
561
+ * signature-free, so the publisher can run it before registering anything and the recipient can re-run it at the
562
+ * point of reading. Returns the pin for an artifact share and `undefined` for any other share.
563
+ */
564
+ declare function assertArtifactBinding(view: ArtifactBindingView, expected?: ExpectedArtifact): ArtifactPin | undefined;
565
+ /**
566
+ * Check that the trusted owner signed this envelope (and so its pin), then the pin binding. Throws `ArtifactPinError`;
567
+ * never returns a partial answer. Only the owner's Ed25519 signature over the envelope is checked here, because that
568
+ * is what authenticates the pin. The rest of the envelope (policy signature, owner roots, enforcer binding) is
569
+ * `verifyEnvelopeV3`'s job, and `resolvePolicyShare` runs both before it trusts a link. (Folding the two into one
570
+ * call was measured: +911 gzip bytes in the canonical ESM bundle, for a saved ed25519 verify.)
571
+ */
572
+ declare function verifyArtifactShare(envelope: ShareEnvelopeV3, options: VerifyArtifactShareOptions): ArtifactPin | undefined;
573
+
574
+ export { type ArtifactBindingView, ArtifactPinError, type ArtifactPinErrorCode, CredentialInvitationError, type CredentialInvitationErrorCode, type CredentialInvitationReceipt, type CredentialInvitationResult, DEFAULT_MAX_CONTENT_BLOB_BYTES, DEFAULT_MAX_SEALED_BLOB_BYTES, type ExpectedArtifact, MemoryShareCache, NATIVE_SHARE_FRAGMENT_PARAMETER, type NativeShareResult, type NativeSharingService, type ParsedAddressedEnvelope, SHARE_RESULT_VERSION, SHARE_V2_PROTOCOL, SenderShareRecord, SenderShareRecordStorage, ShareAuthorizationAdapter, ShareAuthorizationMethod, ShareAuthorizationResult, ShareAuthorizedContent, type ShareCache, type ShareCacheEntry, type ShareCacheKey, type ShareCacheMetadata, type ShareDeliveryAdapter, type ShareErrorCode, type ShareErrorInfo, type ShareFetchOptions, type ShareHistoryView, type ShareInspection, type ShareMetadata, type ShareNodeTrust, ShareNotifyError, type ShareNotifyInput, type ShareNotifyResult, type ShareNotifyState, type SharePolicyChallenge, type SharePolicyDelegationLink, type SharePolicyPublishAdapter, type SharePolicyRootRevocation, type SharePolicySession, type SharePresentationMaterial, type ShareReceiveAuthorizationRequired, ShareReceiveError, type ShareReceiveOutcome, type ShareReceiveResult, ShareRecipientClient, type ShareRecipientClientOptions, type ShareRevocationAdapter, type ShareRevocationResult, ShareTarget, TargetPublishInput, TargetPublishOutcome, type VerifyArtifactShareOptions, artifactBindingView, assertArtifactBinding, canonicalShareFilename, claimShare, createAddressedAuthorization, createNativeShare, createShareV2HolderBindingArtifact, deliverCredentialInvitation, hasUnsafeFilenameCodePoint, inspectShare, listShares, notifyShare, openNativeShare, parseAddressedEnvelope, parseNativeShareUrl, publishPolicyShare, receiveShare, recipientMatchesShareRecord, resumeShareAuthorization, revokeShare, shareDeliveryWindowExpiresAt, showShare, toShareErrorInfo, verifyArtifactShare };