@spacesprotocol/libveritas 0.0.0-dev.20260306102312 → 0.0.0-dev.20260306204125
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/README.md +13 -12
- package/libveritas.d.ts +3 -2
- package/libveritas.js +23 -7
- package/libveritas_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,30 +13,31 @@ npm install @spacesprotocol/libveritas
|
|
|
13
13
|
### Verifying a message
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
|
-
import { Veritas, QueryContext } from "@spacesprotocol/libveritas";
|
|
16
|
+
import { Veritas, QueryContext, Message } from "@spacesprotocol/libveritas";
|
|
17
17
|
|
|
18
18
|
// Load trust anchors
|
|
19
|
-
const veritas = new Veritas(anchors
|
|
19
|
+
const veritas = new Veritas(anchors);
|
|
20
20
|
|
|
21
|
-
console.log(`Anchors: ${veritas.
|
|
21
|
+
console.log(`Anchors: ${veritas.oldestAnchor()} .. ${veritas.newestAnchor()}`);
|
|
22
22
|
|
|
23
23
|
// Build query context (empty = verify all handles)
|
|
24
24
|
const ctx = new QueryContext();
|
|
25
|
-
ctx.
|
|
25
|
+
ctx.addRequest("alice@bitcoin");
|
|
26
26
|
|
|
27
27
|
// Verify a message (binary data from relay)
|
|
28
|
-
const
|
|
28
|
+
const msg = new Message(messageBytes);
|
|
29
|
+
const result = veritas.verifyMessage(ctx, msg);
|
|
29
30
|
|
|
30
31
|
// Inspect verified zones
|
|
31
32
|
for (const zone of result.zones()) {
|
|
32
33
|
console.log(`${zone.handle()} -> ${zone.sovereignty()}`);
|
|
33
34
|
|
|
34
35
|
// Store zone for later comparison
|
|
35
|
-
const bytes = zone.
|
|
36
|
+
const bytes = zone.toBytes();
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
// Compare zones
|
|
39
|
-
const better = newerZone.
|
|
40
|
+
const better = newerZone.isBetterThan(olderZone);
|
|
40
41
|
|
|
41
42
|
// Get certificates
|
|
42
43
|
for (const cert of result.certificates()) {
|
|
@@ -57,18 +58,18 @@ let offchainBytes = OffchainData.from(rs, sig);
|
|
|
57
58
|
// Build a message with certificates and offchain data
|
|
58
59
|
let builder = new MessageBuilder([
|
|
59
60
|
{ name: "@bitcoin", cert: rootCertBytes },
|
|
60
|
-
{ name: "alice@bitcoin",
|
|
61
|
+
{ name: "alice@bitcoin", offchainData: offchainBytes, cert: leafCertBytes },
|
|
61
62
|
]);
|
|
62
63
|
|
|
63
64
|
// Get the chain proof request to send to a provider
|
|
64
|
-
let request = builder.
|
|
65
|
+
let request = builder.chainProofRequest();
|
|
65
66
|
|
|
66
67
|
// ... send request to provider, get chain proof back ...
|
|
67
68
|
|
|
68
69
|
let msg = builder.build(chainProofBytes);
|
|
69
70
|
|
|
70
71
|
// Serialize for transport
|
|
71
|
-
let bytes = msg.
|
|
72
|
+
let bytes = msg.toBytes();
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
### Updating offchain data
|
|
@@ -82,10 +83,10 @@ let sig = wallet.signSchnorr(rs.id());
|
|
|
82
83
|
let offchainBytes = OffchainData.from(rs, sig);
|
|
83
84
|
|
|
84
85
|
msg.update([
|
|
85
|
-
{ name: "alice@bitcoin",
|
|
86
|
+
{ name: "alice@bitcoin", offchainData: offchainBytes },
|
|
86
87
|
]);
|
|
87
88
|
|
|
88
|
-
let updatedBytes = msg.
|
|
89
|
+
let updatedBytes = msg.toBytes();
|
|
89
90
|
```
|
|
90
91
|
|
|
91
92
|
## Building from source
|
package/libveritas.d.ts
CHANGED
|
@@ -148,14 +148,15 @@ export class Veritas {
|
|
|
148
148
|
free(): void;
|
|
149
149
|
[Symbol.dispose](): void;
|
|
150
150
|
is_finalized(commitment_height: number): boolean;
|
|
151
|
-
constructor(anchors: any
|
|
151
|
+
constructor(anchors: any);
|
|
152
152
|
newest_anchor(): number;
|
|
153
153
|
oldest_anchor(): number;
|
|
154
154
|
sovereignty_for(commitment_height: number): string;
|
|
155
155
|
/**
|
|
156
156
|
* Verify a message against a query context.
|
|
157
157
|
*/
|
|
158
|
-
verify_message(ctx: QueryContext, msg:
|
|
158
|
+
verify_message(ctx: QueryContext, msg: Message): VerifiedMessage;
|
|
159
|
+
static withDevMode(anchors: any): Veritas;
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
export class Zone {
|
package/libveritas.js
CHANGED
|
@@ -352,6 +352,13 @@ if (Symbol.dispose) VerifiedMessage.prototype[Symbol.dispose] = VerifiedMessage.
|
|
|
352
352
|
exports.VerifiedMessage = VerifiedMessage;
|
|
353
353
|
|
|
354
354
|
class Veritas {
|
|
355
|
+
static __wrap(ptr) {
|
|
356
|
+
ptr = ptr >>> 0;
|
|
357
|
+
const obj = Object.create(Veritas.prototype);
|
|
358
|
+
obj.__wbg_ptr = ptr;
|
|
359
|
+
VeritasFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
360
|
+
return obj;
|
|
361
|
+
}
|
|
355
362
|
__destroy_into_raw() {
|
|
356
363
|
const ptr = this.__wbg_ptr;
|
|
357
364
|
this.__wbg_ptr = 0;
|
|
@@ -372,10 +379,9 @@ class Veritas {
|
|
|
372
379
|
}
|
|
373
380
|
/**
|
|
374
381
|
* @param {any} anchors
|
|
375
|
-
* @param {boolean} dev_mode
|
|
376
382
|
*/
|
|
377
|
-
constructor(anchors
|
|
378
|
-
const ret = wasm.veritas_new(anchors
|
|
383
|
+
constructor(anchors) {
|
|
384
|
+
const ret = wasm.veritas_new(anchors);
|
|
379
385
|
if (ret[2]) {
|
|
380
386
|
throw takeFromExternrefTable0(ret[1]);
|
|
381
387
|
}
|
|
@@ -416,19 +422,29 @@ class Veritas {
|
|
|
416
422
|
/**
|
|
417
423
|
* Verify a message against a query context.
|
|
418
424
|
* @param {QueryContext} ctx
|
|
419
|
-
* @param {
|
|
425
|
+
* @param {Message} msg
|
|
420
426
|
* @returns {VerifiedMessage}
|
|
421
427
|
*/
|
|
422
428
|
verify_message(ctx, msg) {
|
|
423
429
|
_assertClass(ctx, QueryContext);
|
|
424
|
-
|
|
425
|
-
const
|
|
426
|
-
const ret = wasm.veritas_verify_message(this.__wbg_ptr, ctx.__wbg_ptr, ptr0, len0);
|
|
430
|
+
_assertClass(msg, Message);
|
|
431
|
+
const ret = wasm.veritas_verify_message(this.__wbg_ptr, ctx.__wbg_ptr, msg.__wbg_ptr);
|
|
427
432
|
if (ret[2]) {
|
|
428
433
|
throw takeFromExternrefTable0(ret[1]);
|
|
429
434
|
}
|
|
430
435
|
return VerifiedMessage.__wrap(ret[0]);
|
|
431
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* @param {any} anchors
|
|
439
|
+
* @returns {Veritas}
|
|
440
|
+
*/
|
|
441
|
+
static withDevMode(anchors) {
|
|
442
|
+
const ret = wasm.veritas_withDevMode(anchors);
|
|
443
|
+
if (ret[2]) {
|
|
444
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
445
|
+
}
|
|
446
|
+
return Veritas.__wrap(ret[0]);
|
|
447
|
+
}
|
|
432
448
|
}
|
|
433
449
|
if (Symbol.dispose) Veritas.prototype[Symbol.dispose] = Veritas.prototype.free;
|
|
434
450
|
exports.Veritas = Veritas;
|
package/libveritas_bg.wasm
CHANGED
|
Binary file
|