improve: nix flakebox fmt

This commit is contained in:
thesimplekid
2023-10-22 16:42:22 +01:00
parent dafa0079e8
commit bf5ea01c1f
80 changed files with 1028 additions and 261 deletions

1
.config/flakebox/id Normal file
View File

@@ -0,0 +1 @@
6ed8d7bac0d49950f28394f623607c29d00896bcf1505d366717626babadd81f8f111f93afd1b991b7087d5ce0684b4bcc10124aad93b3876ba1aba600a09cb4

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
root="$(git rev-parse --show-toplevel)"
dot_git="$(git rev-parse --git-common-dir)"
if [[ ! -d "${dot_git}/hooks" ]]; then mkdir -p "${dot_git}/hooks"; fi
# fix old bug
rm -f "${dot_git}/hooks/comit-msg"
rm -f "${dot_git}/hooks/commit-msg"
ln -sf "${root}/misc/git-hooks/commit-msg" "${dot_git}/hooks/commit-msg"
root="$(git rev-parse --show-toplevel)"
dot_git="$(git rev-parse --git-common-dir)"
if [[ ! -d "${dot_git}/hooks" ]]; then mkdir -p "${dot_git}/hooks"; fi
# fix old bug
rm -f "${dot_git}/hooks/pre-comit"
rm -f "${dot_git}/hooks/pre-commit"
ln -sf "${root}/misc/git-hooks/pre-commit" "${dot_git}/hooks/pre-commit"
# set template
git config commit.template misc/git-hooks/commit-template.txt
if ! flakebox lint --silent; then
>&2 echo " Project recommendations detected. Run 'flakebox lint' for more info."
fi
if [ -n "${DIRENV_IN_ENVRC:-}" ]; then
# and not set DIRENV_LOG_FORMAT
if [ -n "${DIRENV_LOG_FORMAT:-}" ]; then
>&2 echo "💡 Set 'DIRENV_LOG_FORMAT=\"\"' in your shell environment variables for a cleaner output of direnv"
fi
fi
>&2 echo "💡 Run 'just' for a list of available 'just ...' helper recipes"

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake

78
.github/workflows/flakebox-ci.yml vendored Normal file
View File

@@ -0,0 +1,78 @@
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION
jobs:
build:
name: Build
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- name: Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Build on ${{ matrix.host }}
run: 'nix flake check -L .#
'
strategy:
matrix:
host:
- macos
- linux
include:
- host: linux
runs-on: ubuntu-latest
timeout: 60
- host: macos
runs-on: macos-12
timeout: 60
timeout-minutes: ${{ matrix.timeout }}
flake:
name: Flake self-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check Nix flake inputs
uses: DeterminateSystems/flake-checker-action@v5
with:
fail-mode: true
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- name: Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Cargo Cache
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
path: ~/.cargo
- name: Commit Check
run: '# run the same check that git `pre-commit` hook does
nix develop --ignore-environment .#lint --command ./misc/git-hooks/pre-commit
'
name: CI
'on':
merge_group:
branches:
- master
- main
pull_request:
branches:
- master
- main
push:
branches:
- master
- main
tags:
- v*
workflow_dispatch: {}
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION

View File

@@ -0,0 +1,35 @@
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION
jobs:
flakehub-publish:
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ (inputs.tag != null) && format('refs/tags/{0}', inputs.tag) || ''
}}
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- name: Flakehub Push
uses: DeterminateSystems/flakehub-push@main
with:
name: ${{ github.repository }}
tag: ${{ inputs.tag }}
visibility: public
name: Publish to Flakehub
'on':
push:
tags:
- v?[0-9]+.[0-9]+.[0-9]+*
workflow_dispatch:
inputs:
tags:
description: The existing tag to publish to FlakeHub
required: true
type: string
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION

4
.rustfmt.toml Normal file
View File

@@ -0,0 +1,4 @@
group_imports = "StdExternalCrate"
wrap_comments = true
format_code_in_doc_comments = true
imports_granularity = "Module"

View File

@@ -3,12 +3,15 @@ mod nuts;
mod types;
mod ffi {
pub use cashu::types::InvoiceStatus;
pub use crate::error::CashuError;
pub use crate::nuts::nut00::blinded_message::BlindedMessage;
pub use crate::nuts::nut00::blinded_messages::BlindedMessages;
pub use crate::nuts::nut00::blinded_signature::BlindedSignature;
pub use crate::nuts::nut00::mint_proofs::MintProofs;
pub use crate::nuts::nut00::proof::{mint::Proof as MintProof, Proof};
pub use crate::nuts::nut00::proof::mint::Proof as MintProof;
pub use crate::nuts::nut00::proof::Proof;
pub use crate::nuts::nut00::token::Token;
pub use crate::nuts::nut01::key_pair::KeyPair;
pub use crate::nuts::nut01::keys::{Keys, KeysResponse};
@@ -26,11 +29,7 @@ mod ffi {
pub use crate::nuts::nut08::{MeltRequest, MeltResponse};
pub use crate::nuts::nut09::{MintInfo, MintVersion};
pub use crate::types::amount::Amount;
pub use crate::types::Bolt11Invoice;
pub use crate::types::KeySetInfo;
pub use crate::types::Secret;
pub use cashu::types::InvoiceStatus;
pub use crate::types::{Bolt11Invoice, KeySetInfo, Secret};
// UDL
uniffi::include_scaffolding!("cashu");

View File

@@ -1,8 +1,10 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu::nuts::nut00::wallet::BlindedMessages as BlindedMessagesSdk;
use crate::{error::Result, Amount, BlindedMessage, Secret, SecretKey};
use crate::error::Result;
use crate::{Amount, BlindedMessage, Secret, SecretKey};
pub struct BlindedMessages {
inner: BlindedMessagesSdk,

View File

@@ -3,9 +3,7 @@ use std::sync::Arc;
use cashu::nuts::nut00::BlindedSignature as BlindedSignatureSdk;
use crate::Amount;
use crate::Id;
use crate::PublicKey;
use crate::{Amount, Id, PublicKey};
pub struct BlindedSignature {
inner: BlindedSignatureSdk,

View File

@@ -1,8 +1,10 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu::nuts::nut00::Proof as ProofSdk;
use crate::{types::Secret, Amount, Id, PublicKey};
use crate::types::Secret;
use crate::{Amount, Id, PublicKey};
pub struct Proof {
inner: ProofSdk,
@@ -73,9 +75,7 @@ pub mod mint {
use cashu::nuts::nut00::mint::Proof as ProofSdk;
use crate::types::Secret;
use crate::Amount;
use crate::Id;
use crate::PublicKey;
use crate::{Amount, Id, PublicKey};
pub struct Proof {
inner: ProofSdk,

View File

@@ -5,8 +5,7 @@ use cashu::nuts::nut00::wallet::Token as TokenSdk;
use cashu::url::UncheckedUrl;
use crate::error::Result;
use crate::MintProofs;
use crate::Proof;
use crate::{MintProofs, Proof};
pub struct Token {
inner: TokenSdk,

View File

@@ -1,7 +1,9 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu::nuts::nut01::mint::KeyPair as KeyPairSdk;
use crate::{PublicKey, SecretKey};
use cashu::nuts::nut01::mint::KeyPair as KeyPairSdk;
pub struct KeyPair {
inner: KeyPairSdk,

View File

@@ -1,9 +1,12 @@
use std::{collections::HashMap, ops::Deref, sync::Arc};
use std::collections::HashMap;
use std::ops::Deref;
use std::sync::Arc;
use crate::{Amount, PublicKey};
use cashu::nuts::nut01::{Keys as KeysSdk, Response as KeysResponseSdk};
use cashu::Amount as AmountSdk;
use crate::{Amount, PublicKey};
pub struct Keys {
inner: KeysSdk,
}

View File

@@ -1,9 +1,7 @@
use std::ops::Deref;
use std::sync::Arc;
use cashu::nuts::nut02::Id as IdSdk;
use cashu::nuts::nut02::KeySet as KeySetSdk;
use cashu::nuts::nut02::Response;
use cashu::nuts::nut02::{Id as IdSdk, KeySet as KeySetSdk, Response};
use crate::error::Result;
use crate::nuts::nut01::keys::Keys;

View File

@@ -1,6 +1,7 @@
use std::str::FromStr;
use cashu::{nuts::nut03::RequestMintResponse as RequestMintResponseSdk, Bolt11Invoice};
use cashu::nuts::nut03::RequestMintResponse as RequestMintResponseSdk;
use cashu::Bolt11Invoice;
use crate::error::Result;

View File

@@ -1,4 +1,5 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu::nuts::nut04::{MintRequest as MintRequestSdk, PostMintResponse as PostMintResponseSdk};

View File

@@ -1,14 +1,15 @@
use std::{ops::Deref, str::FromStr, sync::Arc};
use std::ops::Deref;
use std::str::FromStr;
use std::sync::Arc;
use cashu::{
nuts::nut05::{
use cashu::nuts::nut05::{
CheckFeesRequest as CheckFeesRequestSdk, CheckFeesResponse as CheckFeesResponseSdk,
MeltRequest as MeltRequestSdk, MeltResponse as MeltResponseSdk,
},
Bolt11Invoice,
};
use cashu::Bolt11Invoice;
use crate::{error::Result, Amount, Proof};
use crate::error::Result;
use crate::{Amount, Proof};
pub struct CheckFeesRequest {
inner: CheckFeesRequestSdk,

View File

@@ -1,4 +1,5 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu::nuts::nut06::{SplitRequest as SplitRequestSdk, SplitResponse as SplitResponseSdk};

View File

@@ -1,4 +1,5 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu::nuts::nut07::{
CheckSpendableRequest as CheckSpendableRequestSdk,

View File

@@ -1,4 +1,5 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu::nuts::nut09::{MintInfo as MintInfoSdk, MintVersion as MintVersionSdk};

View File

@@ -1,4 +1,5 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu::Amount as AmountSdk;

View File

@@ -1,8 +1,11 @@
use std::{ops::Deref, str::FromStr, sync::Arc};
use std::ops::Deref;
use std::str::FromStr;
use std::sync::Arc;
use cashu::Bolt11Invoice as Bolt11InvoiceSdk;
use crate::{error::Result, Amount};
use crate::error::Result;
use crate::Amount;
pub struct Bolt11Invoice {
inner: Bolt11InvoiceSdk,

View File

@@ -1,4 +1,5 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu::types::KeysetInfo as KeySetInfoSdk;

View File

@@ -14,7 +14,7 @@
set -e
cd $(dirname "$0")/..
cd "$(dirname "$0")"/..
WASM_BINDGEN_WEAKREF=1 wasm-pack build --target nodejs --scope rust-cashu --out-dir pkg "${WASM_PACK_ARGS[@]}"

View File

@@ -1,8 +1,7 @@
use std::ops::Deref;
use wasm_bindgen::prelude::*;
use cashu::nuts::nut00::wallet::BlindedMessages;
use wasm_bindgen::prelude::*;
use crate::error::{into_err, Result};
use crate::types::JsAmount;

View File

@@ -3,7 +3,9 @@ use std::ops::Deref;
use cashu::nuts::nut00::BlindedSignature;
use wasm_bindgen::prelude::*;
use crate::{nuts::nut01::JsPublicKey, nuts::nut02::JsId, types::JsAmount};
use crate::nuts::nut01::JsPublicKey;
use crate::nuts::nut02::JsId;
use crate::types::JsAmount;
#[wasm_bindgen(js_name = BlindedSignature)]
pub struct JsBlindedSignature {

View File

@@ -3,7 +3,9 @@ use std::ops::Deref;
use cashu::nuts::nut00::Proof;
use wasm_bindgen::prelude::*;
use crate::{nuts::nut01::JsPublicKey, nuts::nut02::JsId, types::JsAmount, types::JsSecret};
use crate::nuts::nut01::JsPublicKey;
use crate::nuts::nut02::JsId;
use crate::types::{JsAmount, JsSecret};
#[wasm_bindgen(js_name = Proof)]
pub struct JsProof {

View File

@@ -1,6 +1,8 @@
use std::{ops::Deref, str::FromStr};
use std::ops::Deref;
use std::str::FromStr;
use cashu::{nuts::nut00::wallet::Token, url::UncheckedUrl};
use cashu::nuts::nut00::wallet::Token;
use cashu::url::UncheckedUrl;
use wasm_bindgen::prelude::*;
use crate::error::{into_err, Result};

View File

@@ -3,12 +3,9 @@ use std::ops::Deref;
use cashu::nuts::nut01::Keys;
use wasm_bindgen::prelude::*;
use crate::{
error::{into_err, Result},
types::JsAmount,
};
use super::JsPublicKey;
use crate::error::{into_err, Result};
use crate::types::JsAmount;
#[wasm_bindgen(js_name = Keys)]
pub struct JsKeys {

View File

@@ -4,10 +4,8 @@ use cashu::nuts::nut01::Response as KeysResponse;
use cashu::nuts::nut02::{Id, KeySet, Response as KeySetsResponse};
use wasm_bindgen::prelude::*;
use crate::{
error::{into_err, Result},
nuts::nut01::JsKeys,
};
use crate::error::{into_err, Result};
use crate::nuts::nut01::JsKeys;
#[wasm_bindgen(js_name = Id)]
pub struct JsId {

View File

@@ -1,8 +1,5 @@
mod keyset;
mod mint_keyset;
pub use keyset::JsId;
pub use keyset::JsKeySet;
pub use keyset::JsKeySetsResponse;
pub use keyset::JsKeysResponse;
pub use keyset::{JsId, JsKeySet, JsKeySetsResponse, JsKeysResponse};
pub use mint_keyset::JsMintKeySet;

View File

@@ -3,10 +3,8 @@ use std::ops::Deref;
use cashu::nuts::nut04::{MintRequest, PostMintResponse};
use wasm_bindgen::prelude::*;
use crate::{
error::{into_err, Result},
types::JsAmount,
};
use crate::error::{into_err, Result};
use crate::types::JsAmount;
#[wasm_bindgen(js_name = MintRequest)]
pub struct JsMintRequest {

View File

@@ -3,10 +3,8 @@ use std::ops::Deref;
use cashu::nuts::nut05::{CheckFeesRequest, CheckFeesResponse};
use wasm_bindgen::prelude::*;
use crate::{
error::Result,
types::{JsAmount, JsBolt11Invoice},
};
use crate::error::Result;
use crate::types::{JsAmount, JsBolt11Invoice};
#[wasm_bindgen(js_name = CheckFeesRequest)]
pub struct JsCheckFeesRequest {

View File

@@ -3,10 +3,8 @@ use std::ops::Deref;
use cashu::nuts::nut06::{SplitRequest, SplitResponse};
use wasm_bindgen::prelude::*;
use crate::{
error::{into_err, Result},
types::JsAmount,
};
use crate::error::{into_err, Result};
use crate::types::JsAmount;
#[wasm_bindgen(js_name = SplitRequest)]
pub struct JsSplitRequest {

View File

@@ -1,15 +1,11 @@
use std::ops::Deref;
use cashu::nuts::{
nut00::{BlindedMessage, BlindedSignature, Proof},
nut08::{MeltRequest, MeltResponse},
};
use cashu::nuts::nut00::{BlindedMessage, BlindedSignature, Proof};
use cashu::nuts::nut08::{MeltRequest, MeltResponse};
use wasm_bindgen::prelude::*;
use crate::{
error::{into_err, Result},
types::{JsAmount, JsBolt11Invoice},
};
use crate::error::{into_err, Result};
use crate::types::{JsAmount, JsBolt11Invoice};
#[wasm_bindgen(js_name = MeltRequest)]
pub struct JsMeltRequest {

View File

@@ -3,9 +3,8 @@ use std::ops::Deref;
use cashu::nuts::nut09::{MintInfo, MintVersion};
use wasm_bindgen::prelude::*;
use crate::error::{into_err, Result};
use super::nut01::JsPublicKey;
use crate::error::{into_err, Result};
#[wasm_bindgen(js_name = MintVersion)]
pub struct JsMintVersion {

View File

@@ -1,4 +1,5 @@
use std::{ops::Deref, str::FromStr};
use std::ops::Deref;
use std::str::FromStr;
use cashu::Bolt11Invoice;
use wasm_bindgen::prelude::*;

View File

@@ -1,7 +1,5 @@
use std::{
ops::Deref,
sync::{Arc, RwLock},
};
use std::ops::Deref;
use std::sync::{Arc, RwLock};
use cashu_ffi::{
Amount, CheckSpendableRequest, CheckSpendableResponse, Id, KeySet, KeySetInfo, KeySetResponse,

View File

@@ -1,8 +1,8 @@
use std::{ops::Deref, sync::Arc};
use cashu_sdk::types::Melted as MeltedSdk;
use std::ops::Deref;
use std::sync::Arc;
use cashu_ffi::Proof;
use cashu_sdk::types::Melted as MeltedSdk;
pub struct Melted {
inner: MeltedSdk,

View File

@@ -1,4 +1,5 @@
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use std::sync::Arc;
use cashu_sdk::types::ProofsStatus as ProofsStatusSdk;

View File

@@ -1,8 +1,8 @@
use std::{ops::Deref, sync::Arc};
use cashu_sdk::types::SendProofs as SendProofsSdk;
use std::ops::Deref;
use std::sync::Arc;
use cashu_ffi::Proof;
use cashu_sdk::types::SendProofs as SendProofsSdk;
pub struct SendProofs {
inner: SendProofsSdk,

View File

@@ -7,12 +7,10 @@ use cashu_ffi::{
use cashu_sdk::types::ProofsStatus;
use cashu_sdk::wallet::Wallet as WalletSdk;
use crate::{
client::Client,
error::Result,
types::{Melted, SendProofs},
Amount, Keys, MintProof,
};
use crate::client::Client;
use crate::error::Result;
use crate::types::{Melted, SendProofs};
use crate::{Amount, Keys, MintProof};
pub struct Wallet {
inner: WalletSdk,

View File

@@ -14,7 +14,7 @@
set -e
cd $(dirname "$0")/..
cd "$(dirname "$0")"/..
WASM_BINDGEN_WEAKREF=1 wasm-pack build --target nodejs --scope rust-cashu --out-dir pkg "${WASM_PACK_ARGS[@]}"

View File

@@ -1,16 +1,14 @@
use std::ops::Deref;
use cashu_js::{
nuts::{
nut02::{JsId, JsKeySet, JsKeySetsResponse, JsKeysResponse, JsMintKeySet},
nut04::{JsMintRequest, JsPostMintResponse},
nut06::{JsSplitRequest, JsSplitResponse},
nut07::{JsCheckSpendableRequest, JsCheckSpendableResponse},
nut08::{JsMeltRequest, JsMeltResponse},
},
JsAmount,
};
use cashu_sdk::{mint::Mint, nuts::nut01, nuts::nut02::KeySet};
use cashu_js::nuts::nut02::{JsId, JsKeySet, JsKeySetsResponse, JsKeysResponse, JsMintKeySet};
use cashu_js::nuts::nut04::{JsMintRequest, JsPostMintResponse};
use cashu_js::nuts::nut06::{JsSplitRequest, JsSplitResponse};
use cashu_js::nuts::nut07::{JsCheckSpendableRequest, JsCheckSpendableResponse};
use cashu_js::nuts::nut08::{JsMeltRequest, JsMeltResponse};
use cashu_js::JsAmount;
use cashu_sdk::mint::Mint;
use cashu_sdk::nuts::nut01;
use cashu_sdk::nuts::nut02::KeySet;
use wasm_bindgen::prelude::*;
use crate::error::{into_err, Result};

View File

@@ -1,17 +1,15 @@
use std::ops::Deref;
use cashu_js::nuts::nut00::{JsBlindedMessages, JsToken};
use cashu_js::nuts::nut01::JsKeys;
use cashu_js::nuts::nut03::JsRequestMintResponse;
use cashu_js::{nuts::nut01::JsKeys, JsAmount};
use cashu_js::{JsBolt11Invoice, JsProofsStatus};
use cashu_js::{JsAmount, JsBolt11Invoice, JsProofsStatus};
use cashu_sdk::wallet::Wallet;
use wasm_bindgen::prelude::*;
use crate::error::{into_err, Result};
use crate::types::{JsMelted, JsSendProofs};
use crate::{
error::{into_err, Result},
JsClient,
};
use crate::JsClient;
#[wasm_bindgen(js_name = Wallet)]
pub struct JsWallet {

View File

@@ -1,22 +1,18 @@
use crate::RUNTIME;
use cashu::{
nuts::{
nut00::{self, wallet::BlindedMessages, BlindedMessage, Proof},
nut01::Keys,
nut02,
nut03::RequestMintResponse,
nut04::PostMintResponse,
nut05::CheckFeesResponse,
nut06::{SplitRequest, SplitResponse},
nut07::CheckSpendableResponse,
nut08::MeltResponse,
nut09::MintInfo,
},
Amount, Bolt11Invoice,
};
use cashu::nuts::nut00::wallet::BlindedMessages;
use cashu::nuts::nut00::{self, BlindedMessage, Proof};
use cashu::nuts::nut01::Keys;
use cashu::nuts::nut02;
use cashu::nuts::nut03::RequestMintResponse;
use cashu::nuts::nut04::PostMintResponse;
use cashu::nuts::nut05::CheckFeesResponse;
use cashu::nuts::nut06::{SplitRequest, SplitResponse};
use cashu::nuts::nut07::CheckSpendableResponse;
use cashu::nuts::nut08::MeltResponse;
use cashu::nuts::nut09::MintInfo;
use cashu::{Amount, Bolt11Invoice};
use super::Error;
use crate::RUNTIME;
#[derive(Debug, Clone)]
pub struct Client {

View File

@@ -2,12 +2,8 @@
use std::fmt;
use std::str::FromStr;
use cashu::url::UncheckedUrl;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use url::Url;
use cashu::nuts::nut00::{wallet::BlindedMessages, BlindedMessage, Proof};
use cashu::nuts::nut00::wallet::BlindedMessages;
use cashu::nuts::nut00::{BlindedMessage, Proof};
use cashu::nuts::nut01::Keys;
use cashu::nuts::nut03::RequestMintResponse;
use cashu::nuts::nut04::{MintRequest, PostMintResponse};
@@ -17,11 +13,13 @@ use cashu::nuts::nut07::{CheckSpendableRequest, CheckSpendableResponse};
use cashu::nuts::nut08::{MeltRequest, MeltResponse};
use cashu::nuts::nut09::MintInfo;
use cashu::nuts::*;
use cashu::utils;
use cashu::Amount;
use cashu::url::UncheckedUrl;
use cashu::{utils, Amount};
#[cfg(target_arch = "wasm32")]
use gloo::net::http::Request;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use url::Url;
#[cfg(feature = "blocking")]
pub mod blocking;

View File

@@ -1,15 +1,13 @@
#[cfg(all(target_arch = "wasm32", feature = "blocking"))]
compile_error!("`blocking` feature can't be enabled for WASM targets");
#[cfg(feature = "blocking")]
use futures_util::Future;
#[cfg(feature = "blocking")]
use once_cell::sync::Lazy;
#[cfg(feature = "blocking")]
use tokio::runtime::Runtime;
#[cfg(feature = "blocking")]
use futures_util::Future;
#[cfg(feature = "wallet")]
pub mod client;

View File

@@ -1,20 +1,13 @@
use std::collections::{HashMap, HashSet};
use cashu::dhke::{sign_message, verify_message};
pub use cashu::error::mint::Error;
use cashu::dhke::sign_message;
use cashu::dhke::verify_message;
use cashu::nuts::nut00::BlindedMessage;
use cashu::nuts::nut00::BlindedSignature;
use cashu::nuts::nut00::Proof;
use cashu::nuts::nut00::{BlindedMessage, BlindedSignature, Proof};
use cashu::nuts::nut02::mint::KeySet;
use cashu::nuts::nut02::Id;
use cashu::nuts::nut06::SplitRequest;
use cashu::nuts::nut06::SplitResponse;
use cashu::nuts::nut07::CheckSpendableRequest;
use cashu::nuts::nut07::CheckSpendableResponse;
use cashu::nuts::nut08::MeltRequest;
use cashu::nuts::nut08::MeltResponse;
use cashu::nuts::nut06::{SplitRequest, SplitResponse};
use cashu::nuts::nut07::{CheckSpendableRequest, CheckSpendableResponse};
use cashu::nuts::nut08::{MeltRequest, MeltResponse};
use cashu::nuts::*;
use cashu::secret::Secret;
use cashu::types::KeysetInfo;

View File

@@ -3,11 +3,9 @@ use std::error::Error as StdError;
use std::fmt;
use std::str::FromStr;
use cashu::dhke::construct_proofs;
use cashu::dhke::unblind_message;
use cashu::nuts::nut00::{
mint, wallet::BlindedMessages, wallet::Token, BlindedSignature, Proof, Proofs,
};
use cashu::dhke::{construct_proofs, unblind_message};
use cashu::nuts::nut00::wallet::{BlindedMessages, Token};
use cashu::nuts::nut00::{mint, BlindedSignature, Proof, Proofs};
use cashu::nuts::nut01::Keys;
use cashu::nuts::nut03::RequestMintResponse;
use cashu::nuts::nut06::{SplitPayload, SplitRequest};
@@ -18,7 +16,6 @@ use tracing::warn;
#[cfg(feature = "blocking")]
use crate::client::blocking::Client;
#[cfg(not(feature = "blocking"))]
use crate::client::Client;

View File

@@ -2,25 +2,19 @@
use std::ops::Mul;
use bitcoin::hashes::sha256;
use bitcoin::hashes::Hash;
use bitcoin::hashes::{sha256, Hash};
#[cfg(feature = "wallet")]
use k256::ProjectivePoint;
use k256::{Scalar, SecretKey};
use crate::error;
use crate::secret::Secret;
#[cfg(feature = "wallet")]
use crate::nuts::nut00::{BlindedSignature, Proof, Proofs};
#[cfg(feature = "wallet")]
use crate::nuts::nut01::{Keys, PublicKey};
#[cfg(feature = "wallet")]
use crate::nuts::*;
use crate::secret::Secret;
fn hash_to_curve(message: &[u8]) -> k256::PublicKey {
let mut msg_to_hash = message.to_vec();
@@ -145,7 +139,6 @@ pub fn verify_message(
#[cfg(test)]
mod tests {
use hex::decode;
use k256::elliptic_curve::scalar::ScalarPrimitive;
use super::*;

View File

@@ -1,11 +1,13 @@
//! Notation and Models
// https://github.com/cashubtc/nuts/blob/main/00.md
use crate::{secret::Secret, url::UncheckedUrl, Amount};
use serde::{Deserialize, Serialize};
use super::nut01::PublicKey;
use super::nut02::Id;
use crate::secret::Secret;
use crate::url::UncheckedUrl;
use crate::Amount;
/// Blinded Message [NUT-00]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -21,21 +23,20 @@ pub struct BlindedMessage {
pub mod wallet {
use std::str::FromStr;
use base64::{engine::general_purpose, Engine as _};
use base64::engine::general_purpose;
use base64::Engine as _;
use serde::{Deserialize, Serialize};
use url::Url;
use crate::error;
use super::MintProofs;
use crate::dhke::blind_message;
use crate::error::wallet;
use crate::nuts::nut00::BlindedMessage;
use crate::nuts::nut00::Proofs;
use crate::nuts::nut00::{BlindedMessage, Proofs};
use crate::nuts::nut01;
use crate::secret::Secret;
use crate::url::UncheckedUrl;
use crate::Amount;
use crate::{dhke::blind_message, utils::split_amount};
use super::MintProofs;
use crate::utils::split_amount;
use crate::{error, Amount};
/// Blinded Messages [NUT-00]
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)]
@@ -221,9 +222,10 @@ impl From<Proof> for mint::Proof {
pub mod mint {
use serde::{Deserialize, Serialize};
use crate::{nuts::nut02::Id, secret::Secret, Amount};
use super::PublicKey;
use crate::nuts::nut02::Id;
use crate::secret::Secret;
use crate::Amount;
/// Proofs [NUT-00]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -273,9 +275,7 @@ mod tests {
assert_eq!(
token.token[0].mint,
UncheckedUrl::from_str("https://8333.space:3338")
.unwrap()
.into()
UncheckedUrl::from_str("https://8333.space:3338").unwrap()
);
assert_eq!(
token.token[0].proofs[0].clone().id.unwrap(),

View File

@@ -1,8 +1,7 @@
//! Mint public key exchange
// https://github.com/cashubtc/nuts/blob/main/01.md
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use serde::{Deserialize, Serialize};
@@ -156,7 +155,8 @@ impl<'de> serde::de::Deserialize<'de> for Response {
keys.insert(amount, pubkey);
}
// TODO: Should return an error if an amount or key is invalid and not continue
// TODO: Should return an error if an amount or key is
// invalid and not continue
}
Ok(Response { keys: Keys(keys) })
@@ -172,11 +172,9 @@ pub mod mint {
use serde::Serialize;
use super::{PublicKey, SecretKey};
use crate::Amount;
use super::PublicKey;
use super::SecretKey;
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Keys(pub BTreeMap<Amount, KeyPair>);

View File

@@ -4,9 +4,9 @@
use std::collections::HashSet;
use std::fmt;
use base64::{engine::general_purpose, Engine as _};
use bitcoin::hashes::sha256;
use bitcoin::hashes::Hash;
use base64::engine::general_purpose;
use base64::Engine as _;
use bitcoin::hashes::{sha256, Hash};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
@@ -41,10 +41,8 @@ impl Id {
const STRLEN: usize = 12;
pub fn try_from_base64(b64: &str) -> Result<Self, Error> {
use base64::{
engine::general_purpose::{STANDARD, URL_SAFE},
Engine as _,
};
use base64::engine::general_purpose::{STANDARD, URL_SAFE};
use base64::Engine as _;
if b64.len() != Self::STRLEN {
return Err(Error::Length);
@@ -174,14 +172,12 @@ pub mod mint {
use std::collections::BTreeMap;
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::Hash;
use bitcoin::hashes::HashEngine;
use bitcoin::hashes::{Hash, HashEngine};
use itertools::Itertools;
use k256::SecretKey;
use serde::Serialize;
use super::Id;
use crate::nuts::nut01::mint::{KeyPair, Keys};
use crate::Amount;
@@ -268,9 +264,8 @@ pub mod mint {
#[cfg(test)]
mod test {
use crate::nuts::nut02::Id;
use super::Keys;
use crate::nuts::nut02::Id;
const SHORT_KEYSET_ID: &str = "esom3oyNLLit";
const SHORT_KEYSET: &str = r#"

View File

@@ -5,8 +5,7 @@ use serde::{Deserialize, Serialize};
use super::nut00::Proofs;
use crate::error::Error;
use crate::Amount;
use crate::Bolt11Invoice;
use crate::{Amount, Bolt11Invoice};
/// Check Fees Response [NUT-05]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]

View File

@@ -2,13 +2,11 @@
// https://github.com/cashubtc/nuts/blob/main/06.md
use serde::{Deserialize, Serialize};
use crate::nuts::nut00::{BlindedMessage, Proofs};
use crate::Amount;
use super::nut00::BlindedSignature;
#[cfg(feature = "wallet")]
use crate::nuts::nut00::wallet::BlindedMessages;
use super::nut00::BlindedSignature;
use crate::nuts::nut00::{BlindedMessage, Proofs};
use crate::Amount;
#[cfg(feature = "wallet")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]

View File

@@ -4,9 +4,9 @@
use lightning_invoice::Bolt11Invoice;
use serde::{Deserialize, Serialize};
use crate::{error::Error, Amount};
use super::nut00::{BlindedMessage, BlindedSignature, Proofs};
use crate::error::Error;
use crate::Amount;
/// Melt Request [NUT-08]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]

View File

@@ -26,7 +26,8 @@ impl Secret {
const BIT_LENGTH: usize = 128;
/// Create secret value
pub fn new() -> Self {
use base64::{engine::general_purpose::URL_SAFE, Engine as _};
use base64::engine::general_purpose::URL_SAFE;
use base64::Engine as _;
use rand::RngCore;
let mut rng = rand::thread_rng();

View File

@@ -21,7 +21,8 @@ pub mod serde_url {
}
pub mod bytes_base64 {
use base64::{engine::general_purpose, Engine as _};
use base64::engine::general_purpose;
use base64::Engine as _;
use serde::Deserialize;
pub fn serialize<S>(my_bytes: &Vec<u8>, serializer: S) -> Result<S::Ok, S::Error>

View File

@@ -2,10 +2,8 @@
use serde::{Deserialize, Serialize};
use crate::nuts::{
nut00::{mint, Proofs},
nut02::Id,
};
use crate::nuts::nut00::{mint, Proofs};
use crate::nuts::nut02::Id;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProofsStatus {

View File

@@ -5,6 +5,7 @@
use core::fmt;
use core::str::FromStr;
use serde::{Deserialize, Serialize};
use url::{ParseError, Url};
@@ -115,6 +116,7 @@ mod tests {
assert_eq!(relay, unchecked_relay_url.to_string());
// assert_eq!(relay, serde_json::to_string(&unchecked_relay_url).unwrap())
// assert_eq!(relay,
// serde_json::to_string(&unchecked_relay_url).unwrap())
}
}

View File

@@ -48,9 +48,9 @@ mod tests {
split_amount(Amount::from_sat(3)),
vec![Amount::from_sat(1), Amount::from_sat(2)]
);
let amounts: Vec<Amount> = vec![1, 2, 8].iter().map(|a| Amount::from_sat(*a)).collect();
let amounts: Vec<Amount> = [1, 2, 8].iter().map(|a| Amount::from_sat(*a)).collect();
assert_eq!(split_amount(Amount::from_sat(11)), amounts);
let amounts: Vec<Amount> = vec![1, 2, 4, 8, 16, 32, 64, 128]
let amounts: Vec<Amount> = [1, 2, 4, 8, 16, 32, 64, 128]
.iter()
.map(|a| Amount::from_sat(*a))
.collect();

375
flake.lock generated Normal file
View File

@@ -0,0 +1,375 @@
{
"nodes": {
"android-nixpkgs": {
"inputs": {
"devshell": "devshell",
"flake-utils": "flake-utils_2",
"nixpkgs": [
"flakebox",
"nixpkgs"
]
},
"locked": {
"lastModified": 1695500413,
"narHash": "sha256-yinrAWIc4XZbWQoXOYkUO0lCNQ5z/vMyl+QCYuIwdPc=",
"owner": "dpc",
"repo": "android-nixpkgs",
"rev": "2e42268a196375ce9b010a10ec5250d2f91a09b4",
"type": "github"
},
"original": {
"owner": "dpc",
"repo": "android-nixpkgs",
"rev": "2e42268a196375ce9b010a10ec5250d2f91a09b4",
"type": "github"
}
},
"crane": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils_3",
"nixpkgs": [
"flakebox",
"nixpkgs"
],
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1697596235,
"narHash": "sha256-4VTrrTdoA1u1wyf15krZCFl3c29YLesSNioYEgfb2FY=",
"owner": "dpc",
"repo": "crane",
"rev": "c97a0c0d83bfdf01c29113c5592a3defc27cb315",
"type": "github"
},
"original": {
"owner": "dpc",
"repo": "crane",
"rev": "c97a0c0d83bfdf01c29113c5592a3defc27cb315",
"type": "github"
}
},
"devshell": {
"inputs": {
"nixpkgs": [
"flakebox",
"android-nixpkgs",
"nixpkgs"
],
"systems": "systems_2"
},
"locked": {
"lastModified": 1695195896,
"narHash": "sha256-pq9q7YsGXnQzJFkR5284TmxrLNFc0wo4NQ/a5E93CQU=",
"owner": "numtide",
"repo": "devshell",
"rev": "05d40d17bf3459606316e3e9ec683b784ff28f16",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"flakebox",
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1696918968,
"narHash": "sha256-18rAHsM9YsGp7aKKemO4gKIeWfrSyDsdJZ/mk4dQ3JI=",
"owner": "nix-community",
"repo": "fenix",
"rev": "638fc95a2a3d01b372c76f71cbb6d73c63909d6e",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_3"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_3": {
"inputs": {
"systems": "systems_4"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_4": {
"inputs": {
"systems": [
"flakebox",
"systems"
]
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flakebox": {
"inputs": {
"android-nixpkgs": "android-nixpkgs",
"crane": "crane",
"fenix": "fenix",
"flake-utils": "flake-utils_4",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-unstable": "nixpkgs-unstable",
"systems": "systems_5"
},
"locked": {
"lastModified": 1697876216,
"narHash": "sha256-Sxf43+wj7bW11yNMstEzn6mbI/Pk9fMSYWFF+swQV5s=",
"owner": "rustshop",
"repo": "flakebox",
"rev": "be3482250c7e7427e86aa8c2523df2cbc478ae5f",
"type": "github"
},
"original": {
"owner": "rustshop",
"repo": "flakebox",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1697777081,
"narHash": "sha256-n2vQARhKevRGyeo+LAa8g+CdUQsdH/caNk8jnylcPhY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "679cadfdfed2b90311a247b2d6ef6dfd3d6cab73",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1697456312,
"narHash": "sha256-roiSnrqb5r+ehnKCauPLugoU8S36KgmWraHgRqVYndo=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "ca012a02bf8327be9e488546faecae5e05d7d749",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"flakebox": "flakebox",
"nixpkgs": "nixpkgs"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1696840854,
"narHash": "sha256-wphOvjDSDsUN5DMe3MOhdargANIab7YE3hkh3Qv7qso=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "aaa1e8e1b82d742b876d164a30dda02f318ce809",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"flakebox",
"crane",
"flake-utils"
],
"nixpkgs": [
"flakebox",
"crane",
"nixpkgs"
]
},
"locked": {
"lastModified": 1695003086,
"narHash": "sha256-d1/ZKuBRpxifmUf7FaedCqhy0lyVbqj44Oc2s+P5bdA=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "b87a14abea512d956f0b89d0d8a1e9b41f3e20ff",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_3": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_4": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_5": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

25
flake.nix Normal file
View File

@@ -0,0 +1,25 @@
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
flakebox = {
url = "github:rustshop/flakebox";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flakebox, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
flakeboxLib = flakebox.lib.${system} { };
in
{
devShells = flakeboxLib.mkShells {
packages = [ ];
};
});
}

107
justfile
View File

@@ -1,20 +1,87 @@
precommit:
rustup default stable
cargo fmt
cargo check -p cashu
cargo check -p cashu-sdk --no-default-features --features mint
cargo check -p cashu-sdk --no-default-features --features wallet
cargo check -p cashu-sdk --no-default-features --features blocking
typos
cargo test -p cashu
cargo test -p cashu-sdk
cargo clippy --target wasm32-unknown-unknown -p cashu
cargo clippy --target wasm32-unknown-unknown -p cashu-sdk
rustup default 1.70.0
cargo check -p cashu
cargo check -p cashu-sdk --no-default-features --features mint
cargo check -p cashu-sdk --no-default-features --features wallet
cargo check -p cashu-sdk --no-default-features --features blocking
cargo test -p cashu
cargo test -p cashu-sdk
rustup default stable
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION
alias b := build
alias c := check
alias t := test
[private]
default:
@just --list
# run `cargo build` on everything
build:
cargo build --workspace --all-targets
# run `cargo check` on everything
check:
cargo check --workspace --all-targets
# run all checks recommended before opening a PR
final-check: lint clippy
cargo test --doc
just test
# run code formatters
format:
cargo fmt --all
nixpkgs-fmt $(echo **.nix)
# run lints (git pre-commit hook)
lint:
env NO_STASH=true $(git rev-parse --git-common-dir)/hooks/pre-commit
# run tests
test: build
cargo test
# run and restart on changes
watch:
env RUST_LOG=${RUST_LOG:-debug} cargo watch -x run
# run `cargo clippy` on everything
clippy:
cargo clippy --locked --offline --workspace --all-targets -- --deny warnings --allow deprecated
# run `cargo clippy --fix` on everything
clippy-fix:
cargo clippy --locked --offline --workspace --all-targets --fix
# run `semgrep`
semgrep:
env SEMGREP_ENABLE_VERSION_CHECK=0 \
semgrep --error --no-rewrite-rule-ids --config .config/semgrep.yaml
# check typos
[no-exit-message]
typos *PARAMS:
#!/usr/bin/env bash
set -eo pipefail
export FLAKEBOX_GIT_LS
FLAKEBOX_GIT_LS="$(git ls-files)"
export FLAKEBOX_GIT_LS_TEXT
FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "^db/|\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico)\$")"
if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos {{PARAMS}} --file-list - --force-exclude ; then
>&2 echo "Typos found: Valid new words can be added to '.typos.toml'"
return 1
fi
# fix all typos
[no-exit-message]
typos-fix-all:
just typos -w
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION

23
misc/git-hooks/commit-msg Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Sanitize file first, by removing leading lines that are empty or start with a hash,
# as `convco` currently does not do it automatically (but git will)
# TODO: next release of convco should be able to do it automatically
MESSAGE="$(
while read -r line ; do
# skip any initial comments (possibly from previous run)
if [ -z "${body_detected:-}" ] && { [[ "$line" =~ ^#.*$ ]] || [ "$line" == "" ]; }; then
continue
fi
body_detected="true"
echo "$line"
done < "$1"
)"
# convco fails on fixup!, so remove fixup! prefix
MESSAGE="${MESSAGE#fixup! }"
if ! convco check --from-stdin <<<"$MESSAGE" ; then
>&2 echo "Please follow conventional commits(https://www.conventionalcommits.org)"
>&2 echo "Use git recommit <args> to fix your commit"
exit 1
fi

View File

@@ -0,0 +1,2 @@
# Explain *why* this change is being made width limit ->|

165
misc/git-hooks/pre-commit Executable file
View File

@@ -0,0 +1,165 @@
#!/usr/bin/env bash
set -euo pipefail
set +e
git diff-files --quiet
is_unclean=$?
set -e
# Revert `git stash` on exit
function revert_git_stash {
>&2 echo "Unstashing uncommitted changes..."
git stash pop -q
}
# Stash pending changes and revert them when script ends
if [ -z "${NO_STASH:-}" ] && [ $is_unclean -ne 0 ]; then
>&2 echo "Stashing uncommitted changes..."
GIT_LITERAL_PATHSPECS=0 git stash -q --keep-index
trap revert_git_stash EXIT
fi
export FLAKEBOX_GIT_LS
FLAKEBOX_GIT_LS="$(git ls-files)"
export FLAKEBOX_GIT_LS_TEXT
FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico|gif)\$")"
function check_nothing() {
true
}
export -f check_nothing
function check_cargo_fmt() {
set -euo pipefail
cargo fmt --all --check
}
export -f check_cargo_fmt
function check_cargo_lock() {
set -euo pipefail
# https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5
cargo update --workspace --locked
}
export -f check_cargo_lock
function check_leftover_dbg() {
set -euo pipefail
errors=""
for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do
if grep 'dbg!(' "$path" > /dev/null; then
>&2 echo "$path contains dbg! macro"
errors="true"
fi
done
if [ -n "$errors" ]; then
>&2 echo "Fix the problems above or use --no-verify" 1>&2
return 1
fi
}
export -f check_leftover_dbg
function check_semgrep() {
set -euo pipefail
# semgrep is not available on MacOS
if ! command -v semgrep > /dev/null ; then
>&2 echo "Skipping semgrep check: not available"
return 0
fi
if [ ! -f .config/semgrep.yaml ] ; then
>&2 echo "Skipping semgrep check: .config/semgrep.yaml doesn't exist"
return 0
fi
if [ ! -s .config/semgrep.yaml ] ; then
>&2 echo "Skipping semgrep check: .config/semgrep.yaml empty"
return 0
fi
env SEMGREP_ENABLE_VERSION_CHECK=0 \
semgrep -q --error --no-rewrite-rule-ids --config .config/semgrep.yaml
}
export -f check_semgrep
function check_shellcheck() {
set -euo pipefail
for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep -E '.*\.sh$'); do
shellcheck --severity=warning "$path"
done
}
export -f check_shellcheck
function check_trailing_newline() {
set -euo pipefail
errors=""
for path in $(echo "$FLAKEBOX_GIT_LS_TEXT"); do
# extra branches for clarity
if [ ! -s "$path" ]; then
# echo "$path is empty"
true
elif [ -z "$(tail -c 1 < "$path")" ]; then
# echo "$path ends with a newline or with a null byte"
true
else
>&2 echo "$path doesn't end with a newline" 1>&2
errors="true"
fi
done
if [ -n "$errors" ]; then
>&2 echo "Fix the problems above or use --no-verify" 1>&2
return 1
fi
}
export -f check_trailing_newline
function check_trailing_whitespace() {
set -euo pipefail
if ! git diff --check HEAD ; then
echo "Trailing whitespace detected. Please remove them before committing."
return 1
fi
}
export -f check_trailing_whitespace
function check_typos() {
set -euo pipefail
if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos --file-list - --force-exclude ; then
>&2 echo "Typos found: Valid new words can be added to '.typos.toml'"
return 1
fi
}
export -f check_typos
parallel \
--nonotice \
::: \
check_cargo_fmt \
check_cargo_lock \
check_leftover_dbg \
check_semgrep \
check_shellcheck \
check_trailing_newline \
check_trailing_whitespace \
check_typos \
check_nothing