Skip to content

Commit

Permalink
language on retained dids
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe committed May 13, 2024
1 parent ace9cfa commit 3fbb90e
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 101 deletions.
6 changes: 3 additions & 3 deletions impl/internal/did/pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func hasLeadingZeros(hash string, difficulty int) bool {
return strings.HasPrefix(binaryHash, target)
}

// computeRetentionProof generates the Retention Proof Hash and checks if it meets the criteria.
func computeRetentionProof(didIdentifier, bitcoinBlockHash string, difficulty, nonce int) (string, bool) {
// solveRetentionChallenge generates the Retention Challenge Hash and checks if it meets the criteria.
func solveRetentionChallenge(didIdentifier, inputHash string, difficulty, nonce int) (string, bool) {
// Concatenating the DID identifier with the retention value
retentionValue := didIdentifier + (bitcoinBlockHash + fmt.Sprintf("%d", nonce))
retentionValue := didIdentifier + (inputHash + fmt.Sprintf("%d", nonce))

// Computing the SHA-256 hash
hash := computeSHA256Hash(retentionValue)
Expand Down
9 changes: 5 additions & 4 deletions impl/internal/did/pow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ import (
)

func TestPOW(t *testing.T) {
// Example usage of computeRetentionProof
// Example usage of solveRetentionChallenge
didIdentifier := "did:dht:test"
bitcoinBlockHash := "000000000000000000022be0c55caae4152d023dd57e8d63dc1a55c1f6de46e7"
inputHash := "000000000000000000022be0c55caae4152d023dd57e8d63dc1a55c1f6de46e7"

// 26 leading zeros
difficulty := 26

timer := time.Now()
for nonce := 0; nonce < math.MaxInt; nonce++ {
hash, isValid := computeRetentionProof(didIdentifier, bitcoinBlockHash, difficulty, nonce)
hash, isValid := solveRetentionChallenge(didIdentifier, inputHash, difficulty, nonce)
if isValid {
fmt.Printf("Hash: %s\n", hash)
fmt.Printf("Valid Retention Proof: %v\n", isValid)
fmt.Printf("Valid Retention Challenge: %v\n", isValid)
fmt.Printf("Nonce: %d\n", nonce)
break
}
}

fmt.Printf("Time taken: %s\n", time.Since(timer))
}
Loading

0 comments on commit 3fbb90e

Please sign in to comment.