@seed-hypermedia/client 0.0.68 → 0.0.70

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 (84) hide show
  1. package/LICENSE +201 -0
  2. package/dist/auth.d.ts +79 -0
  3. package/dist/auth.mjs +266 -0
  4. package/dist/auto-link.d.ts +3 -2
  5. package/dist/auto-link.mjs +21 -0
  6. package/dist/base64.mjs +9 -0
  7. package/dist/blobs.d.ts +170 -0
  8. package/dist/blobs.mjs +51 -0
  9. package/dist/block-diff.mjs +17 -0
  10. package/dist/blocks-to-markdown.mjs +22 -0
  11. package/dist/capability.d.ts +7 -2
  12. package/dist/capability.mjs +14 -0
  13. package/dist/cbor.d.ts +13 -0
  14. package/dist/cbor.mjs +13 -0
  15. package/dist/change.d.ts +8 -7
  16. package/dist/change.mjs +24 -0
  17. package/dist/chunk-2MD3FXKB.mjs +14 -0
  18. package/dist/chunk-37WRGUK4.mjs +125 -0
  19. package/dist/chunk-3KESF5XJ.mjs +297 -0
  20. package/dist/chunk-3TPCJCVO.mjs +24 -0
  21. package/dist/chunk-4Q3SAL5R.mjs +75 -0
  22. package/dist/chunk-52P3E6H6.mjs +459 -0
  23. package/dist/chunk-BUPMCRR4.mjs +48 -0
  24. package/dist/chunk-CBELM7KX.mjs +29 -0
  25. package/dist/{chunk-KCR3277A.mjs → chunk-DBHL3BYB.mjs} +9 -14
  26. package/dist/chunk-DR3HJ6BV.mjs +25 -0
  27. package/dist/chunk-EU36RFR3.mjs +159 -0
  28. package/dist/chunk-EY6RQVAP.mjs +138 -0
  29. package/dist/chunk-H7L4TI6X.mjs +705 -0
  30. package/dist/chunk-HBIVZA6C.mjs +102 -0
  31. package/dist/chunk-IT5LLTMP.mjs +209 -0
  32. package/dist/chunk-JT57MV7Y.mjs +136 -0
  33. package/dist/chunk-KO4XH5L2.mjs +475 -0
  34. package/dist/chunk-LVAHHQIK.mjs +41 -0
  35. package/dist/chunk-LYECQKZE.mjs +49 -0
  36. package/dist/chunk-N3P7S5YZ.mjs +118 -0
  37. package/dist/chunk-NPG76WUS.mjs +348 -0
  38. package/dist/chunk-NYWCMQTH.mjs +412 -0
  39. package/dist/chunk-OZKQOI2X.mjs +334 -0
  40. package/dist/chunk-PJ2RFT5A.mjs +113 -0
  41. package/dist/chunk-PPAY4WZX.mjs +40 -0
  42. package/dist/chunk-S2PVJK2P.mjs +517 -0
  43. package/dist/chunk-SHOAYNJY.mjs +289 -0
  44. package/dist/chunk-T5BTAJPW.mjs +725 -0
  45. package/dist/{chunk-EGCUJ6D6.mjs → chunk-UOL3F6XQ.mjs} +0 -12
  46. package/dist/chunk-VN7F33SS.mjs +108 -0
  47. package/dist/chunk-YNVFRCUH.mjs +171 -0
  48. package/dist/client.d.ts +3 -2
  49. package/dist/client.mjs +15 -0
  50. package/dist/comment.d.ts +5 -4
  51. package/dist/comment.mjs +19 -0
  52. package/dist/contact.d.ts +5 -4
  53. package/dist/contact.mjs +15 -0
  54. package/dist/document-state.mjs +8 -0
  55. package/dist/editor-types.mjs +0 -0
  56. package/dist/editorblock-to-hmblock.mjs +11 -0
  57. package/dist/encryption.mjs +13 -0
  58. package/dist/errors.mjs +11 -0
  59. package/dist/file-to-ipfs.mjs +13 -0
  60. package/dist/grobid.mjs +11 -0
  61. package/dist/hm-resolver.mjs +10 -0
  62. package/dist/hmauth.d.ts +169 -0
  63. package/dist/hmauth.mjs +53 -0
  64. package/dist/hmblock-to-editorblock.mjs +12 -0
  65. package/dist/index.d.ts +2 -0
  66. package/dist/index.mjs +132 -5453
  67. package/dist/keyfile.mjs +19 -0
  68. package/dist/markdown-to-blocks.mjs +15 -0
  69. package/dist/pdf-to-blocks-embedded.mjs +7 -0
  70. package/dist/pdf-to-blocks.mjs +11 -0
  71. package/dist/ref.d.ts +5 -4
  72. package/dist/ref.mjs +13 -0
  73. package/dist/resource-read.mjs +15 -0
  74. package/dist/signer.d.ts +42 -0
  75. package/dist/signer.mjs +9 -0
  76. package/dist/signing.d.ts +10 -2
  77. package/dist/signing.mjs +16 -0
  78. package/dist/tei-to-blocks.mjs +8 -0
  79. package/dist/unicode.mjs +19 -0
  80. package/dist/vault-local.mjs +10 -6
  81. package/dist/vault.d.ts +14 -4
  82. package/dist/vault.mjs +6 -2
  83. package/package.json +18 -28
  84. package/src/index.ts +0 -144
@@ -0,0 +1,170 @@
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
+ import { type AnySigner } from './signer';
11
+ export type { AnySigner };
12
+ export declare const ED25519_VARINT_PREFIX: Uint8Array<ArrayBuffer>;
13
+ export declare const ED25519_SIGNATURE_SIZE = 64;
14
+ export declare const ED25519_PUBLIC_KEY_SIZE = 32;
15
+ export declare const ED25519_PRINCIPAL_SIZE: number;
16
+ /** Packed binary public key: `<multicodec-varint><raw-key-bytes>`. */
17
+ export type Principal = Uint8Array;
18
+ /** Cryptographic signature bytes. */
19
+ export type Signature = Uint8Array;
20
+ /** Unix timestamp in milliseconds. */
21
+ export type Timestamp = number;
22
+ /** Role values for capability blobs. */
23
+ export type Role = 'WRITER' | 'AGENT';
24
+ /** Signs data and produces a cryptographic signature. */
25
+ export interface Signer {
26
+ readonly principal: Principal;
27
+ sign(data: Uint8Array): Promise<Signature>;
28
+ }
29
+ /** Verifies a signature against data. */
30
+ export interface Verifier {
31
+ verify(data: Uint8Array, sig: Signature): Promise<boolean>;
32
+ }
33
+ /**
34
+ * Ed25519 key pair using @noble/curves. Stores the raw 32-byte private key seed,
35
+ * suitable for vault keys that need to persist the seed in encrypted storage.
36
+ */
37
+ export declare class NobleKeyPair implements Signer {
38
+ readonly principal: Principal;
39
+ readonly publicKey: Uint8Array;
40
+ /** Raw 32-byte Ed25519 private key seed. Needed for vault storage. */
41
+ readonly seed: Uint8Array;
42
+ constructor(seed: Uint8Array);
43
+ sign(data: Uint8Array): Promise<Signature>;
44
+ }
45
+ /** Generate a random Ed25519 key pair with an accessible raw seed. */
46
+ export declare function generateNobleKeyPair(): NobleKeyPair;
47
+ /** Restore a NobleKeyPair from a stored 32-byte seed. */
48
+ export declare function nobleKeyPairFromSeed(seed: Uint8Array): NobleKeyPair;
49
+ /**
50
+ * Ed25519 key pair using Web Crypto. The private key is **non-exportable**,
51
+ * suitable for browser session keys that must not leave the browser's crypto subsystem.
52
+ */
53
+ export declare class WebCryptoKeyPair implements Signer {
54
+ readonly principal: Principal;
55
+ readonly publicKey: Uint8Array;
56
+ /** The Web Crypto key pair. Exposed for LocalWebIdentity compatibility. */
57
+ readonly keyPair: CryptoKeyPair;
58
+ constructor(keyPair: CryptoKeyPair, publicKeyRaw: Uint8Array);
59
+ sign(data: Uint8Array): Promise<Signature>;
60
+ }
61
+ /** Generate a random Ed25519 key pair with an unexportable private key. */
62
+ export declare function generateWebCryptoKeyPair(): Promise<WebCryptoKeyPair>;
63
+ /**
64
+ * Verify the signature of a blob against its embedded signer Principal.
65
+ * Uses @noble/curves/ed25519 directly — works with any blob regardless of how it was signed.
66
+ */
67
+ export declare function verify(blob: Blob): boolean;
68
+ /** Create a Principal from a raw Ed25519 public key (32 bytes). */
69
+ export declare function principalFromEd25519(rawPublicKey: Uint8Array): Principal;
70
+ /** Encode a Principal to its base58btc multibase string (starts with 'z'). */
71
+ export declare function principalToString(p: Principal): string;
72
+ /** Decode a Principal from its base58btc multibase string. */
73
+ export declare function principalFromString(s: string): Principal;
74
+ /** Check if two Principals are equal. */
75
+ export declare function principalEqual(a: Principal, b: Principal): boolean;
76
+ /** Open-ended base blob shape. Any blob type can be signed and verified through this interface. */
77
+ export interface Blob {
78
+ readonly type: string;
79
+ readonly signer: Principal;
80
+ readonly sig: Signature;
81
+ readonly ts: Timestamp;
82
+ readonly [key: string]: unknown;
83
+ }
84
+ /** Profile blob representing user identity information. */
85
+ export interface Profile extends Blob {
86
+ readonly type: 'Profile';
87
+ /** Points to another key acting as an identity redirect. */
88
+ readonly alias?: Principal;
89
+ /** Display name for the profile. */
90
+ readonly name?: string;
91
+ /** Icon/avatar URI (wire key is "avatar" for legacy compatibility with Go). */
92
+ readonly avatar?: string;
93
+ /** Short text description. */
94
+ readonly description?: string;
95
+ /** Account principal when signed by an agent key on behalf of the account. */
96
+ readonly account?: Principal;
97
+ }
98
+ /** Create a signed and encoded Profile blob. */
99
+ export declare function createProfile(anySigner: AnySigner, opts: {
100
+ /** Display name (required for non-alias profiles). */
101
+ name: string;
102
+ /** Icon/avatar URI. */
103
+ avatar?: string;
104
+ /** Short text description. */
105
+ description?: string;
106
+ /** Account principal. Omitted from encoding if it equals the signer. */
107
+ account?: Principal;
108
+ }, ts: Timestamp): Promise<Encoded<Profile>>;
109
+ /** Create a signed and encoded alias Profile blob (identity redirect). */
110
+ export declare function createProfileAlias(anySigner: AnySigner, alias: Principal, ts: Timestamp): Promise<Encoded<Profile>>;
111
+ /** Capability blob granting rights from issuer to delegate. */
112
+ export interface Capability extends Blob {
113
+ readonly type: 'Capability';
114
+ /** Public key receiving the delegation. */
115
+ readonly delegate: Principal;
116
+ /** For direct authentication against another principal. */
117
+ readonly audience?: Principal;
118
+ /** Path scope for the capability. */
119
+ readonly path?: string;
120
+ /** Access role being granted. */
121
+ readonly role: Role;
122
+ /** Human-readable label. */
123
+ readonly label?: string;
124
+ }
125
+ /** Create a signed and encoded Capability blob. */
126
+ export declare function createCapability(anyIssuer: AnySigner, delegate: Principal, role: Role, ts: Timestamp, opts?: {
127
+ /** Path scope. */
128
+ path?: string;
129
+ /** Human-readable label. */
130
+ label?: string;
131
+ /** Audience principal for direct auth. */
132
+ audience?: Principal;
133
+ }): Promise<Encoded<Capability>>;
134
+ /** A decoded blob stored alongside its content-addressed CID. */
135
+ export interface Decoded<T extends Blob> {
136
+ readonly cid: CID;
137
+ readonly decoded: T;
138
+ }
139
+ /** A blob with its CID and decoded + encoded data. */
140
+ export interface Encoded<T extends Blob> extends Decoded<T> {
141
+ readonly data: Uint8Array;
142
+ }
143
+ /**
144
+ * Sign a blob with a Signer.
145
+ * Fills sig with zeros, CBOR-encodes, signs, replaces sig.
146
+ */
147
+ export declare function sign<T extends Blob>(signer: AnySigner, blob: T): Promise<T>;
148
+ /** Encode a signed blob to DAG-CBOR and compute its content-addressed CID. */
149
+ export declare function encode<T extends Blob>(blob: T): Encoded<T>;
150
+ /**
151
+ * Decode raw CBOR bytes into a blob, verifying the CID matches.
152
+ * Throws if the recomputed CID doesn't match the expected one.
153
+ */
154
+ export declare function decodeBlob<T extends Blob>(data: Uint8Array, expectedCid: CID): Encoded<T>;
155
+ /**
156
+ * @deprecated Use `NobleKeyPair` or `WebCryptoKeyPair` directly.
157
+ * Kept temporarily for consumers that haven't migrated yet.
158
+ */
159
+ export type KeyPair = Signer & {
160
+ readonly publicKey: Uint8Array;
161
+ readonly keyPair?: CryptoKeyPair;
162
+ };
163
+ /**
164
+ * @deprecated Use `generateNobleKeyPair()` instead.
165
+ */
166
+ export declare function generateKeyPair(): Promise<NobleKeyPair>;
167
+ /**
168
+ * @deprecated Use `nobleKeyPairFromSeed()` instead.
169
+ */
170
+ export declare function keyPairFromPrivateKey(rawPrivateKey: Uint8Array): Promise<NobleKeyPair>;
package/dist/blobs.mjs ADDED
@@ -0,0 +1,51 @@
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-IT5LLTMP.mjs";
25
+ import "./chunk-DR3HJ6BV.mjs";
26
+ import "./chunk-3TPCJCVO.mjs";
27
+ import "./chunk-7P6ASYW6.mjs";
28
+ export {
29
+ ED25519_PRINCIPAL_SIZE,
30
+ ED25519_PUBLIC_KEY_SIZE,
31
+ ED25519_SIGNATURE_SIZE,
32
+ ED25519_VARINT_PREFIX,
33
+ NobleKeyPair,
34
+ WebCryptoKeyPair,
35
+ createCapability,
36
+ createProfile,
37
+ createProfileAlias,
38
+ decodeBlob,
39
+ encode,
40
+ generateKeyPair,
41
+ generateNobleKeyPair,
42
+ generateWebCryptoKeyPair,
43
+ keyPairFromPrivateKey,
44
+ nobleKeyPairFromSeed,
45
+ principalEqual,
46
+ principalFromEd25519,
47
+ principalFromString,
48
+ principalToString,
49
+ sign,
50
+ verify
51
+ };
@@ -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
+ };
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Capability SDK — create and resolve capabilities (delegate access to other accounts).
3
3
  */
4
- import type { HMPublishBlobsInput, HMSigner } from './hm-types';
4
+ import type { HMPublishBlobsInput } from './hm-types';
5
+ import type { AnySigner } from './signer';
5
6
  import type { SeedClient } from './client';
6
7
  /** Role values for capability blobs. */
7
8
  export type CapabilityRole = 'WRITER' | 'AGENT';
@@ -18,8 +19,12 @@ export type CreateCapabilityInput = {
18
19
  /**
19
20
  * Create a signed capability blob ready for publishing.
20
21
  * The signer is the issuer granting access to the delegate.
22
+ *
23
+ * Wraps the blob primitive in `./blobs`, which is the single implementation of
24
+ * the Capability wire format; this adds the string-keyed input shape and the
25
+ * publish envelope the rest of the SDK expects.
21
26
  */
22
- export declare function createCapability(input: CreateCapabilityInput, signer: HMSigner): Promise<HMPublishBlobsInput>;
27
+ export declare function createCapability(input: CreateCapabilityInput, signer: AnySigner): Promise<HMPublishBlobsInput>;
23
28
  /**
24
29
  * Find a WRITER or AGENT capability for `signerAccount` on `targetAccount`.
25
30
  * Returns the capability CID if found, undefined if not needed (same account) or not found.
@@ -0,0 +1,14 @@
1
+ import {
2
+ createCapability,
3
+ resolveCapability
4
+ } from "./chunk-BUPMCRR4.mjs";
5
+ import "./chunk-LVAHHQIK.mjs";
6
+ import "./chunk-IT5LLTMP.mjs";
7
+ import "./chunk-DR3HJ6BV.mjs";
8
+ import "./chunk-SQEUO7FO.mjs";
9
+ import "./chunk-3TPCJCVO.mjs";
10
+ import "./chunk-7P6ASYW6.mjs";
11
+ export {
12
+ createCapability,
13
+ resolveCapability
14
+ };
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
+ };
package/dist/change.d.ts CHANGED
@@ -7,8 +7,9 @@
7
7
  *
8
8
  * Convenience wrappers combine both steps for common use cases.
9
9
  */
10
- import type { HMPrepareDocumentChangeInput, HMPublishBlobsInput, HMSigner } from './hm-types';
10
+ import type { HMPrepareDocumentChangeInput, HMPublishBlobsInput } from './hm-types';
11
11
  import { CID } from 'multiformats';
12
+ import type { AnySigner } from './signer';
12
13
  export type DocumentOperation = {
13
14
  type: 'SetAttributes';
14
15
  attrs: Array<{
@@ -55,14 +56,14 @@ export declare function createChangeOps(input: CreateChangeOpsInput): {
55
56
  * 4. Sign the CBOR-encoded blob (with zeroed sig)
56
57
  * 5. Encode final blob and compute SHA256 CID
57
58
  */
58
- export declare function createChange(unsignedBytes: Uint8Array, signer: HMSigner): Promise<{
59
+ export declare function createChange(unsignedBytes: Uint8Array, signer: AnySigner): Promise<{
59
60
  bytes: Uint8Array;
60
61
  cid: CID;
61
62
  genesis: CID | null;
62
63
  ts: number | undefined;
63
64
  }>;
64
65
  /** @deprecated Use createChange instead */
65
- export declare const signPreparedChange: (unsignedBytes: Uint8Array, signer: HMSigner) => Promise<{
66
+ export declare const signPreparedChange: (unsignedBytes: Uint8Array, signer: AnySigner) => Promise<{
66
67
  signedBytes: Uint8Array;
67
68
  cid: CID;
68
69
  genesis: CID | null;
@@ -71,7 +72,7 @@ export declare const signPreparedChange: (unsignedBytes: Uint8Array, signer: HMS
71
72
  * Create a signed genesis Change blob (empty, ts=0).
72
73
  * This deterministic sentinel is only intended for home documents.
73
74
  */
74
- export declare function createGenesisChange(signer: HMSigner): Promise<{
75
+ export declare function createGenesisChange(signer: AnySigner): Promise<{
75
76
  bytes: Uint8Array;
76
77
  cid: CID;
77
78
  }>;
@@ -81,7 +82,7 @@ export type CreateDocumentChangeFromOpsInput = CreateChangeOpsInput;
81
82
  * Convenience: create unsigned ops + sign in one step.
82
83
  * @deprecated Use createChangeOps() + createChange() for the decoupled API.
83
84
  */
84
- export declare function createDocumentChangeFromOps(input: CreateChangeOpsInput, signer: HMSigner): Promise<{
85
+ export declare function createDocumentChangeFromOps(input: CreateChangeOpsInput, signer: AnySigner): Promise<{
85
86
  bytes: Uint8Array;
86
87
  cid: CID;
87
88
  ts: bigint;
@@ -100,7 +101,7 @@ export type CreateDocumentChangeInput = {
100
101
  * Create a signed document Change blob from proto-format changes.
101
102
  * Only supports setMetadata — for all ops, use createChangeOps + createChange.
102
103
  */
103
- export declare function createDocumentChange(input: CreateDocumentChangeInput, signer: HMSigner): Promise<{
104
+ export declare function createDocumentChange(input: CreateDocumentChangeInput, signer: AnySigner): Promise<{
104
105
  bytes: Uint8Array;
105
106
  cid: CID;
106
107
  }>;
@@ -131,7 +132,7 @@ export type SignDocumentChangeInput = {
131
132
  * Combines: createChange + createVersionRef into a single publish payload.
132
133
  * The caller is responsible for calling PrepareChange beforehand and submitting via publishBlobs.
133
134
  */
134
- export declare function signDocumentChange(input: SignDocumentChangeInput, signer: HMSigner): Promise<{
135
+ export declare function signDocumentChange(input: SignDocumentChangeInput, signer: AnySigner): Promise<{
135
136
  changeCid: CID;
136
137
  publishInput: HMPublishBlobsInput;
137
138
  }>;
@@ -0,0 +1,24 @@
1
+ import {
2
+ createChange,
3
+ createChangeOps,
4
+ createDocumentChange,
5
+ createDocumentChangeFromOps,
6
+ createGenesisChange,
7
+ signDocumentChange,
8
+ signPreparedChange,
9
+ visibilityToCbor
10
+ } from "./chunk-JT57MV7Y.mjs";
11
+ import "./chunk-PJ2RFT5A.mjs";
12
+ import "./chunk-LVAHHQIK.mjs";
13
+ import "./chunk-DR3HJ6BV.mjs";
14
+ import "./chunk-7P6ASYW6.mjs";
15
+ export {
16
+ createChange,
17
+ createChangeOps,
18
+ createDocumentChange,
19
+ createDocumentChangeFromOps,
20
+ createGenesisChange,
21
+ signDocumentChange,
22
+ signPreparedChange,
23
+ visibilityToCbor
24
+ };
@@ -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,125 @@
1
+ import {
2
+ signObject,
3
+ signerPublicKey,
4
+ toPublishInput
5
+ } from "./chunk-LVAHHQIK.mjs";
6
+
7
+ // src/contact.ts
8
+ import { decode as cborDecode, encode as cborEncode } from "@ipld/dag-cbor";
9
+ import { base58btc } from "multiformats/bases/base58";
10
+ function extractTsid(contactId) {
11
+ const parts = contactId.split("/");
12
+ const tsid = parts[1];
13
+ if (!tsid) {
14
+ throw new Error(`Invalid contact ID format: ${contactId}. Expected "authority/tsid".`);
15
+ }
16
+ return tsid;
17
+ }
18
+ function extractAuthority(contactId) {
19
+ const parts = contactId.split("/");
20
+ const authority = parts[0];
21
+ if (!authority || parts.length !== 2) {
22
+ throw new Error(`Invalid contact ID format: ${contactId}. Expected "authority/tsid".`);
23
+ }
24
+ return authority;
25
+ }
26
+ async function computeTSID(timestampMs, blobData) {
27
+ const buf = new ArrayBuffer(8);
28
+ new DataView(buf).setBigUint64(0, timestampMs, false);
29
+ const tsBytes = new Uint8Array(buf, 2, 6);
30
+ const hashBuffer = await crypto.subtle.digest("SHA-256", blobData);
31
+ const hashBytes = new Uint8Array(hashBuffer, 0, 4);
32
+ const tsidBytes = new Uint8Array(10);
33
+ tsidBytes.set(tsBytes, 0);
34
+ tsidBytes.set(hashBytes, 6);
35
+ return base58btc.encode(tsidBytes);
36
+ }
37
+ async function createContact(input, signer) {
38
+ const signerKey = await signerPublicKey(signer);
39
+ const ts = BigInt(Date.now());
40
+ const signerUid = base58btc.encode(new Uint8Array(signerKey));
41
+ const authority = input.accountUid || signerUid;
42
+ const unsigned = {
43
+ type: "Contact",
44
+ signer: new Uint8Array(signerKey),
45
+ sig: new Uint8Array(64),
46
+ ts,
47
+ subject: new Uint8Array(base58btc.decode(input.subjectUid))
48
+ };
49
+ if (input.name) {
50
+ unsigned.name = input.name;
51
+ }
52
+ if (input.accountUid) {
53
+ unsigned.account = new Uint8Array(base58btc.decode(input.accountUid));
54
+ }
55
+ if (input.subscribe) {
56
+ unsigned.subscribe = input.subscribe;
57
+ }
58
+ unsigned.sig = await signObject(signer, unsigned);
59
+ const encoded = cborEncode(unsigned);
60
+ const tsid = await computeTSID(ts, encoded);
61
+ return {
62
+ ...toPublishInput(encoded),
63
+ recordId: `${authority}/${tsid}`
64
+ };
65
+ }
66
+ async function updateContact(input, signer) {
67
+ const signerKey = await signerPublicKey(signer);
68
+ const tsid = extractTsid(input.contactId);
69
+ const accountUid = input.accountUid || extractAuthority(input.contactId);
70
+ const unsigned = {
71
+ type: "Contact",
72
+ signer: new Uint8Array(signerKey),
73
+ sig: new Uint8Array(64),
74
+ ts: BigInt(Date.now()),
75
+ id: tsid,
76
+ subject: new Uint8Array(base58btc.decode(input.subjectUid))
77
+ };
78
+ if (input.name) {
79
+ unsigned.name = input.name;
80
+ }
81
+ if (accountUid) {
82
+ unsigned.account = new Uint8Array(base58btc.decode(accountUid));
83
+ }
84
+ if (input.subscribe) {
85
+ unsigned.subscribe = input.subscribe;
86
+ }
87
+ unsigned.sig = await signObject(signer, unsigned);
88
+ return toPublishInput(cborEncode(unsigned));
89
+ }
90
+ async function deleteContact(input, signer) {
91
+ const signerKey = await signerPublicKey(signer);
92
+ const tsid = extractTsid(input.contactId);
93
+ const accountUid = input.accountUid || extractAuthority(input.contactId);
94
+ const unsigned = {
95
+ type: "Contact",
96
+ signer: new Uint8Array(signerKey),
97
+ sig: new Uint8Array(64),
98
+ ts: BigInt(Date.now()),
99
+ id: tsid
100
+ };
101
+ if (accountUid) {
102
+ unsigned.account = new Uint8Array(base58btc.decode(accountUid));
103
+ }
104
+ unsigned.sig = await signObject(signer, unsigned);
105
+ return toPublishInput(cborEncode(unsigned));
106
+ }
107
+ async function contactRecordIdFromBlob(blobData) {
108
+ const decoded = cborDecode(blobData);
109
+ if (decoded.type !== "Contact") {
110
+ throw new Error(`Expected Contact blob, got "${decoded.type}"`);
111
+ }
112
+ const signerBytes = decoded.signer;
113
+ const ts = BigInt(decoded.ts);
114
+ const accountBytes = decoded.account;
115
+ const authority = base58btc.encode(new Uint8Array(accountBytes || signerBytes));
116
+ const tsid = await computeTSID(ts, blobData);
117
+ return `${authority}/${tsid}`;
118
+ }
119
+
120
+ export {
121
+ createContact,
122
+ updateContact,
123
+ deleteContact,
124
+ contactRecordIdFromBlob
125
+ };