-
Notifications
You must be signed in to change notification settings - Fork 111
HashEscrow: separate hash-based escrow identity flow (#1657) #1678
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
Closed
Flamki
wants to merge
19
commits into
LFDT-Panurus:main
from
Flamki:feature/issue-1657-hash-based-escrow
Closed
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0f38be9
feat(hashescrow): add separate hash-based escrow identity flow (#1657)
Flamki 56749b4
feat(hashescrow): resolve recipient by preimage with dual hashes
Flamki f6ebaae
test(hashescrow): add interop coverage
Flamki 39505ee
fix(hashescrow): address review feedback
Flamki 7859f5c
fix(hashescrow): address gofix and lock accept CI
Flamki ae0a4d5
fix(hashescrow): avoid output scan in lock view
Flamki 3eca8c5
test(hashescrow): wait for claimable script
Flamki 9069379
test(hashescrow): submit sender return claim from sender
Flamki 23a17b2
test(hashescrow): prune after repeated claim rejection
Flamki 7bf5ad0
test(hashescrow): isolate repeated claim rejection
Flamki 7358ed0
test(hashescrow): wait before store consistency checks
Flamki 7db62dc
test(hashescrow): distribute claims to both parties
Flamki 26719a2
test(hashescrow): send canonical claim transaction
Flamki ccec63c
test(hashescrow): omit envelope for claim observer
Flamki fecec39
test(hashescrow): isolate claim observer session
Flamki 699e90e
test(hashescrow): guard observer payload envelope
Flamki 2f38df1
test(hashescrow): normalize observer claim payload
Flamki 4ad474c
test(hashescrow): stabilize claim observer session
Flamki 3c02447
Merge branch 'main' into feature/issue-1657-hash-based-escrow
Flamki 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
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,81 @@ | ||
| /* | ||
| Copyright IBM Corp. All Rights Reserved. | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package hashescrow | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors" | ||
| "github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/assert" | ||
| "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/id" | ||
| "github.com/hyperledger-labs/fabric-smart-client/platform/view/view" | ||
| "github.com/hyperledger-labs/fabric-token-sdk/token" | ||
| "github.com/hyperledger-labs/fabric-token-sdk/token/services/interop/hashescrow" | ||
| "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx" | ||
| ) | ||
|
|
||
| type Claim struct { | ||
| TMSID token.TMSID | ||
| Wallet string | ||
| PreImage []byte | ||
| } | ||
|
|
||
| type ClaimView struct { | ||
| *Claim | ||
| } | ||
|
|
||
| func (r *ClaimView) Call(ctx view.Context) (res interface{}, err error) { | ||
| var tx *hashescrow.Transaction | ||
| defer func() { | ||
| if e := recover(); e != nil { | ||
| txID := "none" | ||
| if tx != nil { | ||
| txID = tx.ID() | ||
| } | ||
| if err == nil { | ||
| err = errors.Errorf("<<<[%s]>>>: %s", txID, e) | ||
| } else { | ||
| err = errors.Errorf("<<<[%s]>>>: %s", txID, err) | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| claimWallet := hashescrow.GetWallet(ctx, r.Wallet, token.WithTMSID(r.TMSID)) | ||
| assert.NotNil(claimWallet, "wallet [%s] not found", r.Wallet) | ||
|
|
||
| matched, err := hashescrow.Wallet(claimWallet).ListByPreImage(ctx.Context(), r.PreImage) | ||
| assert.NoError(err, "failed looking up hash escrow script") | ||
| assert.True(matched.Count() == 1, "expected only one hash escrow script to match [%s], got [%d]", view.Identity(r.PreImage), matched.Count()) | ||
|
|
||
| idProvider, err := id.GetProvider(ctx) | ||
| assert.NoError(err, "failed getting id provider") | ||
| tx, err = hashescrow.NewAnonymousTransaction( | ||
| ctx, | ||
| ttx.WithAuditor(idProvider.Identity("auditor")), | ||
| ttx.WithTMSID(r.TMSID), | ||
| ) | ||
| assert.NoError(err, "failed to create a hash escrow transaction") | ||
| assert.NoError(tx.Claim(claimWallet, matched.At(0), r.PreImage), "failed adding a hash escrow claim for [%s]", matched.At(0).Id) | ||
|
|
||
| _, err = ctx.RunView(ttx.NewCollectEndorsementsView(tx.Transaction)) | ||
| assert.NoError(err, "failed to collect endorsements on hash escrow transaction") | ||
|
|
||
| _, err = ctx.RunView(ttx.NewOrderingAndFinalityView(tx.Transaction)) | ||
| assert.NoError(err, "failed to commit hash escrow transaction") | ||
|
|
||
| return tx.ID(), nil | ||
| } | ||
|
|
||
| type ClaimViewFactory struct{} | ||
|
|
||
| func (p *ClaimViewFactory) NewView(in []byte) (view.View, error) { | ||
| f := &ClaimView{Claim: &Claim{}} | ||
| err := json.Unmarshal(in, f.Claim) | ||
| assert.NoError(err, "failed unmarshalling input") | ||
|
|
||
| return f, 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Claim is called by either sender or recipient, maybe we call it instead lock. This could be addressed in another PR.