@seed-hypermedia/client 0.0.80 → 0.0.82
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/auth.mjs +2 -2
- package/dist/blobs.d.ts +2 -1
- package/dist/blobs.mjs +3 -1
- package/dist/block-diff.mjs +1 -1
- package/dist/blocks-to-markdown.d.ts +16 -11
- package/dist/blocks-to-markdown.mjs +1 -1
- package/dist/capability.mjs +2 -2
- package/dist/{chunk-EZ5UFUMQ.mjs → chunk-2JSUDZLE.mjs} +1 -1
- package/dist/{chunk-OZKQOI2X.mjs → chunk-3KLY2B27.mjs} +51 -4
- package/dist/{chunk-SHOAYNJY.mjs → chunk-7PB3EULG.mjs} +1 -1
- package/dist/{chunk-SPVX5N6S.mjs → chunk-BO2QSSIU.mjs} +1 -1
- package/dist/{chunk-IT5LLTMP.mjs → chunk-NBCHK76Q.mjs} +27 -0
- package/dist/{chunk-YH52VFVR.mjs → chunk-TET43O3D.mjs} +296 -178
- package/dist/chunk-XB6E7EVC.mjs +872 -0
- package/dist/hmauth.mjs +2 -2
- package/dist/index.mjs +5 -5
- package/dist/markdown-to-blocks.d.ts +27 -32
- package/dist/markdown-to-blocks.mjs +3 -1
- package/dist/vault-local.mjs +2 -2
- package/dist/vault-merge.mjs +2 -2
- package/dist/vault.mjs +2 -2
- package/package.json +1 -1
- package/dist/chunk-H7L4TI6X.mjs +0 -705
package/dist/auth.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
PARAM_TS,
|
|
12
12
|
validateClientId,
|
|
13
13
|
validateRedirectUri
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-7PB3EULG.mjs";
|
|
15
15
|
import {
|
|
16
16
|
decode,
|
|
17
17
|
encode
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
principalFromString,
|
|
24
24
|
principalToString,
|
|
25
25
|
verify
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-NBCHK76Q.mjs";
|
|
27
27
|
import "./chunk-DR3HJ6BV.mjs";
|
|
28
28
|
import {
|
|
29
29
|
decode as decode2
|
package/dist/blobs.d.ts
CHANGED
|
@@ -60,9 +60,10 @@ export declare class WebCryptoKeyPair implements Signer {
|
|
|
60
60
|
}
|
|
61
61
|
/** Generate a random Ed25519 key pair with an unexportable private key. */
|
|
62
62
|
export declare function generateWebCryptoKeyPair(): Promise<WebCryptoKeyPair>;
|
|
63
|
+
export declare const nativeCryptoReady: Promise<void>;
|
|
63
64
|
/**
|
|
64
65
|
* Verify the signature of a blob against its embedded signer Principal.
|
|
65
|
-
* Uses
|
|
66
|
+
* Uses native Ed25519 when available (server), @noble in the browser.
|
|
66
67
|
*/
|
|
67
68
|
export declare function verify(blob: Blob): boolean;
|
|
68
69
|
/** Create a Principal from a raw Ed25519 public key (32 bytes). */
|
package/dist/blobs.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
generateNobleKeyPair,
|
|
15
15
|
generateWebCryptoKeyPair,
|
|
16
16
|
keyPairFromPrivateKey,
|
|
17
|
+
nativeCryptoReady,
|
|
17
18
|
nobleKeyPairFromSeed,
|
|
18
19
|
principalEqual,
|
|
19
20
|
principalFromEd25519,
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
21
22
|
principalToString,
|
|
22
23
|
sign,
|
|
23
24
|
verify
|
|
24
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-NBCHK76Q.mjs";
|
|
25
26
|
import "./chunk-DR3HJ6BV.mjs";
|
|
26
27
|
import "./chunk-3TPCJCVO.mjs";
|
|
27
28
|
import "./chunk-7P6ASYW6.mjs";
|
|
@@ -41,6 +42,7 @@ export {
|
|
|
41
42
|
generateNobleKeyPair,
|
|
42
43
|
generateWebCryptoKeyPair,
|
|
43
44
|
keyPairFromPrivateKey,
|
|
45
|
+
nativeCryptoReady,
|
|
44
46
|
nobleKeyPairFromSeed,
|
|
45
47
|
principalEqual,
|
|
46
48
|
principalFromEd25519,
|
package/dist/block-diff.mjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Seed block tree → Markdown formatter.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
4
|
+
* The lossless half of the markdown pair (see `markdown-to-blocks.ts` for the
|
|
5
|
+
* dialect). Converts HMDocument/HMBlockNode trees to markdown with:
|
|
6
|
+
* - YAML frontmatter carrying every metadata key
|
|
7
|
+
* - a trailing `<!-- id:X [type:T] [attrs:{…}] -->` comment on every block
|
|
8
|
+
* - nesting by indentation, heading level by heading depth
|
|
9
|
+
* - annotations as markdown markers, split at boundaries so they nest
|
|
8
10
|
*
|
|
9
11
|
* This module is purely synchronous and does NOT resolve embeds, mentions,
|
|
10
|
-
* or queries over the network. For resolved output,
|
|
11
|
-
* which
|
|
12
|
+
* or queries over the network. For resolved output, see the
|
|
13
|
+
* `documentToResolvedMarkdown` family below, which is a display format and
|
|
14
|
+
* not round-trip safe.
|
|
12
15
|
*
|
|
13
|
-
* Round-trip
|
|
14
|
-
*
|
|
16
|
+
* Round-trip: `parseMarkdown(blocksToMarkdown(doc))` reproduces `doc`, and
|
|
17
|
+
* exporting that parse reproduces the same markdown. Use
|
|
18
|
+
* `{ipfsGateway: false}` to keep `ipfs://` links verbatim.
|
|
15
19
|
*/
|
|
16
20
|
import type { SeedClient } from './client';
|
|
17
21
|
import type { HMBlockNode, HMComment, HMDocument, HMMetadata } from './hm-types';
|
|
@@ -20,9 +24,10 @@ export type BlocksToMarkdownOptions = {
|
|
|
20
24
|
ipfsGateway?: boolean;
|
|
21
25
|
};
|
|
22
26
|
/**
|
|
23
|
-
* Emit YAML frontmatter from HMMetadata.
|
|
24
|
-
*
|
|
25
|
-
* System fields (authors, version, genesis, account) are
|
|
27
|
+
* Emit YAML frontmatter from HMMetadata. Every defined key is emitted,
|
|
28
|
+
* including nested values and keys this client does not know about.
|
|
29
|
+
* System fields (authors, version, genesis, account) are not metadata and
|
|
30
|
+
* are never present here.
|
|
26
31
|
*/
|
|
27
32
|
export declare function emitFrontmatter(metadata: HMMetadata): string;
|
|
28
33
|
/**
|
package/dist/capability.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createCapability,
|
|
3
3
|
resolveCapability
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-BO2QSSIU.mjs";
|
|
5
5
|
import "./chunk-LVAHHQIK.mjs";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-NBCHK76Q.mjs";
|
|
7
7
|
import "./chunk-DR3HJ6BV.mjs";
|
|
8
8
|
import "./chunk-MZUGCZJ6.mjs";
|
|
9
9
|
import "./chunk-3TPCJCVO.mjs";
|
|
@@ -24,7 +24,7 @@ function matchBlockIds(oldNodes, newNodes) {
|
|
|
24
24
|
if (oldNode && oldNode.block.type === newNode.block.type) {
|
|
25
25
|
matchedId = oldNode.block.id;
|
|
26
26
|
}
|
|
27
|
-
const matchedChildren = matchBlockIds((oldNode == null ? void 0 : oldNode.children) ?? [], newNode.children);
|
|
27
|
+
const matchedChildren = newNode.block.type === "Table" ? newNode.children : matchBlockIds((oldNode == null ? void 0 : oldNode.children) ?? [], newNode.children);
|
|
28
28
|
return {
|
|
29
29
|
block: { ...newNode.block, id: matchedId },
|
|
30
30
|
children: matchedChildren
|
|
@@ -217,6 +217,19 @@ function computeReplaceOps(oldMap, matchedTree, parentId = "") {
|
|
|
217
217
|
}
|
|
218
218
|
return ops;
|
|
219
219
|
}
|
|
220
|
+
function oldSiblingOrder(oldMap, parentId) {
|
|
221
|
+
const byLeft = /* @__PURE__ */ new Map();
|
|
222
|
+
for (const [id, entry] of Object.entries(oldMap)) {
|
|
223
|
+
if (entry.parent === parentId) byLeft.set(entry.left, id);
|
|
224
|
+
}
|
|
225
|
+
const order = [];
|
|
226
|
+
let cur = byLeft.get("");
|
|
227
|
+
while (cur !== void 0 && !order.includes(cur)) {
|
|
228
|
+
order.push(cur);
|
|
229
|
+
cur = byLeft.get(cur);
|
|
230
|
+
}
|
|
231
|
+
return order;
|
|
232
|
+
}
|
|
220
233
|
function computeReplaceOpsInner(oldMap, matchedTree, parentId, touchedIds) {
|
|
221
234
|
const ops = [];
|
|
222
235
|
const blockIdsAtLevel = [];
|
|
@@ -253,7 +266,9 @@ function computeReplaceOpsInner(oldMap, matchedTree, parentId, touchedIds) {
|
|
|
253
266
|
ops.push(...computeReplaceOpsInner(oldMap, node.children, blockId, touchedIds));
|
|
254
267
|
}
|
|
255
268
|
});
|
|
256
|
-
|
|
269
|
+
const oldOrder = oldSiblingOrder(oldMap, parentId);
|
|
270
|
+
const sameOrder = oldOrder.length === blockIdsAtLevel.length && blockIdsAtLevel.every((id, i) => oldOrder[i] === id);
|
|
271
|
+
if (blockIdsAtLevel.length > 0 && !sameOrder) {
|
|
257
272
|
ops.push({
|
|
258
273
|
type: "MoveBlocks",
|
|
259
274
|
blocks: blockIdsAtLevel,
|
|
@@ -272,12 +287,44 @@ function attrsEqual(a, b) {
|
|
|
272
287
|
}
|
|
273
288
|
return true;
|
|
274
289
|
}
|
|
290
|
+
function compareAnnotations(a, b) {
|
|
291
|
+
var _a, _b, _c, _d;
|
|
292
|
+
const sa = ((_a = a.starts) == null ? void 0 : _a[0]) ?? 0;
|
|
293
|
+
const sb = ((_b = b.starts) == null ? void 0 : _b[0]) ?? 0;
|
|
294
|
+
const ea = ((_c = a.ends) == null ? void 0 : _c[0]) ?? 0;
|
|
295
|
+
const eb = ((_d = b.ends) == null ? void 0 : _d[0]) ?? 0;
|
|
296
|
+
return sa - sb || eb - ea || String(a.type).localeCompare(String(b.type));
|
|
297
|
+
}
|
|
298
|
+
function hasRange(a) {
|
|
299
|
+
const starts = a.starts || [];
|
|
300
|
+
const ends = a.ends || [];
|
|
301
|
+
return starts.some((s, i) => (ends[i] ?? -1) > s);
|
|
302
|
+
}
|
|
303
|
+
function canonicalAnnotation(ann) {
|
|
304
|
+
const a = ann || {};
|
|
305
|
+
const starts = a.starts || [];
|
|
306
|
+
const ends = a.ends || [];
|
|
307
|
+
const keep = starts.map((_, i) => i).filter((i) => (ends[i] ?? -1) > starts[i]);
|
|
308
|
+
const out = {
|
|
309
|
+
type: a.type,
|
|
310
|
+
starts: keep.map((i) => starts[i]),
|
|
311
|
+
ends: keep.map((i) => ends[i])
|
|
312
|
+
};
|
|
313
|
+
if (a.link) out.link = a.link;
|
|
314
|
+
const attrs = a.attributes;
|
|
315
|
+
if (attrs && Object.keys(attrs).length > 0) {
|
|
316
|
+
const sorted = {};
|
|
317
|
+
for (const k of Object.keys(attrs).sort()) sorted[k] = attrs[k];
|
|
318
|
+
out.attributes = sorted;
|
|
319
|
+
}
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
275
322
|
function isBlockContentEqual(old, newBlock) {
|
|
276
323
|
if (old.type !== newBlock.type) return false;
|
|
277
324
|
if ((old.text || "") !== (newBlock.text || "")) return false;
|
|
278
325
|
if ((old.link || "") !== (newBlock.link || "")) return false;
|
|
279
|
-
const oldAnn = old.annotations || [];
|
|
280
|
-
const newAnn = newBlock.annotations || [];
|
|
326
|
+
const oldAnn = (old.annotations || []).map(canonicalAnnotation).filter(hasRange).sort(compareAnnotations);
|
|
327
|
+
const newAnn = (newBlock.annotations || []).map(canonicalAnnotation).filter(hasRange).sort(compareAnnotations);
|
|
281
328
|
if (oldAnn.length !== newAnn.length) return false;
|
|
282
329
|
if (oldAnn.length > 0 && JSON.stringify(oldAnn) !== JSON.stringify(newAnn)) {
|
|
283
330
|
return false;
|
|
@@ -61,6 +61,31 @@ async function generateWebCryptoKeyPair() {
|
|
|
61
61
|
const publicKeyRaw = new Uint8Array(await crypto.subtle.exportKey("raw", keyPair.publicKey));
|
|
62
62
|
return new WebCryptoKeyPair(keyPair, publicKeyRaw);
|
|
63
63
|
}
|
|
64
|
+
var ED25519_SPKI_DER_PREFIX = new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 112, 3, 33, 0]);
|
|
65
|
+
var nativeCrypto;
|
|
66
|
+
var nativeCryptoReady = (async () => {
|
|
67
|
+
try {
|
|
68
|
+
const mod = await import("module");
|
|
69
|
+
const base = (typeof process !== "undefined" && process.cwd ? process.cwd() : "/") + "/";
|
|
70
|
+
nativeCrypto = mod.createRequire(base)("node:crypto");
|
|
71
|
+
} catch {
|
|
72
|
+
nativeCrypto = null;
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
75
|
+
var nativeKeyCache = /* @__PURE__ */ new Map();
|
|
76
|
+
function nativeVerify(nc, sig, data, rawPubKey) {
|
|
77
|
+
const cacheKey = base58btc.encode(rawPubKey);
|
|
78
|
+
let key = nativeKeyCache.get(cacheKey);
|
|
79
|
+
if (key === void 0) {
|
|
80
|
+
const spki = new Uint8Array(ED25519_SPKI_DER_PREFIX.length + rawPubKey.length);
|
|
81
|
+
spki.set(ED25519_SPKI_DER_PREFIX);
|
|
82
|
+
spki.set(rawPubKey, ED25519_SPKI_DER_PREFIX.length);
|
|
83
|
+
key = nc.createPublicKey({ key: spki, format: "der", type: "spki" });
|
|
84
|
+
if (nativeKeyCache.size > 1e3) nativeKeyCache.clear();
|
|
85
|
+
nativeKeyCache.set(cacheKey, key);
|
|
86
|
+
}
|
|
87
|
+
return nc.verify(null, data, key, sig);
|
|
88
|
+
}
|
|
64
89
|
function verify(blob) {
|
|
65
90
|
if (blob.signer[0] !== ED25519_VARINT_PREFIX[0] || blob.signer[1] !== ED25519_VARINT_PREFIX[1]) return false;
|
|
66
91
|
const rawPubKey = blob.signer.slice(ED25519_VARINT_PREFIX.length);
|
|
@@ -69,6 +94,7 @@ function verify(blob) {
|
|
|
69
94
|
const unsigned = { ...blob, sig: new Uint8Array(ED25519_SIGNATURE_SIZE) };
|
|
70
95
|
const data = new Uint8Array(encode(unsigned));
|
|
71
96
|
try {
|
|
97
|
+
if (nativeCrypto) return nativeVerify(nativeCrypto, sigCopy, data, rawPubKey);
|
|
72
98
|
return ed25519.verify(sigCopy, data, rawPubKey);
|
|
73
99
|
} catch {
|
|
74
100
|
return false;
|
|
@@ -193,6 +219,7 @@ export {
|
|
|
193
219
|
nobleKeyPairFromSeed,
|
|
194
220
|
WebCryptoKeyPair,
|
|
195
221
|
generateWebCryptoKeyPair,
|
|
222
|
+
nativeCryptoReady,
|
|
196
223
|
verify,
|
|
197
224
|
principalFromEd25519,
|
|
198
225
|
principalToString,
|