@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,348 @@
1
+ import {
2
+ AnnotationSet
3
+ } from "./chunk-N3P7S5YZ.mjs";
4
+ import {
5
+ HMBlockButtonAlignmentSchema,
6
+ HMBlockSchema,
7
+ codePointLength,
8
+ toNumber
9
+ } from "./chunk-SQEUO7FO.mjs";
10
+
11
+ // src/editorblock-to-hmblock.ts
12
+ function toHMBlockType(editorBlockType) {
13
+ if (editorBlockType === "heading") return "Heading";
14
+ if (editorBlockType === "paragraph") return "Paragraph";
15
+ if (editorBlockType === "code-block") return "Code";
16
+ if (editorBlockType === "math") return "Math";
17
+ if (editorBlockType === "image") return "Image";
18
+ if (editorBlockType === "video") return "Video";
19
+ if (editorBlockType === "file") return "File";
20
+ if (editorBlockType === "button") return "Button";
21
+ if (editorBlockType === "embed") return "Embed";
22
+ if (editorBlockType === "web-embed") return "WebEmbed";
23
+ if (editorBlockType === "query") return "Query";
24
+ if (editorBlockType === "table") return "Table";
25
+ if (editorBlockType === "tableRow") return "TableRow";
26
+ if (editorBlockType === "tableColumn") return "TableColumn";
27
+ return void 0;
28
+ }
29
+ function toImageWidthNumber(width) {
30
+ if (width == null ? void 0 : width.trim().endsWith("%")) {
31
+ const percentage = Number(width.trim().slice(0, -1));
32
+ return Number.isFinite(percentage) && percentage > 0 ? percentage : null;
33
+ }
34
+ if (width == null || width === "") return null;
35
+ return toNumber(width);
36
+ }
37
+ function unknownEditorBlockToHMBlock(editorBlock) {
38
+ const props = editorBlock.props ?? {};
39
+ if (props.originalData) {
40
+ try {
41
+ const parsed = JSON.parse(props.originalData);
42
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
43
+ return { ...parsed, id: editorBlock.id };
44
+ }
45
+ } catch {
46
+ }
47
+ }
48
+ return {
49
+ id: editorBlock.id,
50
+ type: props.originalType || "unknown",
51
+ text: "",
52
+ annotations: [],
53
+ attributes: {}
54
+ };
55
+ }
56
+ function editorBlockToHMBlock(editorBlock) {
57
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
58
+ if (editorBlock.type === "unknown") {
59
+ return unknownEditorBlockToHMBlock(editorBlock);
60
+ }
61
+ const blockType = toHMBlockType(editorBlock.type);
62
+ if (!blockType) throw new Error("Unsupported block type " + editorBlock.type);
63
+ let block = {
64
+ id: normalizeEditorBlockId(editorBlock.id),
65
+ type: blockType,
66
+ attributes: {},
67
+ text: "",
68
+ annotations: []
69
+ };
70
+ let leaves = flattenLeaves(editorBlock.content);
71
+ if (editorBlock.props.childrenType == "Group") {
72
+ block.attributes.childrenType = "Group";
73
+ } else if (editorBlock.props.childrenType == "Unordered") {
74
+ block.attributes.childrenType = "Unordered";
75
+ } else if (editorBlock.props.childrenType == "Ordered") {
76
+ block.attributes.childrenType = "Ordered";
77
+ } else if (editorBlock.props.childrenType == "Blockquote") {
78
+ block.attributes.childrenType = "Blockquote";
79
+ } else if (editorBlock.props.childrenType == "Grid") {
80
+ block.attributes.childrenType = "Grid";
81
+ if (editorBlock.props.columnCount) {
82
+ block.attributes.columnCount = Number(editorBlock.props.columnCount);
83
+ }
84
+ }
85
+ const annotations = new AnnotationSet();
86
+ let pos = 0;
87
+ for (let leaf of leaves) {
88
+ const start = pos;
89
+ const charCount = codePointLength(leaf.text);
90
+ const end = start + charCount;
91
+ if ((_a = leaf.styles) == null ? void 0 : _a.bold) {
92
+ annotations.addSpan("Bold", null, start, end);
93
+ }
94
+ if ((_b = leaf.styles) == null ? void 0 : _b.italic) {
95
+ annotations.addSpan("Italic", null, start, end);
96
+ }
97
+ if ((_c = leaf.styles) == null ? void 0 : _c.underline) {
98
+ annotations.addSpan("Underline", null, start, end);
99
+ }
100
+ if ((_d = leaf.styles) == null ? void 0 : _d.strike) {
101
+ annotations.addSpan("Strike", null, start, end);
102
+ }
103
+ if ((_e = leaf.styles) == null ? void 0 : _e.code) {
104
+ annotations.addSpan("Code", null, start, end);
105
+ }
106
+ if ((_f = leaf.styles) == null ? void 0 : _f.math) {
107
+ annotations.addSpan("Math", null, start, end);
108
+ }
109
+ if (leaf.type == "inline-embed") {
110
+ annotations.addSpan("Embed", { link: leaf.link }, start, end);
111
+ }
112
+ if (leaf.type == "link") {
113
+ annotations.addSpan("Link", { link: leaf.href }, start, end);
114
+ }
115
+ if ((_g = leaf.styles) == null ? void 0 : _g.textColor) {
116
+ annotations.addSpan("TextColor", { value: leaf.styles.textColor }, start, end);
117
+ }
118
+ if ((_h = leaf.styles) == null ? void 0 : _h.backgroundColor) {
119
+ annotations.addSpan("BackgroundColor", { value: leaf.styles.backgroundColor }, start, end);
120
+ }
121
+ if ((_i = leaf.styles) == null ? void 0 : _i.textSize) {
122
+ annotations.addSpan("TextSize", { value: leaf.styles.textSize }, start, end);
123
+ }
124
+ if ((_j = leaf.styles) == null ? void 0 : _j.textFamily) {
125
+ annotations.addSpan("TextFamily", { value: leaf.styles.textFamily }, start, end);
126
+ }
127
+ block.text += leaf.text;
128
+ pos += charCount;
129
+ }
130
+ let outAnnotations = annotations.list();
131
+ if (outAnnotations) {
132
+ block.annotations = outAnnotations;
133
+ }
134
+ const blockCode = block.type === "Code" ? block : void 0;
135
+ if (blockCode && editorBlock.type == "code-block") {
136
+ blockCode.attributes.language = editorBlock.props.language;
137
+ }
138
+ const blockImage = block.type === "Image" ? block : void 0;
139
+ if (blockImage && editorBlock.type == "image") {
140
+ if (editorBlock.props.url && !editorBlock.props.mediaRef) {
141
+ blockImage.link = editorBlock.props.url;
142
+ } else if (editorBlock.props.mediaRef) {
143
+ blockImage.link = "";
144
+ } else if (editorBlock.props.displaySrc) {
145
+ blockImage.link = editorBlock.props.displaySrc;
146
+ } else if (editorBlock.props.src) {
147
+ blockImage.link = editorBlock.props.src;
148
+ } else {
149
+ blockImage.link = "";
150
+ }
151
+ const width = toImageWidthNumber(editorBlock.props.width);
152
+ if (width) {
153
+ blockImage.attributes.width = width;
154
+ }
155
+ }
156
+ const blockVideo = block.type === "Video" ? block : void 0;
157
+ if (blockVideo && editorBlock.type == "video") {
158
+ blockVideo.text = "";
159
+ if (editorBlock.props.url && !editorBlock.props.mediaRef) {
160
+ blockVideo.link = editorBlock.props.url;
161
+ } else if (editorBlock.props.mediaRef) {
162
+ blockVideo.link = "";
163
+ }
164
+ if (editorBlock.props.width != null && editorBlock.props.width !== "") {
165
+ const width = toNumber(editorBlock.props.width);
166
+ if (width) blockVideo.attributes.width = width;
167
+ }
168
+ if (editorBlock.props.name) {
169
+ blockVideo.attributes.name = editorBlock.props.name;
170
+ }
171
+ if (editorBlock.props.autoplay === "true") {
172
+ blockVideo.attributes.autoplay = true;
173
+ }
174
+ if (editorBlock.props.loop === "true") {
175
+ blockVideo.attributes.loop = true;
176
+ }
177
+ if (editorBlock.props.muted === "true") {
178
+ blockVideo.attributes.muted = true;
179
+ }
180
+ }
181
+ const blockFile = block.type === "File" ? block : void 0;
182
+ if (blockFile && editorBlock.type == "file") {
183
+ if (editorBlock.props.url && !editorBlock.props.mediaRef) {
184
+ blockFile.link = editorBlock.props.url;
185
+ } else if (editorBlock.props.mediaRef) {
186
+ blockFile.link = "";
187
+ }
188
+ if (editorBlock.props.name) blockFile.attributes.name = editorBlock.props.name;
189
+ if (editorBlock.props.size != null && editorBlock.props.size !== "") {
190
+ const size = toNumber(editorBlock.props.size);
191
+ if (size) blockFile.attributes.size = size;
192
+ }
193
+ }
194
+ const blockButton = block.type === "Button" ? block : void 0;
195
+ if (blockButton && editorBlock.type == "button") {
196
+ if (editorBlock.props.url) blockButton.link = editorBlock.props.url;
197
+ if (editorBlock.props.name) blockButton.attributes.name = editorBlock.props.name;
198
+ if (editorBlock.props.alignment)
199
+ blockButton.attributes.alignment = HMBlockButtonAlignmentSchema.parse(editorBlock.props.alignment);
200
+ }
201
+ const blockWebEmbed = block.type === "WebEmbed" ? block : void 0;
202
+ if (blockWebEmbed && editorBlock.type == "web-embed" && editorBlock.props.url) {
203
+ blockWebEmbed.link = editorBlock.props.url;
204
+ }
205
+ const blockEmbed = block.type === "Embed" ? block : void 0;
206
+ if (blockEmbed && editorBlock.type == "embed") {
207
+ block.text = "";
208
+ if (editorBlock.props.url) blockEmbed.link = editorBlock.props.url;
209
+ if (editorBlock.props.view) blockEmbed.attributes.view = editorBlock.props.view;
210
+ }
211
+ const blockParagraph = block.type === "Paragraph" ? block : void 0;
212
+ if (blockParagraph && editorBlock.type == "paragraph") {
213
+ if (editorBlock.props.columnId) {
214
+ blockParagraph.attributes.columnId = editorBlock.props.columnId;
215
+ }
216
+ }
217
+ const blockTable = block.type === "Table" ? block : void 0;
218
+ if (blockTable && editorBlock.type == "table") {
219
+ blockTable.text = "";
220
+ }
221
+ const blockTableRow = block.type === "TableRow" ? block : void 0;
222
+ if (blockTableRow && editorBlock.type == "tableRow") {
223
+ blockTableRow.text = "";
224
+ if (editorBlock.props.isHeader) blockTableRow.attributes.isHeader = true;
225
+ }
226
+ const blockTableColumn = block.type === "TableColumn" ? block : void 0;
227
+ if (blockTableColumn && editorBlock.type == "tableColumn") {
228
+ blockTableColumn.text = "";
229
+ if (editorBlock.props.width != null && editorBlock.props.width !== "") {
230
+ const width = toNumber(editorBlock.props.width);
231
+ if (width) blockTableColumn.attributes.width = width;
232
+ }
233
+ if (editorBlock.props.isHeader) blockTableColumn.attributes.isHeader = true;
234
+ }
235
+ const blockQuery = block.type === "Query" ? block : void 0;
236
+ if (blockQuery && editorBlock.type == "query") {
237
+ blockQuery.attributes.style = editorBlock.props.style;
238
+ blockQuery.attributes.columnCount = Number(editorBlock.props.columnCount);
239
+ const query = {
240
+ includes: [],
241
+ sort: []
242
+ };
243
+ if (editorBlock.props.queryIncludes) query.includes = JSON.parse(editorBlock.props.queryIncludes);
244
+ if (editorBlock.props.querySort) query.sort = JSON.parse(editorBlock.props.querySort);
245
+ if (editorBlock.props.queryLimit) query.limit = Number(editorBlock.props.queryLimit);
246
+ blockQuery.attributes.query = query;
247
+ blockQuery.attributes.banner = editorBlock.props.banner == "true";
248
+ if (editorBlock.props.tableConfig) blockQuery.attributes.table = JSON.parse(editorBlock.props.tableConfig);
249
+ }
250
+ const blockParse = HMBlockSchema.safeParse(block);
251
+ if (blockParse.success) {
252
+ return blockParse.data;
253
+ }
254
+ const failedParse = blockParse;
255
+ console.error("Failed to validate block for writing", block, failedParse.error);
256
+ throw new Error("Failed to validate block for writing " + JSON.stringify(failedParse.error));
257
+ }
258
+ function editorBlocksToHMBlockNodes(editorBlocks, parentEditorType) {
259
+ const parentIsTable = parentEditorType === "table";
260
+ let rowIdx = 0;
261
+ let colIdx = 0;
262
+ return editorBlocks.filter((block) => {
263
+ if ((block.type === "tableRow" || block.type === "tableColumn") && !parentIsTable) {
264
+ console.warn(
265
+ `[editorBlocksToHMBlockNodes] dropping orphan ${block.type} block (parent type: ${parentEditorType ?? "root"})`,
266
+ block.id
267
+ );
268
+ return false;
269
+ }
270
+ return true;
271
+ }).map((block) => {
272
+ var _a, _b, _c;
273
+ let positionIdx;
274
+ if (parentIsTable) {
275
+ if (block.type === "tableRow") positionIdx = rowIdx++;
276
+ else if (block.type === "tableColumn") positionIdx = colIdx++;
277
+ }
278
+ let hmNode;
279
+ try {
280
+ hmNode = {
281
+ block: editorBlockToHMBlock(block),
282
+ children: ((_a = block.children) == null ? void 0 : _a.length) ? editorBlocksToHMBlockNodes(block.children, block.type) : void 0
283
+ };
284
+ } catch {
285
+ hmNode = {
286
+ block: {
287
+ id: block.id || "unknown",
288
+ type: "Paragraph",
289
+ text: `[Unsupported block type: ${block.type}]`,
290
+ annotations: [],
291
+ attributes: {}
292
+ },
293
+ children: ((_b = block.children) == null ? void 0 : _b.length) ? editorBlocksToHMBlockNodes(block.children, block.type) : void 0
294
+ };
295
+ }
296
+ if (positionIdx !== void 0 && positionIdx > 0) {
297
+ const attrs = (_c = hmNode.block) == null ? void 0 : _c.attributes;
298
+ if (attrs && "isHeader" in attrs) {
299
+ delete attrs.isHeader;
300
+ }
301
+ }
302
+ return hmNode;
303
+ }).filter(Boolean);
304
+ }
305
+ function flattenLeaves(content) {
306
+ let result = [];
307
+ for (let i = 0; i < content.length; i++) {
308
+ const leaf = content[i];
309
+ if (!leaf) continue;
310
+ if (leaf.type == "link") {
311
+ let nestedLeaves = flattenLeaves(leaf.content).map(
312
+ (l) => ({
313
+ ...l,
314
+ href: leaf.href,
315
+ type: "link"
316
+ })
317
+ );
318
+ result.push(...nestedLeaves);
319
+ }
320
+ if (leaf.type == "inline-embed") {
321
+ result.push({
322
+ ...leaf,
323
+ text: "\uFFFC",
324
+ link: leaf.link
325
+ });
326
+ }
327
+ if (leaf.type == "text") {
328
+ result.push(leaf);
329
+ }
330
+ }
331
+ return result;
332
+ }
333
+ function normalizeEditorBlockId(id) {
334
+ return id && id !== "empty" ? id : generateBlockId();
335
+ }
336
+ function generateBlockId(length = 8) {
337
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
338
+ let result = "";
339
+ for (let i = 0; i < length; i++) {
340
+ result += characters.charAt(Math.floor(Math.random() * characters.length));
341
+ }
342
+ return result;
343
+ }
344
+
345
+ export {
346
+ editorBlockToHMBlock,
347
+ editorBlocksToHMBlockNodes
348
+ };
@@ -0,0 +1,124 @@
1
+ import {
2
+ signObject,
3
+ toPublishInput
4
+ } from "./chunk-YZX54L3G.mjs";
5
+
6
+ // src/contact.ts
7
+ import { decode as cborDecode, encode as cborEncode } from "@ipld/dag-cbor";
8
+ import { base58btc } from "multiformats/bases/base58";
9
+ function extractTsid(contactId) {
10
+ const parts = contactId.split("/");
11
+ const tsid = parts[1];
12
+ if (!tsid) {
13
+ throw new Error(`Invalid contact ID format: ${contactId}. Expected "authority/tsid".`);
14
+ }
15
+ return tsid;
16
+ }
17
+ function extractAuthority(contactId) {
18
+ const parts = contactId.split("/");
19
+ const authority = parts[0];
20
+ if (!authority || parts.length !== 2) {
21
+ throw new Error(`Invalid contact ID format: ${contactId}. Expected "authority/tsid".`);
22
+ }
23
+ return authority;
24
+ }
25
+ async function computeTSID(timestampMs, blobData) {
26
+ const buf = new ArrayBuffer(8);
27
+ new DataView(buf).setBigUint64(0, timestampMs, false);
28
+ const tsBytes = new Uint8Array(buf, 2, 6);
29
+ const hashBuffer = await crypto.subtle.digest("SHA-256", blobData);
30
+ const hashBytes = new Uint8Array(hashBuffer, 0, 4);
31
+ const tsidBytes = new Uint8Array(10);
32
+ tsidBytes.set(tsBytes, 0);
33
+ tsidBytes.set(hashBytes, 6);
34
+ return base58btc.encode(tsidBytes);
35
+ }
36
+ async function createContact(input, signer) {
37
+ const signerKey = await signer.getPublicKey();
38
+ const ts = BigInt(Date.now());
39
+ const signerUid = base58btc.encode(new Uint8Array(signerKey));
40
+ const authority = input.accountUid || signerUid;
41
+ const unsigned = {
42
+ type: "Contact",
43
+ signer: new Uint8Array(signerKey),
44
+ sig: new Uint8Array(64),
45
+ ts,
46
+ subject: new Uint8Array(base58btc.decode(input.subjectUid))
47
+ };
48
+ if (input.name) {
49
+ unsigned.name = input.name;
50
+ }
51
+ if (input.accountUid) {
52
+ unsigned.account = new Uint8Array(base58btc.decode(input.accountUid));
53
+ }
54
+ if (input.subscribe) {
55
+ unsigned.subscribe = input.subscribe;
56
+ }
57
+ unsigned.sig = await signObject(signer, unsigned);
58
+ const encoded = cborEncode(unsigned);
59
+ const tsid = await computeTSID(ts, encoded);
60
+ return {
61
+ ...toPublishInput(encoded),
62
+ recordId: `${authority}/${tsid}`
63
+ };
64
+ }
65
+ async function updateContact(input, signer) {
66
+ const signerKey = await signer.getPublicKey();
67
+ const tsid = extractTsid(input.contactId);
68
+ const accountUid = input.accountUid || extractAuthority(input.contactId);
69
+ const unsigned = {
70
+ type: "Contact",
71
+ signer: new Uint8Array(signerKey),
72
+ sig: new Uint8Array(64),
73
+ ts: BigInt(Date.now()),
74
+ id: tsid,
75
+ subject: new Uint8Array(base58btc.decode(input.subjectUid))
76
+ };
77
+ if (input.name) {
78
+ unsigned.name = input.name;
79
+ }
80
+ if (accountUid) {
81
+ unsigned.account = new Uint8Array(base58btc.decode(accountUid));
82
+ }
83
+ if (input.subscribe) {
84
+ unsigned.subscribe = input.subscribe;
85
+ }
86
+ unsigned.sig = await signObject(signer, unsigned);
87
+ return toPublishInput(cborEncode(unsigned));
88
+ }
89
+ async function deleteContact(input, signer) {
90
+ const signerKey = await signer.getPublicKey();
91
+ const tsid = extractTsid(input.contactId);
92
+ const accountUid = input.accountUid || extractAuthority(input.contactId);
93
+ const unsigned = {
94
+ type: "Contact",
95
+ signer: new Uint8Array(signerKey),
96
+ sig: new Uint8Array(64),
97
+ ts: BigInt(Date.now()),
98
+ id: tsid
99
+ };
100
+ if (accountUid) {
101
+ unsigned.account = new Uint8Array(base58btc.decode(accountUid));
102
+ }
103
+ unsigned.sig = await signObject(signer, unsigned);
104
+ return toPublishInput(cborEncode(unsigned));
105
+ }
106
+ async function contactRecordIdFromBlob(blobData) {
107
+ const decoded = cborDecode(blobData);
108
+ if (decoded.type !== "Contact") {
109
+ throw new Error(`Expected Contact blob, got "${decoded.type}"`);
110
+ }
111
+ const signerBytes = decoded.signer;
112
+ const ts = BigInt(decoded.ts);
113
+ const accountBytes = decoded.account;
114
+ const authority = base58btc.encode(new Uint8Array(accountBytes || signerBytes));
115
+ const tsid = await computeTSID(ts, blobData);
116
+ return `${authority}/${tsid}`;
117
+ }
118
+
119
+ export {
120
+ createContact,
121
+ updateContact,
122
+ deleteContact,
123
+ contactRecordIdFromBlob
124
+ };