Skip to content

Commit

Permalink
Add library example
Browse files Browse the repository at this point in the history
  • Loading branch information
naz3eh committed Aug 15, 2024
1 parent 973aa3e commit e97f62c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
29 changes: 29 additions & 0 deletions examples/library/Forc.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[[package]]
name = "core"
source = "path+from-root-0DAF035ABF1276AD"

[[package]]
name = "library"
source = "member"
dependencies = [
"std",
"sway_libs",
]

[[package]]
name = "standards"
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.5.0#348f7175df4c012b23c86cdb18aab79025ca1f18"
dependencies = ["std"]

[[package]]
name = "std"
source = "git+https://github.com/fuellabs/sway?rev#4c2c38430264472221dd4c68142013d819843b01"
dependencies = ["core"]

[[package]]
name = "sway_libs"
source = "git+https://github.com/FuelLabs/sway-libs?tag=v0.22.0#172adbbcc36e561a56c5820209445f86f0856bfc"
dependencies = [
"standards",
"std",
]
8 changes: 8 additions & 0 deletions examples/library/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Nazeeh Vahora"]
entry = "main.sw"
license = "Apache-2.0"
name = "library"

[dependencies]
sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.22.0" }
15 changes: 15 additions & 0 deletions examples/library/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
library;

use std::hash::sha256;
use std::hash::Hash;

/// Generates a SHA-256 hash of the input.
pub fn generate_sha256<T: Hash>(input: T) -> b256 {
sha256(input)
}

/// Verifies if the SHA-256 hash of the input matches the provided hash.
pub fn verify_sha256<T: Hash>(input: T, expected_hash: b256) -> bool {
let computed_hash = sha256(input);
computed_hash == expected_hash
}

0 comments on commit e97f62c

Please sign in to comment.