@seed-hypermedia/client 0.0.48 → 0.0.49
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/change.d.ts +1 -0
- package/dist/index.mjs +35 -8
- package/dist/ref.d.ts +2 -0
- package/package.json +1 -1
package/dist/change.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export declare function createChange(unsignedBytes: Uint8Array, signer: HMSigner
|
|
|
59
59
|
bytes: Uint8Array;
|
|
60
60
|
cid: CID;
|
|
61
61
|
genesis: CID | null;
|
|
62
|
+
ts: number | undefined;
|
|
62
63
|
}>;
|
|
63
64
|
/** @deprecated Use createChange instead */
|
|
64
65
|
export declare const signPreparedChange: (unsignedBytes: Uint8Array, signer: HMSigner) => Promise<{
|
package/dist/index.mjs
CHANGED
|
@@ -116,14 +116,15 @@ function buildUnsignedRef({
|
|
|
116
116
|
genesis,
|
|
117
117
|
generation,
|
|
118
118
|
capability,
|
|
119
|
-
visibility
|
|
119
|
+
visibility,
|
|
120
|
+
ts
|
|
120
121
|
}) {
|
|
121
122
|
const signerBytes = new Uint8Array(signerKey);
|
|
122
123
|
const spaceBytes = new Uint8Array(base58btc2.decode(space));
|
|
123
124
|
const unsigned = {
|
|
124
125
|
type: "Ref",
|
|
125
126
|
signer: signerBytes,
|
|
126
|
-
ts: BigInt(Date.now()),
|
|
127
|
+
ts: BigInt(ts ?? Date.now()),
|
|
127
128
|
sig: new Uint8Array(64),
|
|
128
129
|
genesisBlob: CID.parse(genesis)
|
|
129
130
|
};
|
|
@@ -153,7 +154,8 @@ async function createVersionRef(input, signer) {
|
|
|
153
154
|
genesis: input.genesis,
|
|
154
155
|
generation: input.generation,
|
|
155
156
|
capability: input.capability,
|
|
156
|
-
visibility: input.visibility
|
|
157
|
+
visibility: input.visibility,
|
|
158
|
+
ts: input.ts
|
|
157
159
|
});
|
|
158
160
|
unsigned.heads = input.version.split(".").map((v) => CID.parse(v));
|
|
159
161
|
unsigned.sig = await signObject(signer, unsigned);
|
|
@@ -221,11 +223,12 @@ function createChangeOps(input) {
|
|
|
221
223
|
async function createChange(unsignedBytes, signer) {
|
|
222
224
|
const change = cborDecode(unsignedBytes);
|
|
223
225
|
const genesis = change.genesis instanceof CID2 ? change.genesis : null;
|
|
226
|
+
const ts = timestampToNumber(change.ts);
|
|
224
227
|
change.signer = new Uint8Array(await signer.getPublicKey());
|
|
225
228
|
change.sig = new Uint8Array(64);
|
|
226
229
|
change.sig = await signer.sign(cborEncode4(change));
|
|
227
230
|
const block = await Block.encode({ value: change, codec: cborCodec, hasher: sha256 });
|
|
228
|
-
return { bytes: block.bytes, cid: block.cid, genesis };
|
|
231
|
+
return { bytes: block.bytes, cid: block.cid, genesis, ts };
|
|
229
232
|
}
|
|
230
233
|
var signPreparedChange = async (unsignedBytes, signer) => {
|
|
231
234
|
const result = await createChange(unsignedBytes, signer);
|
|
@@ -275,10 +278,20 @@ var RESOURCE_VISIBILITY_PRIVATE = 2;
|
|
|
275
278
|
function visibilityToCbor(protoVisibility) {
|
|
276
279
|
return protoVisibility === RESOURCE_VISIBILITY_PRIVATE ? "Private" : void 0;
|
|
277
280
|
}
|
|
281
|
+
function timestampToNumber(ts) {
|
|
282
|
+
if (typeof ts === "number") return ts;
|
|
283
|
+
if (typeof ts === "bigint") return Number(ts);
|
|
284
|
+
return void 0;
|
|
285
|
+
}
|
|
278
286
|
async function signDocumentChange(input, signer) {
|
|
279
|
-
const {
|
|
287
|
+
const {
|
|
288
|
+
bytes: signedBytes,
|
|
289
|
+
cid: changeCid,
|
|
290
|
+
genesis: changeGenesis,
|
|
291
|
+
ts: changeTs
|
|
292
|
+
} = await createChange(input.unsignedChange, signer);
|
|
280
293
|
const effectiveGenesis = input.genesis || (changeGenesis ? changeGenesis.toString() : changeCid.toString());
|
|
281
|
-
const effectiveGeneration = input.generation != null ? Number(input.generation) : Date.now();
|
|
294
|
+
const effectiveGeneration = input.generation != null ? Number(input.generation) : changeTs ?? Date.now();
|
|
282
295
|
const refBlobs = await createVersionRef(
|
|
283
296
|
{
|
|
284
297
|
space: input.account,
|
|
@@ -287,7 +300,8 @@ async function signDocumentChange(input, signer) {
|
|
|
287
300
|
version: changeCid.toString(),
|
|
288
301
|
generation: effectiveGeneration,
|
|
289
302
|
capability: input.capability,
|
|
290
|
-
visibility: visibilityToCbor(input.visibility)
|
|
303
|
+
visibility: visibilityToCbor(input.visibility),
|
|
304
|
+
ts: changeTs
|
|
291
305
|
},
|
|
292
306
|
signer
|
|
293
307
|
);
|
|
@@ -446,7 +460,7 @@ function createSeedClient(baseUrl, options) {
|
|
|
446
460
|
} catch {
|
|
447
461
|
}
|
|
448
462
|
throw new SeedClientError(
|
|
449
|
-
|
|
463
|
+
formatHTTPErrorMessage(key, response.status, response.statusText, errorBody),
|
|
450
464
|
response.status,
|
|
451
465
|
errorBody
|
|
452
466
|
);
|
|
@@ -521,6 +535,19 @@ function createSeedClient(baseUrl, options) {
|
|
|
521
535
|
publishDocument
|
|
522
536
|
};
|
|
523
537
|
}
|
|
538
|
+
function formatHTTPErrorMessage(key, status, statusText, body) {
|
|
539
|
+
const base = `HTTP ${status} from ${key}: ${statusText}`;
|
|
540
|
+
if (!body) return base;
|
|
541
|
+
try {
|
|
542
|
+
const parsed = JSON.parse(body);
|
|
543
|
+
if (parsed && typeof parsed === "object" && typeof parsed.error === "string" && parsed.error.trim()) {
|
|
544
|
+
return `${base}: ${parsed.error}`;
|
|
545
|
+
}
|
|
546
|
+
} catch {
|
|
547
|
+
}
|
|
548
|
+
const trimmed = body.trim();
|
|
549
|
+
return trimmed ? `${base}: ${trimmed}` : base;
|
|
550
|
+
}
|
|
524
551
|
function isAbortError(err) {
|
|
525
552
|
return typeof DOMException !== "undefined" && err instanceof DOMException && err.name === "AbortError";
|
|
526
553
|
}
|
package/dist/ref.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export type CreateVersionRefInput = {
|
|
|
17
17
|
capability?: string;
|
|
18
18
|
/** Optional CBOR visibility value (e.g., "Private"). Omit or leave empty for public. */
|
|
19
19
|
visibility?: string;
|
|
20
|
+
/** Optional timestamp in Unix milliseconds. Defaults to Date.now(). */
|
|
21
|
+
ts?: number;
|
|
20
22
|
};
|
|
21
23
|
export type CreateTombstoneRefInput = {
|
|
22
24
|
/** Account UID (base58btc-encoded principal) */
|