@poolse/crypto 3.9.0 → 3.10.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/CHANGELOG.md +17 -0
- package/README.md +84 -0
- package/dist/index.cjs +464 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +283 -1
- package/dist/index.d.ts +283 -1
- package/dist/index.js +442 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -803,4 +803,286 @@ declare function createHttpBlobTransport(options: HttpBlobTransportOptions): Blo
|
|
|
803
803
|
}): Promise<BlobChangesPage>;
|
|
804
804
|
};
|
|
805
805
|
|
|
806
|
-
|
|
806
|
+
/**
|
|
807
|
+
* Workspace notes (apps/workspace/NOTES.md) on top of the primitives: the
|
|
808
|
+
* associated data every note ciphertext binds, sealing and opening a note's
|
|
809
|
+
* `meta` and `content`, folder names, share wraps for recipients' devices,
|
|
810
|
+
* key rotation on revoke or expiry (NT5, NT15), walking `key_history` for
|
|
811
|
+
* versions (NT8), the recovery-key auth and the device signatures the server
|
|
812
|
+
* checks (NT10), and the plain document handed to an agent (NT12).
|
|
813
|
+
*
|
|
814
|
+
* Everything here returns base64url strings in the field names the
|
|
815
|
+
* Workspace API uses, so a result can go straight into a request body.
|
|
816
|
+
*/
|
|
817
|
+
|
|
818
|
+
/** `{itemId: note.id, version: revision, slot: "meta" | "content"}`. */
|
|
819
|
+
declare function noteAssociatedData(noteId: string, revision: number, slot: 'meta' | 'content'): {
|
|
820
|
+
readonly itemId: string;
|
|
821
|
+
readonly version: number;
|
|
822
|
+
readonly slot: "meta" | "content";
|
|
823
|
+
};
|
|
824
|
+
/** `{itemId: note.id, attachmentId}` for `encryptAttachment` / `decryptAttachment`. */
|
|
825
|
+
declare function noteAttachmentAssociatedData(noteId: string, attachmentId: string): {
|
|
826
|
+
readonly itemId: string;
|
|
827
|
+
readonly attachmentId: string;
|
|
828
|
+
};
|
|
829
|
+
/** `{itemId: folder.id, slot: "folder"}`. */
|
|
830
|
+
declare function folderAssociatedData(folderId: string): {
|
|
831
|
+
readonly itemId: string;
|
|
832
|
+
readonly slot: "folder";
|
|
833
|
+
};
|
|
834
|
+
/** What a note holds: title, body and metadata (tags, pinned, attachment names…). */
|
|
835
|
+
type NoteContent = ItemContent;
|
|
836
|
+
/** The encrypted fields of an e2e note write. */
|
|
837
|
+
interface SealedNote {
|
|
838
|
+
/** `{title, body: null, metadata}` — what lists show. */
|
|
839
|
+
meta: string;
|
|
840
|
+
/** The whole note. */
|
|
841
|
+
content: string;
|
|
842
|
+
key_version: number;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Encrypt a note for the revision this write creates (`base_revision + 1`).
|
|
846
|
+
* `meta` carries the title and metadata without the body, so lists can show
|
|
847
|
+
* a title and tags without fetching the content.
|
|
848
|
+
*/
|
|
849
|
+
declare function sealNote(key: ItemKey, note: NoteContent, options: {
|
|
850
|
+
noteId: string;
|
|
851
|
+
revision: number;
|
|
852
|
+
}): Promise<SealedNote>;
|
|
853
|
+
/** Decrypt a note's `meta` (listing form): title and metadata. */
|
|
854
|
+
declare function openNoteMeta(key: ItemKey, meta: string, options: {
|
|
855
|
+
noteId: string;
|
|
856
|
+
revision: number;
|
|
857
|
+
}): Promise<{
|
|
858
|
+
title: string;
|
|
859
|
+
metadata: {
|
|
860
|
+
[key: string]: JsonValue;
|
|
861
|
+
};
|
|
862
|
+
}>;
|
|
863
|
+
/**
|
|
864
|
+
* Decrypt a note's `content` — the note itself, or one of its versions
|
|
865
|
+
* (NT8: pass the version's own `revision`, and the key for its
|
|
866
|
+
* `key_version` from `noteKeyForVersion`).
|
|
867
|
+
*/
|
|
868
|
+
declare function openNoteContent(key: ItemKey, content: string, options: {
|
|
869
|
+
noteId: string;
|
|
870
|
+
revision: number;
|
|
871
|
+
}): Promise<NoteContent>;
|
|
872
|
+
/** The key version an envelope (`meta`, `content`, a version) was written with. */
|
|
873
|
+
declare function envelopeKeyVersion(envelope: string): number;
|
|
874
|
+
/**
|
|
875
|
+
* The key a version was written with (NT8): `current` when the versions
|
|
876
|
+
* match, else unwrap `key_history` back one step at a time
|
|
877
|
+
* (`key_history[v]` is key `v` wrapped under key `v + 1`).
|
|
878
|
+
*/
|
|
879
|
+
declare function noteKeyForVersion(current: ItemKey, keyHistory: Readonly<Record<string, string>>, version: number, options: {
|
|
880
|
+
noteId: string;
|
|
881
|
+
}): Promise<ItemKey>;
|
|
882
|
+
/** A new folder key, its name envelope and its key wrap under the account key. */
|
|
883
|
+
declare function sealFolder(name: string, accountKey: AccountKey, options: {
|
|
884
|
+
folderId: string;
|
|
885
|
+
key?: ItemKey;
|
|
886
|
+
}): Promise<{
|
|
887
|
+
key: ItemKey;
|
|
888
|
+
name_envelope: string;
|
|
889
|
+
key_wrap: string;
|
|
890
|
+
}>;
|
|
891
|
+
declare function openFolderName(key: ItemKey, nameEnvelope: string, options: {
|
|
892
|
+
folderId: string;
|
|
893
|
+
}): Promise<string>;
|
|
894
|
+
/** A recipient from `POST /notes/keys/lookup`: their approved devices. */
|
|
895
|
+
interface NoteRecipient {
|
|
896
|
+
memberId: string;
|
|
897
|
+
devices: readonly DevicePublicKeys[];
|
|
898
|
+
}
|
|
899
|
+
/** One entry of `wraps` / `share_wraps`. */
|
|
900
|
+
interface NoteShareWrap {
|
|
901
|
+
member_id: string;
|
|
902
|
+
device_id: string;
|
|
903
|
+
wrap: string;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* The note key wrapped to every device of every recipient, signed by this
|
|
907
|
+
* device — the `wraps` of `POST /notes/:id/shares` and `POST /notes/:id/wraps`.
|
|
908
|
+
* Viewers and editors (NT16) get the same wrap: an editor writes content
|
|
909
|
+
* with the same key, and the server enforces who may write.
|
|
910
|
+
*/
|
|
911
|
+
declare function shareWrapsFor(key: ItemKey, recipients: readonly NoteRecipient[], options: {
|
|
912
|
+
noteId: string;
|
|
913
|
+
signer: DeviceKeys;
|
|
914
|
+
}): Promise<NoteShareWrap[]>;
|
|
915
|
+
/** The fields of a `PUT /notes/:id` that rotates the key. */
|
|
916
|
+
interface RotatedNote extends SealedNote {
|
|
917
|
+
key: ItemKey;
|
|
918
|
+
key_wrap: string;
|
|
919
|
+
key_history: Record<string, string>;
|
|
920
|
+
share_wraps: NoteShareWrap[];
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Rotate a note's key after a revoke or an expired share (`notes:rotate`):
|
|
924
|
+
* a new key one version up, the note re-encrypted for `revision`, the new
|
|
925
|
+
* key wrapped for the owner, the old key kept readable under the new one
|
|
926
|
+
* (`key_history`), and wraps for the people who keep access. Send it with
|
|
927
|
+
* the note's current `base_revision`; nothing written after this is
|
|
928
|
+
* readable with the old key.
|
|
929
|
+
*/
|
|
930
|
+
declare function rotateNoteKey(previous: ItemKey, note: NoteContent, options: {
|
|
931
|
+
noteId: string;
|
|
932
|
+
revision: number;
|
|
933
|
+
accountKey: AccountKey;
|
|
934
|
+
signer: DeviceKeys;
|
|
935
|
+
/** Everyone still shared with, with their devices. */
|
|
936
|
+
remaining: readonly NoteRecipient[];
|
|
937
|
+
}): Promise<RotatedNote>;
|
|
938
|
+
/** Whether a share has ended by `now` (NT15): the owner then rotates like on a revoke. */
|
|
939
|
+
declare function shareExpired(expiresAt: string | null | undefined, now?: number): boolean;
|
|
940
|
+
/**
|
|
941
|
+
* 32 bytes the server keeps the SHA-256 of, proving a device holds the
|
|
942
|
+
* recovery key without revealing it: HKDF-SHA-256 of the key's secret
|
|
943
|
+
* (empty salt, info `poolse-crypto/v1/recovery-auth`). Send as
|
|
944
|
+
* `recovery.auth` / `recovery_auth` (base64url).
|
|
945
|
+
*/
|
|
946
|
+
declare function recoveryAuth(recoveryKey: RecoveryKey): Promise<Uint8Array>;
|
|
947
|
+
/** Raw ECDSA P-256 / SHA-256 signature (`r‖s`, 64 bytes) by this device's signing key. */
|
|
948
|
+
declare function signForServer(device: DeviceKeys, message: Uint8Array): Promise<Uint8Array>;
|
|
949
|
+
/**
|
|
950
|
+
* `"poolse-notes/v1/approve" ‖ 0 ‖ member_id ‖ 0 ‖ new device_id ‖ 0 ‖ SHA-256(grant)` —
|
|
951
|
+
* what the approving device signs for `POST …/devices/:id/grant`.
|
|
952
|
+
*/
|
|
953
|
+
declare function deviceApprovalMessage(memberId: string, newDeviceId: string, grant: Uint8Array): Promise<Bytes>;
|
|
954
|
+
/**
|
|
955
|
+
* `"poolse-notes/v1/recovery" ‖ 0 ‖ member_id ‖ 0 ‖ key_id ‖ 0 ‖ SHA-256(wrap) ‖ SHA-256(auth)` —
|
|
956
|
+
* what an approved device signs for `PUT /notes/keys/me/recovery`.
|
|
957
|
+
*/
|
|
958
|
+
declare function recoveryReplaceMessage(memberId: string, keyId: string, wrap: Uint8Array, auth: Uint8Array): Promise<Bytes>;
|
|
959
|
+
/** The body of `POST …/devices/:id/grant`, signed by `approver`. */
|
|
960
|
+
declare function signedDeviceGrant(grant: Uint8Array, options: {
|
|
961
|
+
memberId: string;
|
|
962
|
+
newDeviceId: string;
|
|
963
|
+
approver: DeviceKeys;
|
|
964
|
+
}): Promise<{
|
|
965
|
+
grant: string;
|
|
966
|
+
approver_device_id: string;
|
|
967
|
+
signature: string;
|
|
968
|
+
}>;
|
|
969
|
+
/**
|
|
970
|
+
* A decrypted note as a plain Markdown document for one agent task. Only
|
|
971
|
+
* this note leaves the device, decrypted; call it only after the member
|
|
972
|
+
* explicitly chose to hand it over. A body that isn't a string (an editor
|
|
973
|
+
* document tree) needs `toMarkdown`.
|
|
974
|
+
*/
|
|
975
|
+
declare function noteAsDocument(note: NoteContent, toMarkdown?: (body: JsonValue) => string): {
|
|
976
|
+
title: string;
|
|
977
|
+
markdown: string;
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
/** Lowercased, accent-free words of `text` (letters and digits). */
|
|
981
|
+
declare function searchWords(text: string): string[];
|
|
982
|
+
/** What one note contributes to the index. */
|
|
983
|
+
interface SearchDocument {
|
|
984
|
+
title: string;
|
|
985
|
+
/** Plain text of the body (and anything else searchable: tags, attachment names). */
|
|
986
|
+
text: string;
|
|
987
|
+
/** For ordering ties: ISO time or ms. */
|
|
988
|
+
updatedAt?: string | number;
|
|
989
|
+
}
|
|
990
|
+
interface SearchHit {
|
|
991
|
+
id: string;
|
|
992
|
+
score: number;
|
|
993
|
+
}
|
|
994
|
+
declare class NoteSearchIndex {
|
|
995
|
+
#private;
|
|
996
|
+
/** Notes in the index. */
|
|
997
|
+
get size(): number;
|
|
998
|
+
/** Add or replace a note. */
|
|
999
|
+
put(id: string, doc: SearchDocument): void;
|
|
1000
|
+
remove(id: string): void;
|
|
1001
|
+
has(id: string): boolean;
|
|
1002
|
+
clear(): void;
|
|
1003
|
+
/** Note ids matching every word of `query`, best first. Empty query → nothing. */
|
|
1004
|
+
search(query: string, limit?: number): SearchHit[];
|
|
1005
|
+
/** The index encrypted for this device's storage. `name` keeps several indexes apart. */
|
|
1006
|
+
seal(accountKey: AccountKey, name?: string): Promise<Uint8Array>;
|
|
1007
|
+
static open(sealed: Uint8Array, accountKey: AccountKey, name?: string): Promise<NoteSearchIndex>;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
/** One waiting write. `data` is whatever the app needs to seal it (plaintext). */
|
|
1011
|
+
interface OutboxEntry<T> {
|
|
1012
|
+
noteId: string;
|
|
1013
|
+
op: 'put' | 'delete';
|
|
1014
|
+
/** The revision the edit was made on (0 for a note made offline). */
|
|
1015
|
+
baseRevision: number;
|
|
1016
|
+
data: T | null;
|
|
1017
|
+
/** When it was queued (ms). */
|
|
1018
|
+
queuedAt: number;
|
|
1019
|
+
/** Failed attempts so far. */
|
|
1020
|
+
attempts: number;
|
|
1021
|
+
}
|
|
1022
|
+
/** Where the sealed queue lives: a file, IndexedDB, AsyncStorage… */
|
|
1023
|
+
interface OutboxStorage {
|
|
1024
|
+
read(): Promise<Uint8Array | null>;
|
|
1025
|
+
write(data: Uint8Array): Promise<void>;
|
|
1026
|
+
}
|
|
1027
|
+
/** What `send` reports for one write. */
|
|
1028
|
+
type OutboxSendResult<T> = {
|
|
1029
|
+
status: 'ok';
|
|
1030
|
+
revision: number;
|
|
1031
|
+
}
|
|
1032
|
+
/** `409 revision_conflict`: the server's current note, decrypted by the app. */
|
|
1033
|
+
| {
|
|
1034
|
+
status: 'conflict';
|
|
1035
|
+
revision: number;
|
|
1036
|
+
current: T | null;
|
|
1037
|
+
}
|
|
1038
|
+
/** Gone for good (deleted, access lost): drop the entry. */
|
|
1039
|
+
| {
|
|
1040
|
+
status: 'gone';
|
|
1041
|
+
};
|
|
1042
|
+
interface FlushOptions<T> {
|
|
1043
|
+
/** Seal and send one write (`PUT /notes/:id` with `base_revision`, or `DELETE`). Throw to stop and retry later. */
|
|
1044
|
+
send: (entry: OutboxEntry<T>) => Promise<OutboxSendResult<T>>;
|
|
1045
|
+
/**
|
|
1046
|
+
* Merge a conflicting edit with the server's version (`current`). Return
|
|
1047
|
+
* the data to write on top of `revision`, or `null` to drop the local
|
|
1048
|
+
* edit. Default: keep the local edit (last writer wins).
|
|
1049
|
+
*/
|
|
1050
|
+
resolve?: (local: T | null, current: T | null, entry: OutboxEntry<T>) => T | null | Promise<T | null>;
|
|
1051
|
+
/** Called after each accepted write with the note's new revision. */
|
|
1052
|
+
onWritten?: (noteId: string, revision: number) => void;
|
|
1053
|
+
/** Conflicts retried per entry before it's dropped. Default 3. */
|
|
1054
|
+
maxConflicts?: number;
|
|
1055
|
+
}
|
|
1056
|
+
interface FlushResult {
|
|
1057
|
+
written: string[];
|
|
1058
|
+
dropped: string[];
|
|
1059
|
+
/** Entries still waiting (the send threw). */
|
|
1060
|
+
pending: number;
|
|
1061
|
+
error?: unknown;
|
|
1062
|
+
}
|
|
1063
|
+
declare class NoteOutbox<T> {
|
|
1064
|
+
#private;
|
|
1065
|
+
private constructor();
|
|
1066
|
+
static load<T>(options: {
|
|
1067
|
+
storage: OutboxStorage;
|
|
1068
|
+
accountKey: AccountKey;
|
|
1069
|
+
}): Promise<NoteOutbox<T>>;
|
|
1070
|
+
/** Waiting writes, oldest first. */
|
|
1071
|
+
get entries(): readonly OutboxEntry<T>[];
|
|
1072
|
+
/** Whether a note has unsent edits (show "Not synced yet"). */
|
|
1073
|
+
isPending(noteId: string): boolean;
|
|
1074
|
+
/** Queue an edit (or a new note, `baseRevision` 0). Replaces an earlier queued edit of the note. */
|
|
1075
|
+
put(noteId: string, baseRevision: number, data: T): Promise<void>;
|
|
1076
|
+
/** Queue a delete. A note made offline and never sent is just forgotten. */
|
|
1077
|
+
delete(noteId: string, baseRevision: number): Promise<void>;
|
|
1078
|
+
/** Send everything, in order. Concurrent calls share one run. */
|
|
1079
|
+
flush(options: FlushOptions<T>): Promise<FlushResult>;
|
|
1080
|
+
}
|
|
1081
|
+
/** An in-memory `OutboxStorage` for tests. */
|
|
1082
|
+
declare class MemoryOutboxStorage implements OutboxStorage {
|
|
1083
|
+
data: Uint8Array | null;
|
|
1084
|
+
read(): Promise<Uint8Array | null>;
|
|
1085
|
+
write(data: Uint8Array): Promise<void>;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
export { ATTACHMENT_HEADER_LENGTH, type AcceptedDeviceGrant, type AccountContext, AccountKey, Alg, type AlgorithmId, type AssociatedData, type AttachmentAssociatedData, type BlobChange, type BlobChangesPage, BlobConflictError, type BlobInfo, type BlobLimits, type BlobListOptions, type BlobListPage, type BlobPrecondition, type BlobTransport, BlobTransportError, type BlobTransportErrorCode, type ByteSource, DEFAULT_CHUNK_SIZE, DEFAULT_REQUEST_MAX_AGE_MS, DeviceKeys, type DevicePublicKeys, type DeviceRequest, type EncryptAttachmentOptions, EncryptedBlobStore, type EncryptedBlobStoreOptions, type EnvelopeInfo, type EnvelopeKind, type ExportDeviceKeysOptions, FORMAT_VERSION, type FlushOptions, type FlushResult, type HttpBlobTransportOptions, type ImportDeviceKeysOptions, type ItemAssociatedData, type ItemContent, type ItemContext, ItemKey, type JsonValue, Kind, MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, MemoryBlobTransport, MemoryOutboxStorage, type NoteContent, NoteOutbox, type NoteRecipient, NoteSearchIndex, type NoteShareWrap, type OutboxEntry, type OutboxSendResult, type OutboxStorage, type PendingDeviceRequest, PoolseCryptoError, type PoolseCryptoErrorCode, type PutOptions, RecoveryKey, type RevisionStore, type RotatedNote, type SealedNote, type SearchDocument, type SearchHit, type SyncedBlob, type UnwrapResult, WrapPurpose, type WrapPurposeId, acceptDeviceGrant, approveDeviceRequest, checkCryptoSupport, constantTimeEqual, createDeviceRequest, createHttpBlobTransport, decodeDevicePublicKeys, decryptAttachment, decryptAttachmentBytes, decryptBytes, decryptItem, deviceApprovalMessage, deviceFingerprint, devicePublicKeys, encodeAssociatedData, encodeDevicePublicKeys, encryptAttachment, encryptAttachmentBytes, encryptBytes, encryptItem, encryptedAttachmentSize, envelopeKeyVersion, folderAssociatedData, fromBase32, fromBase64Url, fromHex, generateRecoveryKey, inspectEnvelope, isValidBlobKey, noteAsDocument, noteAssociatedData, noteAttachmentAssociatedData, noteKeyForVersion, openFolderName, openNoteContent, openNoteMeta, openSharedItemKey, padmeLength, parseRecoveryKey, readDeviceRequest, recoveryAuth, recoveryReplaceMessage, rotateItemKey, rotateNoteKey, sameDevice, sealFolder, sealNote, searchWords, shareExpired, shareItemKey, shareItemKeyWithDevices, shareWrapsFor, signForServer, signedDeviceGrant, toBase32, toBase64Url, toHex, unwrapAccountKeyForDevice, unwrapAccountKeyWithRecoveryKey, unwrapItemKey, unwrapPreviousItemKey, wrapAccountKeyForDevice, wrapAccountKeyWithRecoveryKey, wrapItemKey, wrapPreviousItemKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -803,4 +803,286 @@ declare function createHttpBlobTransport(options: HttpBlobTransportOptions): Blo
|
|
|
803
803
|
}): Promise<BlobChangesPage>;
|
|
804
804
|
};
|
|
805
805
|
|
|
806
|
-
|
|
806
|
+
/**
|
|
807
|
+
* Workspace notes (apps/workspace/NOTES.md) on top of the primitives: the
|
|
808
|
+
* associated data every note ciphertext binds, sealing and opening a note's
|
|
809
|
+
* `meta` and `content`, folder names, share wraps for recipients' devices,
|
|
810
|
+
* key rotation on revoke or expiry (NT5, NT15), walking `key_history` for
|
|
811
|
+
* versions (NT8), the recovery-key auth and the device signatures the server
|
|
812
|
+
* checks (NT10), and the plain document handed to an agent (NT12).
|
|
813
|
+
*
|
|
814
|
+
* Everything here returns base64url strings in the field names the
|
|
815
|
+
* Workspace API uses, so a result can go straight into a request body.
|
|
816
|
+
*/
|
|
817
|
+
|
|
818
|
+
/** `{itemId: note.id, version: revision, slot: "meta" | "content"}`. */
|
|
819
|
+
declare function noteAssociatedData(noteId: string, revision: number, slot: 'meta' | 'content'): {
|
|
820
|
+
readonly itemId: string;
|
|
821
|
+
readonly version: number;
|
|
822
|
+
readonly slot: "meta" | "content";
|
|
823
|
+
};
|
|
824
|
+
/** `{itemId: note.id, attachmentId}` for `encryptAttachment` / `decryptAttachment`. */
|
|
825
|
+
declare function noteAttachmentAssociatedData(noteId: string, attachmentId: string): {
|
|
826
|
+
readonly itemId: string;
|
|
827
|
+
readonly attachmentId: string;
|
|
828
|
+
};
|
|
829
|
+
/** `{itemId: folder.id, slot: "folder"}`. */
|
|
830
|
+
declare function folderAssociatedData(folderId: string): {
|
|
831
|
+
readonly itemId: string;
|
|
832
|
+
readonly slot: "folder";
|
|
833
|
+
};
|
|
834
|
+
/** What a note holds: title, body and metadata (tags, pinned, attachment names…). */
|
|
835
|
+
type NoteContent = ItemContent;
|
|
836
|
+
/** The encrypted fields of an e2e note write. */
|
|
837
|
+
interface SealedNote {
|
|
838
|
+
/** `{title, body: null, metadata}` — what lists show. */
|
|
839
|
+
meta: string;
|
|
840
|
+
/** The whole note. */
|
|
841
|
+
content: string;
|
|
842
|
+
key_version: number;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Encrypt a note for the revision this write creates (`base_revision + 1`).
|
|
846
|
+
* `meta` carries the title and metadata without the body, so lists can show
|
|
847
|
+
* a title and tags without fetching the content.
|
|
848
|
+
*/
|
|
849
|
+
declare function sealNote(key: ItemKey, note: NoteContent, options: {
|
|
850
|
+
noteId: string;
|
|
851
|
+
revision: number;
|
|
852
|
+
}): Promise<SealedNote>;
|
|
853
|
+
/** Decrypt a note's `meta` (listing form): title and metadata. */
|
|
854
|
+
declare function openNoteMeta(key: ItemKey, meta: string, options: {
|
|
855
|
+
noteId: string;
|
|
856
|
+
revision: number;
|
|
857
|
+
}): Promise<{
|
|
858
|
+
title: string;
|
|
859
|
+
metadata: {
|
|
860
|
+
[key: string]: JsonValue;
|
|
861
|
+
};
|
|
862
|
+
}>;
|
|
863
|
+
/**
|
|
864
|
+
* Decrypt a note's `content` — the note itself, or one of its versions
|
|
865
|
+
* (NT8: pass the version's own `revision`, and the key for its
|
|
866
|
+
* `key_version` from `noteKeyForVersion`).
|
|
867
|
+
*/
|
|
868
|
+
declare function openNoteContent(key: ItemKey, content: string, options: {
|
|
869
|
+
noteId: string;
|
|
870
|
+
revision: number;
|
|
871
|
+
}): Promise<NoteContent>;
|
|
872
|
+
/** The key version an envelope (`meta`, `content`, a version) was written with. */
|
|
873
|
+
declare function envelopeKeyVersion(envelope: string): number;
|
|
874
|
+
/**
|
|
875
|
+
* The key a version was written with (NT8): `current` when the versions
|
|
876
|
+
* match, else unwrap `key_history` back one step at a time
|
|
877
|
+
* (`key_history[v]` is key `v` wrapped under key `v + 1`).
|
|
878
|
+
*/
|
|
879
|
+
declare function noteKeyForVersion(current: ItemKey, keyHistory: Readonly<Record<string, string>>, version: number, options: {
|
|
880
|
+
noteId: string;
|
|
881
|
+
}): Promise<ItemKey>;
|
|
882
|
+
/** A new folder key, its name envelope and its key wrap under the account key. */
|
|
883
|
+
declare function sealFolder(name: string, accountKey: AccountKey, options: {
|
|
884
|
+
folderId: string;
|
|
885
|
+
key?: ItemKey;
|
|
886
|
+
}): Promise<{
|
|
887
|
+
key: ItemKey;
|
|
888
|
+
name_envelope: string;
|
|
889
|
+
key_wrap: string;
|
|
890
|
+
}>;
|
|
891
|
+
declare function openFolderName(key: ItemKey, nameEnvelope: string, options: {
|
|
892
|
+
folderId: string;
|
|
893
|
+
}): Promise<string>;
|
|
894
|
+
/** A recipient from `POST /notes/keys/lookup`: their approved devices. */
|
|
895
|
+
interface NoteRecipient {
|
|
896
|
+
memberId: string;
|
|
897
|
+
devices: readonly DevicePublicKeys[];
|
|
898
|
+
}
|
|
899
|
+
/** One entry of `wraps` / `share_wraps`. */
|
|
900
|
+
interface NoteShareWrap {
|
|
901
|
+
member_id: string;
|
|
902
|
+
device_id: string;
|
|
903
|
+
wrap: string;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* The note key wrapped to every device of every recipient, signed by this
|
|
907
|
+
* device — the `wraps` of `POST /notes/:id/shares` and `POST /notes/:id/wraps`.
|
|
908
|
+
* Viewers and editors (NT16) get the same wrap: an editor writes content
|
|
909
|
+
* with the same key, and the server enforces who may write.
|
|
910
|
+
*/
|
|
911
|
+
declare function shareWrapsFor(key: ItemKey, recipients: readonly NoteRecipient[], options: {
|
|
912
|
+
noteId: string;
|
|
913
|
+
signer: DeviceKeys;
|
|
914
|
+
}): Promise<NoteShareWrap[]>;
|
|
915
|
+
/** The fields of a `PUT /notes/:id` that rotates the key. */
|
|
916
|
+
interface RotatedNote extends SealedNote {
|
|
917
|
+
key: ItemKey;
|
|
918
|
+
key_wrap: string;
|
|
919
|
+
key_history: Record<string, string>;
|
|
920
|
+
share_wraps: NoteShareWrap[];
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Rotate a note's key after a revoke or an expired share (`notes:rotate`):
|
|
924
|
+
* a new key one version up, the note re-encrypted for `revision`, the new
|
|
925
|
+
* key wrapped for the owner, the old key kept readable under the new one
|
|
926
|
+
* (`key_history`), and wraps for the people who keep access. Send it with
|
|
927
|
+
* the note's current `base_revision`; nothing written after this is
|
|
928
|
+
* readable with the old key.
|
|
929
|
+
*/
|
|
930
|
+
declare function rotateNoteKey(previous: ItemKey, note: NoteContent, options: {
|
|
931
|
+
noteId: string;
|
|
932
|
+
revision: number;
|
|
933
|
+
accountKey: AccountKey;
|
|
934
|
+
signer: DeviceKeys;
|
|
935
|
+
/** Everyone still shared with, with their devices. */
|
|
936
|
+
remaining: readonly NoteRecipient[];
|
|
937
|
+
}): Promise<RotatedNote>;
|
|
938
|
+
/** Whether a share has ended by `now` (NT15): the owner then rotates like on a revoke. */
|
|
939
|
+
declare function shareExpired(expiresAt: string | null | undefined, now?: number): boolean;
|
|
940
|
+
/**
|
|
941
|
+
* 32 bytes the server keeps the SHA-256 of, proving a device holds the
|
|
942
|
+
* recovery key without revealing it: HKDF-SHA-256 of the key's secret
|
|
943
|
+
* (empty salt, info `poolse-crypto/v1/recovery-auth`). Send as
|
|
944
|
+
* `recovery.auth` / `recovery_auth` (base64url).
|
|
945
|
+
*/
|
|
946
|
+
declare function recoveryAuth(recoveryKey: RecoveryKey): Promise<Uint8Array>;
|
|
947
|
+
/** Raw ECDSA P-256 / SHA-256 signature (`r‖s`, 64 bytes) by this device's signing key. */
|
|
948
|
+
declare function signForServer(device: DeviceKeys, message: Uint8Array): Promise<Uint8Array>;
|
|
949
|
+
/**
|
|
950
|
+
* `"poolse-notes/v1/approve" ‖ 0 ‖ member_id ‖ 0 ‖ new device_id ‖ 0 ‖ SHA-256(grant)` —
|
|
951
|
+
* what the approving device signs for `POST …/devices/:id/grant`.
|
|
952
|
+
*/
|
|
953
|
+
declare function deviceApprovalMessage(memberId: string, newDeviceId: string, grant: Uint8Array): Promise<Bytes>;
|
|
954
|
+
/**
|
|
955
|
+
* `"poolse-notes/v1/recovery" ‖ 0 ‖ member_id ‖ 0 ‖ key_id ‖ 0 ‖ SHA-256(wrap) ‖ SHA-256(auth)` —
|
|
956
|
+
* what an approved device signs for `PUT /notes/keys/me/recovery`.
|
|
957
|
+
*/
|
|
958
|
+
declare function recoveryReplaceMessage(memberId: string, keyId: string, wrap: Uint8Array, auth: Uint8Array): Promise<Bytes>;
|
|
959
|
+
/** The body of `POST …/devices/:id/grant`, signed by `approver`. */
|
|
960
|
+
declare function signedDeviceGrant(grant: Uint8Array, options: {
|
|
961
|
+
memberId: string;
|
|
962
|
+
newDeviceId: string;
|
|
963
|
+
approver: DeviceKeys;
|
|
964
|
+
}): Promise<{
|
|
965
|
+
grant: string;
|
|
966
|
+
approver_device_id: string;
|
|
967
|
+
signature: string;
|
|
968
|
+
}>;
|
|
969
|
+
/**
|
|
970
|
+
* A decrypted note as a plain Markdown document for one agent task. Only
|
|
971
|
+
* this note leaves the device, decrypted; call it only after the member
|
|
972
|
+
* explicitly chose to hand it over. A body that isn't a string (an editor
|
|
973
|
+
* document tree) needs `toMarkdown`.
|
|
974
|
+
*/
|
|
975
|
+
declare function noteAsDocument(note: NoteContent, toMarkdown?: (body: JsonValue) => string): {
|
|
976
|
+
title: string;
|
|
977
|
+
markdown: string;
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
/** Lowercased, accent-free words of `text` (letters and digits). */
|
|
981
|
+
declare function searchWords(text: string): string[];
|
|
982
|
+
/** What one note contributes to the index. */
|
|
983
|
+
interface SearchDocument {
|
|
984
|
+
title: string;
|
|
985
|
+
/** Plain text of the body (and anything else searchable: tags, attachment names). */
|
|
986
|
+
text: string;
|
|
987
|
+
/** For ordering ties: ISO time or ms. */
|
|
988
|
+
updatedAt?: string | number;
|
|
989
|
+
}
|
|
990
|
+
interface SearchHit {
|
|
991
|
+
id: string;
|
|
992
|
+
score: number;
|
|
993
|
+
}
|
|
994
|
+
declare class NoteSearchIndex {
|
|
995
|
+
#private;
|
|
996
|
+
/** Notes in the index. */
|
|
997
|
+
get size(): number;
|
|
998
|
+
/** Add or replace a note. */
|
|
999
|
+
put(id: string, doc: SearchDocument): void;
|
|
1000
|
+
remove(id: string): void;
|
|
1001
|
+
has(id: string): boolean;
|
|
1002
|
+
clear(): void;
|
|
1003
|
+
/** Note ids matching every word of `query`, best first. Empty query → nothing. */
|
|
1004
|
+
search(query: string, limit?: number): SearchHit[];
|
|
1005
|
+
/** The index encrypted for this device's storage. `name` keeps several indexes apart. */
|
|
1006
|
+
seal(accountKey: AccountKey, name?: string): Promise<Uint8Array>;
|
|
1007
|
+
static open(sealed: Uint8Array, accountKey: AccountKey, name?: string): Promise<NoteSearchIndex>;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
/** One waiting write. `data` is whatever the app needs to seal it (plaintext). */
|
|
1011
|
+
interface OutboxEntry<T> {
|
|
1012
|
+
noteId: string;
|
|
1013
|
+
op: 'put' | 'delete';
|
|
1014
|
+
/** The revision the edit was made on (0 for a note made offline). */
|
|
1015
|
+
baseRevision: number;
|
|
1016
|
+
data: T | null;
|
|
1017
|
+
/** When it was queued (ms). */
|
|
1018
|
+
queuedAt: number;
|
|
1019
|
+
/** Failed attempts so far. */
|
|
1020
|
+
attempts: number;
|
|
1021
|
+
}
|
|
1022
|
+
/** Where the sealed queue lives: a file, IndexedDB, AsyncStorage… */
|
|
1023
|
+
interface OutboxStorage {
|
|
1024
|
+
read(): Promise<Uint8Array | null>;
|
|
1025
|
+
write(data: Uint8Array): Promise<void>;
|
|
1026
|
+
}
|
|
1027
|
+
/** What `send` reports for one write. */
|
|
1028
|
+
type OutboxSendResult<T> = {
|
|
1029
|
+
status: 'ok';
|
|
1030
|
+
revision: number;
|
|
1031
|
+
}
|
|
1032
|
+
/** `409 revision_conflict`: the server's current note, decrypted by the app. */
|
|
1033
|
+
| {
|
|
1034
|
+
status: 'conflict';
|
|
1035
|
+
revision: number;
|
|
1036
|
+
current: T | null;
|
|
1037
|
+
}
|
|
1038
|
+
/** Gone for good (deleted, access lost): drop the entry. */
|
|
1039
|
+
| {
|
|
1040
|
+
status: 'gone';
|
|
1041
|
+
};
|
|
1042
|
+
interface FlushOptions<T> {
|
|
1043
|
+
/** Seal and send one write (`PUT /notes/:id` with `base_revision`, or `DELETE`). Throw to stop and retry later. */
|
|
1044
|
+
send: (entry: OutboxEntry<T>) => Promise<OutboxSendResult<T>>;
|
|
1045
|
+
/**
|
|
1046
|
+
* Merge a conflicting edit with the server's version (`current`). Return
|
|
1047
|
+
* the data to write on top of `revision`, or `null` to drop the local
|
|
1048
|
+
* edit. Default: keep the local edit (last writer wins).
|
|
1049
|
+
*/
|
|
1050
|
+
resolve?: (local: T | null, current: T | null, entry: OutboxEntry<T>) => T | null | Promise<T | null>;
|
|
1051
|
+
/** Called after each accepted write with the note's new revision. */
|
|
1052
|
+
onWritten?: (noteId: string, revision: number) => void;
|
|
1053
|
+
/** Conflicts retried per entry before it's dropped. Default 3. */
|
|
1054
|
+
maxConflicts?: number;
|
|
1055
|
+
}
|
|
1056
|
+
interface FlushResult {
|
|
1057
|
+
written: string[];
|
|
1058
|
+
dropped: string[];
|
|
1059
|
+
/** Entries still waiting (the send threw). */
|
|
1060
|
+
pending: number;
|
|
1061
|
+
error?: unknown;
|
|
1062
|
+
}
|
|
1063
|
+
declare class NoteOutbox<T> {
|
|
1064
|
+
#private;
|
|
1065
|
+
private constructor();
|
|
1066
|
+
static load<T>(options: {
|
|
1067
|
+
storage: OutboxStorage;
|
|
1068
|
+
accountKey: AccountKey;
|
|
1069
|
+
}): Promise<NoteOutbox<T>>;
|
|
1070
|
+
/** Waiting writes, oldest first. */
|
|
1071
|
+
get entries(): readonly OutboxEntry<T>[];
|
|
1072
|
+
/** Whether a note has unsent edits (show "Not synced yet"). */
|
|
1073
|
+
isPending(noteId: string): boolean;
|
|
1074
|
+
/** Queue an edit (or a new note, `baseRevision` 0). Replaces an earlier queued edit of the note. */
|
|
1075
|
+
put(noteId: string, baseRevision: number, data: T): Promise<void>;
|
|
1076
|
+
/** Queue a delete. A note made offline and never sent is just forgotten. */
|
|
1077
|
+
delete(noteId: string, baseRevision: number): Promise<void>;
|
|
1078
|
+
/** Send everything, in order. Concurrent calls share one run. */
|
|
1079
|
+
flush(options: FlushOptions<T>): Promise<FlushResult>;
|
|
1080
|
+
}
|
|
1081
|
+
/** An in-memory `OutboxStorage` for tests. */
|
|
1082
|
+
declare class MemoryOutboxStorage implements OutboxStorage {
|
|
1083
|
+
data: Uint8Array | null;
|
|
1084
|
+
read(): Promise<Uint8Array | null>;
|
|
1085
|
+
write(data: Uint8Array): Promise<void>;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
export { ATTACHMENT_HEADER_LENGTH, type AcceptedDeviceGrant, type AccountContext, AccountKey, Alg, type AlgorithmId, type AssociatedData, type AttachmentAssociatedData, type BlobChange, type BlobChangesPage, BlobConflictError, type BlobInfo, type BlobLimits, type BlobListOptions, type BlobListPage, type BlobPrecondition, type BlobTransport, BlobTransportError, type BlobTransportErrorCode, type ByteSource, DEFAULT_CHUNK_SIZE, DEFAULT_REQUEST_MAX_AGE_MS, DeviceKeys, type DevicePublicKeys, type DeviceRequest, type EncryptAttachmentOptions, EncryptedBlobStore, type EncryptedBlobStoreOptions, type EnvelopeInfo, type EnvelopeKind, type ExportDeviceKeysOptions, FORMAT_VERSION, type FlushOptions, type FlushResult, type HttpBlobTransportOptions, type ImportDeviceKeysOptions, type ItemAssociatedData, type ItemContent, type ItemContext, ItemKey, type JsonValue, Kind, MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, MemoryBlobTransport, MemoryOutboxStorage, type NoteContent, NoteOutbox, type NoteRecipient, NoteSearchIndex, type NoteShareWrap, type OutboxEntry, type OutboxSendResult, type OutboxStorage, type PendingDeviceRequest, PoolseCryptoError, type PoolseCryptoErrorCode, type PutOptions, RecoveryKey, type RevisionStore, type RotatedNote, type SealedNote, type SearchDocument, type SearchHit, type SyncedBlob, type UnwrapResult, WrapPurpose, type WrapPurposeId, acceptDeviceGrant, approveDeviceRequest, checkCryptoSupport, constantTimeEqual, createDeviceRequest, createHttpBlobTransport, decodeDevicePublicKeys, decryptAttachment, decryptAttachmentBytes, decryptBytes, decryptItem, deviceApprovalMessage, deviceFingerprint, devicePublicKeys, encodeAssociatedData, encodeDevicePublicKeys, encryptAttachment, encryptAttachmentBytes, encryptBytes, encryptItem, encryptedAttachmentSize, envelopeKeyVersion, folderAssociatedData, fromBase32, fromBase64Url, fromHex, generateRecoveryKey, inspectEnvelope, isValidBlobKey, noteAsDocument, noteAssociatedData, noteAttachmentAssociatedData, noteKeyForVersion, openFolderName, openNoteContent, openNoteMeta, openSharedItemKey, padmeLength, parseRecoveryKey, readDeviceRequest, recoveryAuth, recoveryReplaceMessage, rotateItemKey, rotateNoteKey, sameDevice, sealFolder, sealNote, searchWords, shareExpired, shareItemKey, shareItemKeyWithDevices, shareWrapsFor, signForServer, signedDeviceGrant, toBase32, toBase64Url, toHex, unwrapAccountKeyForDevice, unwrapAccountKeyWithRecoveryKey, unwrapItemKey, unwrapPreviousItemKey, wrapAccountKeyForDevice, wrapAccountKeyWithRecoveryKey, wrapItemKey, wrapPreviousItemKey };
|