Skip to content

Commit 84b8a36

Browse files
authored
Merge pull request #957 from hirosystems/develop
add new recipes
2 parents 859a411 + cf3bd94 commit 84b8a36

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Create a SHA-256 hash using Clarity
2+
3+
A scripts in Clarity that creates a sha256 hash
4+
that can be created in javascript as well.
5+
6+
## Use cases
7+
8+
- validate a secret vote
9+
10+
## Example usage
11+
12+
```typescript
13+
const hash = createSha256Hash("deadbeef"); //b462657d5547c972e675cfd7ee2e313eb033e6aa74f668ca7bd1d79a056c9fea
14+
```
15+
16+
```clarity
17+
;; vote
18+
(define-map votes principal (buff 32))
19+
(map-set votes tx-sender 0xb462657d5547c972e675cfd7ee2e313eb033e6aa74f668ca7bd1d79a056c9fea)
20+
21+
;; validate vote
22+
23+
(define-read-only (validate-vote (vote (buff 8)))
24+
(is-eq (map-get? votes tx-sender) (some (create-sha256-hash vote))))
25+
26+
(validate-vote 0xdeadbeef)
27+
```
28+
29+
## Resources
30+
31+
**Recipes**
32+
33+
- [Create a SHA-256 hash using Stacks.js](/cookbook/create-sha256-hash-stacks-js)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Create a SHA-256 hash using Stacks.js
2+
3+
A scripts in javascript that creates a sha256 hash
4+
that can be created in Clarity as well.
5+
6+
## Use cases
7+
8+
- validate a secret vote
9+
10+
## Example usage
11+
12+
```typescript
13+
const hash = createSha256Hash("deadbeef"); //b462657d5547c972e675cfd7ee2e313eb033e6aa74f668ca7bd1d79a056c9fea
14+
```
15+
16+
```clarity
17+
;; vote
18+
(define-map votes principal (buff 32))
19+
(map-set votes tx-sender 0xb462657d5547c972e675cfd7ee2e313eb033e6aa74f668ca7bd1d79a056c9fea)
20+
21+
;; validate vote
22+
23+
(define-read-only (validate-vote (vote (buff 8)))
24+
(is-eq (map-get? votes tx-sender) (some (create-sha256-hash vote))))
25+
26+
(validate-vote 0xdeadbeef)
27+
```
28+
29+
## Resources
30+
31+
**Recipes**
32+
33+
- [Create a SHA-256 hash using Clarity](/cookbook/create-sha256-hash-clarity)

0 commit comments

Comments
 (0)