-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #957 from hirosystems/develop
add new recipes
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,33 @@ | ||
# Create a SHA-256 hash using Clarity | ||
|
||
A scripts in Clarity that creates a sha256 hash | ||
that can be created in javascript as well. | ||
|
||
## Use cases | ||
|
||
- validate a secret vote | ||
|
||
## Example usage | ||
|
||
```typescript | ||
const hash = createSha256Hash("deadbeef"); //b462657d5547c972e675cfd7ee2e313eb033e6aa74f668ca7bd1d79a056c9fea | ||
``` | ||
|
||
```clarity | ||
;; vote | ||
(define-map votes principal (buff 32)) | ||
(map-set votes tx-sender 0xb462657d5547c972e675cfd7ee2e313eb033e6aa74f668ca7bd1d79a056c9fea) | ||
;; validate vote | ||
(define-read-only (validate-vote (vote (buff 8))) | ||
(is-eq (map-get? votes tx-sender) (some (create-sha256-hash vote)))) | ||
(validate-vote 0xdeadbeef) | ||
``` | ||
|
||
## Resources | ||
|
||
**Recipes** | ||
|
||
- [Create a SHA-256 hash using Stacks.js](/cookbook/create-sha256-hash-stacks-js) |
This file contains 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,33 @@ | ||
# Create a SHA-256 hash using Stacks.js | ||
|
||
A scripts in javascript that creates a sha256 hash | ||
that can be created in Clarity as well. | ||
|
||
## Use cases | ||
|
||
- validate a secret vote | ||
|
||
## Example usage | ||
|
||
```typescript | ||
const hash = createSha256Hash("deadbeef"); //b462657d5547c972e675cfd7ee2e313eb033e6aa74f668ca7bd1d79a056c9fea | ||
``` | ||
|
||
```clarity | ||
;; vote | ||
(define-map votes principal (buff 32)) | ||
(map-set votes tx-sender 0xb462657d5547c972e675cfd7ee2e313eb033e6aa74f668ca7bd1d79a056c9fea) | ||
;; validate vote | ||
(define-read-only (validate-vote (vote (buff 8))) | ||
(is-eq (map-get? votes tx-sender) (some (create-sha256-hash vote)))) | ||
(validate-vote 0xdeadbeef) | ||
``` | ||
|
||
## Resources | ||
|
||
**Recipes** | ||
|
||
- [Create a SHA-256 hash using Clarity](/cookbook/create-sha256-hash-clarity) |