@seed-hypermedia/client 0.0.67 → 0.0.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +201 -0
  2. package/dist/auth.d.ts +79 -0
  3. package/dist/auth.mjs +265 -0
  4. package/dist/auto-link.mjs +20 -0
  5. package/dist/base64.mjs +9 -0
  6. package/dist/blobs.d.ts +168 -0
  7. package/dist/blobs.mjs +50 -0
  8. package/dist/block-diff.d.ts +37 -1
  9. package/dist/block-diff.mjs +17 -0
  10. package/dist/blocks-to-markdown.mjs +22 -0
  11. package/dist/capability.mjs +11 -0
  12. package/dist/cbor.d.ts +13 -0
  13. package/dist/cbor.mjs +13 -0
  14. package/dist/change.mjs +23 -0
  15. package/dist/chunk-2MD3FXKB.mjs +14 -0
  16. package/dist/chunk-3TPCJCVO.mjs +24 -0
  17. package/dist/chunk-52P3E6H6.mjs +459 -0
  18. package/dist/{chunk-KCR3277A.mjs → chunk-5EWV4OPF.mjs} +1 -1
  19. package/dist/chunk-CBELM7KX.mjs +29 -0
  20. package/dist/chunk-DXDF36H5.mjs +289 -0
  21. package/dist/chunk-EY6RQVAP.mjs +138 -0
  22. package/dist/chunk-FYUZZ3HT.mjs +199 -0
  23. package/dist/chunk-GKGWSN6J.mjs +75 -0
  24. package/dist/chunk-H7L4TI6X.mjs +705 -0
  25. package/dist/chunk-HBIVZA6C.mjs +102 -0
  26. package/dist/chunk-I3YUHKYW.mjs +135 -0
  27. package/dist/chunk-KO4XH5L2.mjs +475 -0
  28. package/dist/chunk-LYECQKZE.mjs +49 -0
  29. package/dist/chunk-MKUWQB5W.mjs +297 -0
  30. package/dist/chunk-N3P7S5YZ.mjs +118 -0
  31. package/dist/chunk-NPG76WUS.mjs +348 -0
  32. package/dist/chunk-NX7YFFRX.mjs +124 -0
  33. package/dist/chunk-OZKQOI2X.mjs +334 -0
  34. package/dist/chunk-PPAY4WZX.mjs +40 -0
  35. package/dist/chunk-QS7TPMYT.mjs +411 -0
  36. package/dist/chunk-S2PVJK2P.mjs +517 -0
  37. package/dist/chunk-T5BTAJPW.mjs +725 -0
  38. package/dist/{chunk-EGCUJ6D6.mjs → chunk-UOL3F6XQ.mjs} +0 -12
  39. package/dist/chunk-VN7F33SS.mjs +108 -0
  40. package/dist/chunk-W4OGV22Y.mjs +57 -0
  41. package/dist/chunk-WJQSJ6UM.mjs +159 -0
  42. package/dist/chunk-XI2LXZM7.mjs +112 -0
  43. package/dist/chunk-YNVFRCUH.mjs +171 -0
  44. package/dist/chunk-YZX54L3G.mjs +33 -0
  45. package/dist/client.mjs +14 -0
  46. package/dist/comment.mjs +18 -0
  47. package/dist/contact.mjs +14 -0
  48. package/dist/document-state.mjs +8 -0
  49. package/dist/editor-types.mjs +0 -0
  50. package/dist/editorblock-to-hmblock.mjs +11 -0
  51. package/dist/encryption.mjs +13 -0
  52. package/dist/errors.mjs +11 -0
  53. package/dist/file-to-ipfs.mjs +13 -0
  54. package/dist/grobid.mjs +11 -0
  55. package/dist/hm-resolver.mjs +10 -0
  56. package/dist/hm-types.d.ts +566 -566
  57. package/dist/hmauth.d.ts +169 -0
  58. package/dist/hmauth.mjs +52 -0
  59. package/dist/hmblock-to-editorblock.mjs +12 -0
  60. package/dist/index.d.ts +1 -1
  61. package/dist/index.mjs +126 -5006
  62. package/dist/keyfile.mjs +19 -0
  63. package/dist/markdown-to-blocks.d.ts +7 -0
  64. package/dist/markdown-to-blocks.mjs +15 -0
  65. package/dist/pdf-to-blocks-embedded.mjs +7 -0
  66. package/dist/pdf-to-blocks.mjs +11 -0
  67. package/dist/ref.mjs +12 -0
  68. package/dist/resource-read.mjs +14 -0
  69. package/dist/signing.mjs +13 -0
  70. package/dist/tei-to-blocks.mjs +8 -0
  71. package/dist/unicode.mjs +19 -0
  72. package/dist/vault-local.mjs +7 -6
  73. package/dist/vault.mjs +3 -2
  74. package/package.json +18 -28
  75. package/src/index.ts +0 -137
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Blob types and signing infrastructure for the Seed Hypermedia protocol.
3
+ * Port of the Go blob and core packages, supporting Profile and Capability blob types.
4
+ *
5
+ * Provides two signing implementations:
6
+ * - NobleKeyPair: uses @noble/curves/ed25519 directly. For vault keys where raw seed storage is needed.
7
+ * - WebCryptoKeyPair: uses crypto.subtle with unexportable keys. For browser session keys.
8
+ */
9
+ import { CID } from 'multiformats/cid';
10
+ export declare const ED25519_VARINT_PREFIX: Uint8Array<ArrayBuffer>;
11
+ export declare const ED25519_SIGNATURE_SIZE = 64;
12
+ export declare const ED25519_PUBLIC_KEY_SIZE = 32;
13
+ export declare const ED25519_PRINCIPAL_SIZE: number;
14
+ /** Packed binary public key: `<multicodec-varint><raw-key-bytes>`. */
15
+ export type Principal = Uint8Array;
16
+ /** Cryptographic signature bytes. */
17
+ export type Signature = Uint8Array;
18
+ /** Unix timestamp in milliseconds. */
19
+ export type Timestamp = number;
20
+ /** Role values for capability blobs. */
21
+ export type Role = 'WRITER' | 'AGENT';
22
+ /** Signs data and produces a cryptographic signature. */
23
+ export interface Signer {
24
+ readonly principal: Principal;
25
+ sign(data: Uint8Array): Promise<Signature>;
26
+ }
27
+ /** Verifies a signature against data. */
28
+ export interface Verifier {
29
+ verify(data: Uint8Array, sig: Signature): Promise<boolean>;
30
+ }
31
+ /**
32
+ * Ed25519 key pair using @noble/curves. Stores the raw 32-byte private key seed,
33
+ * suitable for vault keys that need to persist the seed in encrypted storage.
34
+ */
35
+ export declare class NobleKeyPair implements Signer {
36
+ readonly principal: Principal;
37
+ readonly publicKey: Uint8Array;
38
+ /** Raw 32-byte Ed25519 private key seed. Needed for vault storage. */
39
+ readonly seed: Uint8Array;
40
+ constructor(seed: Uint8Array);
41
+ sign(data: Uint8Array): Promise<Signature>;
42
+ }
43
+ /** Generate a random Ed25519 key pair with an accessible raw seed. */
44
+ export declare function generateNobleKeyPair(): NobleKeyPair;
45
+ /** Restore a NobleKeyPair from a stored 32-byte seed. */
46
+ export declare function nobleKeyPairFromSeed(seed: Uint8Array): NobleKeyPair;
47
+ /**
48
+ * Ed25519 key pair using Web Crypto. The private key is **non-exportable**,
49
+ * suitable for browser session keys that must not leave the browser's crypto subsystem.
50
+ */
51
+ export declare class WebCryptoKeyPair implements Signer {
52
+ readonly principal: Principal;
53
+ readonly publicKey: Uint8Array;
54
+ /** The Web Crypto key pair. Exposed for LocalWebIdentity compatibility. */
55
+ readonly keyPair: CryptoKeyPair;
56
+ constructor(keyPair: CryptoKeyPair, publicKeyRaw: Uint8Array);
57
+ sign(data: Uint8Array): Promise<Signature>;
58
+ }
59
+ /** Generate a random Ed25519 key pair with an unexportable private key. */
60
+ export declare function generateWebCryptoKeyPair(): Promise<WebCryptoKeyPair>;
61
+ /**
62
+ * Verify the signature of a blob against its embedded signer Principal.
63
+ * Uses @noble/curves/ed25519 directly — works with any blob regardless of how it was signed.
64
+ */
65
+ export declare function verify(blob: Blob): boolean;
66
+ /** Create a Principal from a raw Ed25519 public key (32 bytes). */
67
+ export declare function principalFromEd25519(rawPublicKey: Uint8Array): Principal;
68
+ /** Encode a Principal to its base58btc multibase string (starts with 'z'). */
69
+ export declare function principalToString(p: Principal): string;
70
+ /** Decode a Principal from its base58btc multibase string. */
71
+ export declare function principalFromString(s: string): Principal;
72
+ /** Check if two Principals are equal. */
73
+ export declare function principalEqual(a: Principal, b: Principal): boolean;
74
+ /** Open-ended base blob shape. Any blob type can be signed and verified through this interface. */
75
+ export interface Blob {
76
+ readonly type: string;
77
+ readonly signer: Principal;
78
+ readonly sig: Signature;
79
+ readonly ts: Timestamp;
80
+ readonly [key: string]: unknown;
81
+ }
82
+ /** Profile blob representing user identity information. */
83
+ export interface Profile extends Blob {
84
+ readonly type: 'Profile';
85
+ /** Points to another key acting as an identity redirect. */
86
+ readonly alias?: Principal;
87
+ /** Display name for the profile. */
88
+ readonly name?: string;
89
+ /** Icon/avatar URI (wire key is "avatar" for legacy compatibility with Go). */
90
+ readonly avatar?: string;
91
+ /** Short text description. */
92
+ readonly description?: string;
93
+ /** Account principal when signed by an agent key on behalf of the account. */
94
+ readonly account?: Principal;
95
+ }
96
+ /** Create a signed and encoded Profile blob. */
97
+ export declare function createProfile(signer: Signer, opts: {
98
+ /** Display name (required for non-alias profiles). */
99
+ name: string;
100
+ /** Icon/avatar URI. */
101
+ avatar?: string;
102
+ /** Short text description. */
103
+ description?: string;
104
+ /** Account principal. Omitted from encoding if it equals the signer. */
105
+ account?: Principal;
106
+ }, ts: Timestamp): Promise<Encoded<Profile>>;
107
+ /** Create a signed and encoded alias Profile blob (identity redirect). */
108
+ export declare function createProfileAlias(signer: Signer, alias: Principal, ts: Timestamp): Promise<Encoded<Profile>>;
109
+ /** Capability blob granting rights from issuer to delegate. */
110
+ export interface Capability extends Blob {
111
+ readonly type: 'Capability';
112
+ /** Public key receiving the delegation. */
113
+ readonly delegate: Principal;
114
+ /** For direct authentication against another principal. */
115
+ readonly audience?: Principal;
116
+ /** Path scope for the capability. */
117
+ readonly path?: string;
118
+ /** Access role being granted. */
119
+ readonly role: Role;
120
+ /** Human-readable label. */
121
+ readonly label?: string;
122
+ }
123
+ /** Create a signed and encoded Capability blob. */
124
+ export declare function createCapability(issuer: Signer, delegate: Principal, role: Role, ts: Timestamp, opts?: {
125
+ /** Path scope. */
126
+ path?: string;
127
+ /** Human-readable label. */
128
+ label?: string;
129
+ /** Audience principal for direct auth. */
130
+ audience?: Principal;
131
+ }): Promise<Encoded<Capability>>;
132
+ /** A decoded blob stored alongside its content-addressed CID. */
133
+ export interface Decoded<T extends Blob> {
134
+ readonly cid: CID;
135
+ readonly decoded: T;
136
+ }
137
+ /** A blob with its CID and decoded + encoded data. */
138
+ export interface Encoded<T extends Blob> extends Decoded<T> {
139
+ readonly data: Uint8Array;
140
+ }
141
+ /**
142
+ * Sign a blob with a Signer.
143
+ * Fills sig with zeros, CBOR-encodes, signs, replaces sig.
144
+ */
145
+ export declare function sign<T extends Blob>(signer: Signer, blob: T): Promise<T>;
146
+ /** Encode a signed blob to DAG-CBOR and compute its content-addressed CID. */
147
+ export declare function encode<T extends Blob>(blob: T): Encoded<T>;
148
+ /**
149
+ * Decode raw CBOR bytes into a blob, verifying the CID matches.
150
+ * Throws if the recomputed CID doesn't match the expected one.
151
+ */
152
+ export declare function decodeBlob<T extends Blob>(data: Uint8Array, expectedCid: CID): Encoded<T>;
153
+ /**
154
+ * @deprecated Use `NobleKeyPair` or `WebCryptoKeyPair` directly.
155
+ * Kept temporarily for consumers that haven't migrated yet.
156
+ */
157
+ export type KeyPair = Signer & {
158
+ readonly publicKey: Uint8Array;
159
+ readonly keyPair?: CryptoKeyPair;
160
+ };
161
+ /**
162
+ * @deprecated Use `generateNobleKeyPair()` instead.
163
+ */
164
+ export declare function generateKeyPair(): Promise<NobleKeyPair>;
165
+ /**
166
+ * @deprecated Use `nobleKeyPairFromSeed()` instead.
167
+ */
168
+ export declare function keyPairFromPrivateKey(rawPrivateKey: Uint8Array): Promise<NobleKeyPair>;
package/dist/blobs.mjs ADDED
@@ -0,0 +1,50 @@
1
+ import {
2
+ ED25519_PRINCIPAL_SIZE,
3
+ ED25519_PUBLIC_KEY_SIZE,
4
+ ED25519_SIGNATURE_SIZE,
5
+ ED25519_VARINT_PREFIX,
6
+ NobleKeyPair,
7
+ WebCryptoKeyPair,
8
+ createCapability,
9
+ createProfile,
10
+ createProfileAlias,
11
+ decodeBlob,
12
+ encode,
13
+ generateKeyPair,
14
+ generateNobleKeyPair,
15
+ generateWebCryptoKeyPair,
16
+ keyPairFromPrivateKey,
17
+ nobleKeyPairFromSeed,
18
+ principalEqual,
19
+ principalFromEd25519,
20
+ principalFromString,
21
+ principalToString,
22
+ sign,
23
+ verify
24
+ } from "./chunk-FYUZZ3HT.mjs";
25
+ import "./chunk-3TPCJCVO.mjs";
26
+ import "./chunk-7P6ASYW6.mjs";
27
+ export {
28
+ ED25519_PRINCIPAL_SIZE,
29
+ ED25519_PUBLIC_KEY_SIZE,
30
+ ED25519_SIGNATURE_SIZE,
31
+ ED25519_VARINT_PREFIX,
32
+ NobleKeyPair,
33
+ WebCryptoKeyPair,
34
+ createCapability,
35
+ createProfile,
36
+ createProfileAlias,
37
+ decodeBlob,
38
+ encode,
39
+ generateKeyPair,
40
+ generateNobleKeyPair,
41
+ generateWebCryptoKeyPair,
42
+ keyPairFromPrivateKey,
43
+ nobleKeyPairFromSeed,
44
+ principalEqual,
45
+ principalFromEd25519,
46
+ principalFromString,
47
+ principalToString,
48
+ sign,
49
+ verify
50
+ };
@@ -10,6 +10,12 @@
10
10
  * treated as new. Old blocks whose IDs don't appear in the new tree
11
11
  * are deleted. This gives per-block granularity — a mix of known and
12
12
  * unknown IDs is handled correctly.
13
+ *
14
+ * Tables get an extra identity pass (rebindTableIdentities): the markdown
15
+ * dialect only carries table, column, and row ids, so cell block ids are
16
+ * re-derived from (row id, column id) against the old document, and
17
+ * attributes markdown cannot express (column width, header column) are
18
+ * carried over from the old blocks.
13
19
  */
14
20
  import type { DocumentOperation } from './change';
15
21
  import type { HMBlockNode } from './hm-types';
@@ -42,6 +48,25 @@ export declare function createBlocksMap(nodes: APIBlockNode[], parentId?: string
42
48
  * Returns a new tree with IDs reassigned (does not mutate inputs).
43
49
  */
44
50
  export declare function matchBlockIds(oldNodes: APIBlockNode[], newNodes: BlockNode[]): BlockNode[];
51
+ /**
52
+ * Rebind identity inside every Table in the new tree against the old tree.
53
+ *
54
+ * For a new Table whose id matches an old Table:
55
+ * - Columns match by explicit id first, then by header-cell text (unique,
56
+ * non-empty texts only), then by position among the still-unmatched.
57
+ * - Rows match by explicit id first, then by position among the unmatched.
58
+ * - Cells reuse the old cell's block id for (matched row, matched column) —
59
+ * cell ids never travel through markdown.
60
+ * - Attributes markdown cannot express (column width, header column, any
61
+ * future keys) are carried over from the matched old block. A row's
62
+ * isHeader comes from the new tree (the dialect does express it).
63
+ * - Position-0 invariants are enforced: only the first column / first row
64
+ * may carry isHeader.
65
+ *
66
+ * Fresh tables (no old match) are passed through with invariants enforced.
67
+ * Non-table blocks are returned unchanged (children walked recursively).
68
+ */
69
+ export declare function rebindTableIdentities(oldNodes: APIBlockNode[], newNodes: BlockNode[]): BlockNode[];
45
70
  /**
46
71
  * Compare the new block tree against the old blocks map and produce
47
72
  * the minimal set of DocumentOperations:
@@ -49,14 +74,25 @@ export declare function matchBlockIds(oldNodes: APIBlockNode[], newNodes: BlockN
49
74
  * - ReplaceBlock for new or content-changed blocks
50
75
  * - MoveBlocks for positioning (new blocks or position changes)
51
76
  * - DeleteBlocks for blocks removed from the document
77
+ *
78
+ * The delete pass is global: every old block whose id does not appear
79
+ * anywhere in the new tree is deleted, including descendants of deleted
80
+ * blocks (so removing a table row also removes its cells, leaving no
81
+ * orphans), while blocks that moved to a different parent are kept.
52
82
  */
53
83
  export declare function computeReplaceOps(oldMap: BlocksMap, matchedTree: BlockNode[], parentId?: string): DocumentOperation[];
84
+ /**
85
+ * Normalize an HMBlockNode tree (API response shape) into APIBlockNode with
86
+ * all fields defaulted, for use as the "old document" side of the diff.
87
+ */
88
+ export declare function toAPIBlockNode(node: HMBlockNode): APIBlockNode;
54
89
  /**
55
90
  * Convert an HMBlockNode tree (from JSON input or API response) into
56
91
  * a BlockNode tree compatible with the diff pipeline.
57
92
  *
58
93
  * HMBlockNode nests childrenType/language inside `attributes`, while
59
- * SeedBlock/BlockNode has them at the top level.
94
+ * SeedBlock/BlockNode has them at the top level. All other attributes
95
+ * (columnId, isHeader, width, …) are preserved in `block.attributes`.
60
96
  */
61
97
  export declare function hmBlockNodeToBlockNode(node: HMBlockNode): BlockNode;
62
98
  export {};
@@ -0,0 +1,17 @@
1
+ import {
2
+ computeReplaceOps,
3
+ createBlocksMap,
4
+ hmBlockNodeToBlockNode,
5
+ matchBlockIds,
6
+ rebindTableIdentities,
7
+ toAPIBlockNode
8
+ } from "./chunk-OZKQOI2X.mjs";
9
+ import "./chunk-7P6ASYW6.mjs";
10
+ export {
11
+ computeReplaceOps,
12
+ createBlocksMap,
13
+ hmBlockNodeToBlockNode,
14
+ matchBlockIds,
15
+ rebindTableIdentities,
16
+ toAPIBlockNode
17
+ };
@@ -0,0 +1,22 @@
1
+ import {
2
+ blocksToMarkdown,
3
+ commentToResolvedMarkdown,
4
+ contentToResolvedMarkdown,
5
+ documentToResolvedMarkdown,
6
+ draftFilename,
7
+ emitFrontmatter,
8
+ parseDraftFilename,
9
+ slugify
10
+ } from "./chunk-T5BTAJPW.mjs";
11
+ import "./chunk-SQEUO7FO.mjs";
12
+ import "./chunk-7P6ASYW6.mjs";
13
+ export {
14
+ blocksToMarkdown,
15
+ commentToResolvedMarkdown,
16
+ contentToResolvedMarkdown,
17
+ documentToResolvedMarkdown,
18
+ draftFilename,
19
+ emitFrontmatter,
20
+ parseDraftFilename,
21
+ slugify
22
+ };
@@ -0,0 +1,11 @@
1
+ import {
2
+ createCapability,
3
+ resolveCapability
4
+ } from "./chunk-W4OGV22Y.mjs";
5
+ import "./chunk-YZX54L3G.mjs";
6
+ import "./chunk-SQEUO7FO.mjs";
7
+ import "./chunk-7P6ASYW6.mjs";
8
+ export {
9
+ createCapability,
10
+ resolveCapability
11
+ };
package/dist/cbor.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import * as cborg from 'cborg';
2
+ export declare const encodeOpts: {
3
+ typeEncoders: {
4
+ undefined: () => null;
5
+ Map: (map: Map<any, any>) => null;
6
+ Object: (obj: any) => cborg.Token[] | null;
7
+ number: (num: number) => null;
8
+ };
9
+ float64: boolean;
10
+ };
11
+ export declare const code: 113;
12
+ export declare function encode<T = any>(obj: T): Uint8Array;
13
+ export declare function decode<T = any>(data: Uint8Array): T;
package/dist/cbor.mjs ADDED
@@ -0,0 +1,13 @@
1
+ import {
2
+ code,
3
+ decode,
4
+ encode,
5
+ encodeOpts
6
+ } from "./chunk-3TPCJCVO.mjs";
7
+ import "./chunk-7P6ASYW6.mjs";
8
+ export {
9
+ code,
10
+ decode,
11
+ encode,
12
+ encodeOpts
13
+ };
@@ -0,0 +1,23 @@
1
+ import {
2
+ createChange,
3
+ createChangeOps,
4
+ createDocumentChange,
5
+ createDocumentChangeFromOps,
6
+ createGenesisChange,
7
+ signDocumentChange,
8
+ signPreparedChange,
9
+ visibilityToCbor
10
+ } from "./chunk-I3YUHKYW.mjs";
11
+ import "./chunk-XI2LXZM7.mjs";
12
+ import "./chunk-YZX54L3G.mjs";
13
+ import "./chunk-7P6ASYW6.mjs";
14
+ export {
15
+ createChange,
16
+ createChangeOps,
17
+ createDocumentChange,
18
+ createDocumentChangeFromOps,
19
+ createGenesisChange,
20
+ signDocumentChange,
21
+ signPreparedChange,
22
+ visibilityToCbor
23
+ };
@@ -0,0 +1,14 @@
1
+ // src/base64.ts
2
+ import "core-js/modules/es.uint8-array.from-base64.js";
3
+ import "core-js/modules/es.uint8-array.to-base64.js";
4
+ function encode(data) {
5
+ return data.toBase64({ alphabet: "base64url", omitPadding: true });
6
+ }
7
+ function decode(data) {
8
+ return Uint8Array.fromBase64(data, { alphabet: "base64url" });
9
+ }
10
+
11
+ export {
12
+ encode,
13
+ decode
14
+ };
@@ -0,0 +1,24 @@
1
+ // src/cbor.ts
2
+ import * as dagCBOR from "@ipld/dag-cbor";
3
+ import * as cborg from "cborg";
4
+ var encodeOpts = {
5
+ ...dagCBOR.encodeOptions,
6
+ typeEncoders: {
7
+ ...dagCBOR.encodeOptions.typeEncoders,
8
+ undefined: () => null
9
+ }
10
+ };
11
+ var code2 = dagCBOR.code;
12
+ function encode2(obj) {
13
+ return cborg.encode(obj, encodeOpts);
14
+ }
15
+ function decode2(data) {
16
+ return dagCBOR.decode(data);
17
+ }
18
+
19
+ export {
20
+ encodeOpts,
21
+ code2 as code,
22
+ encode2 as encode,
23
+ decode2 as decode
24
+ };