@atproto/repo 0.2.0 → 0.3.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 (79) hide show
  1. package/dist/data-diff.d.ts +11 -9
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +404 -1655
  4. package/dist/index.js.map +4 -4
  5. package/dist/mst/mst.d.ts +10 -6
  6. package/dist/readable-repo.d.ts +1 -1
  7. package/dist/repo.d.ts +1 -4
  8. package/dist/storage/index.d.ts +0 -1
  9. package/dist/storage/memory-blockstore.d.ts +7 -12
  10. package/dist/storage/types.d.ts +28 -0
  11. package/dist/sync/consumer.d.ts +13 -17
  12. package/dist/sync/provider.d.ts +1 -5
  13. package/dist/types.d.ts +228 -39
  14. package/dist/util.d.ts +3 -5
  15. package/package.json +2 -2
  16. package/src/data-diff.ts +46 -44
  17. package/src/index.ts +0 -1
  18. package/src/mst/diff.ts +14 -36
  19. package/src/mst/mst.ts +14 -4
  20. package/src/readable-repo.ts +3 -3
  21. package/src/repo.ts +49 -70
  22. package/src/storage/index.ts +0 -1
  23. package/src/storage/memory-blockstore.ts +18 -77
  24. package/src/storage/types.ts +29 -0
  25. package/src/sync/consumer.ts +170 -116
  26. package/src/sync/provider.ts +2 -40
  27. package/src/types.ts +49 -23
  28. package/src/util.ts +24 -79
  29. package/tests/_util.ts +38 -67
  30. package/tests/mst.test.ts +4 -1
  31. package/tests/{sync/narrow.test.ts → proofs.test.ts} +9 -20
  32. package/tests/repo.test.ts +5 -4
  33. package/tests/sync.test.ts +97 -0
  34. package/tsconfig.build.tsbuildinfo +1 -1
  35. package/dist/src/block-map.d.ts +0 -23
  36. package/dist/src/blockstore/index.d.ts +0 -2
  37. package/dist/src/blockstore/ipld-store.d.ts +0 -27
  38. package/dist/src/blockstore/memory-blockstore.d.ts +0 -13
  39. package/dist/src/blockstore/persistent-blockstore.d.ts +0 -12
  40. package/dist/src/cid-set.d.ts +0 -14
  41. package/dist/src/collection.d.ts +0 -22
  42. package/dist/src/data-diff.d.ts +0 -34
  43. package/dist/src/error.d.ts +0 -21
  44. package/dist/src/index.d.ts +0 -7
  45. package/dist/src/logger.d.ts +0 -2
  46. package/dist/src/mst/diff.d.ts +0 -33
  47. package/dist/src/mst/index.d.ts +0 -4
  48. package/dist/src/mst/mst.d.ts +0 -106
  49. package/dist/src/mst/util.d.ts +0 -9
  50. package/dist/src/mst/walker.d.ts +0 -22
  51. package/dist/src/parse.d.ts +0 -11
  52. package/dist/src/readable-repo.d.ts +0 -25
  53. package/dist/src/repo.d.ts +0 -39
  54. package/dist/src/storage/error.d.ts +0 -22
  55. package/dist/src/storage/index.d.ts +0 -1
  56. package/dist/src/storage/memory-blobstore.d.ts +0 -1
  57. package/dist/src/storage/memory-blockstore.d.ts +0 -28
  58. package/dist/src/storage/readable-blockstore.d.ts +0 -21
  59. package/dist/src/storage/repo-storage.d.ts +0 -18
  60. package/dist/src/storage/sync-storage.d.ts +0 -15
  61. package/dist/src/storage/types.d.ts +0 -12
  62. package/dist/src/storage/util.d.ts +0 -17
  63. package/dist/src/structure.d.ts +0 -39
  64. package/dist/src/sync/consumer.d.ts +0 -19
  65. package/dist/src/sync/index.d.ts +0 -2
  66. package/dist/src/sync/producer.d.ts +0 -13
  67. package/dist/src/sync/provider.d.ts +0 -11
  68. package/dist/src/sync.d.ts +0 -9
  69. package/dist/src/types.d.ts +0 -368
  70. package/dist/src/util.d.ts +0 -13
  71. package/dist/src/verify.d.ts +0 -5
  72. package/dist/storage/repo-storage.d.ts +0 -19
  73. package/dist/tsconfig.build.tsbuildinfo +0 -1
  74. package/dist/verify.d.ts +0 -32
  75. package/src/storage/repo-storage.ts +0 -43
  76. package/src/verify.ts +0 -268
  77. package/tests/rebase.test.ts +0 -37
  78. package/tests/sync/checkout.test.ts +0 -75
  79. package/tests/sync/diff.test.ts +0 -92
package/dist/index.js CHANGED
@@ -13141,8 +13141,8 @@ var require_varint = __commonJS({
13141
13141
  });
13142
13142
 
13143
13143
  // src/index.ts
13144
- var src_exports6 = {};
13145
- __export(src_exports6, {
13144
+ var src_exports4 = {};
13145
+ __export(src_exports4, {
13146
13146
  BlobNotFoundError: () => BlobNotFoundError,
13147
13147
  BlockMap: () => BlockMap,
13148
13148
  CidSet: () => CidSet,
@@ -13153,7 +13153,6 @@ __export(src_exports6, {
13153
13153
  MstWalker: () => MstWalker,
13154
13154
  ReadableBlockstore: () => ReadableBlockstore,
13155
13155
  Repo: () => Repo,
13156
- RepoStorage: () => RepoStorage,
13157
13156
  RepoVerificationError: () => RepoVerificationError,
13158
13157
  SyncStorage: () => SyncStorage,
13159
13158
  WriteOpAction: () => WriteOpAction,
@@ -13162,44 +13161,35 @@ __export(src_exports6, {
13162
13161
  cborToLex: () => cborToLex,
13163
13162
  cborToLexRecord: () => cborToLexRecord,
13164
13163
  cidForRecord: () => cidForRecord,
13165
- collapseDiffs: () => collapseDiffs,
13166
- collapseWriteLog: () => collapseWriteLog,
13167
13164
  def: () => def2,
13168
13165
  diffToWriteDescripts: () => diffToWriteDescripts,
13166
+ ensureCreates: () => ensureCreates,
13167
+ ensureV3Commit: () => ensureV3Commit,
13169
13168
  formatDataKey: () => formatDataKey,
13170
- getCheckout: () => getCheckout,
13171
- getCommits: () => getCommits,
13172
13169
  getFullRepo: () => getFullRepo,
13173
13170
  getRecords: () => getRecords,
13174
- getWriteLog: () => getWriteLog,
13175
- loadCheckout: () => loadCheckout,
13176
- loadDiff: () => loadDiff,
13177
- loadFullRepo: () => loadFullRepo,
13178
13171
  metaEqual: () => metaEqual,
13179
13172
  mstDiff: () => mstDiff,
13180
13173
  mstUtil: () => util_exports2,
13181
13174
  nodeDataDef: () => nodeDataDef,
13182
13175
  nullDiff: () => nullDiff,
13183
13176
  parseDataKey: () => parseDataKey,
13184
- persistUpdates: () => persistUpdates,
13185
13177
  readCar: () => readCar,
13186
13178
  readCarWithRoot: () => readCarWithRoot,
13187
13179
  schema: () => schema2,
13188
13180
  signCommit: () => signCommit,
13189
- verifyCheckout: () => verifyCheckout,
13190
- verifyCheckoutWithCids: () => verifyCheckoutWithCids,
13191
- verifyCommitPath: () => verifyCommitPath,
13192
13181
  verifyCommitSig: () => verifyCommitSig,
13193
- verifyFullHistory: () => verifyFullHistory,
13182
+ verifyDiff: () => verifyDiff,
13183
+ verifyDiffCar: () => verifyDiffCar,
13194
13184
  verifyIncomingCarBlocks: () => verifyIncomingCarBlocks,
13195
13185
  verifyProofs: () => verifyProofs,
13196
13186
  verifyRecords: () => verifyRecords,
13197
- verifyUpdates: () => verifyUpdates,
13187
+ verifyRepo: () => verifyRepo,
13188
+ verifyRepoCar: () => verifyRepoCar,
13198
13189
  writeCar: () => writeCar,
13199
- writeCarStream: () => writeCarStream,
13200
- writeCommitsToCarStream: () => writeCommitsToCarStream
13190
+ writeCarStream: () => writeCarStream
13201
13191
  });
13202
- module.exports = __toCommonJS(src_exports6);
13192
+ module.exports = __toCommonJS(src_exports4);
13203
13193
 
13204
13194
  // ../../node_modules/zod/lib/index.mjs
13205
13195
  var util;
@@ -16790,7 +16780,7 @@ var z = /* @__PURE__ */ Object.freeze({
16790
16780
  ZodError
16791
16781
  });
16792
16782
 
16793
- // ../nsid/src/index.ts
16783
+ // ../syntax/src/nsid.ts
16794
16784
  var NSID = class {
16795
16785
  constructor(nsid2) {
16796
16786
  this.segments = [];
@@ -16895,6 +16885,108 @@ var streamToBuffer = async (stream) => {
16895
16885
  }
16896
16886
  return flattenUint8Arrays(arrays);
16897
16887
  };
16888
+ var S32_CHAR = "234567abcdefghijklmnopqrstuvwxyz";
16889
+ var s32encode = (i) => {
16890
+ let s = "";
16891
+ while (i) {
16892
+ const c = i % 32;
16893
+ i = Math.floor(i / 32);
16894
+ s = S32_CHAR.charAt(c) + s;
16895
+ }
16896
+ return s;
16897
+ };
16898
+ var s32decode = (s) => {
16899
+ let i = 0;
16900
+ for (const c of s) {
16901
+ i = i * 32 + S32_CHAR.indexOf(c);
16902
+ }
16903
+ return i;
16904
+ };
16905
+
16906
+ // ../common-web/src/tid.ts
16907
+ var TID_LEN = 13;
16908
+ var lastTimestamp = 0;
16909
+ var timestampCount = 0;
16910
+ var clockid = null;
16911
+ function dedash(str) {
16912
+ return str.replaceAll("-", "");
16913
+ }
16914
+ var TID = class {
16915
+ constructor(str) {
16916
+ const noDashes = dedash(str);
16917
+ if (noDashes.length !== TID_LEN) {
16918
+ throw new Error(`Poorly formatted TID: ${noDashes.length} length`);
16919
+ }
16920
+ this.str = noDashes;
16921
+ }
16922
+ static next(prev) {
16923
+ const time = Math.max(Date.now(), lastTimestamp);
16924
+ if (time === lastTimestamp) {
16925
+ timestampCount++;
16926
+ }
16927
+ lastTimestamp = time;
16928
+ const timestamp = time * 1e3 + timestampCount;
16929
+ if (clockid === null) {
16930
+ clockid = Math.floor(Math.random() * 32);
16931
+ }
16932
+ const tid = TID.fromTime(timestamp, clockid);
16933
+ if (!prev || tid.newerThan(prev)) {
16934
+ return tid;
16935
+ }
16936
+ return TID.fromTime(prev.timestamp() + 1, clockid);
16937
+ }
16938
+ static nextStr(prev) {
16939
+ return TID.next(prev ? new TID(prev) : void 0).toString();
16940
+ }
16941
+ static fromTime(timestamp, clockid2) {
16942
+ const str = `${s32encode(timestamp)}${s32encode(clockid2).padStart(2, "2")}`;
16943
+ return new TID(str);
16944
+ }
16945
+ static fromStr(str) {
16946
+ return new TID(str);
16947
+ }
16948
+ static oldestFirst(a, b) {
16949
+ return a.compareTo(b);
16950
+ }
16951
+ static newestFirst(a, b) {
16952
+ return b.compareTo(a);
16953
+ }
16954
+ static is(str) {
16955
+ return dedash(str).length === TID_LEN;
16956
+ }
16957
+ timestamp() {
16958
+ return s32decode(this.str.slice(0, 11));
16959
+ }
16960
+ clockid() {
16961
+ return s32decode(this.str.slice(11, 13));
16962
+ }
16963
+ formatted() {
16964
+ const str = this.toString();
16965
+ return `${str.slice(0, 4)}-${str.slice(4, 7)}-${str.slice(
16966
+ 7,
16967
+ 11
16968
+ )}-${str.slice(11, 13)}`;
16969
+ }
16970
+ toString() {
16971
+ return this.str;
16972
+ }
16973
+ compareTo(other) {
16974
+ if (this.str > other.str)
16975
+ return 1;
16976
+ if (this.str < other.str)
16977
+ return -1;
16978
+ return 0;
16979
+ }
16980
+ equals(other) {
16981
+ return this.str === other.str;
16982
+ }
16983
+ newerThan(other) {
16984
+ return this.compareTo(other) > 0;
16985
+ }
16986
+ olderThan(other) {
16987
+ return this.compareTo(other) < 0;
16988
+ }
16989
+ };
16898
16990
 
16899
16991
  // ../../node_modules/multiformats/esm/vendor/varint.js
16900
16992
  var encode_1 = encode;
@@ -18095,1054 +18187,6 @@ var DAY = HOUR * 24;
18095
18187
  // ../common-web/src/strings.ts
18096
18188
  var import_graphemer = __toESM(require_lib());
18097
18189
 
18098
- // ../identifier/src/reserved.ts
18099
- var atpSpecific = [
18100
- "at",
18101
- "atp",
18102
- "plc",
18103
- "pds",
18104
- "did",
18105
- "repo",
18106
- "tid",
18107
- "nsid",
18108
- "xrpc",
18109
- "lex",
18110
- "lexicon",
18111
- "bsky",
18112
- "bluesky",
18113
- "handle"
18114
- ];
18115
- var commonlyReserved = [
18116
- "about",
18117
- "abuse",
18118
- "access",
18119
- "account",
18120
- "accounts",
18121
- "acme",
18122
- "activate",
18123
- "activities",
18124
- "activity",
18125
- "ad",
18126
- "add",
18127
- "address",
18128
- "adm",
18129
- "admanager",
18130
- "admin",
18131
- "administration",
18132
- "administrator",
18133
- "administrators",
18134
- "admins",
18135
- "ads",
18136
- "adsense",
18137
- "adult",
18138
- "advertising",
18139
- "adwords",
18140
- "affiliate",
18141
- "affiliatepage",
18142
- "affiliates",
18143
- "afp",
18144
- "ajax",
18145
- "all",
18146
- "alpha",
18147
- "analysis",
18148
- "analytics",
18149
- "android",
18150
- "anon",
18151
- "anonymous",
18152
- "answer",
18153
- "answers",
18154
- "ap",
18155
- "api",
18156
- "apis",
18157
- "app",
18158
- "appengine",
18159
- "appnews",
18160
- "apps",
18161
- "archive",
18162
- "archives",
18163
- "article",
18164
- "asdf",
18165
- "asset",
18166
- "assets",
18167
- "auth",
18168
- "authentication",
18169
- "avatar",
18170
- "backup",
18171
- "bank",
18172
- "banner",
18173
- "banners",
18174
- "base",
18175
- "beginners",
18176
- "beta",
18177
- "billing",
18178
- "bin",
18179
- "binaries",
18180
- "binary",
18181
- "blackberry",
18182
- "blog",
18183
- "blogs",
18184
- "blogsearch",
18185
- "board",
18186
- "book",
18187
- "bookmark",
18188
- "bookmarks",
18189
- "books",
18190
- "bot",
18191
- "bots",
18192
- "bug",
18193
- "bugs",
18194
- "business",
18195
- "buy",
18196
- "buzz",
18197
- "cache",
18198
- "calendar",
18199
- "call",
18200
- "campaign",
18201
- "cancel",
18202
- "captcha",
18203
- "career",
18204
- "careers",
18205
- "cart",
18206
- "catalog",
18207
- "catalogs",
18208
- "categories",
18209
- "category",
18210
- "cdn",
18211
- "cgi",
18212
- "cgi-bin",
18213
- "changelog",
18214
- "chart",
18215
- "charts",
18216
- "chat",
18217
- "check",
18218
- "checked",
18219
- "checking",
18220
- "checkout",
18221
- "client",
18222
- "cliente",
18223
- "clients",
18224
- "clients1",
18225
- "cnarne",
18226
- "code",
18227
- "comercial",
18228
- "comment",
18229
- "comments",
18230
- "communities",
18231
- "community",
18232
- "company",
18233
- "compare",
18234
- "compras",
18235
- "config",
18236
- "configuration",
18237
- "confirm",
18238
- "confirmation",
18239
- "connect",
18240
- "contact",
18241
- "contacts",
18242
- "contactus",
18243
- "contact-us",
18244
- "contact_us",
18245
- "content",
18246
- "contest",
18247
- "contribute",
18248
- "contributor",
18249
- "contributors",
18250
- "coppa",
18251
- "copyright",
18252
- "copyrights",
18253
- "core",
18254
- "corp",
18255
- "countries",
18256
- "country",
18257
- "cpanel",
18258
- "create",
18259
- "css",
18260
- "cssproxy",
18261
- "customise",
18262
- "customize",
18263
- "dashboard",
18264
- "data",
18265
- "db",
18266
- "default",
18267
- "delete",
18268
- "demo",
18269
- "design",
18270
- "designer",
18271
- "desktop",
18272
- "destroy",
18273
- "dev",
18274
- "devel",
18275
- "developer",
18276
- "developers",
18277
- "devs",
18278
- "diagram",
18279
- "diary",
18280
- "dict",
18281
- "dictionary",
18282
- "die",
18283
- "dir",
18284
- "directory",
18285
- "direct_messages",
18286
- "direct-messages",
18287
- "dist",
18288
- "diversity",
18289
- "dl",
18290
- "dmca",
18291
- "doc",
18292
- "docs",
18293
- "documentation",
18294
- "documentations",
18295
- "documents",
18296
- "domain",
18297
- "domains",
18298
- "donate",
18299
- "download",
18300
- "downloads",
18301
- "e",
18302
- "e-mail",
18303
- "earth",
18304
- "ecommerce",
18305
- "edit",
18306
- "edits",
18307
- "editor",
18308
- "edu",
18309
- "education",
18310
- "email",
18311
- "embed",
18312
- "embedded",
18313
- "employment",
18314
- "employments",
18315
- "empty",
18316
- "enable",
18317
- "encrypted",
18318
- "end",
18319
- "engine",
18320
- "enterprise",
18321
- "enterprises",
18322
- "entries",
18323
- "entry",
18324
- "error",
18325
- "errorlog",
18326
- "errors",
18327
- "eval",
18328
- "event",
18329
- "example",
18330
- "examplecommunity",
18331
- "exampleopenid",
18332
- "examplesyn",
18333
- "examplesyndicated",
18334
- "exampleusername",
18335
- "exchange",
18336
- "exit",
18337
- "explore",
18338
- "faq",
18339
- "faqs",
18340
- "favorite",
18341
- "favorites",
18342
- "favourite",
18343
- "favourites",
18344
- "feature",
18345
- "features",
18346
- "feed",
18347
- "feedback",
18348
- "feedburner",
18349
- "feedproxy",
18350
- "feeds",
18351
- "file",
18352
- "files",
18353
- "finance",
18354
- "folder",
18355
- "folders",
18356
- "first",
18357
- "following",
18358
- "forgot",
18359
- "form",
18360
- "forms",
18361
- "forum",
18362
- "forums",
18363
- "founder",
18364
- "free",
18365
- "friend",
18366
- "friends",
18367
- "ftp",
18368
- "fuck",
18369
- "fun",
18370
- "fusion",
18371
- "gadget",
18372
- "gadgets",
18373
- "game",
18374
- "games",
18375
- "gears",
18376
- "general",
18377
- "geographic",
18378
- "get",
18379
- "gettingstarted",
18380
- "gift",
18381
- "gifts",
18382
- "gist",
18383
- "git",
18384
- "github",
18385
- "gmail",
18386
- "go",
18387
- "golang",
18388
- "goto",
18389
- "gov",
18390
- "graph",
18391
- "graphs",
18392
- "group",
18393
- "groups",
18394
- "guest",
18395
- "guests",
18396
- "guide",
18397
- "guides",
18398
- "hack",
18399
- "hacks",
18400
- "head",
18401
- "help",
18402
- "home",
18403
- "homepage",
18404
- "host",
18405
- "hosting",
18406
- "hostmaster",
18407
- "hostname",
18408
- "howto",
18409
- "how-to",
18410
- "how_to",
18411
- "html",
18412
- "htrnl",
18413
- "http",
18414
- "httpd",
18415
- "https",
18416
- "i",
18417
- "iamges",
18418
- "icon",
18419
- "icons",
18420
- "id",
18421
- "idea",
18422
- "ideas",
18423
- "im",
18424
- "image",
18425
- "images",
18426
- "img",
18427
- "imap",
18428
- "inbox",
18429
- "inboxes",
18430
- "index",
18431
- "indexes",
18432
- "info",
18433
- "information",
18434
- "inquiry",
18435
- "intranet",
18436
- "investor",
18437
- "investors",
18438
- "invitation",
18439
- "invitations",
18440
- "invite",
18441
- "invoice",
18442
- "invoices",
18443
- "imac",
18444
- "ios",
18445
- "ipad",
18446
- "iphone",
18447
- "irc",
18448
- "irnages",
18449
- "irng",
18450
- "is",
18451
- "issue",
18452
- "issues",
18453
- "it",
18454
- "item",
18455
- "items",
18456
- "java",
18457
- "javascript",
18458
- "job",
18459
- "jobs",
18460
- "join",
18461
- "js",
18462
- "json",
18463
- "jump",
18464
- "kb",
18465
- "knowledge-base",
18466
- "knowledgebase",
18467
- "lab",
18468
- "labs",
18469
- "language",
18470
- "languages",
18471
- "last",
18472
- "ldap_status",
18473
- "ldap-status",
18474
- "ldapstatus",
18475
- "legal",
18476
- "license",
18477
- "licenses",
18478
- "link",
18479
- "links",
18480
- "linux",
18481
- "list",
18482
- "lists",
18483
- "livejournal",
18484
- "lj",
18485
- "local",
18486
- "locale",
18487
- "location",
18488
- "log",
18489
- "log-in",
18490
- "log-out",
18491
- "login",
18492
- "logout",
18493
- "logs",
18494
- "log_in",
18495
- "log_out",
18496
- "m",
18497
- "mac",
18498
- "macos",
18499
- "macosx",
18500
- "mac-os",
18501
- "mac-os-x",
18502
- "mac_os_x",
18503
- "mail",
18504
- "mailer",
18505
- "mailing",
18506
- "main",
18507
- "maintenance",
18508
- "manage",
18509
- "manager",
18510
- "manual",
18511
- "map",
18512
- "maps",
18513
- "marketing",
18514
- "master",
18515
- "me",
18516
- "media",
18517
- "member",
18518
- "members",
18519
- "memories",
18520
- "memory",
18521
- "merchandise",
18522
- "message",
18523
- "messages",
18524
- "messenger",
18525
- "mg",
18526
- "microblog",
18527
- "microblogs",
18528
- "mine",
18529
- "mis",
18530
- "misc",
18531
- "mms",
18532
- "mob",
18533
- "mobile",
18534
- "model",
18535
- "models",
18536
- "money",
18537
- "movie",
18538
- "movies",
18539
- "mp3",
18540
- "mp4",
18541
- "msg",
18542
- "msn",
18543
- "music",
18544
- "mx",
18545
- "my",
18546
- "mymme",
18547
- "mysql",
18548
- "name",
18549
- "named",
18550
- "nan",
18551
- "navi",
18552
- "navigation",
18553
- "net",
18554
- "network",
18555
- "networks",
18556
- "new",
18557
- "news",
18558
- "newsletter",
18559
- "nick",
18560
- "nickname",
18561
- "nil",
18562
- "none",
18563
- "notes",
18564
- "noticias",
18565
- "notification",
18566
- "notifications",
18567
- "notify",
18568
- "ns",
18569
- "ns1",
18570
- "ns2",
18571
- "ns3",
18572
- "ns4",
18573
- "ns5",
18574
- "null",
18575
- "oauth",
18576
- "oauth-clients",
18577
- "oauth_clients",
18578
- "ocsp",
18579
- "offer",
18580
- "offers",
18581
- "official",
18582
- "old",
18583
- "online",
18584
- "openid",
18585
- "operator",
18586
- "option",
18587
- "options",
18588
- "order",
18589
- "orders",
18590
- "org",
18591
- "organization",
18592
- "organizations",
18593
- "other",
18594
- "overview",
18595
- "owner",
18596
- "owners",
18597
- "p0rn",
18598
- "pack",
18599
- "page",
18600
- "pager",
18601
- "pages",
18602
- "paid",
18603
- "panel",
18604
- "partner",
18605
- "partnerpage",
18606
- "partners",
18607
- "password",
18608
- "patch",
18609
- "pay",
18610
- "payment",
18611
- "people",
18612
- "perl",
18613
- "person",
18614
- "phone",
18615
- "photo",
18616
- "photoalbum",
18617
- "photos",
18618
- "php",
18619
- "phpmyadmin",
18620
- "phppgadmin",
18621
- "phpredisadmin",
18622
- "pic",
18623
- "pics",
18624
- "picture",
18625
- "pictures",
18626
- "ping",
18627
- "pixel",
18628
- "places",
18629
- "plan",
18630
- "plans",
18631
- "plugin",
18632
- "plugins",
18633
- "podcasts",
18634
- "policies",
18635
- "policy",
18636
- "pop",
18637
- "pop3",
18638
- "popular",
18639
- "porn",
18640
- "portal",
18641
- "portals",
18642
- "post",
18643
- "postfix",
18644
- "postmaster",
18645
- "posts",
18646
- "pr",
18647
- "pr0n",
18648
- "premium",
18649
- "press",
18650
- "price",
18651
- "pricing",
18652
- "principles",
18653
- "print",
18654
- "privacy",
18655
- "privacy-policy",
18656
- "privacypolicy",
18657
- "privacy_policy",
18658
- "private",
18659
- "prod",
18660
- "product",
18661
- "production",
18662
- "products",
18663
- "profile",
18664
- "profiles",
18665
- "project",
18666
- "projects",
18667
- "promo",
18668
- "promotions",
18669
- "proxies",
18670
- "proxy",
18671
- "pub",
18672
- "public",
18673
- "purchase",
18674
- "purpose",
18675
- "put",
18676
- "python",
18677
- "queries",
18678
- "query",
18679
- "radio",
18680
- "random",
18681
- "ranking",
18682
- "read",
18683
- "reader",
18684
- "readme",
18685
- "recent",
18686
- "recruit",
18687
- "recruitment",
18688
- "redirect",
18689
- "register",
18690
- "registration",
18691
- "release",
18692
- "remove",
18693
- "replies",
18694
- "report",
18695
- "reports",
18696
- "repositories",
18697
- "repository",
18698
- "req",
18699
- "request",
18700
- "requests",
18701
- "research",
18702
- "reset",
18703
- "resolve",
18704
- "resolver",
18705
- "review",
18706
- "rnail",
18707
- "rnicrosoft",
18708
- "roc",
18709
- "root",
18710
- "rss",
18711
- "ruby",
18712
- "rule",
18713
- "sag",
18714
- "sale",
18715
- "sales",
18716
- "sample",
18717
- "samples",
18718
- "sandbox",
18719
- "save",
18720
- "scholar",
18721
- "school",
18722
- "schools",
18723
- "script",
18724
- "scripts",
18725
- "search",
18726
- "secure",
18727
- "security",
18728
- "self",
18729
- "seminars",
18730
- "send",
18731
- "server",
18732
- "server-info",
18733
- "server_info",
18734
- "server-status",
18735
- "server_status",
18736
- "servers",
18737
- "service",
18738
- "services",
18739
- "session",
18740
- "sessions",
18741
- "setting",
18742
- "settings",
18743
- "setup",
18744
- "share",
18745
- "shop",
18746
- "shopping",
18747
- "shortcut",
18748
- "shortcuts",
18749
- "show",
18750
- "sign-in",
18751
- "sign-up",
18752
- "signin",
18753
- "signout",
18754
- "signup",
18755
- "sign_in",
18756
- "sign_up",
18757
- "site",
18758
- "sitemap",
18759
- "sitemaps",
18760
- "sitenews",
18761
- "sites",
18762
- "sketchup",
18763
- "sky",
18764
- "slash",
18765
- "slashinvoice",
18766
- "slut",
18767
- "smartphone",
18768
- "sms",
18769
- "smtp",
18770
- "soap",
18771
- "software",
18772
- "sorry",
18773
- "source",
18774
- "spec",
18775
- "special",
18776
- "spreadsheet",
18777
- "spreadsheets",
18778
- "sql",
18779
- "src",
18780
- "srntp",
18781
- "ssh",
18782
- "ssl",
18783
- "ssladmin",
18784
- "ssladministrator",
18785
- "sslwebmaster",
18786
- "ssytem",
18787
- "staff",
18788
- "stage",
18789
- "staging",
18790
- "start",
18791
- "stat",
18792
- "state",
18793
- "static",
18794
- "statistics",
18795
- "stats",
18796
- "status",
18797
- "store",
18798
- "stores",
18799
- "stories",
18800
- "style",
18801
- "styleguide",
18802
- "styles",
18803
- "stylesheet",
18804
- "stylesheets",
18805
- "subdomain",
18806
- "subscribe",
18807
- "subscription",
18808
- "subscriptions",
18809
- "suggest",
18810
- "suggestqueries",
18811
- "support",
18812
- "survey",
18813
- "surveys",
18814
- "surveytool",
18815
- "svn",
18816
- "swf",
18817
- "syn",
18818
- "sync",
18819
- "syndicated",
18820
- "sys",
18821
- "sysadmin",
18822
- "sysadministrator",
18823
- "sysadmins",
18824
- "system",
18825
- "tablet",
18826
- "tablets",
18827
- "tag",
18828
- "tags",
18829
- "talk",
18830
- "talkgadget",
18831
- "task",
18832
- "tasks",
18833
- "team",
18834
- "teams",
18835
- "tech",
18836
- "telnet",
18837
- "term",
18838
- "terms",
18839
- "terms-of-service",
18840
- "termsofservice",
18841
- "terms_of_service",
18842
- "test",
18843
- "testing",
18844
- "tests",
18845
- "text",
18846
- "theme",
18847
- "themes",
18848
- "thread",
18849
- "threads",
18850
- "ticket",
18851
- "tickets",
18852
- "tmp",
18853
- "todo",
18854
- "to-do",
18855
- "to_do",
18856
- "toml",
18857
- "tool",
18858
- "toolbar",
18859
- "toolbars",
18860
- "tools",
18861
- "top",
18862
- "topic",
18863
- "topics",
18864
- "tos",
18865
- "tour",
18866
- "trac",
18867
- "translate",
18868
- "trace",
18869
- "translation",
18870
- "translations",
18871
- "translator",
18872
- "trends",
18873
- "tutorial",
18874
- "tux",
18875
- "tv",
18876
- "twitter",
18877
- "txt",
18878
- "ul",
18879
- "undef",
18880
- "unfollow",
18881
- "unsubscribe",
18882
- "update",
18883
- "updates",
18884
- "upgrade",
18885
- "upgrades",
18886
- "upi",
18887
- "upload",
18888
- "uploads",
18889
- "url",
18890
- "usage",
18891
- "user",
18892
- "username",
18893
- "usernames",
18894
- "users",
18895
- "uuid",
18896
- "validation",
18897
- "validations",
18898
- "ver",
18899
- "version",
18900
- "video",
18901
- "videos",
18902
- "video-stats",
18903
- "visitor",
18904
- "visitors",
18905
- "voice",
18906
- "volunteer",
18907
- "volunteers",
18908
- "w",
18909
- "watch",
18910
- "wave",
18911
- "weather",
18912
- "web",
18913
- "webdisk",
18914
- "webhook",
18915
- "webhooks",
18916
- "webmail",
18917
- "webmaster",
18918
- "webmasters",
18919
- "webrnail",
18920
- "website",
18921
- "websites",
18922
- "welcome",
18923
- "whm",
18924
- "whois",
18925
- "widget",
18926
- "widgets",
18927
- "wifi",
18928
- "wiki",
18929
- "wikis",
18930
- "win",
18931
- "windows",
18932
- "word",
18933
- "work",
18934
- "works",
18935
- "workshop",
18936
- "wpad",
18937
- "ww",
18938
- "wws",
18939
- "www",
18940
- "wwws",
18941
- "wwww",
18942
- "xfn",
18943
- "xhtml",
18944
- "xhtrnl",
18945
- "xml",
18946
- "xmpp",
18947
- "xpg",
18948
- "xxx",
18949
- "yaml",
18950
- "year",
18951
- "yml",
18952
- "you",
18953
- "yourdomain",
18954
- "yourname",
18955
- "yoursite",
18956
- "yourusername"
18957
- ];
18958
- var famousAccounts = [
18959
- "10ronaldinho",
18960
- "3gerardpique",
18961
- "aclu",
18962
- "adele",
18963
- "akshaykumar",
18964
- "aliaa08",
18965
- "aliciakeys",
18966
- "amitshah",
18967
- "andresiniesta8",
18968
- "anushkasharma",
18969
- "arianagrande",
18970
- "arrahman",
18971
- "arvindkejriwal",
18972
- "avrillavigne",
18973
- "barackobama",
18974
- "bbcbreaking",
18975
- "bbcworld",
18976
- "beingsalmankhan",
18977
- "billgates",
18978
- "britneyspears",
18979
- "brunomars",
18980
- "bts_bighit",
18981
- "bts_twt",
18982
- "championsleague",
18983
- "chrisbrown",
18984
- "cnnbrk",
18985
- "coldplay",
18986
- "conanobrien",
18987
- "cristiano",
18988
- "danieltosh",
18989
- "davidguetta",
18990
- "ddlovato",
18991
- "deepikapadukone",
18992
- "drake",
18993
- "elisapie",
18994
- "ellendegeneres",
18995
- "elonmusk",
18996
- "eminem",
18997
- "emmawatson",
18998
- "fcbarcelona",
18999
- "foxnews",
19000
- "harry_styles",
19001
- "hillaryclinton",
19002
- "iamsrk",
19003
- "ihrithik",
19004
- "imvkohli",
19005
- "instagram",
19006
- "jimmyfallon",
19007
- "jlo",
19008
- "joebiden",
19009
- "jtimberlake",
19010
- "justinbieber",
19011
- "kaka",
19012
- "kanyewest",
19013
- "katyperry",
19014
- "kendalljenner",
19015
- "kevinhart4real",
19016
- "khloekardashian",
19017
- "kimkardashian",
19018
- "kingjames",
19019
- "kourtneykardash",
19020
- "kyliejenner",
19021
- "ladygaga",
19022
- "liampayne",
19023
- "liltunechi",
19024
- "manutd",
19025
- "mariahcarey",
19026
- "mileycyrus",
19027
- "mohamadalarefe",
19028
- "narendramodi",
19029
- "nasa",
19030
- "nba",
19031
- "neymarjr",
19032
- "nfl",
19033
- "niallofficial",
19034
- "nickiminaj",
19035
- "npr",
19036
- "nytimes",
19037
- "onedirection",
19038
- "oprah",
19039
- "pink",
19040
- "pitbull",
19041
- "playstation",
19042
- "pmoindia",
19043
- "premierleague",
19044
- "priyankachopra",
19045
- "realdonaldtrump",
19046
- "ricky_martin",
19047
- "rihanna",
19048
- "sachin_rt",
19049
- "selenagomez",
19050
- "shakira",
19051
- "shawnmendes",
19052
- "sportscenter",
19053
- "srbachchan",
19054
- "subhisharma100",
19055
- "taylorswift13",
19056
- "theeconomist",
19057
- "twitter",
19058
- "virendersehwag",
19059
- "whitehouse45",
19060
- "wizkhalifa",
19061
- "youtube",
19062
- "zaynmalik",
19063
- "beyonce",
19064
- "billieeilish",
19065
- "leomessi",
19066
- "natgeo",
19067
- "nike",
19068
- "snoopdogg",
19069
- "taylorswift",
19070
- "therock",
19071
- "10downingstreet",
19072
- "aoc",
19073
- "carterjwm",
19074
- "dril",
19075
- "gretathunberg",
19076
- "kamalaharris",
19077
- "kremlinrussia_e",
19078
- "potus",
19079
- "rondesantisfl",
19080
- "ukraine",
19081
- "washingtonpost",
19082
- "yousuck2020",
19083
- "zelenskyyua",
19084
- "akiko_lawson",
19085
- "ariyoshihiroiki",
19086
- "asahi",
19087
- "dozle_official",
19088
- "famima_now",
19089
- "ff_xiv_jp",
19090
- "fujitv",
19091
- "gigazine",
19092
- "hajimesyacho",
19093
- "hikakin",
19094
- "jocx",
19095
- "jotx",
19096
- "kiyo_saiore",
19097
- "mainichi",
19098
- "matsu_bouzu",
19099
- "naomiosaka",
19100
- "nhk",
19101
- "nikkei",
19102
- "nintendo",
19103
- "ntv",
19104
- "oowareware1945",
19105
- "pamyurin",
19106
- "poke_times",
19107
- "rolaworld",
19108
- "seikintv",
19109
- "starbucksjapan",
19110
- "tbs",
19111
- "tbs_pr",
19112
- "tvasahi",
19113
- "tvtokyo",
19114
- "yokoono",
19115
- "yomiuri_online",
19116
- "brasildefato",
19117
- "claudialeitte",
19118
- "correio",
19119
- "em_com",
19120
- "estadao",
19121
- "folha",
19122
- "gazetadopovo",
19123
- "ivetesangalo",
19124
- "jairbolsonaro",
19125
- "jornaldobrasil",
19126
- "jornaloglobo",
19127
- "lucianohuck",
19128
- "lulaoficial",
19129
- "marcosmion",
19130
- "paulocoelho",
19131
- "portalr7",
19132
- "rede_globo",
19133
- "zerohora"
19134
- ];
19135
- var reservedSubdomains = [
19136
- ...atpSpecific,
19137
- ...commonlyReserved,
19138
- ...famousAccounts
19139
- ].reduce((acc, cur) => {
19140
- return {
19141
- ...acc,
19142
- [cur]: true
19143
- };
19144
- }, {});
19145
-
19146
18190
  // ../lexicon/src/validators/formats.ts
19147
18191
  var import_iso_datestring_validator = __toESM(require_dist());
19148
18192
 
@@ -23596,26 +22640,46 @@ var cid_set_default = CidSet;
23596
22640
  // src/types.ts
23597
22641
  var unsignedCommit = z.object({
23598
22642
  did: z.string(),
23599
- version: z.number(),
23600
- prev: schema.cid.nullable(),
23601
- data: schema.cid
22643
+ version: z.literal(3),
22644
+ data: schema.cid,
22645
+ rev: z.string(),
22646
+ prev: schema.cid.nullable().optional()
23602
22647
  });
23603
22648
  var commit = z.object({
23604
22649
  did: z.string(),
23605
- version: z.number(),
23606
- prev: schema.cid.nullable(),
22650
+ version: z.literal(3),
23607
22651
  data: schema.cid,
22652
+ rev: z.string(),
22653
+ prev: schema.cid.nullable().optional(),
23608
22654
  sig: schema.bytes
23609
22655
  });
22656
+ var legacyV2Commit = z.object({
22657
+ did: z.string(),
22658
+ version: z.literal(2),
22659
+ data: schema.cid,
22660
+ rev: z.string().optional(),
22661
+ prev: schema.cid.nullable(),
22662
+ sig: schema.bytes
22663
+ });
22664
+ var versionedCommit = z.discriminatedUnion("version", [
22665
+ commit,
22666
+ legacyV2Commit
22667
+ ]);
23610
22668
  var schema2 = {
23611
22669
  ...schema,
23612
- commit
22670
+ commit,
22671
+ legacyV2Commit,
22672
+ versionedCommit
23613
22673
  };
23614
22674
  var def2 = {
23615
22675
  ...def,
23616
22676
  commit: {
23617
22677
  name: "commit",
23618
22678
  schema: schema2.commit
22679
+ },
22680
+ versionedCommit: {
22681
+ name: "versioned_commit",
22682
+ schema: schema2.versionedCommit
23619
22683
  }
23620
22684
  };
23621
22685
  var WriteOpAction = /* @__PURE__ */ ((WriteOpAction2) => {
@@ -23644,7 +22708,8 @@ __export(util_exports2, {
23644
22708
  // ../crypto/src/const.ts
23645
22709
  var P256_DID_PREFIX = new Uint8Array([128, 36]);
23646
22710
  var SECP256K1_DID_PREFIX = new Uint8Array([231, 1]);
23647
- var BASE58_DID_PREFIX = "did:key:z";
22711
+ var BASE58_MULTIBASE_PREFIX = "z";
22712
+ var DID_KEY_PREFIX = "did:key:";
23648
22713
  var P256_JWT_ALG = "ES256";
23649
22714
  var SECP256K1_JWT_ALG = "ES256K";
23650
22715
 
@@ -25526,12 +24591,12 @@ var plugins = [plugin_default, plugin_default2];
25526
24591
  var plugins_default = plugins;
25527
24592
 
25528
24593
  // ../crypto/src/did.ts
25529
- var parseDidKey = (did2) => {
25530
- if (!did2.startsWith(BASE58_DID_PREFIX)) {
25531
- throw new Error(`Incorrect prefix for did:key: ${did2}`);
24594
+ var parseMultikey = (multikey) => {
24595
+ if (!multikey.startsWith(BASE58_MULTIBASE_PREFIX)) {
24596
+ throw new Error(`Incorrect prefix for multikey: ${multikey}`);
25532
24597
  }
25533
24598
  const prefixedBytes = fromString2(
25534
- did2.slice(BASE58_DID_PREFIX.length),
24599
+ multikey.slice(BASE58_MULTIBASE_PREFIX.length),
25535
24600
  "base58btc"
25536
24601
  );
25537
24602
  const plugin = plugins_default.find((p) => hasPrefix(prefixedBytes, p.prefix));
@@ -25549,6 +24614,12 @@ var parseDidKey = (did2) => {
25549
24614
  keyBytes
25550
24615
  };
25551
24616
  };
24617
+ var parseDidKey = (did2) => {
24618
+ if (!did2.startsWith(DID_KEY_PREFIX)) {
24619
+ throw new Error(`Incorrect prefix for did:key: ${did2}`);
24620
+ }
24621
+ return parseMultikey(did2.slice(DID_KEY_PREFIX.length));
24622
+ };
25552
24623
  var hasPrefix = (bytes3, prefix) => {
25553
24624
  return equals3(prefix, bytes3.subarray(0, prefix.byteLength));
25554
24625
  };
@@ -25709,14 +24780,6 @@ var MissingBlocksError = class extends Error {
25709
24780
  this.cids = cids;
25710
24781
  }
25711
24782
  };
25712
- var MissingCommitBlocksError = class extends Error {
25713
- constructor(commit2, cids) {
25714
- const cidStr = cids.map((c) => c.toString());
25715
- super(`missing blocks for commit ${commit2.toString()}: ${cidStr}`);
25716
- this.commit = commit2;
25717
- this.cids = cids;
25718
- }
25719
- };
25720
24783
  var UnexpectedObjectError = class extends Error {
25721
24784
  constructor(cid2, def3) {
25722
24785
  super(`unexpected object at ${cid2.toString()}, expected: ${def3}`);
@@ -26266,93 +25329,6 @@ var CarWriter2 = class extends CarWriter {
26266
25329
  }
26267
25330
  };
26268
25331
 
26269
- // src/data-diff.ts
26270
- var DataDiff = class {
26271
- constructor() {
26272
- this.adds = {};
26273
- this.updates = {};
26274
- this.deletes = {};
26275
- this.newCids = new cid_set_default();
26276
- this.removedCids = new cid_set_default();
26277
- }
26278
- static async of(curr, prev) {
26279
- return mstDiff(curr, prev);
26280
- }
26281
- recordAdd(key, cid2) {
26282
- this.adds[key] = { key, cid: cid2 };
26283
- this.newCids.add(cid2);
26284
- }
26285
- recordUpdate(key, prev, cid2) {
26286
- this.updates[key] = { key, prev, cid: cid2 };
26287
- this.newCids.add(cid2);
26288
- }
26289
- recordDelete(key, cid2) {
26290
- this.deletes[key] = { key, cid: cid2 };
26291
- }
26292
- recordNewCid(cid2) {
26293
- if (this.removedCids.has(cid2)) {
26294
- this.removedCids.delete(cid2);
26295
- } else {
26296
- this.newCids.add(cid2);
26297
- }
26298
- }
26299
- recordRemovedCid(cid2) {
26300
- if (this.newCids.has(cid2)) {
26301
- this.newCids.delete(cid2);
26302
- } else {
26303
- this.removedCids.add(cid2);
26304
- }
26305
- }
26306
- addDiff(diff) {
26307
- for (const add of diff.addList()) {
26308
- if (this.deletes[add.key]) {
26309
- const del = this.deletes[add.key];
26310
- if (del.cid !== add.cid) {
26311
- this.recordUpdate(add.key, del.cid, add.cid);
26312
- }
26313
- delete this.deletes[add.key];
26314
- } else {
26315
- this.recordAdd(add.key, add.cid);
26316
- }
26317
- }
26318
- for (const update of diff.updateList()) {
26319
- this.recordUpdate(update.key, update.prev, update.cid);
26320
- delete this.adds[update.key];
26321
- delete this.deletes[update.key];
26322
- }
26323
- for (const del of diff.deleteList()) {
26324
- if (this.adds[del.key]) {
26325
- delete this.adds[del.key];
26326
- } else {
26327
- delete this.updates[del.key];
26328
- this.recordDelete(del.key, del.cid);
26329
- }
26330
- }
26331
- this.newCids.addSet(diff.newCids);
26332
- }
26333
- addList() {
26334
- return Object.values(this.adds);
26335
- }
26336
- updateList() {
26337
- return Object.values(this.updates);
26338
- }
26339
- deleteList() {
26340
- return Object.values(this.deletes);
26341
- }
26342
- newCidList() {
26343
- return this.newCids.toList();
26344
- }
26345
- updatedKeys() {
26346
- const keys = [
26347
- ...Object.keys(this.adds),
26348
- ...Object.keys(this.updates),
26349
- ...Object.keys(this.deletes)
26350
- ];
26351
- return [...new Set(keys)];
26352
- }
26353
- };
26354
- var data_diff_default = DataDiff;
26355
-
26356
25332
  // src/util.ts
26357
25333
  async function* verifyIncomingCarBlocks(car) {
26358
25334
  for await (const block of car) {
@@ -26408,27 +25384,6 @@ var readCarWithRoot = async (bytes3) => {
26408
25384
  blocks
26409
25385
  };
26410
25386
  };
26411
- var getWriteLog = async (storage, latest, earliest) => {
26412
- const commits = await storage.getCommitPath(latest, earliest);
26413
- if (!commits)
26414
- throw new Error("Could not find shared history");
26415
- const heads = await Promise.all(commits.map((c) => repo_default.load(storage, c)));
26416
- let prev = await MST.create(storage);
26417
- const msts = heads.map((h) => h.data);
26418
- const diffs = [];
26419
- for (const mst of msts) {
26420
- diffs.push(await data_diff_default.of(mst, prev));
26421
- prev = mst;
26422
- }
26423
- const fullDiff = collapseDiffs(diffs);
26424
- const diffBlocks = await storage.getBlocks(fullDiff.newCidList());
26425
- if (diffBlocks.missing.length > 0) {
26426
- throw new MissingBlocksError("write op log", diffBlocks.missing);
26427
- }
26428
- return Promise.all(
26429
- diffs.map((diff) => diffToWriteDescripts(diff, diffBlocks.blocks))
26430
- );
26431
- };
26432
25387
  var diffToWriteDescripts = (diff, blocks) => {
26433
25388
  return Promise.all([
26434
25389
  ...diff.addList().map(async (add) => {
@@ -26465,54 +25420,16 @@ var diffToWriteDescripts = (diff, blocks) => {
26465
25420
  })
26466
25421
  ]);
26467
25422
  };
26468
- var collapseWriteLog = (log) => {
26469
- const creates = {};
26470
- const updates = {};
26471
- const deletes = {};
26472
- for (const commit2 of log) {
26473
- for (const op of commit2) {
26474
- const key = op.collection + "/" + op.rkey;
26475
- if (op.action === "create" /* Create */) {
26476
- const del = deletes[key];
26477
- if (del) {
26478
- if (del.cid !== op.cid) {
26479
- updates[key] = {
26480
- ...op,
26481
- action: "update" /* Update */,
26482
- prev: del.cid
26483
- };
26484
- }
26485
- delete deletes[key];
26486
- } else {
26487
- creates[key] = op;
26488
- }
26489
- } else if (op.action === "update" /* Update */) {
26490
- updates[key] = op;
26491
- delete creates[key];
26492
- delete deletes[key];
26493
- } else if (op.action === "delete" /* Delete */) {
26494
- if (creates[key]) {
26495
- delete creates[key];
26496
- } else {
26497
- delete updates[key];
26498
- deletes[key] = op;
26499
- }
26500
- } else {
26501
- throw new Error(`unknown action: ${op}`);
26502
- }
25423
+ var ensureCreates = (descripts) => {
25424
+ const creates = [];
25425
+ for (const descript of descripts) {
25426
+ if (descript.action !== "create" /* Create */) {
25427
+ throw new Error(`Unexpected action: ${descript.action}`);
25428
+ } else {
25429
+ creates.push(descript);
26503
25430
  }
26504
25431
  }
26505
- return [
26506
- ...Object.values(creates),
26507
- ...Object.values(updates),
26508
- ...Object.values(deletes)
26509
- ];
26510
- };
26511
- var collapseDiffs = (diffs) => {
26512
- return diffs.reduce((acc, cur) => {
26513
- acc.addDiff(cur);
26514
- return acc;
26515
- }, new data_diff_default());
25432
+ return creates;
26516
25433
  };
26517
25434
  var parseDataKey = (key) => {
26518
25435
  const parts = key.split("/");
@@ -26552,6 +25469,17 @@ var cborToLexRecord = (val) => {
26552
25469
  var cidForRecord = async (val) => {
26553
25470
  return cidForCbor(lexToIpld(val));
26554
25471
  };
25472
+ var ensureV3Commit = (commit2) => {
25473
+ if (commit2.version === 3) {
25474
+ return commit2;
25475
+ } else {
25476
+ return {
25477
+ ...commit2,
25478
+ version: 3,
25479
+ rev: commit2.rev ?? TID.nextStr()
25480
+ };
25481
+ }
25482
+ };
26555
25483
 
26556
25484
  // src/parse.ts
26557
25485
  var getAndParseRecord = async (blocks, cid2) => {
@@ -26640,6 +25568,12 @@ var MST = class {
26640
25568
  async getPointer() {
26641
25569
  if (!this.outdatedPointer)
26642
25570
  return this.pointer;
25571
+ const { cid: cid2 } = await this.serialize();
25572
+ this.pointer = cid2;
25573
+ this.outdatedPointer = false;
25574
+ return this.pointer;
25575
+ }
25576
+ async serialize() {
26643
25577
  let entries = await this.getEntries();
26644
25578
  const outdated = entries.filter(
26645
25579
  (e) => e.isTree() && e.outdatedPointer
@@ -26648,9 +25582,12 @@ var MST = class {
26648
25582
  await Promise.all(outdated.map((e) => e.getPointer()));
26649
25583
  entries = await this.getEntries();
26650
25584
  }
26651
- this.pointer = await cidForEntries(entries);
26652
- this.outdatedPointer = false;
26653
- return this.pointer;
25585
+ const data = serializeNodeData(entries);
25586
+ const block = await dataToCborBlock(data);
25587
+ return {
25588
+ cid: block.cid,
25589
+ bytes: block.bytes
25590
+ };
26654
25591
  }
26655
25592
  async getLayer() {
26656
25593
  this.layer = await this.attemptGetLayer();
@@ -27151,6 +26088,95 @@ var Leaf = class {
27151
26088
  }
27152
26089
  };
27153
26090
 
26091
+ // src/data-diff.ts
26092
+ var DataDiff = class {
26093
+ constructor() {
26094
+ this.adds = {};
26095
+ this.updates = {};
26096
+ this.deletes = {};
26097
+ this.newMstBlocks = new block_map_default();
26098
+ this.newLeafCids = new cid_set_default();
26099
+ this.removedCids = new cid_set_default();
26100
+ }
26101
+ static async of(curr, prev) {
26102
+ return mstDiff(curr, prev);
26103
+ }
26104
+ async nodeAdd(node) {
26105
+ if (node.isLeaf()) {
26106
+ this.leafAdd(node.key, node.value);
26107
+ } else {
26108
+ const data = await node.serialize();
26109
+ this.treeAdd(data.cid, data.bytes);
26110
+ }
26111
+ }
26112
+ async nodeDelete(node) {
26113
+ if (node.isLeaf()) {
26114
+ const key = node.key;
26115
+ const cid2 = node.value;
26116
+ this.deletes[key] = { key, cid: cid2 };
26117
+ this.removedCids.add(cid2);
26118
+ } else {
26119
+ const cid2 = await node.getPointer();
26120
+ this.treeDelete(cid2);
26121
+ }
26122
+ }
26123
+ leafAdd(key, cid2) {
26124
+ this.adds[key] = { key, cid: cid2 };
26125
+ if (this.removedCids.has(cid2)) {
26126
+ this.removedCids.delete(cid2);
26127
+ } else {
26128
+ this.newLeafCids.add(cid2);
26129
+ }
26130
+ }
26131
+ leafUpdate(key, prev, cid2) {
26132
+ if (prev.equals(cid2))
26133
+ return;
26134
+ this.updates[key] = { key, prev, cid: cid2 };
26135
+ this.removedCids.add(prev);
26136
+ this.newLeafCids.add(cid2);
26137
+ }
26138
+ leafDelete(key, cid2) {
26139
+ this.deletes[key] = { key, cid: cid2 };
26140
+ if (this.newLeafCids.has(cid2)) {
26141
+ this.newLeafCids.delete(cid2);
26142
+ } else {
26143
+ this.removedCids.add(cid2);
26144
+ }
26145
+ }
26146
+ treeAdd(cid2, bytes3) {
26147
+ if (this.removedCids.has(cid2)) {
26148
+ this.removedCids.delete(cid2);
26149
+ } else {
26150
+ this.newMstBlocks.set(cid2, bytes3);
26151
+ }
26152
+ }
26153
+ treeDelete(cid2) {
26154
+ if (this.newMstBlocks.has(cid2)) {
26155
+ this.newMstBlocks.delete(cid2);
26156
+ } else {
26157
+ this.removedCids.add(cid2);
26158
+ }
26159
+ }
26160
+ addList() {
26161
+ return Object.values(this.adds);
26162
+ }
26163
+ updateList() {
26164
+ return Object.values(this.updates);
26165
+ }
26166
+ deleteList() {
26167
+ return Object.values(this.deletes);
26168
+ }
26169
+ updatedKeys() {
26170
+ const keys = [
26171
+ ...Object.keys(this.adds),
26172
+ ...Object.keys(this.updates),
26173
+ ...Object.keys(this.deletes)
26174
+ ];
26175
+ return [...new Set(keys)];
26176
+ }
26177
+ };
26178
+ var data_diff_default = DataDiff;
26179
+
27154
26180
  // src/mst/walker.ts
27155
26181
  var MstWalker = class {
27156
26182
  constructor(root) {
@@ -27249,11 +26275,7 @@ var walker_default = MstWalker;
27249
26275
  var nullDiff = async (tree2) => {
27250
26276
  const diff = new DataDiff();
27251
26277
  for await (const entry of tree2.walk()) {
27252
- if (entry.isLeaf()) {
27253
- diff.recordAdd(entry.key, entry.value);
27254
- } else {
27255
- diff.recordNewCid(entry.pointer);
27256
- }
26278
+ await diff.nodeAdd(entry);
27257
26279
  }
27258
26280
  return diff;
27259
26281
  };
@@ -27268,21 +26290,11 @@ var mstDiff = async (curr, prev) => {
27268
26290
  const rightWalker = new walker_default(curr);
27269
26291
  while (!leftWalker.status.done || !rightWalker.status.done) {
27270
26292
  if (leftWalker.status.done && !rightWalker.status.done) {
27271
- const node = rightWalker.status.curr;
27272
- if (node.isLeaf()) {
27273
- diff.recordAdd(node.key, node.value);
27274
- } else {
27275
- diff.recordNewCid(node.pointer);
27276
- }
26293
+ await diff.nodeAdd(rightWalker.status.curr);
27277
26294
  await rightWalker.advance();
27278
26295
  continue;
27279
26296
  } else if (!leftWalker.status.done && rightWalker.status.done) {
27280
- const node = leftWalker.status.curr;
27281
- if (node.isLeaf()) {
27282
- diff.recordDelete(node.key, node.value);
27283
- } else {
27284
- diff.recordRemovedCid(node.pointer);
27285
- }
26297
+ await diff.nodeDelete(leftWalker.status.curr);
27286
26298
  await leftWalker.advance();
27287
26299
  continue;
27288
26300
  }
@@ -27295,42 +26307,34 @@ var mstDiff = async (curr, prev) => {
27295
26307
  if (left.isLeaf() && right.isLeaf()) {
27296
26308
  if (left.key === right.key) {
27297
26309
  if (!left.value.equals(right.value)) {
27298
- diff.recordUpdate(left.key, left.value, right.value);
26310
+ diff.leafUpdate(left.key, left.value, right.value);
27299
26311
  }
27300
26312
  await leftWalker.advance();
27301
26313
  await rightWalker.advance();
27302
26314
  } else if (left.key < right.key) {
27303
- diff.recordDelete(left.key, left.value);
26315
+ diff.leafDelete(left.key, left.value);
27304
26316
  await leftWalker.advance();
27305
26317
  } else {
27306
- diff.recordAdd(right.key, right.value);
26318
+ diff.leafAdd(right.key, right.value);
27307
26319
  await rightWalker.advance();
27308
26320
  }
27309
26321
  continue;
27310
26322
  }
27311
26323
  if (leftWalker.layer() > rightWalker.layer()) {
27312
26324
  if (left.isLeaf()) {
27313
- if (right.isLeaf()) {
27314
- diff.recordAdd(right.key, right.value);
27315
- } else {
27316
- diff.recordNewCid(right.pointer);
27317
- }
26325
+ await diff.nodeAdd(right);
27318
26326
  await rightWalker.advance();
27319
26327
  } else {
27320
- diff.recordRemovedCid(left.pointer);
26328
+ await diff.nodeDelete(left);
27321
26329
  await leftWalker.stepInto();
27322
26330
  }
27323
26331
  continue;
27324
26332
  } else if (leftWalker.layer() < rightWalker.layer()) {
27325
26333
  if (right.isLeaf()) {
27326
- if (left.isLeaf()) {
27327
- diff.recordDelete(left.key, left.value);
27328
- } else {
27329
- diff.recordRemovedCid(left.pointer);
27330
- }
26334
+ await diff.nodeDelete(left);
27331
26335
  await leftWalker.advance();
27332
26336
  } else {
27333
- diff.recordNewCid(right.pointer);
26337
+ await diff.nodeAdd(right);
27334
26338
  await rightWalker.stepInto();
27335
26339
  }
27336
26340
  continue;
@@ -27340,19 +26344,19 @@ var mstDiff = async (curr, prev) => {
27340
26344
  await leftWalker.stepOver();
27341
26345
  await rightWalker.stepOver();
27342
26346
  } else {
27343
- diff.recordNewCid(right.pointer);
27344
- diff.recordRemovedCid(left.pointer);
26347
+ await diff.nodeAdd(right);
26348
+ await diff.nodeDelete(left);
27345
26349
  await leftWalker.stepInto();
27346
26350
  await rightWalker.stepInto();
27347
26351
  }
27348
26352
  continue;
27349
26353
  }
27350
26354
  if (left.isLeaf() && right.isTree()) {
27351
- diff.recordNewCid(right.pointer);
26355
+ await diff.nodeAdd(right);
27352
26356
  await rightWalker.stepInto();
27353
26357
  continue;
27354
26358
  } else if (left.isTree() && right.isLeaf()) {
27355
- diff.recordRemovedCid(left.pointer);
26359
+ await diff.nodeDelete(left);
27356
26360
  await leftWalker.stepInto();
27357
26361
  continue;
27358
26362
  }
@@ -27374,13 +26378,13 @@ var ReadableRepo = class {
27374
26378
  this.cid = params2.cid;
27375
26379
  }
27376
26380
  static async load(storage, commitCid) {
27377
- const commit2 = await storage.readObj(commitCid, def2.commit);
26381
+ const commit2 = await storage.readObj(commitCid, def2.versionedCommit);
27378
26382
  const data = await MST.load(storage, commit2.data);
27379
26383
  logger_default.info({ did: commit2.did }, "loaded repo for");
27380
26384
  return new ReadableRepo({
27381
26385
  storage,
27382
26386
  data,
27383
- commit: commit2,
26387
+ commit: ensureV3Commit(commit2),
27384
26388
  cid: commitCid
27385
26389
  });
27386
26390
  }
@@ -27430,27 +26434,33 @@ var Repo = class extends ReadableRepo {
27430
26434
  const dataKey = formatDataKey(record.collection, record.rkey);
27431
26435
  data = await data.add(dataKey, cid2);
27432
26436
  }
27433
- const unstoredData = await data.getUnstoredBlocks();
27434
- newBlocks.addMap(unstoredData.blocks);
26437
+ const dataCid = await data.getPointer();
26438
+ const diff = await data_diff_default.of(data, null);
26439
+ newBlocks.addMap(diff.newMstBlocks);
26440
+ const rev = TID.nextStr();
27435
26441
  const commit2 = await signCommit(
27436
26442
  {
27437
26443
  did: did2,
27438
- version: 2,
26444
+ version: 3,
26445
+ rev,
27439
26446
  prev: null,
27440
- data: unstoredData.root
26447
+ data: dataCid
27441
26448
  },
27442
26449
  keypair
27443
26450
  );
27444
26451
  const commitCid = await newBlocks.add(commit2);
27445
26452
  return {
27446
- commit: commitCid,
26453
+ cid: commitCid,
26454
+ rev,
26455
+ since: null,
27447
26456
  prev: null,
27448
- blocks: newBlocks
26457
+ newBlocks,
26458
+ removedCids: diff.removedCids
27449
26459
  };
27450
26460
  }
27451
26461
  static async createFromCommit(storage, commit2) {
27452
26462
  await storage.applyCommit(commit2);
27453
- return Repo.load(storage, commit2.commit);
26463
+ return Repo.load(storage, commit2.cid);
27454
26464
  }
27455
26465
  static async create(storage, did2, keypair, initialWrites = []) {
27456
26466
  const commit2 = await Repo.formatInitCommit(
@@ -27462,31 +26472,31 @@ var Repo = class extends ReadableRepo {
27462
26472
  return Repo.createFromCommit(storage, commit2);
27463
26473
  }
27464
26474
  static async load(storage, cid2) {
27465
- const commitCid = cid2 || await storage.getHead();
26475
+ const commitCid = cid2 || await storage.getRoot();
27466
26476
  if (!commitCid) {
27467
26477
  throw new Error("No cid provided and none in storage");
27468
26478
  }
27469
- const commit2 = await storage.readObj(commitCid, def2.commit);
26479
+ const commit2 = await storage.readObj(commitCid, def2.versionedCommit);
27470
26480
  const data = await MST.load(storage, commit2.data);
27471
26481
  logger_default.info({ did: commit2.did }, "loaded repo for");
27472
26482
  return new Repo({
27473
26483
  storage,
27474
26484
  data,
27475
- commit: commit2,
26485
+ commit: ensureV3Commit(commit2),
27476
26486
  cid: commitCid
27477
26487
  });
27478
26488
  }
27479
26489
  async formatCommit(toWrite, keypair) {
27480
26490
  const writes = Array.isArray(toWrite) ? toWrite : [toWrite];
27481
- const commitBlocks = new block_map_default();
26491
+ const leaves = new block_map_default();
27482
26492
  let data = this.data;
27483
26493
  for (const write of writes) {
27484
26494
  if (write.action === "create" /* Create */) {
27485
- const cid2 = await commitBlocks.add(write.record);
26495
+ const cid2 = await leaves.add(write.record);
27486
26496
  const dataKey = write.collection + "/" + write.rkey;
27487
26497
  data = await data.add(dataKey, cid2);
27488
26498
  } else if (write.action === "update" /* Update */) {
27489
- const cid2 = await commitBlocks.add(write.record);
26499
+ const cid2 = await leaves.add(write.record);
27490
26500
  const dataKey = write.collection + "/" + write.rkey;
27491
26501
  data = await data.update(dataKey, cid2);
27492
26502
  } else if (write.action === "delete" /* Delete */) {
@@ -27494,73 +26504,50 @@ var Repo = class extends ReadableRepo {
27494
26504
  data = await data.delete(dataKey);
27495
26505
  }
27496
26506
  }
27497
- const unstoredData = await data.getUnstoredBlocks();
27498
- commitBlocks.addMap(unstoredData.blocks);
26507
+ const dataCid = await data.getPointer();
27499
26508
  const diff = await data_diff_default.of(data, this.data);
27500
- const found = commitBlocks.getMany(diff.newCidList());
27501
- if (found.missing.length > 0) {
27502
- const fromStorage = await this.storage.getBlocks(found.missing);
27503
- if (fromStorage.missing.length > 0) {
27504
- throw new Error(
27505
- "Could not find block for commit in Datastore or storage"
27506
- );
27507
- }
27508
- commitBlocks.addMap(fromStorage.blocks);
27509
- }
26509
+ const newBlocks = diff.newMstBlocks;
26510
+ const removedCids = diff.removedCids;
26511
+ const addedLeaves = leaves.getMany(diff.newLeafCids.toList());
26512
+ if (addedLeaves.missing.length > 0) {
26513
+ throw new Error(`Missing leaf blocks: ${addedLeaves.missing}`);
26514
+ }
26515
+ newBlocks.addMap(addedLeaves.blocks);
26516
+ const rev = TID.nextStr(this.commit.rev);
27510
26517
  const commit2 = await signCommit(
27511
26518
  {
27512
26519
  did: this.did,
27513
- version: 2,
27514
- prev: this.cid,
27515
- data: unstoredData.root
26520
+ version: 3,
26521
+ rev,
26522
+ prev: null,
26523
+ data: dataCid
27516
26524
  },
27517
26525
  keypair
27518
26526
  );
27519
- const commitCid = await commitBlocks.add(commit2);
26527
+ const commitCid = await newBlocks.add(commit2);
26528
+ if (commitCid.equals(this.cid)) {
26529
+ newBlocks.delete(commitCid);
26530
+ } else {
26531
+ removedCids.add(this.cid);
26532
+ }
27520
26533
  return {
27521
- commit: commitCid,
26534
+ cid: commitCid,
26535
+ rev,
26536
+ since: this.commit.rev,
27522
26537
  prev: this.cid,
27523
- blocks: commitBlocks
26538
+ newBlocks,
26539
+ removedCids
27524
26540
  };
27525
26541
  }
27526
26542
  async applyCommit(commitData) {
27527
26543
  await this.storage.applyCommit(commitData);
27528
- return Repo.load(this.storage, commitData.commit);
26544
+ return Repo.load(this.storage, commitData.cid);
27529
26545
  }
27530
26546
  async applyWrites(toWrite, keypair) {
27531
26547
  const commit2 = await this.formatCommit(toWrite, keypair);
27532
26548
  return this.applyCommit(commit2);
27533
26549
  }
27534
- async formatRebase(keypair) {
27535
- const preservedCids = await this.data.allCids();
27536
- const blocks = new block_map_default();
27537
- const commit2 = await signCommit(
27538
- {
27539
- did: this.did,
27540
- version: 2,
27541
- prev: null,
27542
- data: this.commit.data
27543
- },
27544
- keypair
27545
- );
27546
- const commitCid = await blocks.add(commit2);
27547
- return {
27548
- commit: commitCid,
27549
- rebased: this.cid,
27550
- blocks,
27551
- preservedCids: preservedCids.toList()
27552
- };
27553
- }
27554
- async applyRebase(rebase) {
27555
- await this.storage.applyRebase(rebase);
27556
- return Repo.load(this.storage, rebase.commit);
27557
- }
27558
- async rebase(keypair) {
27559
- const rebaseData = await this.formatRebase(keypair);
27560
- return this.applyRebase(rebaseData);
27561
- }
27562
26550
  };
27563
- var repo_default = Repo;
27564
26551
 
27565
26552
  // src/storage/readable-blockstore.ts
27566
26553
  var ReadableBlockstore = class {
@@ -27598,39 +26585,18 @@ var ReadableBlockstore = class {
27598
26585
  };
27599
26586
  var readable_blockstore_default = ReadableBlockstore;
27600
26587
 
27601
- // src/storage/repo-storage.ts
27602
- var RepoStorage = class extends readable_blockstore_default {
27603
- async applyCommit(commit2) {
27604
- await Promise.all([
27605
- this.indexCommits([commit2]),
27606
- this.updateHead(commit2.commit, commit2.prev)
27607
- ]);
27608
- }
27609
- async getCommits(latest, earliest) {
27610
- const commitPath = await this.getCommitPath(latest, earliest);
27611
- if (!commitPath)
27612
- return null;
27613
- const blocksByCommit = await this.getBlocksForCommits(commitPath);
27614
- return commitPath.map((commit2) => ({
27615
- commit: commit2,
27616
- blocks: blocksByCommit[commit2.toString()] || new block_map_default()
27617
- }));
27618
- }
27619
- };
27620
- var repo_storage_default = RepoStorage;
27621
-
27622
26588
  // src/storage/memory-blockstore.ts
27623
- var MemoryBlockstore = class extends repo_storage_default {
26589
+ var MemoryBlockstore = class extends readable_blockstore_default {
27624
26590
  constructor(blocks) {
27625
26591
  super();
27626
- this.head = null;
26592
+ this.root = null;
27627
26593
  this.blocks = new block_map_default();
27628
26594
  if (blocks) {
27629
26595
  this.blocks.addMap(blocks);
27630
26596
  }
27631
26597
  }
27632
- async getHead() {
27633
- return this.head;
26598
+ async getRoot() {
26599
+ return this.root;
27634
26600
  }
27635
26601
  async getBytes(cid2) {
27636
26602
  return this.blocks.get(cid2) || null;
@@ -27647,68 +26613,18 @@ var MemoryBlockstore = class extends repo_storage_default {
27647
26613
  async putMany(blocks) {
27648
26614
  this.blocks.addMap(blocks);
27649
26615
  }
27650
- async indexCommits(commits) {
27651
- commits.forEach((commit2) => {
27652
- this.blocks.addMap(commit2.blocks);
27653
- });
27654
- }
27655
- async updateHead(cid2, _prev) {
27656
- this.head = cid2;
26616
+ async updateRoot(cid2) {
26617
+ this.root = cid2;
27657
26618
  }
27658
26619
  async applyCommit(commit2) {
27659
- this.blocks.addMap(commit2.blocks);
27660
- this.head = commit2.commit;
27661
- }
27662
- async getCommitPath(latest, earliest) {
27663
- let curr = latest;
27664
- const path = [];
27665
- while (curr !== null) {
27666
- path.push(curr);
27667
- const commit2 = await this.readObj(curr, def2.commit);
27668
- if (!earliest && commit2.prev === null) {
27669
- return path.reverse();
27670
- } else if (earliest && commit2.prev.equals(earliest)) {
27671
- return path.reverse();
27672
- }
27673
- curr = commit2.prev;
27674
- }
27675
- return null;
27676
- }
27677
- async getBlocksForCommits(commits) {
27678
- const commitData = {};
27679
- let prevData = null;
27680
- for (const commitCid of commits) {
27681
- const commit2 = await this.readObj(commitCid, def2.commit);
27682
- const data = await MST.load(this, commit2.data);
27683
- const diff = await data_diff_default.of(data, prevData);
27684
- const { blocks, missing } = await this.getBlocks([
27685
- commitCid,
27686
- ...diff.newCidList()
27687
- ]);
27688
- if (missing.length > 0) {
27689
- throw new MissingCommitBlocksError(commitCid, missing);
27690
- }
27691
- commitData[commitCid.toString()] = blocks;
27692
- prevData = data;
27693
- }
27694
- return commitData;
27695
- }
27696
- async applyRebase(rebase) {
27697
- this.putMany(rebase.blocks);
27698
- const allCids = new cid_set_default([
27699
- ...rebase.preservedCids,
27700
- ...rebase.blocks.cids()
27701
- ]);
27702
- const toDelete = [];
27703
- this.blocks.forEach((_bytes, cid2) => {
27704
- if (!allCids.has(cid2)) {
27705
- toDelete.push(cid2);
27706
- }
27707
- });
27708
- for (const cid2 of toDelete) {
26620
+ this.root = commit2.cid;
26621
+ const rmCids = commit2.removedCids.toList();
26622
+ for (const cid2 of rmCids) {
27709
26623
  this.blocks.delete(cid2);
27710
26624
  }
27711
- await this.updateHead(rebase.commit, null);
26625
+ commit2.newBlocks.forEach((bytes3, cid2) => {
26626
+ this.blocks.set(cid2, bytes3);
26627
+ });
27712
26628
  }
27713
26629
  async sizeInBytes() {
27714
26630
  let total = 0;
@@ -27749,124 +26665,80 @@ var SyncStorage = class extends readable_blockstore_default {
27749
26665
  return await this.staged.has(cid2) || await this.saved.has(cid2);
27750
26666
  }
27751
26667
  };
27752
- var sync_storage_default = SyncStorage;
27753
26668
 
27754
26669
  // src/storage/types.ts
27755
26670
  var BlobNotFoundError = class extends Error {
27756
26671
  };
27757
26672
 
27758
- // src/verify.ts
27759
- var verifyCheckout = async (storage, head, did2, signingKey) => {
27760
- const repo = await verifyRepoRoot(storage, head, did2, signingKey);
27761
- const diff = await data_diff_default.of(repo.data, null);
27762
- const newCids = new cid_set_default([repo.cid]).addSet(diff.newCids);
27763
- const contents = {};
27764
- for (const add of diff.addList()) {
27765
- const { collection, rkey } = parseDataKey(add.key);
27766
- if (!contents[collection]) {
27767
- contents[collection] = {};
27768
- }
27769
- const record = await storage.readRecord(add.cid);
27770
- contents[collection][rkey] = record;
27771
- }
26673
+ // src/sync/consumer.ts
26674
+ var verifyRepoCar = async (carBytes, did2, signingKey) => {
26675
+ const car = await readCarWithRoot(carBytes);
26676
+ return verifyRepo(car.blocks, car.root, did2, signingKey);
26677
+ };
26678
+ var verifyRepo = async (blocks, head, did2, signingKey) => {
26679
+ const diff = await verifyDiff(null, blocks, head, did2, signingKey);
26680
+ const creates = ensureCreates(diff.writes);
27772
26681
  return {
27773
- contents,
27774
- newCids
26682
+ creates,
26683
+ commit: diff.commit
27775
26684
  };
27776
26685
  };
27777
- var verifyCheckoutWithCids = async (storage, head, did2, signingKey) => {
27778
- const repo = await verifyRepoRoot(storage, head, did2, signingKey);
27779
- const diff = await data_diff_default.of(repo.data, null);
27780
- const contents = {};
27781
- for (const add of diff.addList()) {
27782
- const { collection, rkey } = parseDataKey(add.key);
27783
- contents[collection] ?? (contents[collection] = {});
27784
- contents[collection][rkey] = {
27785
- cid: add.cid,
27786
- value: await storage.readRecord(add.cid)
27787
- };
26686
+ var verifyDiffCar = async (repo, carBytes, did2, signingKey) => {
26687
+ const car = await readCarWithRoot(carBytes);
26688
+ return verifyDiff(repo, car.blocks, car.root, did2, signingKey);
26689
+ };
26690
+ var verifyDiff = async (repo, updateBlocks, updateRoot, did2, signingKey) => {
26691
+ const stagedStorage = new MemoryBlockstore(updateBlocks);
26692
+ const updateStorage = repo ? new SyncStorage(stagedStorage, repo.storage) : stagedStorage;
26693
+ const updated = await verifyRepoRoot(
26694
+ updateStorage,
26695
+ updateRoot,
26696
+ did2,
26697
+ signingKey
26698
+ );
26699
+ const diff = await data_diff_default.of(updated.data, repo?.data ?? null);
26700
+ const writes = await diffToWriteDescripts(diff, updateBlocks);
26701
+ const newBlocks = diff.newMstBlocks;
26702
+ const leaves = updateBlocks.getMany(diff.newLeafCids.toList());
26703
+ if (leaves.missing.length > 0) {
26704
+ throw new Error(`missing leaf blocks: ${leaves.missing}`);
26705
+ }
26706
+ newBlocks.addMap(leaves.blocks);
26707
+ const removedCids = diff.removedCids;
26708
+ const commitCid = await newBlocks.add(updated.commit);
26709
+ if (repo) {
26710
+ if (commitCid.equals(repo.cid)) {
26711
+ newBlocks.delete(commitCid);
26712
+ } else {
26713
+ removedCids.add(repo.cid);
26714
+ }
27788
26715
  }
27789
26716
  return {
27790
- commit: repo.cid,
27791
- contents
26717
+ writes,
26718
+ commit: {
26719
+ cid: updated.cid,
26720
+ rev: updated.commit.rev,
26721
+ prev: repo?.cid ?? null,
26722
+ since: repo?.commit.rev ?? null,
26723
+ newBlocks,
26724
+ removedCids
26725
+ }
27792
26726
  };
27793
26727
  };
27794
26728
  var verifyRepoRoot = async (storage, head, did2, signingKey) => {
27795
26729
  const repo = await readable_repo_default.load(storage, head);
27796
- if (repo.did !== did2) {
26730
+ if (did2 !== void 0 && repo.did !== did2) {
27797
26731
  throw new RepoVerificationError(`Invalid repo did: ${repo.did}`);
27798
26732
  }
27799
- const validSig = await verifyCommitSig(repo.commit, signingKey);
27800
- if (!validSig) {
27801
- throw new RepoVerificationError(
27802
- `Invalid signature on commit: ${repo.cid.toString()}`
27803
- );
27804
- }
27805
- return repo;
27806
- };
27807
- var verifyFullHistory = async (storage, head, did2, signingKey) => {
27808
- const commitPath = await storage.getCommitPath(head, null);
27809
- if (commitPath === null) {
27810
- throw new RepoVerificationError("Could not find shared history");
27811
- } else if (commitPath.length < 1) {
27812
- throw new RepoVerificationError("Expected at least one commit");
27813
- }
27814
- const baseRepo = await repo_default.load(storage, commitPath[0]);
27815
- const baseDiff = await data_diff_default.of(baseRepo.data, null);
27816
- const baseRepoCids = new cid_set_default([baseRepo.cid]).addSet(baseDiff.newCids);
27817
- const init = {
27818
- commit: baseRepo.cid,
27819
- prev: null,
27820
- diff: baseDiff,
27821
- newCids: baseRepoCids
27822
- };
27823
- const updates = await verifyCommitPath(
27824
- baseRepo,
27825
- storage,
27826
- commitPath.slice(1),
27827
- did2,
27828
- signingKey
27829
- );
27830
- return [init, ...updates];
27831
- };
27832
- var verifyUpdates = async (repo, updateStorage, updateRoot, did2, signingKey) => {
27833
- const commitPath = await updateStorage.getCommitPath(updateRoot, repo.cid);
27834
- if (commitPath === null) {
27835
- throw new RepoVerificationError("Could not find shared history");
27836
- }
27837
- const syncStorage = new sync_storage_default(updateStorage, repo.storage);
27838
- return verifyCommitPath(repo, syncStorage, commitPath, did2, signingKey);
27839
- };
27840
- var verifyCommitPath = async (baseRepo, storage, commitPath, did2, signingKey) => {
27841
- const updates = [];
27842
- if (commitPath.length === 0)
27843
- return updates;
27844
- let prevRepo = baseRepo;
27845
- for (const commit2 of commitPath) {
27846
- const nextRepo = await readable_repo_default.load(storage, commit2);
27847
- const diff = await data_diff_default.of(nextRepo.data, prevRepo.data);
27848
- if (nextRepo.did !== did2) {
27849
- throw new RepoVerificationError(`Invalid repo did: ${nextRepo.did}`);
27850
- }
27851
- if (!metaEqual(nextRepo.commit, prevRepo.commit)) {
27852
- throw new RepoVerificationError("Not supported: repo metadata updated");
27853
- }
27854
- const validSig = await verifyCommitSig(nextRepo.commit, signingKey);
26733
+ if (signingKey !== void 0) {
26734
+ const validSig = await verifyCommitSig(repo.commit, signingKey);
27855
26735
  if (!validSig) {
27856
26736
  throw new RepoVerificationError(
27857
- `Invalid signature on commit: ${nextRepo.cid.toString()}`
26737
+ `Invalid signature on commit: ${repo.cid.toString()}`
27858
26738
  );
27859
26739
  }
27860
- const newCids = new cid_set_default([nextRepo.cid]).addSet(diff.newCids);
27861
- updates.push({
27862
- commit: nextRepo.cid,
27863
- prev: prevRepo.cid,
27864
- diff,
27865
- newCids
27866
- });
27867
- prevRepo = nextRepo;
27868
26740
  }
27869
- return updates;
26741
+ return repo;
27870
26742
  };
27871
26743
  var verifyProofs = async (proofs, claims, did2, didKey) => {
27872
26744
  const car = await readCarWithRoot(proofs);
@@ -27938,100 +26810,8 @@ var verifyRecords = async (proofs, did2, signingKey) => {
27938
26810
  var RepoVerificationError = class extends Error {
27939
26811
  };
27940
26812
 
27941
- // src/sync/consumer.ts
27942
- var loadCheckout = async (storage, repoCar, did2, signingKey) => {
27943
- const { root, blocks } = await readCarWithRoot(repoCar);
27944
- const updateStorage = new MemoryBlockstore(blocks);
27945
- const checkout = await verifyCheckout(
27946
- updateStorage,
27947
- root,
27948
- did2,
27949
- signingKey
27950
- );
27951
- const checkoutBlocks = await updateStorage.getBlocks(
27952
- checkout.newCids.toList()
27953
- );
27954
- if (checkoutBlocks.missing.length > 0) {
27955
- throw new MissingBlocksError("sync", checkoutBlocks.missing);
27956
- }
27957
- await Promise.all([
27958
- storage.putMany(checkoutBlocks.blocks),
27959
- storage.updateHead(root, null)
27960
- ]);
27961
- return {
27962
- root,
27963
- contents: checkout.contents
27964
- };
27965
- };
27966
- var loadFullRepo = async (storage, repoCar, did2, signingKey) => {
27967
- const { root, blocks } = await readCarWithRoot(repoCar);
27968
- const updateStorage = new MemoryBlockstore(blocks);
27969
- const updates = await verifyFullHistory(
27970
- updateStorage,
27971
- root,
27972
- did2,
27973
- signingKey
27974
- );
27975
- const [writeLog] = await Promise.all([
27976
- persistUpdates(storage, updateStorage, updates),
27977
- storage.updateHead(root, null)
27978
- ]);
27979
- const repo = await repo_default.load(storage, root);
27980
- return {
27981
- root,
27982
- writeLog,
27983
- repo
27984
- };
27985
- };
27986
- var loadDiff = async (repo, diffCar, did2, signingKey) => {
27987
- const { root, blocks } = await readCarWithRoot(diffCar);
27988
- const updateStorage = new MemoryBlockstore(blocks);
27989
- const updates = await verifyUpdates(
27990
- repo,
27991
- updateStorage,
27992
- root,
27993
- did2,
27994
- signingKey
27995
- );
27996
- const [writeLog] = await Promise.all([
27997
- persistUpdates(repo.storage, updateStorage, updates),
27998
- repo.storage.updateHead(root, repo.cid)
27999
- ]);
28000
- return {
28001
- root,
28002
- writeLog
28003
- };
28004
- };
28005
- var persistUpdates = async (storage, updateStorage, updates) => {
28006
- const newCids = new cid_set_default();
28007
- for (const update of updates) {
28008
- newCids.addSet(update.newCids);
28009
- }
28010
- const diffBlocks = await updateStorage.getBlocks(newCids.toList());
28011
- if (diffBlocks.missing.length > 0) {
28012
- throw new MissingBlocksError("sync", diffBlocks.missing);
28013
- }
28014
- const commits = updates.map((update) => {
28015
- const forCommit = diffBlocks.blocks.getMany(update.newCids.toList());
28016
- if (forCommit.missing.length > 0) {
28017
- throw new MissingBlocksError("sync", forCommit.missing);
28018
- }
28019
- return {
28020
- commit: update.commit,
28021
- prev: update.prev,
28022
- blocks: forCommit.blocks
28023
- };
28024
- });
28025
- await storage.indexCommits(commits);
28026
- return Promise.all(
28027
- updates.map(
28028
- (upd) => diffToWriteDescripts(upd.diff, diffBlocks.blocks)
28029
- )
28030
- );
28031
- };
28032
-
28033
26813
  // src/sync/provider.ts
28034
- var getCheckout = (storage, commitCid) => {
26814
+ var getFullRepo = (storage, commitCid) => {
28035
26815
  return writeCar(commitCid, async (car) => {
28036
26816
  const commit2 = await storage.readObjAndBytes(commitCid, def2.commit);
28037
26817
  await car.put({ cid: commitCid, bytes: commit2.bytes });
@@ -28039,27 +26819,6 @@ var getCheckout = (storage, commitCid) => {
28039
26819
  await mst.writeToCarStream(car);
28040
26820
  });
28041
26821
  };
28042
- var getCommits = (storage, latest, earliest) => {
28043
- return writeCar(latest, (car) => {
28044
- return writeCommitsToCarStream(storage, car, latest, earliest);
28045
- });
28046
- };
28047
- var getFullRepo = (storage, cid2) => {
28048
- return getCommits(storage, cid2, null);
28049
- };
28050
- var writeCommitsToCarStream = async (storage, car, latest, earliest) => {
28051
- const commits = await storage.getCommits(latest, earliest);
28052
- if (commits === null) {
28053
- throw new Error("Could not find shared history");
28054
- }
28055
- if (commits.length === 0)
28056
- return;
28057
- for (const commit2 of commits) {
28058
- for (const entry of commit2.blocks.entries()) {
28059
- await car.put(entry);
28060
- }
28061
- }
28062
- };
28063
26822
  var getRecords = (storage, commitCid, paths) => {
28064
26823
  return writeCar(commitCid, async (car) => {
28065
26824
  const commit2 = await storage.readObjAndBytes(commitCid, def2.commit);
@@ -28094,7 +26853,6 @@ var getRecords = (storage, commitCid, paths) => {
28094
26853
  MstWalker,
28095
26854
  ReadableBlockstore,
28096
26855
  Repo,
28097
- RepoStorage,
28098
26856
  RepoVerificationError,
28099
26857
  SyncStorage,
28100
26858
  WriteOpAction,
@@ -28103,42 +26861,33 @@ var getRecords = (storage, commitCid, paths) => {
28103
26861
  cborToLex,
28104
26862
  cborToLexRecord,
28105
26863
  cidForRecord,
28106
- collapseDiffs,
28107
- collapseWriteLog,
28108
26864
  def,
28109
26865
  diffToWriteDescripts,
26866
+ ensureCreates,
26867
+ ensureV3Commit,
28110
26868
  formatDataKey,
28111
- getCheckout,
28112
- getCommits,
28113
26869
  getFullRepo,
28114
26870
  getRecords,
28115
- getWriteLog,
28116
- loadCheckout,
28117
- loadDiff,
28118
- loadFullRepo,
28119
26871
  metaEqual,
28120
26872
  mstDiff,
28121
26873
  mstUtil,
28122
26874
  nodeDataDef,
28123
26875
  nullDiff,
28124
26876
  parseDataKey,
28125
- persistUpdates,
28126
26877
  readCar,
28127
26878
  readCarWithRoot,
28128
26879
  schema,
28129
26880
  signCommit,
28130
- verifyCheckout,
28131
- verifyCheckoutWithCids,
28132
- verifyCommitPath,
28133
26881
  verifyCommitSig,
28134
- verifyFullHistory,
26882
+ verifyDiff,
26883
+ verifyDiffCar,
28135
26884
  verifyIncomingCarBlocks,
28136
26885
  verifyProofs,
28137
26886
  verifyRecords,
28138
- verifyUpdates,
26887
+ verifyRepo,
26888
+ verifyRepoCar,
28139
26889
  writeCar,
28140
- writeCarStream,
28141
- writeCommitsToCarStream
26890
+ writeCarStream
28142
26891
  });
28143
26892
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
28144
26893
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */