@spacesprotocol/libveritas 0.0.0-dev.20260318234945 → 0.0.0-dev.20260320153157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/libveritas.d.ts CHANGED
@@ -8,6 +8,31 @@ export class Anchors {
8
8
  constructor(json: string);
9
9
  }
10
10
 
11
+ /**
12
+ * Batched iterative resolver for nested handle names.
13
+ */
14
+ export class Lookup {
15
+ free(): void;
16
+ [Symbol.dispose](): void;
17
+ /**
18
+ * Feed zones from a resolveAll response.
19
+ * Returns the next batch of handles to look up (empty = done).
20
+ */
21
+ advance(zones: any): string[];
22
+ /**
23
+ * Expand zone handles using the alias map accumulated during resolution.
24
+ */
25
+ expandZones(zones: any): any;
26
+ /**
27
+ * Create a lookup from an array of handle name strings.
28
+ */
29
+ constructor(names: string[]);
30
+ /**
31
+ * Returns the first batch of handles to look up.
32
+ */
33
+ start(): string[];
34
+ }
35
+
11
36
  /**
12
37
  * A message containing chain proofs and handle data.
13
38
  */
@@ -44,6 +69,26 @@ export class Message {
44
69
  export class MessageBuilder {
45
70
  free(): void;
46
71
  [Symbol.dispose](): void;
72
+ /**
73
+ * Add a single certificate.
74
+ */
75
+ addCert(cert_bytes: Uint8Array): void;
76
+ /**
77
+ * Add all certificates from a .spacecert chain.
78
+ */
79
+ addChain(chain_bytes: Uint8Array): void;
80
+ /**
81
+ * Add a .spacecert chain with records.
82
+ */
83
+ addHandle(chain_bytes: Uint8Array, records_bytes: Uint8Array): void;
84
+ /**
85
+ * Add records for a handle.
86
+ */
87
+ addRecords(handle: string, records_bytes: Uint8Array): void;
88
+ /**
89
+ * Add a full data update (records + optional delegate records).
90
+ */
91
+ addUpdate(entry: any): void;
47
92
  /**
48
93
  * Build the message from a borsh-encoded ChainProof.
49
94
  *
@@ -57,16 +102,15 @@ export class MessageBuilder {
57
102
  */
58
103
  chain_proof_request(): any;
59
104
  /**
60
- * Create a builder from a JS array of update requests.
105
+ * Create an empty builder.
61
106
  *
62
107
  * ```js
63
- * let builder = new MessageBuilder([
64
- * { name: "@bitcoin", records: Uint8Array, cert: Uint8Array },
65
- * { name: "alice@bitcoin", records: Uint8Array, cert: Uint8Array }
66
- * ])
108
+ * let builder = new MessageBuilder()
109
+ * builder.addChain(chainBytes)
110
+ * builder.addRecords("alice@bitcoin", recordsBytes)
67
111
  * ```
68
112
  */
69
- constructor(requests: any);
113
+ constructor();
70
114
  }
71
115
 
72
116
  /**
@@ -203,10 +247,13 @@ export class Veritas {
203
247
  oldest_anchor(): number;
204
248
  sovereignty_for(commitment_height: number): string;
205
249
  /**
206
- * Verify a message against a query context.
250
+ * Verify a message with default options (expand_names: true, dev_mode: false).
251
+ */
252
+ verify(ctx: QueryContext, msg: Message): VerifiedMessage;
253
+ /**
254
+ * Verify a message with explicit options.
207
255
  */
208
- verify_message(ctx: QueryContext, msg: Message): VerifiedMessage;
209
- static withDevMode(anchors: Anchors): Veritas;
256
+ verifyWithOptions(ctx: QueryContext, msg: Message, expand_names: boolean, dev_mode: boolean): VerifiedMessage;
210
257
  }
211
258
 
212
259
  /**
package/libveritas.js CHANGED
@@ -38,6 +38,76 @@ class Anchors {
38
38
  if (Symbol.dispose) Anchors.prototype[Symbol.dispose] = Anchors.prototype.free;
39
39
  exports.Anchors = Anchors;
40
40
 
41
+ /**
42
+ * Batched iterative resolver for nested handle names.
43
+ */
44
+ class Lookup {
45
+ __destroy_into_raw() {
46
+ const ptr = this.__wbg_ptr;
47
+ this.__wbg_ptr = 0;
48
+ LookupFinalization.unregister(this);
49
+ return ptr;
50
+ }
51
+ free() {
52
+ const ptr = this.__destroy_into_raw();
53
+ wasm.__wbg_lookup_free(ptr, 0);
54
+ }
55
+ /**
56
+ * Feed zones from a resolveAll response.
57
+ * Returns the next batch of handles to look up (empty = done).
58
+ * @param {any} zones
59
+ * @returns {string[]}
60
+ */
61
+ advance(zones) {
62
+ const ret = wasm.lookup_advance(this.__wbg_ptr, zones);
63
+ if (ret[3]) {
64
+ throw takeFromExternrefTable0(ret[2]);
65
+ }
66
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
67
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
68
+ return v1;
69
+ }
70
+ /**
71
+ * Expand zone handles using the alias map accumulated during resolution.
72
+ * @param {any} zones
73
+ * @returns {any}
74
+ */
75
+ expandZones(zones) {
76
+ const ret = wasm.lookup_expandZones(this.__wbg_ptr, zones);
77
+ if (ret[2]) {
78
+ throw takeFromExternrefTable0(ret[1]);
79
+ }
80
+ return takeFromExternrefTable0(ret[0]);
81
+ }
82
+ /**
83
+ * Create a lookup from an array of handle name strings.
84
+ * @param {string[]} names
85
+ */
86
+ constructor(names) {
87
+ const ptr0 = passArrayJsValueToWasm0(names, wasm.__wbindgen_malloc);
88
+ const len0 = WASM_VECTOR_LEN;
89
+ const ret = wasm.lookup_new(ptr0, len0);
90
+ if (ret[2]) {
91
+ throw takeFromExternrefTable0(ret[1]);
92
+ }
93
+ this.__wbg_ptr = ret[0] >>> 0;
94
+ LookupFinalization.register(this, this.__wbg_ptr, this);
95
+ return this;
96
+ }
97
+ /**
98
+ * Returns the first batch of handles to look up.
99
+ * @returns {string[]}
100
+ */
101
+ start() {
102
+ const ret = wasm.lookup_start(this.__wbg_ptr);
103
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
104
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
105
+ return v1;
106
+ }
107
+ }
108
+ if (Symbol.dispose) Lookup.prototype[Symbol.dispose] = Lookup.prototype.free;
109
+ exports.Lookup = Lookup;
110
+
41
111
  /**
42
112
  * A message containing chain proofs and handle data.
43
113
  */
@@ -122,6 +192,70 @@ class MessageBuilder {
122
192
  const ptr = this.__destroy_into_raw();
123
193
  wasm.__wbg_messagebuilder_free(ptr, 0);
124
194
  }
195
+ /**
196
+ * Add a single certificate.
197
+ * @param {Uint8Array} cert_bytes
198
+ */
199
+ addCert(cert_bytes) {
200
+ const ptr0 = passArray8ToWasm0(cert_bytes, wasm.__wbindgen_malloc);
201
+ const len0 = WASM_VECTOR_LEN;
202
+ const ret = wasm.messagebuilder_addCert(this.__wbg_ptr, ptr0, len0);
203
+ if (ret[1]) {
204
+ throw takeFromExternrefTable0(ret[0]);
205
+ }
206
+ }
207
+ /**
208
+ * Add all certificates from a .spacecert chain.
209
+ * @param {Uint8Array} chain_bytes
210
+ */
211
+ addChain(chain_bytes) {
212
+ const ptr0 = passArray8ToWasm0(chain_bytes, wasm.__wbindgen_malloc);
213
+ const len0 = WASM_VECTOR_LEN;
214
+ const ret = wasm.messagebuilder_addChain(this.__wbg_ptr, ptr0, len0);
215
+ if (ret[1]) {
216
+ throw takeFromExternrefTable0(ret[0]);
217
+ }
218
+ }
219
+ /**
220
+ * Add a .spacecert chain with records.
221
+ * @param {Uint8Array} chain_bytes
222
+ * @param {Uint8Array} records_bytes
223
+ */
224
+ addHandle(chain_bytes, records_bytes) {
225
+ const ptr0 = passArray8ToWasm0(chain_bytes, wasm.__wbindgen_malloc);
226
+ const len0 = WASM_VECTOR_LEN;
227
+ const ptr1 = passArray8ToWasm0(records_bytes, wasm.__wbindgen_malloc);
228
+ const len1 = WASM_VECTOR_LEN;
229
+ const ret = wasm.messagebuilder_addHandle(this.__wbg_ptr, ptr0, len0, ptr1, len1);
230
+ if (ret[1]) {
231
+ throw takeFromExternrefTable0(ret[0]);
232
+ }
233
+ }
234
+ /**
235
+ * Add records for a handle.
236
+ * @param {string} handle
237
+ * @param {Uint8Array} records_bytes
238
+ */
239
+ addRecords(handle, records_bytes) {
240
+ const ptr0 = passStringToWasm0(handle, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
241
+ const len0 = WASM_VECTOR_LEN;
242
+ const ptr1 = passArray8ToWasm0(records_bytes, wasm.__wbindgen_malloc);
243
+ const len1 = WASM_VECTOR_LEN;
244
+ const ret = wasm.messagebuilder_addRecords(this.__wbg_ptr, ptr0, len0, ptr1, len1);
245
+ if (ret[1]) {
246
+ throw takeFromExternrefTable0(ret[0]);
247
+ }
248
+ }
249
+ /**
250
+ * Add a full data update (records + optional delegate records).
251
+ * @param {any} entry
252
+ */
253
+ addUpdate(entry) {
254
+ const ret = wasm.messagebuilder_addUpdate(this.__wbg_ptr, entry);
255
+ if (ret[1]) {
256
+ throw takeFromExternrefTable0(ret[0]);
257
+ }
258
+ }
125
259
  /**
126
260
  * Build the message from a borsh-encoded ChainProof.
127
261
  *
@@ -152,22 +286,17 @@ class MessageBuilder {
152
286
  return takeFromExternrefTable0(ret[0]);
153
287
  }
154
288
  /**
155
- * Create a builder from a JS array of update requests.
289
+ * Create an empty builder.
156
290
  *
157
291
  * ```js
158
- * let builder = new MessageBuilder([
159
- * { name: "@bitcoin", records: Uint8Array, cert: Uint8Array },
160
- * { name: "alice@bitcoin", records: Uint8Array, cert: Uint8Array }
161
- * ])
292
+ * let builder = new MessageBuilder()
293
+ * builder.addChain(chainBytes)
294
+ * builder.addRecords("alice@bitcoin", recordsBytes)
162
295
  * ```
163
- * @param {any} requests
164
296
  */
165
- constructor(requests) {
166
- const ret = wasm.messagebuilder_new(requests);
167
- if (ret[2]) {
168
- throw takeFromExternrefTable0(ret[1]);
169
- }
170
- this.__wbg_ptr = ret[0] >>> 0;
297
+ constructor() {
298
+ const ret = wasm.messagebuilder_new();
299
+ this.__wbg_ptr = ret >>> 0;
171
300
  MessageBuilderFinalization.register(this, this.__wbg_ptr, this);
172
301
  return this;
173
302
  }
@@ -512,13 +641,6 @@ if (Symbol.dispose) VerifiedMessage.prototype[Symbol.dispose] = VerifiedMessage.
512
641
  exports.VerifiedMessage = VerifiedMessage;
513
642
 
514
643
  class Veritas {
515
- static __wrap(ptr) {
516
- ptr = ptr >>> 0;
517
- const obj = Object.create(Veritas.prototype);
518
- obj.__wbg_ptr = ptr;
519
- VeritasFinalization.register(obj, obj.__wbg_ptr, obj);
520
- return obj;
521
- }
522
644
  __destroy_into_raw() {
523
645
  const ptr = this.__wbg_ptr;
524
646
  this.__wbg_ptr = 0;
@@ -590,31 +712,36 @@ class Veritas {
590
712
  }
591
713
  }
592
714
  /**
593
- * Verify a message against a query context.
715
+ * Verify a message with default options (expand_names: true, dev_mode: false).
594
716
  * @param {QueryContext} ctx
595
717
  * @param {Message} msg
596
718
  * @returns {VerifiedMessage}
597
719
  */
598
- verify_message(ctx, msg) {
720
+ verify(ctx, msg) {
599
721
  _assertClass(ctx, QueryContext);
600
722
  _assertClass(msg, Message);
601
- const ret = wasm.veritas_verify_message(this.__wbg_ptr, ctx.__wbg_ptr, msg.__wbg_ptr);
723
+ const ret = wasm.veritas_verify(this.__wbg_ptr, ctx.__wbg_ptr, msg.__wbg_ptr);
602
724
  if (ret[2]) {
603
725
  throw takeFromExternrefTable0(ret[1]);
604
726
  }
605
727
  return VerifiedMessage.__wrap(ret[0]);
606
728
  }
607
729
  /**
608
- * @param {Anchors} anchors
609
- * @returns {Veritas}
730
+ * Verify a message with explicit options.
731
+ * @param {QueryContext} ctx
732
+ * @param {Message} msg
733
+ * @param {boolean} expand_names
734
+ * @param {boolean} dev_mode
735
+ * @returns {VerifiedMessage}
610
736
  */
611
- static withDevMode(anchors) {
612
- _assertClass(anchors, Anchors);
613
- const ret = wasm.veritas_withDevMode(anchors.__wbg_ptr);
737
+ verifyWithOptions(ctx, msg, expand_names, dev_mode) {
738
+ _assertClass(ctx, QueryContext);
739
+ _assertClass(msg, Message);
740
+ const ret = wasm.veritas_verifyWithOptions(this.__wbg_ptr, ctx.__wbg_ptr, msg.__wbg_ptr, expand_names, dev_mode);
614
741
  if (ret[2]) {
615
742
  throw takeFromExternrefTable0(ret[1]);
616
743
  }
617
- return Veritas.__wrap(ret[0]);
744
+ return VerifiedMessage.__wrap(ret[0]);
618
745
  }
619
746
  }
620
747
  if (Symbol.dispose) Veritas.prototype[Symbol.dispose] = Veritas.prototype.free;
@@ -863,6 +990,9 @@ function __wbg_get_imports() {
863
990
  const AnchorsFinalization = (typeof FinalizationRegistry === 'undefined')
864
991
  ? { register: () => {}, unregister: () => {} }
865
992
  : new FinalizationRegistry(ptr => wasm.__wbg_anchors_free(ptr >>> 0, 1));
993
+ const LookupFinalization = (typeof FinalizationRegistry === 'undefined')
994
+ ? { register: () => {}, unregister: () => {} }
995
+ : new FinalizationRegistry(ptr => wasm.__wbg_lookup_free(ptr >>> 0, 1));
866
996
  const MessageFinalization = (typeof FinalizationRegistry === 'undefined')
867
997
  ? { register: () => {}, unregister: () => {} }
868
998
  : new FinalizationRegistry(ptr => wasm.__wbg_message_free(ptr >>> 0, 1));
@@ -965,6 +1095,17 @@ function debugString(val) {
965
1095
  return className;
966
1096
  }
967
1097
 
1098
+ function getArrayJsValueFromWasm0(ptr, len) {
1099
+ ptr = ptr >>> 0;
1100
+ const mem = getDataViewMemory0();
1101
+ const result = [];
1102
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
1103
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
1104
+ }
1105
+ wasm.__externref_drop_slice(ptr, len);
1106
+ return result;
1107
+ }
1108
+
968
1109
  function getArrayU8FromWasm0(ptr, len) {
969
1110
  ptr = ptr >>> 0;
970
1111
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
@@ -1011,6 +1152,16 @@ function passArray8ToWasm0(arg, malloc) {
1011
1152
  return ptr;
1012
1153
  }
1013
1154
 
1155
+ function passArrayJsValueToWasm0(array, malloc) {
1156
+ const ptr = malloc(array.length * 4, 4) >>> 0;
1157
+ for (let i = 0; i < array.length; i++) {
1158
+ const add = addToExternrefTable0(array[i]);
1159
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
1160
+ }
1161
+ WASM_VECTOR_LEN = array.length;
1162
+ return ptr;
1163
+ }
1164
+
1014
1165
  function passStringToWasm0(arg, malloc, realloc) {
1015
1166
  if (realloc === undefined) {
1016
1167
  const buf = cachedTextEncoder.encode(arg);
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spacesprotocol/libveritas",
3
- "version": "0.0.0-dev.20260318234945",
3
+ "version": "0.0.0-dev.20260320153157",
4
4
  "files": [
5
5
  "libveritas_bg.wasm",
6
6
  "libveritas.js",