@arcadiasystems/morse-sdk 0.1.0

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 (156) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +21 -0
  3. package/README.md +404 -0
  4. package/dist/clients.d.ts +12 -0
  5. package/dist/clients.d.ts.map +1 -0
  6. package/dist/clients.js +6 -0
  7. package/dist/clients.js.map +1 -0
  8. package/dist/codecs.d.ts +45 -0
  9. package/dist/codecs.d.ts.map +1 -0
  10. package/dist/codecs.js +132 -0
  11. package/dist/codecs.js.map +1 -0
  12. package/dist/compatibility.d.ts +22 -0
  13. package/dist/compatibility.d.ts.map +1 -0
  14. package/dist/compatibility.js +22 -0
  15. package/dist/compatibility.js.map +1 -0
  16. package/dist/config.d.ts +92 -0
  17. package/dist/config.d.ts.map +1 -0
  18. package/dist/config.js +85 -0
  19. package/dist/config.js.map +1 -0
  20. package/dist/errors.d.ts +101 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.js +214 -0
  23. package/dist/errors.js.map +1 -0
  24. package/dist/index.d.ts +15 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +14 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/ops/cap.d.ts +79 -0
  29. package/dist/ops/cap.d.ts.map +1 -0
  30. package/dist/ops/cap.js +104 -0
  31. package/dist/ops/cap.js.map +1 -0
  32. package/dist/ops/collection.d.ts +50 -0
  33. package/dist/ops/collection.d.ts.map +1 -0
  34. package/dist/ops/collection.js +55 -0
  35. package/dist/ops/collection.js.map +1 -0
  36. package/dist/ops/entry-from-bytes.d.ts +129 -0
  37. package/dist/ops/entry-from-bytes.d.ts.map +1 -0
  38. package/dist/ops/entry-from-bytes.js +137 -0
  39. package/dist/ops/entry-from-bytes.js.map +1 -0
  40. package/dist/ops/entry.d.ts +173 -0
  41. package/dist/ops/entry.d.ts.map +1 -0
  42. package/dist/ops/entry.js +235 -0
  43. package/dist/ops/entry.js.map +1 -0
  44. package/dist/ops/index.d.ts +9 -0
  45. package/dist/ops/index.d.ts.map +1 -0
  46. package/dist/ops/index.js +9 -0
  47. package/dist/ops/index.js.map +1 -0
  48. package/dist/ops/internal.d.ts +21 -0
  49. package/dist/ops/internal.d.ts.map +1 -0
  50. package/dist/ops/internal.js +42 -0
  51. package/dist/ops/internal.js.map +1 -0
  52. package/dist/ops/publication.d.ts +74 -0
  53. package/dist/ops/publication.d.ts.map +1 -0
  54. package/dist/ops/publication.js +123 -0
  55. package/dist/ops/publication.js.map +1 -0
  56. package/dist/ptb/cap.d.ts +36 -0
  57. package/dist/ptb/cap.d.ts.map +1 -0
  58. package/dist/ptb/cap.js +44 -0
  59. package/dist/ptb/cap.js.map +1 -0
  60. package/dist/ptb/collection.d.ts +27 -0
  61. package/dist/ptb/collection.d.ts.map +1 -0
  62. package/dist/ptb/collection.js +33 -0
  63. package/dist/ptb/collection.js.map +1 -0
  64. package/dist/ptb/entry.d.ts +104 -0
  65. package/dist/ptb/entry.d.ts.map +1 -0
  66. package/dist/ptb/entry.js +155 -0
  67. package/dist/ptb/entry.js.map +1 -0
  68. package/dist/ptb/index.d.ts +9 -0
  69. package/dist/ptb/index.d.ts.map +1 -0
  70. package/dist/ptb/index.js +9 -0
  71. package/dist/ptb/index.js.map +1 -0
  72. package/dist/ptb/internal.d.ts +11 -0
  73. package/dist/ptb/internal.d.ts.map +1 -0
  74. package/dist/ptb/internal.js +12 -0
  75. package/dist/ptb/internal.js.map +1 -0
  76. package/dist/ptb/publication.d.ts +51 -0
  77. package/dist/ptb/publication.d.ts.map +1 -0
  78. package/dist/ptb/publication.js +61 -0
  79. package/dist/ptb/publication.js.map +1 -0
  80. package/dist/read/entry-bcs.d.ts +47 -0
  81. package/dist/read/entry-bcs.d.ts.map +1 -0
  82. package/dist/read/entry-bcs.js +36 -0
  83. package/dist/read/entry-bcs.js.map +1 -0
  84. package/dist/read/index.d.ts +5 -0
  85. package/dist/read/index.d.ts.map +1 -0
  86. package/dist/read/index.js +5 -0
  87. package/dist/read/index.js.map +1 -0
  88. package/dist/read/reader.d.ts +148 -0
  89. package/dist/read/reader.d.ts.map +1 -0
  90. package/dist/read/reader.js +403 -0
  91. package/dist/read/reader.js.map +1 -0
  92. package/dist/seal/adapter.d.ts +56 -0
  93. package/dist/seal/adapter.d.ts.map +1 -0
  94. package/dist/seal/adapter.js +7 -0
  95. package/dist/seal/adapter.js.map +1 -0
  96. package/dist/seal/default-adapter.d.ts +90 -0
  97. package/dist/seal/default-adapter.d.ts.map +1 -0
  98. package/dist/seal/default-adapter.js +187 -0
  99. package/dist/seal/default-adapter.js.map +1 -0
  100. package/dist/seal/identity.d.ts +31 -0
  101. package/dist/seal/identity.d.ts.map +1 -0
  102. package/dist/seal/identity.js +79 -0
  103. package/dist/seal/identity.js.map +1 -0
  104. package/dist/seal/index.d.ts +8 -0
  105. package/dist/seal/index.d.ts.map +1 -0
  106. package/dist/seal/index.js +7 -0
  107. package/dist/seal/index.js.map +1 -0
  108. package/dist/types.d.ts +160 -0
  109. package/dist/types.d.ts.map +1 -0
  110. package/dist/types.js +33 -0
  111. package/dist/types.js.map +1 -0
  112. package/dist/wallets/adapter.d.ts +34 -0
  113. package/dist/wallets/adapter.d.ts.map +1 -0
  114. package/dist/wallets/adapter.js +6 -0
  115. package/dist/wallets/adapter.js.map +1 -0
  116. package/dist/wallets/index.d.ts +7 -0
  117. package/dist/wallets/index.d.ts.map +1 -0
  118. package/dist/wallets/index.js +6 -0
  119. package/dist/wallets/index.js.map +1 -0
  120. package/dist/wallets/keypair-adapter.d.ts +31 -0
  121. package/dist/wallets/keypair-adapter.d.ts.map +1 -0
  122. package/dist/wallets/keypair-adapter.js +210 -0
  123. package/dist/wallets/keypair-adapter.js.map +1 -0
  124. package/dist/wallets/wallet-standard-signer.d.ts +118 -0
  125. package/dist/wallets/wallet-standard-signer.d.ts.map +1 -0
  126. package/dist/wallets/wallet-standard-signer.js +207 -0
  127. package/dist/wallets/wallet-standard-signer.js.map +1 -0
  128. package/dist/walrus/adapter.d.ts +91 -0
  129. package/dist/walrus/adapter.d.ts.map +1 -0
  130. package/dist/walrus/adapter.js +11 -0
  131. package/dist/walrus/adapter.js.map +1 -0
  132. package/dist/walrus/default-adapter.d.ts +104 -0
  133. package/dist/walrus/default-adapter.d.ts.map +1 -0
  134. package/dist/walrus/default-adapter.js +146 -0
  135. package/dist/walrus/default-adapter.js.map +1 -0
  136. package/dist/walrus/default-read-adapter.d.ts +89 -0
  137. package/dist/walrus/default-read-adapter.d.ts.map +1 -0
  138. package/dist/walrus/default-read-adapter.js +81 -0
  139. package/dist/walrus/default-read-adapter.js.map +1 -0
  140. package/dist/walrus/http-aggregator-read-adapter.d.ts +107 -0
  141. package/dist/walrus/http-aggregator-read-adapter.d.ts.map +1 -0
  142. package/dist/walrus/http-aggregator-read-adapter.js +174 -0
  143. package/dist/walrus/http-aggregator-read-adapter.js.map +1 -0
  144. package/dist/walrus/http-publisher-write-adapter.d.ts +97 -0
  145. package/dist/walrus/http-publisher-write-adapter.d.ts.map +1 -0
  146. package/dist/walrus/http-publisher-write-adapter.js +249 -0
  147. package/dist/walrus/http-publisher-write-adapter.js.map +1 -0
  148. package/dist/walrus/index.d.ts +11 -0
  149. package/dist/walrus/index.d.ts.map +1 -0
  150. package/dist/walrus/index.js +11 -0
  151. package/dist/walrus/index.js.map +1 -0
  152. package/dist/walrus/quilt-patch-id.d.ts +34 -0
  153. package/dist/walrus/quilt-patch-id.d.ts.map +1 -0
  154. package/dist/walrus/quilt-patch-id.js +103 -0
  155. package/dist/walrus/quilt-patch-id.js.map +1 -0
  156. package/package.json +72 -0
@@ -0,0 +1,249 @@
1
+ /**
2
+ * `WalrusWriteAdapter` that uploads through a Walrus publisher HTTP service
3
+ * instead of fanning out to ~30 storage nodes via `WalrusClient`. The
4
+ * publisher (an operator-run service) pays the WAL storage deposit and
5
+ * handles `register_blob` + `certify_blob` server-side; the consumer's
6
+ * wallet only signs the downstream `add_entry_to_collection` (1 popup).
7
+ *
8
+ * Trade-offs vs `DefaultWalrusWriteAdapter`:
9
+ * - 1 wallet popup vs 2 (the publisher absorbs register + certify).
10
+ * - Operator-paid storage vs consumer-paid storage. Consumers using a
11
+ * paid publisher tier sign whatever auth the publisher requires via
12
+ * the `headers` option.
13
+ * - The publisher returns the blob object owned by `ownerAddress` (via
14
+ * `send_object_to`), which the consumer then references in
15
+ * `addEntry`.
16
+ *
17
+ * NOT compatible with `addEntryFromBytes` / `addEncryptedEntryFromBytes`,
18
+ * which require `WalrusFlowCapable` for the 2-popup combined PTB. The
19
+ * publisher-paid path is naturally a 1-popup path through the standard
20
+ * `uploadBlob` + `addEntry` composition; the from-bytes optimization
21
+ * isn't needed because there's no certify popup to combine.
22
+ */
23
+ import { toBlobObjectId, toWalrusBlobId } from "../codecs.js";
24
+ import { TransportError, ValidationError } from "../errors.js";
25
+ import { decodeQuiltPatchId, quiltPatchIdFromString, } from "./quilt-patch-id.js";
26
+ /**
27
+ * `WalrusWriteAdapter` backed by a Walrus publisher HTTP service. Substitutes
28
+ * an operator-run upload service for the direct-protocol shard fanout.
29
+ * Useful for browser dapps that want a "publisher pays storage" onboarding
30
+ * path (1 wallet popup total) and/or CORS-friendly uploads from environments
31
+ * that block direct storage-node fanout.
32
+ */
33
+ export class HttpPublisherWriteAdapter {
34
+ #publisherUrl;
35
+ #ownerAddress;
36
+ #headers;
37
+ #fetch;
38
+ #parseResponse;
39
+ constructor(options) {
40
+ this.#publisherUrl = options.publisherUrl.replace(/\/+$/, "");
41
+ this.#ownerAddress = options.ownerAddress;
42
+ if (options.headers !== undefined)
43
+ this.#headers = options.headers;
44
+ // Browsers enforce that `window.fetch` is called with `window` as its
45
+ // receiver (WebIDL HostObject check); storing `globalThis.fetch` on
46
+ // the instance and calling it as `this.#fetch(...)` later throws
47
+ // `TypeError: Illegal invocation`. Bind to `globalThis` so the call
48
+ // receiver is correct in browsers. Node's fetch is bind-tolerant so
49
+ // CLI smokes did not surface this regression; the regression test
50
+ // in this file's `default fetch binding` describe block does.
51
+ this.#fetch =
52
+ options.fetch ?? globalThis.fetch.bind(globalThis);
53
+ if (options.parseResponse !== undefined) {
54
+ this.#parseResponse = options.parseResponse;
55
+ }
56
+ }
57
+ /** Mirror `DefaultWalrusWriteAdapter.fromConfig` for symmetry. */
58
+ static fromConfig(options) {
59
+ return new HttpPublisherWriteAdapter(options);
60
+ }
61
+ async uploadBlob(data, options) {
62
+ if (data.length === 0) {
63
+ throw new ValidationError("uploadBlob requires non-empty bytes", "blob");
64
+ }
65
+ if (!Number.isInteger(options.epochs) || options.epochs < 1) {
66
+ throw new ValidationError(`uploadBlob.epochs must be a positive integer; got ${options.epochs}`, "epochs");
67
+ }
68
+ const url = this.buildBlobUrl(options);
69
+ const result = await this.putRequest(url, data, options.signal);
70
+ return this.#parseResponse !== undefined
71
+ ? await this.#parseResponse(result)
72
+ : parseBlobStoreResult(result);
73
+ }
74
+ async uploadQuilt(patches, options) {
75
+ if (patches.length === 0) {
76
+ throw new ValidationError("uploadQuilt requires at least one patch", "patches");
77
+ }
78
+ if (!Number.isInteger(options.epochs) || options.epochs < 1) {
79
+ throw new ValidationError(`uploadQuilt.epochs must be a positive integer; got ${options.epochs}`, "epochs");
80
+ }
81
+ const form = new FormData();
82
+ const metadata = [];
83
+ for (const patch of patches) {
84
+ if (patch.identifier.length === 0) {
85
+ throw new ValidationError("Quilt patch identifier must not be empty", "patches[].identifier");
86
+ }
87
+ // Publisher API treats each form field name as the patch identifier and
88
+ // the field's bytes as the patch content. File-style multipart entries
89
+ // (a Blob with type `application/octet-stream`) are universally accepted
90
+ // by the publisher's multer-style parser.
91
+ const blob = new Blob([patch.contents], {
92
+ type: "application/octet-stream",
93
+ });
94
+ form.append(patch.identifier, blob, patch.identifier);
95
+ if (patch.tags !== undefined && Object.keys(patch.tags).length > 0) {
96
+ metadata.push({
97
+ identifier: patch.identifier,
98
+ tags: { ...patch.tags },
99
+ });
100
+ }
101
+ else {
102
+ metadata.push({ identifier: patch.identifier });
103
+ }
104
+ }
105
+ form.append("_metadata", JSON.stringify(metadata));
106
+ const url = this.buildQuiltUrl(options);
107
+ const result = await this.putRequest(url, form, options.signal);
108
+ if (result.blobStoreResult === undefined) {
109
+ throw new TransportError("Walrus publisher quilt response missing blobStoreResult field");
110
+ }
111
+ // The outer QuiltStoreResult envelope (blobStoreResult + storedQuiltBlobs)
112
+ // is parsed by the built-in path. The inner blobStoreResult is the same
113
+ // shape as the blob endpoint, so it routes through the custom parser
114
+ // when one is set — that lets consumers normalize the same way for both
115
+ // upload paths.
116
+ const parent = this.#parseResponse !== undefined
117
+ ? await this.#parseResponse(result.blobStoreResult)
118
+ : parseBlobStoreResult(result.blobStoreResult);
119
+ const storedPatches = result.storedQuiltBlobs ?? [];
120
+ const patchesOut = storedPatches.map((p) => {
121
+ if (typeof p.identifier !== "string" ||
122
+ typeof p.quiltPatchId !== "string") {
123
+ throw new ValidationError("Walrus publisher storedQuiltBlobs entry missing identifier or quiltPatchId", "quilt.storedQuiltBlobs");
124
+ }
125
+ return {
126
+ identifier: p.identifier,
127
+ patchId: quiltPatchIdFromString(p.quiltPatchId),
128
+ // The publisher exposes a `range` but the contract reads
129
+ // startIndex/endIndex from the patchId itself; decode for symmetry
130
+ // with `DefaultWalrusWriteAdapter`'s result shape.
131
+ ...decodeStartEndFromPatchId(p.quiltPatchId),
132
+ };
133
+ });
134
+ return {
135
+ blobId: parent.blobId,
136
+ blobObjectId: parent.blobObjectId,
137
+ patches: patchesOut,
138
+ };
139
+ }
140
+ buildBlobUrl(options) {
141
+ const params = new URLSearchParams();
142
+ params.set("epochs", String(options.epochs));
143
+ params.set("send_object_to", options.owner ?? this.#ownerAddress);
144
+ // `deletable` query param is deprecated as of publisher v1.33+ (blobs
145
+ // are deletable by default). Send `permanent=false` only when the
146
+ // caller explicitly asks for a non-deletable blob — the Move layer
147
+ // rejects non-deletable blobs so this branch is effectively unreachable
148
+ // from morse-sdk's ops, but the adapter respects the option.
149
+ if (options.deletable === false) {
150
+ params.set("permanent", "true");
151
+ }
152
+ return `${this.#publisherUrl}/v1/blobs?${params.toString()}`;
153
+ }
154
+ buildQuiltUrl(options) {
155
+ const params = new URLSearchParams();
156
+ params.set("epochs", String(options.epochs));
157
+ params.set("send_object_to", options.owner ?? this.#ownerAddress);
158
+ if (options.deletable === false) {
159
+ params.set("permanent", "true");
160
+ }
161
+ return `${this.#publisherUrl}/v1/quilts?${params.toString()}`;
162
+ }
163
+ async putRequest(url, body, signal) {
164
+ let response;
165
+ try {
166
+ response = await this.#fetch(url, {
167
+ method: "PUT",
168
+ body,
169
+ ...(this.#headers === undefined ? {} : { headers: this.#headers }),
170
+ ...(signal === undefined ? {} : { signal }),
171
+ });
172
+ }
173
+ catch (cause) {
174
+ throw new TransportError(`Walrus publisher request failed: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
175
+ }
176
+ if (!response.ok) {
177
+ let detail = "";
178
+ try {
179
+ detail = await response.text();
180
+ }
181
+ catch {
182
+ // ignore body-read failures; surface the status code anyway.
183
+ }
184
+ throw new TransportError(`Walrus publisher returned HTTP ${response.status} ${response.statusText}${detail ? `: ${detail}` : ""}`);
185
+ }
186
+ try {
187
+ return (await response.json());
188
+ }
189
+ catch (cause) {
190
+ throw new TransportError(`Walrus publisher response is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
191
+ }
192
+ }
193
+ }
194
+ function parseBlobStoreResult(result) {
195
+ if (result.newlyCreated !== undefined) {
196
+ const blob = result.newlyCreated.blobObject ?? result.newlyCreated.blob_object;
197
+ const blobIdField = blob?.blobId ?? blob?.blob_id;
198
+ if (blob === undefined ||
199
+ typeof blob.id !== "string" ||
200
+ typeof blobIdField !== "string") {
201
+ throw new ValidationError("Walrus publisher newlyCreated response missing blobObject.id or blobObject.blobId", "blobObject");
202
+ }
203
+ return {
204
+ blobId: toWalrusBlobId(blobIdField),
205
+ blobObjectId: toBlobObjectId(blob.id),
206
+ };
207
+ }
208
+ if (result.alreadyCertified !== undefined) {
209
+ const ac = result.alreadyCertified;
210
+ const blobIdField = ac.blobId ?? ac.blob_id;
211
+ if (typeof blobIdField !== "string") {
212
+ throw new ValidationError("Walrus publisher alreadyCertified response missing blobId", "alreadyCertified");
213
+ }
214
+ if (typeof ac.object !== "string") {
215
+ // The publisher returned an event-id reference (no object) — the blob
216
+ // was already certified by another party, no Sui object exists for our
217
+ // address. morse-sdk consumers need a `blobObjectId` to attach in
218
+ // `addEntry`; surface this as a transport-layer issue with an
219
+ // actionable hint.
220
+ throw new TransportError("Walrus publisher reports the blob is already certified by another party; no owned Sui object is available. Pass `force=true` as a query param (via custom headers escape hatch or a forked adapter), or compose with `DefaultWalrusWriteAdapter` if you need to register your own Blob object.");
221
+ }
222
+ return {
223
+ blobId: toWalrusBlobId(blobIdField),
224
+ blobObjectId: toBlobObjectId(ac.object),
225
+ };
226
+ }
227
+ if (result.markedInvalid !== undefined) {
228
+ const id = result.markedInvalid.blobId ??
229
+ result.markedInvalid.blob_id ??
230
+ "(unknown)";
231
+ throw new TransportError(`Walrus publisher returned markedInvalid for blob ${id}; the blob is known to Walrus but was rejected (storage-node bug, malicious quorum, or invalid encoding).`);
232
+ }
233
+ if (result.error !== undefined) {
234
+ const message = result.error.errorMsg ?? result.error.error_msg ?? "(no message)";
235
+ throw new TransportError(`Walrus publisher returned error: ${message}`);
236
+ }
237
+ throw new TransportError("Walrus publisher response did not match newlyCreated / alreadyCertified / markedInvalid / error");
238
+ }
239
+ /**
240
+ * Quilt patch ids encode `{quiltBlobId, version, startIndex, endIndex}`. Decode
241
+ * via the existing structural codec to surface `startIndex`/`endIndex` in
242
+ * the upload result, matching `DefaultWalrusWriteAdapter`'s shape.
243
+ */
244
+ function decodeStartEndFromPatchId(value) {
245
+ const patchId = quiltPatchIdFromString(value);
246
+ const parts = decodeQuiltPatchId(patchId);
247
+ return { startIndex: parts.startIndex, endIndex: parts.endIndex };
248
+ }
249
+ //# sourceMappingURL=http-publisher-write-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-publisher-write-adapter.js","sourceRoot":"","sources":["../../src/walrus/http-publisher-write-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAW/D,OAAO,EACN,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,qBAAqB,CAAC;AA4G7B;;;;;;GAMG;AACH,MAAM,OAAO,yBAAyB;IAC5B,aAAa,CAAS;IACtB,aAAa,CAAa;IAC1B,QAAQ,CAAe;IACvB,MAAM,CAAY;IAClB,cAAc,CAA0B;IAEjD,YAAY,OAAyC;QACpD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;QAC1C,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS;YAAE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;QACnE,sEAAsE;QACtE,oEAAoE;QACpE,iEAAiE;QACjE,oEAAoE;QACpE,oEAAoE;QACpE,kEAAkE;QAClE,8DAA8D;QAC9D,IAAI,CAAC,MAAM;YACV,OAAO,CAAC,KAAK,IAAK,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAe,CAAC;QACnE,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;QAC7C,CAAC;IACF,CAAC;IAED,kEAAkE;IAClE,MAAM,CAAC,UAAU,CAChB,OAAyC;QAEzC,OAAO,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,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KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,IAAI,cAAc,CAAC;QACnE,MAAM,IAAI,cAAc,CAAC,oCAAoC,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,MAAM,IAAI,cAAc,CACvB,iGAAiG,CACjG,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,KAAa;IAI/C,MAAM,OAAO,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;AACnE,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Walrus subpackage barrel: write adapter interface, default impl, and the
3
+ * QuiltPatchId structural codec.
4
+ */
5
+ export { isWalrusFlowCapable, type QuiltPatchInput, type StartBlobUploadResult, type UploadBlobOptions, type UploadBlobResult, type UploadQuiltOptions, type UploadQuiltPatch, type UploadQuiltResult, type WalrusFlowCapable, type WalrusUploadCommonOptions, type WalrusWriteAdapter, } from "./adapter.js";
6
+ export { DefaultWalrusWriteAdapter, type DefaultWalrusWriteAdapterOptions, type WalrusAdapterConfig, } from "./default-adapter.js";
7
+ export { DefaultWalrusReadAdapter, type WalrusReadAdapter, type WalrusReadAdapterConfig, type WalrusReadOptions, } from "./default-read-adapter.js";
8
+ export { HttpAggregatorReadAdapter, type HttpAggregatorReadAdapterOptions, type WalrusBlobIntegrityCheck, } from "./http-aggregator-read-adapter.js";
9
+ export { HttpPublisherWriteAdapter, type HttpPublisherWriteAdapterOptions, type ParsePublisherResponse, } from "./http-publisher-write-adapter.js";
10
+ export { decodeQuiltPatchId, encodeQuiltPatchId, type QuiltPatchIdParts, quiltPatchIdFromString, quiltPatchIdToString, } from "./quilt-patch-id.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/walrus/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,yBAAyB,EACzB,KAAK,gCAAgC,EACrC,KAAK,mBAAmB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,wBAAwB,EACxB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,GACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,yBAAyB,EACzB,KAAK,gCAAgC,EACrC,KAAK,wBAAwB,GAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACN,yBAAyB,EACzB,KAAK,gCAAgC,EACrC,KAAK,sBAAsB,GAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACN,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,sBAAsB,EACtB,oBAAoB,GACpB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Walrus subpackage barrel: write adapter interface, default impl, and the
3
+ * QuiltPatchId structural codec.
4
+ */
5
+ export { isWalrusFlowCapable, } from "./adapter.js";
6
+ export { DefaultWalrusWriteAdapter, } from "./default-adapter.js";
7
+ export { DefaultWalrusReadAdapter, } from "./default-read-adapter.js";
8
+ export { HttpAggregatorReadAdapter, } from "./http-aggregator-read-adapter.js";
9
+ export { HttpPublisherWriteAdapter, } from "./http-publisher-write-adapter.js";
10
+ export { decodeQuiltPatchId, encodeQuiltPatchId, quiltPatchIdFromString, quiltPatchIdToString, } from "./quilt-patch-id.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/walrus/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,mBAAmB,GAWnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,yBAAyB,GAGzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,wBAAwB,GAIxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,yBAAyB,GAGzB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACN,yBAAyB,GAGzB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACN,kBAAkB,EAClB,kBAAkB,EAElB,sBAAsB,EACtB,oBAAoB,GACpB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Structural codec for the 37-byte Walrus QuiltPatchId. Layout matches
3
+ * `@mysten/walrus`'s BCS schema: `quiltId(32) || version(1) ||
4
+ * startIndex(u16) || endIndex(u16)`. u16s are little-endian (BCS canonical);
5
+ * matching big-endian here would silently corrupt patch IDs.
6
+ *
7
+ * Walrus emits patch IDs as URL-safe base64 (43-byte string). This module
8
+ * decodes that string into structured form and back.
9
+ */
10
+ import { type QuiltPatchId, type WalrusBlobId } from "../types.js";
11
+ /** Default version byte for new patch IDs. Matches Walrus v1. */
12
+ export declare const QUILT_PATCH_ID_VERSION = 1;
13
+ /** Structured view of a quilt patch ID. */
14
+ export interface QuiltPatchIdParts {
15
+ readonly quiltBlobId: WalrusBlobId;
16
+ readonly version: number;
17
+ readonly startIndex: number;
18
+ readonly endIndex: number;
19
+ }
20
+ /**
21
+ * Encode structured fields into a 37-byte branded `QuiltPatchId`.
22
+ * @throws {ValidationError} If indices are out of u16 range or version is not u8.
23
+ */
24
+ export declare function encodeQuiltPatchId(parts: QuiltPatchIdParts): QuiltPatchId;
25
+ /** Decode a branded `QuiltPatchId` back into structured fields. */
26
+ export declare function decodeQuiltPatchId(id: QuiltPatchId): QuiltPatchIdParts;
27
+ /**
28
+ * Decode a Walrus-emitted patch ID string (URL-safe base64, 43+ chars) into
29
+ * a branded `QuiltPatchId`. @throws {ValidationError} On wrong byte length.
30
+ */
31
+ export declare function quiltPatchIdFromString(value: string): QuiltPatchId;
32
+ /** Encode a `QuiltPatchId` to URL-safe base64 (no padding). */
33
+ export declare function quiltPatchIdToString(id: QuiltPatchId): string;
34
+ //# sourceMappingURL=quilt-patch-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quilt-patch-id.d.ts","sourceRoot":"","sources":["../../src/walrus/quilt-patch-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,MAAM,aAAa,CAAC;AAQrB,iEAAiE;AACjE,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,2CAA2C;AAC3C,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA0BzE;AAED,mEAAmE;AACnE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,YAAY,GAAG,iBAAiB,CAStE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAGlE;AAED,+DAA+D;AAC/D,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,YAAY,GAAG,MAAM,CAE7D"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Structural codec for the 37-byte Walrus QuiltPatchId. Layout matches
3
+ * `@mysten/walrus`'s BCS schema: `quiltId(32) || version(1) ||
4
+ * startIndex(u16) || endIndex(u16)`. u16s are little-endian (BCS canonical);
5
+ * matching big-endian here would silently corrupt patch IDs.
6
+ *
7
+ * Walrus emits patch IDs as URL-safe base64 (43-byte string). This module
8
+ * decodes that string into structured form and back.
9
+ */
10
+ import { toQuiltPatchId, toWalrusBlobId } from "../codecs.js";
11
+ import { ValidationError } from "../errors.js";
12
+ import { QUILT_PATCH_ID_LENGTH, } from "../types.js";
13
+ const QUILT_BLOB_ID_BYTES = 32;
14
+ const VERSION_OFFSET = QUILT_BLOB_ID_BYTES;
15
+ const START_INDEX_OFFSET = VERSION_OFFSET + 1;
16
+ const END_INDEX_OFFSET = START_INDEX_OFFSET + 2;
17
+ const MAX_U16 = 0xffff;
18
+ /** Default version byte for new patch IDs. Matches Walrus v1. */
19
+ export const QUILT_PATCH_ID_VERSION = 1;
20
+ /**
21
+ * Encode structured fields into a 37-byte branded `QuiltPatchId`.
22
+ * @throws {ValidationError} If indices are out of u16 range or version is not u8.
23
+ */
24
+ export function encodeQuiltPatchId(parts) {
25
+ assertU8(parts.version, "version");
26
+ assertU16(parts.startIndex, "startIndex");
27
+ assertU16(parts.endIndex, "endIndex");
28
+ if (parts.startIndex > parts.endIndex) {
29
+ throw new ValidationError(`Invalid sliver range: startIndex (${parts.startIndex}) must not exceed endIndex (${parts.endIndex})`, "startIndex");
30
+ }
31
+ const quiltBytes = decodeUrlSafeBase64(parts.quiltBlobId);
32
+ if (quiltBytes.length !== QUILT_BLOB_ID_BYTES) {
33
+ throw new ValidationError(`Invalid quiltBlobId: expected ${QUILT_BLOB_ID_BYTES} bytes after decode, got ${quiltBytes.length}`, "quiltBlobId");
34
+ }
35
+ const out = new Uint8Array(QUILT_PATCH_ID_LENGTH);
36
+ out.set(quiltBytes, 0);
37
+ out[VERSION_OFFSET] = parts.version;
38
+ const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
39
+ view.setUint16(START_INDEX_OFFSET, parts.startIndex, true);
40
+ view.setUint16(END_INDEX_OFFSET, parts.endIndex, true);
41
+ return toQuiltPatchId(out);
42
+ }
43
+ /** Decode a branded `QuiltPatchId` back into structured fields. */
44
+ export function decodeQuiltPatchId(id) {
45
+ const quiltBytes = id.subarray(0, QUILT_BLOB_ID_BYTES);
46
+ const view = new DataView(id.buffer, id.byteOffset, id.byteLength);
47
+ return {
48
+ quiltBlobId: toWalrusBlobId(encodeUrlSafeBase64(quiltBytes)),
49
+ version: id[VERSION_OFFSET] ?? 0,
50
+ startIndex: view.getUint16(START_INDEX_OFFSET, true),
51
+ endIndex: view.getUint16(END_INDEX_OFFSET, true),
52
+ };
53
+ }
54
+ /**
55
+ * Decode a Walrus-emitted patch ID string (URL-safe base64, 43+ chars) into
56
+ * a branded `QuiltPatchId`. @throws {ValidationError} On wrong byte length.
57
+ */
58
+ export function quiltPatchIdFromString(value) {
59
+ const bytes = decodeUrlSafeBase64(value);
60
+ return toQuiltPatchId(bytes);
61
+ }
62
+ /** Encode a `QuiltPatchId` to URL-safe base64 (no padding). */
63
+ export function quiltPatchIdToString(id) {
64
+ return encodeUrlSafeBase64(id);
65
+ }
66
+ function assertU8(value, field) {
67
+ if (!Number.isInteger(value) || value < 0 || value > 0xff) {
68
+ throw new ValidationError(`Invalid ${field}: expected integer in [0, 255], got ${value}`, field);
69
+ }
70
+ }
71
+ function assertU16(value, field) {
72
+ if (!Number.isInteger(value) || value < 0 || value > MAX_U16) {
73
+ throw new ValidationError(`Invalid ${field}: expected integer in [0, ${MAX_U16}], got ${value}`, field);
74
+ }
75
+ }
76
+ function decodeUrlSafeBase64(value) {
77
+ const standard = value.replace(/-/g, "+").replace(/_/g, "/");
78
+ const padding = (4 - (standard.length % 4)) % 4;
79
+ const padded = standard + "=".repeat(padding);
80
+ let binary;
81
+ try {
82
+ binary = atob(padded);
83
+ }
84
+ catch (cause) {
85
+ throw new ValidationError(`Invalid URL-safe base64: ${JSON.stringify(value)}`, "value", { cause });
86
+ }
87
+ const bytes = new Uint8Array(binary.length);
88
+ for (let i = 0; i < binary.length; i += 1) {
89
+ bytes[i] = binary.charCodeAt(i);
90
+ }
91
+ return bytes;
92
+ }
93
+ function encodeUrlSafeBase64(bytes) {
94
+ let binary = "";
95
+ for (let i = 0; i < bytes.length; i += 1) {
96
+ binary += String.fromCharCode(bytes[i] ?? 0);
97
+ }
98
+ return btoa(binary)
99
+ .replace(/\+/g, "-")
100
+ .replace(/\//g, "_")
101
+ .replace(/=+$/, "");
102
+ }
103
+ //# sourceMappingURL=quilt-patch-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quilt-patch-id.js","sourceRoot":"","sources":["../../src/walrus/quilt-patch-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACN,qBAAqB,GAGrB,MAAM,aAAa,CAAC;AAErB,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAC3C,MAAM,kBAAkB,GAAG,cAAc,GAAG,CAAC,CAAC;AAC9C,MAAM,gBAAgB,GAAG,kBAAkB,GAAG,CAAC,CAAC;AAChD,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,iEAAiE;AACjE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAUxC;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAwB;IAC1D,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACnC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IAC1C,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,eAAe,CACxB,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1.0",
4
+ "description": "TypeScript SDK for Morse dCMS on the Sui blockchain.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "sideEffects": false,
11
+ "keywords": [
12
+ "sui",
13
+ "walrus",
14
+ "seal",
15
+ "cms",
16
+ "decentralized",
17
+ "blockchain"
18
+ ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/TheDivic/morse-dcms.git",
22
+ "directory": "morse-sdk"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "LICENSE",
28
+ "CHANGELOG.md"
29
+ ],
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js"
36
+ }
37
+ },
38
+ "scripts": {
39
+ "prebuild": "rm -rf dist",
40
+ "build": "tsc -p tsconfig.build.json",
41
+ "typecheck": "tsc --noEmit",
42
+ "lint": "biome check .",
43
+ "lint:fix": "biome check --write .",
44
+ "test": "bun test",
45
+ "test:coverage": "bun test --coverage"
46
+ },
47
+ "engines": {
48
+ "bun": ">=1.2.0"
49
+ },
50
+ "peerDependencies": {
51
+ "@mysten/seal": ">=1.1.3 <1.2.0",
52
+ "@mysten/sui": ">=2.16.2 <2.17.0",
53
+ "@mysten/walrus": ">=1.1.6 <1.2.0"
54
+ },
55
+ "peerDependenciesMeta": {
56
+ "@mysten/seal": {
57
+ "optional": true
58
+ },
59
+ "@mysten/walrus": {
60
+ "optional": true
61
+ }
62
+ },
63
+ "devDependencies": {
64
+ "@biomejs/biome": "2.4.7",
65
+ "@mysten/bcs": "2.0.3",
66
+ "@mysten/seal": "1.1.3",
67
+ "@mysten/sui": "2.16.2",
68
+ "@mysten/walrus": "1.1.6",
69
+ "@types/bun": "latest",
70
+ "typescript": "^5.6.0"
71
+ }
72
+ }