-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add custom issuer guard (jwt-guard) #64
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
Changes from 1 commit
cd39719
ddf9d58
7f0ea8f
6cf4703
ea98607
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /target |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| [package] | ||
| name = "jwt-guard" | ||
| description = "jwt-guard" | ||
| version = "0.1.0-rc.1" | ||
| edition = "2021" | ||
| repository = "https://github.com/Peersyst/fast-auth" | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib", "rlib"] | ||
|
|
||
| # fields to configure build with WASM reproducibility, according to specs | ||
| # in https://github.com/near/NEPs/blob/master/neps/nep-0330.md | ||
| [package.metadata.near.reproducible_build] | ||
| # docker image, descriptor of build environment | ||
| image = "sourcescan/cargo-near:0.13.4-rust-1.85.1" | ||
| # tag after colon above serves only descriptive purpose; image is identified by digest | ||
| image_digest = "sha256:1f8b71742802f38990d442e8678aa4c0cd1c8317dd3ff493f41c079675d4f35b" | ||
| # list of environment variables names, whose values, if set, will be used as external build parameters | ||
| # in a reproducible manner | ||
| # supported by `sourcescan/cargo-near:0.10.1-rust-1.82.0` image or later images | ||
| passed_env = [] | ||
| # build command inside of docker container | ||
| # if docker image from default gallery is used https://hub.docker.com/r/sourcescan/cargo-near/tags, | ||
| # the command may be any combination of flags of `cargo-near`, | ||
| # supported by respective version of binary inside the container besides `--no-locked` flag | ||
| container_build_command = [ | ||
| "cargo", | ||
| "near", | ||
| "build", | ||
| "non-reproducible-wasm", | ||
| "--locked", | ||
| ] | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
| [dependencies] | ||
| base-jwt-guard = { path = "../base-jwt-guard" } | ||
| near-sdk = "5.9" | ||
| near-contract-standards = "5.17.2" | ||
| near-plugins = { git = "https://github.com/Near-One/near-plugins", tag = "v0.5.0" } | ||
| serde = { version = "1", features = ["derive"] } | ||
| borsh = { version = "1.3.1", features = ["unstable__schema"] } | ||
| schemars = "0.8" | ||
| serde_with = { version = "3.0", features = ["base64"] } | ||
| sha2 = "0.10.8" | ||
| crypto-bigint = { version = "0.7.0-pre", default-features = false, features = ["zeroize", "alloc"] } | ||
|
|
||
| [dev-dependencies] | ||
| near-sdk = { version = "5.9", features = ["unit-testing"] } | ||
| near-workspaces = { version = "0.18", features = ["unstable"] } | ||
| tokio = { version = "1.12.0", features = ["full"] } | ||
| serde_json = "1" | ||
|
|
||
| [profile.release] | ||
| codegen-units = 1 | ||
| # Tell `rustc` to optimize for small code size. | ||
| opt-level = "z" | ||
| lto = true | ||
| debug = false | ||
| panic = "abort" | ||
| # Opt into extra safety checks on arithmetic operations https://stackoverflow.com/a/64136471/249801 | ||
| overflow-checks = true | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||
| # contracts/custom-issuer-guard | ||||||
|
||||||
| # contracts/custom-issuer-guard | |
| # contracts/jwt-guards/jwt-guard |
🤖 Prompt for AI Agents
In @contracts/jwt-guards/jwt-guard/README.md at line 1, Update the README header
to match the directory path by replacing the current top-line title
"contracts/custom-issuer-guard" with "contracts/jwt-guards/jwt-guard" so the
README accurately reflects the contract name and location; ensure the first
line/title in README.md matches the folder name exactly.
GuillemGarciaDev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "name": "@contracts/custom-issuer-guard", | ||
| "version": "0.0.0", | ||
| "description": "", | ||
| "scripts": { | ||
| "build": "cargo near build non-reproducible-wasm", | ||
| "test": "cargo test", | ||
| "lint": "cargo clippy -- -D warnings" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC" | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| use near_sdk::{near, AccountId}; | ||
| use std::collections::{HashMap, HashSet}; | ||
| use base_jwt_guard::{JwtPublicKey, assert_valid_public_key}; | ||
| use crate::{ | ||
| error::CustomIssuerGuardError, | ||
| require_err, | ||
| utils::{assert_valid_account_id}, | ||
| }; | ||
| use super::Role; | ||
|
|
||
| #[near(serializers = [json])] | ||
| #[derive(Clone)] | ||
| pub struct CustomIssuerGuardConfig { | ||
| pub public_keys: Vec<JwtPublicKey>, | ||
| pub roles: RolesConfig, | ||
| } | ||
|
|
||
| impl CustomIssuerGuardConfig { | ||
| /// Asserts that the config is valid | ||
| /// # Arguments | ||
| /// * `config` - The config | ||
| /// # Panics | ||
| /// * If the config is not valid | ||
| pub fn assert_valid(&self) { | ||
| // Public key validation | ||
| for public_key in self.public_keys.iter() { | ||
| assert_valid_public_key(public_key.clone()); | ||
| } | ||
| // Roles validation | ||
| self.roles.assert_valid(); | ||
| } | ||
| } | ||
|
|
||
| #[near(serializers = [json])] | ||
| #[derive(Debug, Clone)] | ||
| pub struct RolesConfig { | ||
| pub super_admins: HashSet<AccountId>, | ||
| pub admins: HashMap<Role, HashSet<AccountId>>, | ||
| pub grantees: HashMap<Role, HashSet<AccountId>>, | ||
| } | ||
|
|
||
| impl RolesConfig { | ||
| /// Asserts that the roles config is valid | ||
| /// # Arguments | ||
| /// * `roles` - The roles config | ||
| /// # Panics | ||
| /// * If the roles config is not valid | ||
| pub fn assert_valid(&self) { | ||
| require_err!( | ||
| !self.super_admins.is_empty(), | ||
| CustomIssuerGuardError::SuperAdminsMustBeNonEmpty | ||
| ); | ||
| for super_admin in self.super_admins.iter() { | ||
| assert_valid_account_id(super_admin); | ||
| } | ||
| for account_ids in self.admins.values() { | ||
| for account_id in account_ids.iter() { | ||
| assert_valid_account_id(account_id); | ||
| } | ||
| } | ||
| for account_ids in self.grantees.values() { | ||
| for account_id in account_ids.iter() { | ||
| assert_valid_account_id(account_id); | ||
| } | ||
| } | ||
| } | ||
| } |
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.
🧩 Analysis chain
🌐 Web query:
crypto-bigint crate latest stable version releases💡 Result:
The latest stable release is crypto-bigint 0.6.1 (released 2025-02-14). [1][2]
Sources:
Consider using stable crypto-bigint version.
The
crypto-bigintdependency is pinned to0.7.0-pre, a prerelease version. The latest stable release is0.6.1(released February 2025). For production use in a NEAR contract, consider using the stable version or ensure the prerelease has been thoroughly tested and approved for production deployment.🤖 Prompt for AI Agents