Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ authors = ["Buffrr <contact@buffrr.dev>"]

[workspace.dependencies]
fabric-resolver = { path = "fabric", version = "0.1.4" }
libveritas = { version = "0.1" }
libveritas_testutil = { version = "0.1" }
libveritas = { version = "0.2" }
libveritas_testutil = { version = "0.2" }

spaces_client = { version = "0.1" }
spaces_protocol = { version = "0.1" }
Expand Down
36 changes: 18 additions & 18 deletions fabric/examples/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ import (
func exampleResolveIntro() error {
// <doc:resolve-intro>
f := fabric.New()
resolved, err := f.Resolve("alice@bitcoin")
zone, err := f.Resolve("alice@bitcoin")
// </doc:resolve-intro>
if err != nil {
return err
}
_ = resolved
_ = zone
return nil
}

/// Resolve a single handle
func exampleResolve() error {
// <doc:resolve>
f := fabric.New()
resolved, err := f.Resolve("alice@bitcoin")
zone, err := f.Resolve("alice@bitcoin")
if err != nil {
return err
}
if resolved == nil {
if zone == nil {
fmt.Println("handle not found")
return nil
}

fmt.Printf("Handle found: %s\n", resolved.Zone.Handle)
fmt.Printf("Handle found: %s\n", zone.Handle)
// </doc:resolve>

return nil
Expand All @@ -51,12 +51,12 @@ func exampleTrustAndVerification() error {
// <doc:verification>
// Before pinning a trust id: resolve uses observed (peer) state
// badge() returns Unverified
resolved, err := f.Resolve("alice@bitcoin")
zone, err := f.Resolve("alice@bitcoin")
if err != nil {
return err
}

f.Badge(resolved) // Unverified
f.Badge(*zone) // Unverified

// Pin trust from a QR scan
qr := "veritas://scan?id=14ef902621df01bdeee0b23fedf67458563a20df600af8979a4748dcd9d1b9f9"
Expand All @@ -67,8 +67,8 @@ func exampleTrustAndVerification() error {
}

// Does not require re-resolving, badge now checks
// whether resolved was against a trusted root
f.Badge(resolved) // Orange if handle is sovereign (final certificate)
// whether zone was against a trusted root
f.Badge(*zone) // Orange if handle is sovereign (final certificate)

// Or from a semi-trusted source (e.g. an explorer you trust with qr scanned over HTTPS)
// .Badge() will not show Orange for roots in this trust pool,
Expand All @@ -94,13 +94,13 @@ func exampleTrustAndVerification() error {
/// Unpack records from a resolved handle
func exampleUnpackRecords() error {
f := fabric.New()
resolved, err := f.Resolve("alice@bitcoin")
zone, err := f.Resolve("alice@bitcoin")
if err != nil {
return err
}

// <doc:unpack-records>
records, err := resolved.Zone.Records.Unpack()
records, err := zone.Records.Unpack()
if err != nil {
return err
}
Expand All @@ -123,12 +123,12 @@ func exampleResolveAll() error {
f := fabric.New()

// <doc:resolve-all>
batch, err := f.ResolveAll([]string{"alice@bitcoin", "bob@bitcoin"})
zones, err := f.ResolveAll([]string{"alice@bitcoin", "bob@bitcoin"})
if err != nil {
return err
}

for _, zone := range batch.Zones {
for _, zone := range zones {
fmt.Printf("%s: %s\n", zone.Handle, zone.Sovereignty)
}
// </doc:resolve-all>
Expand Down Expand Up @@ -195,16 +195,16 @@ func exampleResolveById() error {
f := fabric.New()

// <doc:resolve-by-id>
resolved, err := f.ResolveById("num1qx8dtlzq...")
zone, err := f.ResolveById("num1qx8dtlzq...")
if err != nil {
return err
}
if resolved == nil {
if zone == nil {
fmt.Println("handle not found")
return nil
}

fmt.Printf("Handle found: %s\n", resolved.Zone.Handle)
fmt.Printf("Handle found: %s\n", zone.Handle)
// </doc:resolve-by-id>

return nil
Expand All @@ -215,12 +215,12 @@ func exampleSearchAddr() error {
f := fabric.New()

// <doc:search-addr>
batch, err := f.SearchAddr("nostr", "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6")
zones, err := f.SearchAddr("nostr", "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6")
if err != nil {
return err
}

for _, zone := range batch.Zones {
for _, zone := range zones {
fmt.Printf("%s: %s\n", zone.Handle, zone.Sovereignty)
}
// </doc:search-addr>
Expand Down
34 changes: 17 additions & 17 deletions fabric/examples/js/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import { signSchnorr } from "@spacesprotocol/fabric-web/signing";
async function exampleResolveIntro() {
// <doc:resolve-intro>
const fabric = new Fabric();
const resolved = await fabric.resolve("alice@bitcoin");
const zone = await fabric.resolve("alice@bitcoin");
// </doc:resolve-intro>
}

/// Resolve a single handle
async function exampleResolve() {
// <doc:resolve>
const fabric = new Fabric();
const resolved = await fabric.resolve("alice@bitcoin");
if (!resolved) {
const zone = await fabric.resolve("alice@bitcoin");
if (!zone) {
console.log("handle not found");
return;
}

console.log(`Handle found: ${resolved.zone.handle}`);
console.log(`Handle found: ${zone.handle}`);
// </doc:resolve>
}

Expand All @@ -33,9 +33,9 @@ async function exampleTrustAndVerification() {
// <doc:verification>
// Before pinning a trust id: resolve uses observed (peer) state
// badge() returns "unverified"
const resolved = await fabric.resolve("alice@bitcoin");
const zone = await fabric.resolve("alice@bitcoin");

fabric.badge(resolved); // "unverified"
fabric.badge(zone); // "unverified"

// Pin trust from a QR scan
const qr = "veritas://scan?id=14ef902621df01bdeee0b23fedf67458563a20df600af8979a4748dcd9d1b9f9";
Expand All @@ -44,8 +44,8 @@ async function exampleTrustAndVerification() {
await fabric.trustFromQr(qr);

// Does not require re-resolving, badge now checks
// whether resolved was against a trusted root
fabric.badge(resolved); // "orange" if handle is sovereign (final certificate)
// whether the zone's anchor_hash is in the trusted set
fabric.badge(zone); // "orange" if handle is sovereign (final certificate)

// Or from a semi-trusted source (e.g. an explorer you trust with qr scanned over HTTPS)
// .badge() will not show "orange" for roots in this trust pool,
Expand All @@ -65,10 +65,10 @@ async function exampleTrustAndVerification() {
/// Unpack records from a resolved handle
async function exampleUnpackRecords() {
const fabric = new Fabric();
const resolved = await fabric.resolve("alice@bitcoin");
const zone = await fabric.resolve("alice@bitcoin");

// <doc:unpack-records>
const json = resolved.zone.toJson();
const json = zone.toJson();

for (const record of json.records) {
if (record.type === "txt") {
Expand All @@ -85,9 +85,9 @@ async function exampleResolveAll() {
const fabric = new Fabric();

// <doc:resolve-all>
const batch = await fabric.resolveAll(["alice@bitcoin", "bob@bitcoin"]);
const zones = await fabric.resolveAll(["alice@bitcoin", "bob@bitcoin"]);

for (const zone of batch.zones) {
for (const zone of zones) {
console.log(`${zone.handle}`);
}
// </doc:resolve-all>
Expand Down Expand Up @@ -134,13 +134,13 @@ async function exampleResolveById() {
const fabric = new Fabric();

// <doc:resolve-by-id>
const resolved = await fabric.resolveById("num1qx8dtlzq...");
if (!resolved) {
const zone = await fabric.resolveById("num1qx8dtlzq...");
if (!zone) {
console.log("handle not found");
return;
}

console.log(`Handle found: ${resolved.zone.handle}`);
console.log(`Handle found: ${zone.handle}`);
// </doc:resolve-by-id>
}

Expand All @@ -149,9 +149,9 @@ async function exampleSearchAddr() {
const fabric = new Fabric();

// <doc:search-addr>
const batch = await fabric.searchAddr("nostr", "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6");
const zones = await fabric.searchAddr("nostr", "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6");

for (const zone of batch.zones) {
for (const zone of zones) {
console.log(`${zone.handle}`);
}
// </doc:search-addr>
Expand Down
34 changes: 17 additions & 17 deletions fabric/examples/kotlin/Example.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import org.spacesprotocol.fabric.SIG_PRIMARY_ZONE
suspend fun exampleResolveIntro() {
// <doc:resolve-intro>
val fabric = Fabric()
val resolved = fabric.resolve("alice@bitcoin")
val zone = fabric.resolve("alice@bitcoin")
// </doc:resolve-intro>
}

/// Resolve a single handle
suspend fun exampleResolve() {
// <doc:resolve>
val fabric = Fabric()
val resolved = fabric.resolve("alice@bitcoin")
if (resolved == null) {
val zone = fabric.resolve("alice@bitcoin")
if (zone == null) {
println("handle not found")
return
}

println("Handle found: ${resolved.zone.handle}")
println("Handle found: ${zone.handle}")
// </doc:resolve>
}

Expand All @@ -45,10 +45,10 @@ suspend fun exampleTrustAndVerification() {
// <doc:verification>
// Before pinning a trust id: resolve uses observed (peer) state
// badge() returns Unverified
val resolved = fabric.resolve("alice@bitcoin")
val zone = fabric.resolve("alice@bitcoin")
?: throw IllegalStateException("handle exists")

fabric.badge(resolved) // Unverified
fabric.badge(zone) // Unverified

// Pin trust from a QR scan
val qr = "veritas://scan?id=14ef902621df01bdeee0b23fedf67458563a20df600af8979a4748dcd9d1b9f9"
Expand All @@ -57,8 +57,8 @@ suspend fun exampleTrustAndVerification() {
fabric.trustFromQr(qr)

// Does not require re-resolving, badge now checks
// whether resolved was against a trusted root
fabric.badge(resolved) // Orange if handle is sovereign (final certificate)
// whether zone was against a trusted root
fabric.badge(zone) // Orange if handle is sovereign (final certificate)

// Or from a semi-trusted source (e.g. an explorer you trust with qr scanned over HTTPS)
// .badge() will not show Orange for roots in this trust pool,
Expand All @@ -80,11 +80,11 @@ suspend fun exampleTrustAndVerification() {
/// Unpack records from a resolved handle
suspend fun exampleUnpackRecords() {
val fabric = Fabric()
val resolved = fabric.resolve("alice@bitcoin")
val zone = fabric.resolve("alice@bitcoin")
?: throw IllegalStateException("handle exists")

// <doc:unpack-records>
val records = resolved.zone.records.unpack()
val records = zone.records.unpack()

for (record in records) {
when (record) {
Expand All @@ -101,9 +101,9 @@ suspend fun exampleResolveAll() {
val fabric = Fabric()

// <doc:resolve-all>
val batch = fabric.resolveAll(listOf("alice@bitcoin", "bob@bitcoin"))
val zones = fabric.resolveAll(listOf("alice@bitcoin", "bob@bitcoin"))

for (zone in batch.zones) {
for (zone in zones) {
println("${zone.handle}: ${zone.sovereignty}")
}
// </doc:resolve-all>
Expand Down Expand Up @@ -147,13 +147,13 @@ suspend fun exampleResolveById() {
val fabric = Fabric()

// <doc:resolve-by-id>
val resolved = fabric.resolveById("num1qx8dtlzq...")
if (resolved == null) {
val zone = fabric.resolveById("num1qx8dtlzq...")
if (zone == null) {
println("handle not found")
return
}

println("Handle found: ${resolved.zone.handle}")
println("Handle found: ${zone.handle}")
// </doc:resolve-by-id>
}

Expand All @@ -162,9 +162,9 @@ suspend fun exampleSearchAddr() {
val fabric = Fabric()

// <doc:search-addr>
val batch = fabric.searchAddr("nostr", "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6")
val zones = fabric.searchAddr("nostr", "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6")

for (zone in batch.zones) {
for (zone in zones) {
println("${zone.handle}: ${zone.sovereignty}")
}
// </doc:search-addr>
Expand Down
Loading
Loading