Repository navigation
feat: Attested Signatures + UCAN Principal Clarification #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0801383
ci: add cross-repo workspace test caller
Peeja 35ce799
feat: `ValidateToken` takes options, too
Peeja a95e20f
feat: DID Document parser
Peeja b35609f
feat: Easier to add verification methods to a document
Peeja 7458d1d
refactor: Add Unmarshal tests for `VerificationMethod`
Peeja da3b8a0
feat: Can add a verification method to a relationship
Peeja c1e6d80
refactor: Merge `did/document` into `did` pkg
Peeja 82fe273
fix: `publicKeyMultibase` is technically optional
Peeja 4eeb443
refactor: VerificationMaterial alone determines type
Peeja e1ba089
refactor: `RegisterVerificationMethodType()` finds type name from fac…
Peeja b79af53
refactor: Validator resolves DIDs and verifiers separately
Peeja 61ce354
WIP: Rework principal -> verification
Peeja a9e5fd6
refactor: DID VM types don't need Go types
Peeja 00cee24
feat: Validation error explains reasons for each method
Peeja 9bb76c9
refactor: Varsig doesn't use type parameters
Peeja b0fc9ae
refactor: Clarify and simplify `varsig`
Peeja 4ca1af1
feat: Validator works with any sig algorithm
Peeja d94a2d3
refactor: ErrorModel supports causes
Peeja d374882
feat: did:web, utility resolvers, and more
Peeja ffc616b
doc: Update README
Peeja 0e90a0c
fix: `WithSigner` -> `WithIssuer`
Peeja 4acd74d
refactor: `web.WithInsecure()` takes a boolean
Peeja 5579739
refactor: Restore cut-off doc comments
Peeja afc872b
refactor: `utilresolvers` → `resolver`
Peeja f1ce65b
refactor: Single error for unsupported methods
Peeja a6a94ed
fix: Update `go.sum`
Peeja 0fc2ef3
refactor: Change `resolver.Chain` back to `resolver.Tiered`
Peeja 1cb231f
refactor: `WithSigner()` should be `WithIssuer()`
Peeja 026c806
refactor: Break apart `ucantone/verification`
Peeja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| name: Workspace Test | ||
|
|
||
| on: | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: workspace-test-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| workspace-test: | ||
| uses: fil-forge/libforge/.github/workflows/go-workspace-test.yml@v1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package absentee | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/fil-forge/ucantone/did" | ||
| "github.com/fil-forge/ucantone/ucan" | ||
| "github.com/fil-forge/ucantone/varsig" | ||
| "github.com/fil-forge/ucantone/varsig/algorithm/nonstandard" | ||
| ) | ||
|
|
||
| var SignatureAlgorithm = nonstandard.New() | ||
|
|
||
| // Issuer is a special type of issuer that produces an absent signature, | ||
| // which signals that verifier needs to verify authorization interactively. | ||
| type Issuer struct { | ||
| id did.DID | ||
| } | ||
|
|
||
| var _ ucan.Issuer = Issuer{} | ||
|
|
||
| func (a Issuer) DID() did.DID { | ||
| return a.id | ||
| } | ||
|
|
||
| func (a Issuer) String() string { | ||
| return fmt.Sprintf("%s (absentee)", a.id) | ||
| } | ||
|
|
||
| func (a Issuer) Sign(msg []byte) []byte { | ||
| return []byte{} | ||
| } | ||
|
|
||
| func (a Issuer) SignatureAlgorithm() varsig.Algorithm { | ||
| return SignatureAlgorithm | ||
| } | ||
|
|
||
| func (a Issuer) Verifier() ucan.Verifier { | ||
| panic("absentee issuer does not have a verifier") | ||
| } | ||
|
|
||
| // From creates a special type of issuer that produces an absent signature, | ||
| // which signals that verifier needs to verify authorization interactively. | ||
| func From(id did.DID) Issuer { | ||
| return Issuer{id} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package did | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| ) | ||
|
|
||
| const CoreContext = "https://www.w3.org/ns/did/v1.1" | ||
|
|
||
| // Context handles both string and []string formats for @context field | ||
| // as allowed by the DID Core specification | ||
| type Context []string | ||
|
|
||
| func (fc Context) MarshalJSON() ([]byte, error) { | ||
| return json.Marshal(OneOrMany[string](append([]string{CoreContext}, fc...))) | ||
| } | ||
|
|
||
| func (fc *Context) UnmarshalJSON(data []byte) error { | ||
| var ctxStrs OneOrMany[string] | ||
| err := json.Unmarshal(data, &ctxStrs) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if len(ctxStrs) < 1 || ctxStrs[0] != CoreContext { | ||
| return fmt.Errorf("@context must list %q first", CoreContext) | ||
| } | ||
| *fc = Context(ctxStrs[1:]) | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package did_test | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/fil-forge/ucantone/did" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestContext(t *testing.T) { | ||
| t.Run("to JSON", func(t *testing.T) { | ||
| t.Run("with no additional contexts, produces the DID Core context", func(t *testing.T) { | ||
| ctx := did.Context{} | ||
| b, err := json.Marshal(ctx) | ||
| require.NoError(t, err) | ||
| require.JSONEq(t, `"https://www.w3.org/ns/did/v1.1"`, string(b)) | ||
| }) | ||
|
|
||
| t.Run("with additional contexts, puts the DID Core context first", func(t *testing.T) { | ||
| ctx := did.Context{ | ||
| "https://example.com/context1", | ||
| "https://example.com/context2", | ||
| } | ||
| b, err := json.Marshal(ctx) | ||
| require.NoError(t, err) | ||
| require.JSONEq(t, `[ | ||
| "https://www.w3.org/ns/did/v1.1", | ||
| "https://example.com/context1", | ||
| "https://example.com/context2" | ||
| ]`, string(b)) | ||
| }) | ||
| }) | ||
|
|
||
| t.Run("from JSON", func(t *testing.T) { | ||
| t.Run("with a single string of the DID Core context, produces an empty Context", func(t *testing.T) { | ||
| var ctx did.Context | ||
| err := json.Unmarshal([]byte(`"https://www.w3.org/ns/did/v1.1"`), &ctx) | ||
| require.NoError(t, err) | ||
| require.Equal(t, did.Context{}, ctx) | ||
| }) | ||
|
|
||
| t.Run("with a single string of the wrong context, fails", func(t *testing.T) { | ||
| var ctx did.Context | ||
| err := json.Unmarshal([]byte(`"https://example.com/wrong-context"`), &ctx) | ||
| require.ErrorContains(t, err, `@context must list "https://www.w3.org/ns/did/v1.1" first`) | ||
| }) | ||
|
|
||
| t.Run("with multiple contexts, puts them in the Context", func(t *testing.T) { | ||
| var ctx did.Context | ||
| err := json.Unmarshal([]byte(`["https://www.w3.org/ns/did/v1.1", "https://example.com/context1"]`), &ctx) | ||
| require.NoError(t, err) | ||
| require.Equal(t, did.Context{"https://example.com/context1"}, ctx) | ||
| }) | ||
|
|
||
| t.Run("with multiple contexts missing the DID Core context, fails", func(t *testing.T) { | ||
| var ctx did.Context | ||
| err := json.Unmarshal([]byte(`["https://example.com/context1", "https://example.com/context2"]`), &ctx) | ||
| require.ErrorContains(t, err, `@context must list "https://www.w3.org/ns/did/v1.1" first`) | ||
| }) | ||
|
|
||
| t.Run("with no contexts, fails", func(t *testing.T) { | ||
| var ctx did.Context | ||
| err := json.Unmarshal([]byte(`[]`), &ctx) | ||
| require.ErrorContains(t, err, `@context must list "https://www.w3.org/ns/did/v1.1" first`) | ||
| }) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package did | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "time" | ||
| ) | ||
|
|
||
| type DateTimeStamp time.Time | ||
|
|
||
| func (d DateTimeStamp) Time() time.Time { | ||
| return time.Time(d) | ||
| } | ||
|
|
||
| func (d DateTimeStamp) MarshalJSON() ([]byte, error) { | ||
| return json.Marshal(d.Time().Format(time.RFC3339)) | ||
| } | ||
|
|
||
| func (d *DateTimeStamp) UnmarshalJSON(b []byte) error { | ||
| var s string | ||
| err := json.Unmarshal(b, &s) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| t, err := time.Parse(time.RFC3339, s) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| *d = DateTimeStamp(t) | ||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.