@seed-hypermedia/client 0.0.90 → 0.0.92
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/auto-link.mjs +3 -3
- package/dist/blocks-to-markdown.mjs +2 -2
- package/dist/capability.mjs +2 -2
- package/dist/{chunk-T7WF36LU.mjs → chunk-7RJYOV4D.mjs} +1 -1
- package/dist/{chunk-ZNV6NTUU.mjs → chunk-BRMAKS6Z.mjs} +1 -1
- package/dist/{chunk-XXUI3VKA.mjs → chunk-EB45YSE7.mjs} +1 -1
- package/dist/{chunk-Z72PGJKG.mjs → chunk-HEATDM6O.mjs} +1 -1
- package/dist/{chunk-W7AGZEC2.mjs → chunk-IB26JMU5.mjs} +1 -1
- package/dist/{chunk-4HP5N4I7.mjs → chunk-IJOMB2VD.mjs} +3 -3
- package/dist/{chunk-HNQDRHGQ.mjs → chunk-IO44LDKK.mjs} +2 -2
- package/dist/{chunk-Z2S7TL5U.mjs → chunk-J6LPZ3QP.mjs} +1 -1
- package/dist/{chunk-RRXP7SCF.mjs → chunk-J6N6AF3R.mjs} +1 -1
- package/dist/{chunk-UTZ42CJC.mjs → chunk-JOFKLKIC.mjs} +1 -1
- package/dist/chunk-JSNDXUPG.mjs +407 -0
- package/dist/{chunk-JODNNMBZ.mjs → chunk-M6GKXROC.mjs} +2 -2
- package/dist/{chunk-VNZHLLJE.mjs → chunk-MK35Y35R.mjs} +148 -2
- package/dist/{chunk-XB6E7EVC.mjs → chunk-QVRJGK77.mjs} +1 -1
- package/dist/chunk-RWKSRJA3.mjs +230 -0
- package/dist/chunk-VWSAFDOL.mjs +110 -0
- package/dist/{chunk-UFLGAJWJ.mjs → chunk-WY7T2TES.mjs} +3 -3
- package/dist/chunk-ZWKMAGDU.mjs +10 -0
- package/dist/client.mjs +2 -2
- package/dist/comment.mjs +2 -2
- package/dist/dag-json.d.ts +52 -0
- package/dist/dag-json.mjs +23 -0
- package/dist/document-state.mjs +2 -2
- package/dist/editorblock-to-hmblock.mjs +2 -2
- package/dist/explore-query.d.ts +112 -0
- package/dist/explore-query.mjs +455 -0
- package/dist/hm-resolver.mjs +2 -2
- package/dist/hm-types.d.ts +2953 -0
- package/dist/hm-types.mjs +33 -1
- package/dist/hmblock-to-editorblock.mjs +2 -2
- package/dist/index.mjs +27 -27
- package/dist/markdown-to-blocks.mjs +1 -1
- package/dist/pdf-to-blocks.mjs +3 -3
- package/dist/resource-read.mjs +4 -4
- package/dist/schema-engine.d.ts +127 -0
- package/dist/schema-engine.mjs +83 -0
- package/dist/schema-registry.generated.d.ts +8 -0
- package/dist/schema-registry.generated.mjs +11 -0
- package/dist/schema-resolve.d.ts +135 -0
- package/dist/schema-resolve.mjs +45 -0
- package/dist/schema-subtypes.d.ts +36 -0
- package/dist/schema-subtypes.mjs +94 -0
- package/dist/schema-types.generated.d.ts +1598 -0
- package/dist/schema-types.generated.mjs +0 -0
- package/dist/signed-blob.d.ts +63 -0
- package/dist/signed-blob.mjs +123 -0
- package/dist/tei-to-blocks.mjs +2 -2
- package/dist/unicode.mjs +1 -1
- package/package.json +1 -1
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { HMSigner } from './hm-types';
|
|
2
|
+
import { type SchemaRegistry, type HypermediaSchema } from './schema-engine';
|
|
3
|
+
/** The envelope fields every signed blob carries; filled by the signer, never typed. */
|
|
4
|
+
export declare const SIGNED_BLOB_ENVELOPE: readonly ["signer", "sig", "ts"];
|
|
5
|
+
/** The Ed25519 signature placeholder: what `sig` holds while the blob is being signed. */
|
|
6
|
+
export declare const ZERO_SIGNATURE_LENGTH = 64;
|
|
7
|
+
/** True when the (resolved) schema is a signed blob: it declares signer, sig, and ts. */
|
|
8
|
+
export declare function isSignedBlobSchema(schema: HypermediaSchema | undefined, reg?: SchemaRegistry): boolean;
|
|
9
|
+
/** The single `type` tag a signed-blob schema pins (a literal), if any. */
|
|
10
|
+
export declare function signedBlobTypeTag(schema: HypermediaSchema, reg?: SchemaRegistry): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* The schema with the envelope removed (and the `type` tag, when pinned) — what
|
|
13
|
+
* the person actually fills in. Returns a resolved, self-contained map schema.
|
|
14
|
+
*/
|
|
15
|
+
export declare function stripSignedBlobEnvelope(schema: HypermediaSchema, reg?: SchemaRegistry): HypermediaSchema;
|
|
16
|
+
export type SignedBlobResult = {
|
|
17
|
+
cid: string;
|
|
18
|
+
data: Uint8Array;
|
|
19
|
+
ts: number;
|
|
20
|
+
signer: Uint8Array;
|
|
21
|
+
};
|
|
22
|
+
/** The canonical bytes a signed blob's signature covers: the blob with `sig` zeroed. */
|
|
23
|
+
export declare function signedBlobMessage(blob: Record<string, unknown>): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Sign a blob body with the account's signer and return the encoded blob.
|
|
26
|
+
* `body` is the user-authored part (dag-json form); the envelope is added here.
|
|
27
|
+
*/
|
|
28
|
+
export declare function signBlob(signer: HMSigner, body: Record<string, unknown>, opts?: {
|
|
29
|
+
typeTag?: string;
|
|
30
|
+
ts?: number;
|
|
31
|
+
}): Promise<SignedBlobResult>;
|
|
32
|
+
/** Sign and publish. Refuses a `type` that collides with a built-in Seed blob type it doesn't match. */
|
|
33
|
+
export declare function publishSignedBlob(client: {
|
|
34
|
+
request: (key: 'PublishBlobs', input: {
|
|
35
|
+
blobs: {
|
|
36
|
+
cid: string;
|
|
37
|
+
data: Uint8Array;
|
|
38
|
+
}[];
|
|
39
|
+
}) => Promise<unknown>;
|
|
40
|
+
}, signer: HMSigner, body: Record<string, unknown>, opts?: {
|
|
41
|
+
typeTag?: string;
|
|
42
|
+
ts?: number;
|
|
43
|
+
}): Promise<SignedBlobResult>;
|
|
44
|
+
/** True when a dag-json value carries the signed-blob envelope fields. */
|
|
45
|
+
export declare function hasSignedEnvelope(value: unknown): value is Record<string, unknown>;
|
|
46
|
+
/** The Ed25519 public key inside a principal (multicodec 0xed 0x01 + 32 bytes). */
|
|
47
|
+
export declare function principalToPublicKey(principal: Uint8Array): Uint8Array;
|
|
48
|
+
export type SignatureCheck = {
|
|
49
|
+
ok: boolean;
|
|
50
|
+
signer: string;
|
|
51
|
+
ts?: number;
|
|
52
|
+
reason?: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Verify a signed blob given in dag-json form (as the API returns it): the signature must cover
|
|
56
|
+
* the canonical DAG-CBOR of the blob with `sig` zeroed — the daemon's own rule.
|
|
57
|
+
*/
|
|
58
|
+
export declare function verifySignedBlob(value: Record<string, unknown>): Promise<SignatureCheck>;
|
|
59
|
+
/** Canonical DAG-CBOR bytes of a dag-json value and their CID (v1, sha2-256). */
|
|
60
|
+
export declare function encodeDagCbor(value: unknown): Promise<{
|
|
61
|
+
data: Uint8Array;
|
|
62
|
+
cid: string;
|
|
63
|
+
}>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fieldSchema,
|
|
3
|
+
fieldsToProperties,
|
|
4
|
+
isLiteralSchema,
|
|
5
|
+
literalValue,
|
|
6
|
+
resolveSchema,
|
|
7
|
+
structFields
|
|
8
|
+
} from "./chunk-JSNDXUPG.mjs";
|
|
9
|
+
import "./chunk-ZWKMAGDU.mjs";
|
|
10
|
+
import {
|
|
11
|
+
dagJsonToIpld,
|
|
12
|
+
findSeedIndexerCollision
|
|
13
|
+
} from "./chunk-VWSAFDOL.mjs";
|
|
14
|
+
import {
|
|
15
|
+
code,
|
|
16
|
+
encode
|
|
17
|
+
} from "./chunk-3TPCJCVO.mjs";
|
|
18
|
+
import "./chunk-7P6ASYW6.mjs";
|
|
19
|
+
|
|
20
|
+
// src/signed-blob.ts
|
|
21
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
22
|
+
import { base58btc } from "multiformats/bases/base58";
|
|
23
|
+
import { CID } from "multiformats/cid";
|
|
24
|
+
import { sha256 } from "multiformats/hashes/sha2";
|
|
25
|
+
var SIGNED_BLOB_ENVELOPE = ["signer", "sig", "ts"];
|
|
26
|
+
var ZERO_SIGNATURE_LENGTH = 64;
|
|
27
|
+
function isSignedBlobSchema(schema, reg = {}) {
|
|
28
|
+
if (!schema) return false;
|
|
29
|
+
const { schema: resolved } = resolveSchema(schema, {}, reg);
|
|
30
|
+
const props = resolved.properties;
|
|
31
|
+
return !!props && SIGNED_BLOB_ENVELOPE.every((k) => fieldSchema(resolved, k) !== void 0);
|
|
32
|
+
}
|
|
33
|
+
function signedBlobTypeTag(schema, reg = {}) {
|
|
34
|
+
const { schema: resolved } = resolveSchema(schema, {}, reg);
|
|
35
|
+
const t = fieldSchema(resolved, "type");
|
|
36
|
+
const tag = t !== void 0 && isLiteralSchema(t) ? literalValue(t) : void 0;
|
|
37
|
+
return typeof tag === "string" ? tag : void 0;
|
|
38
|
+
}
|
|
39
|
+
function stripSignedBlobEnvelope(schema, reg = {}) {
|
|
40
|
+
const { schema: resolved } = resolveSchema(schema, {}, reg);
|
|
41
|
+
const hidden = new Set(SIGNED_BLOB_ENVELOPE);
|
|
42
|
+
if (signedBlobTypeTag(schema, reg)) hidden.add("type");
|
|
43
|
+
const { required: _legacy, ...rest } = resolved;
|
|
44
|
+
return { ...rest, properties: fieldsToProperties(structFields(resolved).filter((f) => !hidden.has(f.name))) };
|
|
45
|
+
}
|
|
46
|
+
function signedBlobMessage(blob) {
|
|
47
|
+
return new Uint8Array(encode({ ...blob, sig: new Uint8Array(ZERO_SIGNATURE_LENGTH) }));
|
|
48
|
+
}
|
|
49
|
+
async function signBlob(signer, body, opts = {}) {
|
|
50
|
+
const ipld = dagJsonToIpld(body);
|
|
51
|
+
const principal = new Uint8Array(await signer.getPublicKey());
|
|
52
|
+
const ts = opts.ts ?? Date.now();
|
|
53
|
+
const blob = { ...ipld };
|
|
54
|
+
if (opts.typeTag) blob.type = opts.typeTag;
|
|
55
|
+
blob.signer = principal;
|
|
56
|
+
blob.ts = ts;
|
|
57
|
+
blob.sig = new Uint8Array(await signer.sign(signedBlobMessage(blob)));
|
|
58
|
+
const data = new Uint8Array(encode(blob));
|
|
59
|
+
const digest = await sha256.digest(data);
|
|
60
|
+
return { cid: CID.createV1(code, digest).toString(), data, ts, signer: principal };
|
|
61
|
+
}
|
|
62
|
+
async function publishSignedBlob(client, signer, body, opts = {}) {
|
|
63
|
+
const result = await signBlob(signer, body, opts);
|
|
64
|
+
const collision = findSeedIndexerCollision(result.data);
|
|
65
|
+
if (collision) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`This blob can't be published: its "type" collides with the built-in Seed "${collision}" blob type but does not match its shape. Use a different type tag.`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
await client.request("PublishBlobs", { blobs: [{ cid: result.cid, data: result.data }] });
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
function hasSignedEnvelope(value) {
|
|
74
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && SIGNED_BLOB_ENVELOPE.every((k) => k in value);
|
|
75
|
+
}
|
|
76
|
+
function principalToPublicKey(principal) {
|
|
77
|
+
if (principal.length !== 34 || principal[0] !== 237 || principal[1] !== 1) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`Unsupported principal: expected an Ed25519 multicodec key (34 bytes), got ${principal.length} bytes`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return principal.slice(2);
|
|
83
|
+
}
|
|
84
|
+
async function verifySignedBlob(value) {
|
|
85
|
+
const ipld = dagJsonToIpld(value);
|
|
86
|
+
const signer = ipld.signer;
|
|
87
|
+
const sig = ipld.sig;
|
|
88
|
+
if (!(signer instanceof Uint8Array)) return { ok: false, signer: "", reason: "signer is not bytes" };
|
|
89
|
+
const signerId = base58btc.encode(signer);
|
|
90
|
+
if (!(sig instanceof Uint8Array)) return { ok: false, signer: signerId, reason: "sig is not bytes" };
|
|
91
|
+
let publicKey;
|
|
92
|
+
try {
|
|
93
|
+
publicKey = principalToPublicKey(signer);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return { ok: false, signer: signerId, reason: error.message };
|
|
96
|
+
}
|
|
97
|
+
const ts = typeof ipld.ts === "number" ? ipld.ts : void 0;
|
|
98
|
+
try {
|
|
99
|
+
const ok = ed25519.verify(sig, signedBlobMessage(ipld), publicKey);
|
|
100
|
+
return ok ? { ok, signer: signerId, ts } : { ok, signer: signerId, ts, reason: "signature does not verify" };
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return { ok: false, signer: signerId, ts, reason: error.message };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function encodeDagCbor(value) {
|
|
106
|
+
const data = new Uint8Array(encode(dagJsonToIpld(value)));
|
|
107
|
+
const digest = await sha256.digest(data);
|
|
108
|
+
return { data, cid: CID.createV1(code, digest).toString() };
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
SIGNED_BLOB_ENVELOPE,
|
|
112
|
+
ZERO_SIGNATURE_LENGTH,
|
|
113
|
+
encodeDagCbor,
|
|
114
|
+
hasSignedEnvelope,
|
|
115
|
+
isSignedBlobSchema,
|
|
116
|
+
principalToPublicKey,
|
|
117
|
+
publishSignedBlob,
|
|
118
|
+
signBlob,
|
|
119
|
+
signedBlobMessage,
|
|
120
|
+
signedBlobTypeTag,
|
|
121
|
+
stripSignedBlobEnvelope,
|
|
122
|
+
verifySignedBlob
|
|
123
|
+
};
|
package/dist/tei-to-blocks.mjs
CHANGED
package/dist/unicode.mjs
CHANGED