Files
Olares/cli/pkg/web5/jws/README.md
Eliott van Nuffel df38148149
Some checks failed
Native Verification / Build Docs (pull_request) Successful in 1m12s
Native Verification / Build App-Service Native (pull_request) Successful in 1m27s
Native Verification / Build Daemon Native (pull_request) Successful in 42s
Lint and Test Charts / lint-test (pull_request_target) Failing after 19s
Lint and Test Charts / test-version (pull_request_target) Successful in 0s
Lint and Test Charts / push-image (pull_request_target) Failing after 15s
Lint and Test Charts / upload-cli (pull_request_target) Failing after 1m15s
Lint and Test Charts / upload-daemon (pull_request_target) Failing after 1m12s
Lint and Test Charts / push-deps (pull_request_target) Has been skipped
Lint and Test Charts / push-deps-arm64 (pull_request_target) Has been skipped
Lint and Test Charts / push-image-arm64 (pull_request_target) Has been cancelled
Lint and Test Charts / upload-package (pull_request_target) Has been cancelled
Lint and Test Charts / install-test (pull_request_target) Has been cancelled
continue beOS rebrand and add native verification
2026-03-10 13:48:45 +01:00

2.8 KiB

jws

Table of Contents

Features

  • Signing a JWS (JSON Web Signature) with a DID
  • Verifying a JWS with a DID

Usage

Signing:

package main

import (
    "fmt"
    "github.com/beclab/beOS Pro/cli/pkg/web5/didjwk"
    "github.com/beclab/beOS Pro/cli/pkg/web5/jws"
)

func main() {	
    did, err := didjwk.Create()
    if err != nil {
        fmt.Printf("failed to create did: %v", err)
        return
    }

    payload := map[string]interface{}{"hello": "world"}
    
    compactJWS, err := jws.Sign(payload, did)
    if err != nil {
        fmt.Printf("failed to sign: %v", err)
        return
    }

    fmt.Printf("compact JWS: %s", compactJWS)
}

Detached Content

returning a JWS with detached content can be done like so:

package main

import (
    "fmt"
    "github.com/beclab/beOS Pro/cli/pkg/web5/didjwk"
    "github.com/beclab/beOS Pro/cli/pkg/web5/jws"
)

func main() {	
    did, err := didjwk.Create()
    if err != nil {
        fmt.Printf("failed to create did: %v", err)
        return
    }

    payload := map[string]interface{}{"hello": "world"}
    
    compactJWS, err := jws.Sign(payload, did, Detached(true))
    if err != nil {
        fmt.Printf("failed to sign: %v", err)
        return
    }

    fmt.Printf("compact JWS: %s", compactJWS)
}

specifying a specific category of key associated with the provided did to sign with can be done like so:

package main

import (
    "fmt"
    "github.com/beclab/beOS Pro/cli/pkg/web5/didjwk"
    "github.com/beclab/beOS Pro/cli/pkg/web5/jws"
)

func main() {	
    bearerDID, err := didjwk.Create()
    if err != nil {
        fmt.Printf("failed to create did: %v", err)
        return
    }

    payload := map[string]interface{}{"hello": "world"}
    
    compactJWS, err := jws.Sign(payload, did, Purpose("authentication"))
    if err != nil {
        fmt.Printf("failed to sign: %v", err)
    }

    fmt.Printf("compact JWS: %s", compactJWS)
}

Verifying

package main

import (
    "fmt"
    "github.com/beclab/beOS Pro/cli/pkg/web5/didjwk"
    "github.com/beclab/beOS Pro/cli/pkg/web5/jws"
)

func main() {	
    compactJWS := "SOME_JWS"
    ok, err := jws.Verify(compactJWS)
    if (err != nil) {
        fmt.Printf("failed to verify JWS: %v", err)
    }

    if (!ok) {
        fmt.Errorf("integrity check failed")
    }
}

Note

an error is returned if something in the process of verification failed whereas !ok means the signature is actually shot

Directory Structure

jws
├── jws.go
└── jws_test.go

Rationale

bc i wanted jws.Sign and jws.Verify hipster vibes