Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,34 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@1.87
with:
components: clippy

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Run tests
run: cargo test --verbose

- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- uses: actions/checkout@v4

- name: Install toolchains
uses: jdx/mise-action@v2

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Fetch openapi
run: mise pull-openapi

- name: Run tests
run: cargo test --verbose

- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
target
openapi.json
*.pem
!tests/test_private_key.pem
!tests/test_public_key.pem
10 changes: 1 addition & 9 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[tools]
yq = "latest"
jq = "latest"
# note: rust-toolchain.toml is an 'idiomatic version file' for rust and mise does
# pick it up automatically, but it is currently behind a experimental flag
rust = "{{ exec(command='yq .toolchain.channel rust-toolchain.toml') }}"
rust = "{{ exec(command='./scripts/rust-version.sh') }}"
cargo-binstall = "latest"
"cargo:bacon" = "latest"
"cargo:cargo-progenitor" = "latest"

[env]
_.file = ['.env', '.env.local']
Expand Down Expand Up @@ -38,12 +36,6 @@ run = [
"curl https://api.privy.io/v1/openapi.json | jq -s -f 'scripts/openapi.jq' openapi.overlay.json - | sed \"s/anyOf/oneOf/g\" > openapi.json",
]

[tasks.generate-openapi]
description = "Generate the Rust code from the OpenAPI spec"
run = [
"cargo progenitor --input openapi.json --output crates/privy-api --name privy-api --version 0.0.1 --interface builder --include-client=false"
]

[tasks.gen-p256-key]
description = "Generate P-256 key pair for Privy wallet owner"
run = [
Expand Down
10 changes: 7 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ path = "examples/get_wallets.rs"

[build-dependencies]
prettyplease = "0.2.37"
progenitor = {path = "../progenitor/progenitor"}
# the privy branch includes these PRs:
# https://github.com/oxidecomputer/progenitor/pull/1194
# https://github.com/oxidecomputer/typify/pull/894
progenitor = { git = "https://github.com/arlyon/progenitor", branch = "privy" }
quote = "1.0.40"
serde_json = "1.0"
syn = { version = "2.0.106", features = ["full", "extra-traits"] }
Expand Down
6 changes: 4 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use std::{collections::HashMap, fs};

use heck::{ToPascalCase, ToSnakeCase};
use progenitor::GenerationSettings;
use progenitor::{GenerationSettings, OperationIdStrategy};
use quote::quote;
use serde_yaml::Value;
use syn::{File, Item, ItemImpl, Signature};
Expand Down Expand Up @@ -70,7 +70,9 @@ fn main() {

// Step 1: Generate the base progenitor code
let openapi_spec = load_openapi_spec();
let mut generator = progenitor::Generator::new(&GenerationSettings::default());
let mut generator = progenitor::Generator::new(
&GenerationSettings::default().with_operation_id_strategy(OperationIdStrategy::OmitMissing),
);
let tokens = generator.generate_tokens(&openapi_spec).unwrap();
let ast = syn::parse2(tokens).unwrap();
let content = prettyplease::unparse(&ast);
Expand Down
2 changes: 1 addition & 1 deletion examples/update_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async fn main() -> Result<()> {
&wallet_id,
&ctx,
&UpdateWalletBody {
owner: Some(OwnerInput::Variant0 {
owner: Some(OwnerInput::PublicKeyOwner {
public_key: public_key.to_string(),
}),
..Default::default()
Expand Down
11 changes: 4 additions & 7 deletions examples/wallet_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use anyhow::Result;
use privy_rust::{
PrivyClient,
generated::types::{
GetWalletBalanceAsset, GetWalletBalanceChain, GetWalletBalanceIncludeCurrency,
GetWalletBalanceAsset, GetWalletBalanceAssetString, GetWalletBalanceChain,
GetWalletBalanceChainString, GetWalletBalanceIncludeCurrency,
},
};
use tracing_subscriber::EnvFilter;
Expand Down Expand Up @@ -55,12 +56,8 @@ async fn main() -> Result<()> {
.balance()
.get(
&wallet_id,
&GetWalletBalanceAsset::Variant0(
privy_rust::generated::types::GetWalletBalanceAssetVariant0::Sol,
),
&GetWalletBalanceChain::Variant0(
privy_rust::generated::types::GetWalletBalanceChainVariant0::Solana,
),
&GetWalletBalanceAsset::String(GetWalletBalanceAssetString::Sol),
&GetWalletBalanceChain::String(GetWalletBalanceChainString::Solana),
Some(GetWalletBalanceIncludeCurrency::Usd),
)
.await?;
Expand Down
4 changes: 2 additions & 2 deletions examples/wallet_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use anyhow::Result;
use hex::ToHex;
use privy_rust::{
AuthorizationContext, JwtUser, PrivateKeyFromFile, PrivyClient,
generated::types::{HpkeEncryption, WalletExportRequest},
generated::types::{HpkeEncryption, WalletExportRequestBody},
};
use tracing_subscriber::EnvFilter;

Expand Down Expand Up @@ -67,7 +67,7 @@ async fn main() -> Result<()> {
.export(
&wallet_id,
&ctx,
&WalletExportRequest {
&WalletExportRequestBody {
encryption_type: HpkeEncryption::Hpke,
recipient_public_key,
},
Expand Down
8 changes: 4 additions & 4 deletions examples/wallet_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
use anyhow::Result;
use privy_rust::{
PrivyClient,
generated::types::{WalletTransactionsAsset, WalletTransactionsChain},
generated::types::{
WalletTransactionsAsset, WalletTransactionsAssetString, WalletTransactionsChain,
},
};
use tracing_subscriber::EnvFilter;

Expand Down Expand Up @@ -53,9 +55,7 @@ async fn main() -> Result<()> {
.transactions()
.get(
&wallet_id,
&WalletTransactionsAsset::Variant0(
privy_rust::generated::types::WalletTransactionsAssetVariant0::Sol,
),
&WalletTransactionsAsset::String(WalletTransactionsAssetString::Sol),
WalletTransactionsChain::Base,
None, // No cursor for first page
Some(10.0), // Limit to 10 transactions
Expand Down
1 change: 1 addition & 0 deletions scripts/rust-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
awk -F'"' '/channel/ {print $2}' < rust-toolchain.toml
6 changes: 3 additions & 3 deletions src/subclients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl PoliciesClient {
policy_id: &'a crate::generated::types::CreatePolicyRulePolicyId,
ctx: &'a AuthorizationContext,
body: &'a crate::generated::types::PolicyRule,
) -> Result<ResponseValue<crate::generated::types::RuleResponse>, Error<()>> {
) -> Result<ResponseValue<crate::generated::types::PolicyRuleResponse>, Error<()>> {
let sig = generate_authorization_signatures(
ctx,
&self.app_id,
Expand Down Expand Up @@ -234,8 +234,8 @@ impl WalletsClient {
&'a self,
wallet_id: &'a str,
ctx: &'a AuthorizationContext,
body: &'a crate::generated::types::WalletExportRequest,
) -> Result<ResponseValue<crate::generated::types::WalletExportResponse>, Error<()>> {
body: &'a crate::generated::types::WalletExportRequestBody,
) -> Result<ResponseValue<crate::generated::types::WalletExportResponseBody>, Error<()>> {
let sig = generate_authorization_signatures(
ctx,
&self.app_id,
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ mod tests {

// Create the request body that will be sent using the generated privy-api type
let update_wallet_body = UpdateWalletBody {
owner: Some(OwnerInput::Variant0 {
owner: Some(OwnerInput::PublicKeyOwner {
public_key: public_key.to_string(),
}),
..Default::default()
Expand Down
5 changes: 5 additions & 0 deletions tests/test_private_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIE+GqpjzCyCaTgfXikC2w4Fqnx3j28IDpEOYR93rnrcMoAoGCCqGSM49
AwEHoUQDQgAESYrvEwooR33jt/8Up0lWdDNAcxmgNZrCX23OThCPA+WxDx+dHYrj
RlfPmHX0/aMTopp1PdKAtlQjRJDHSNd8XA==
-----END EC PRIVATE KEY-----
4 changes: 4 additions & 0 deletions tests/test_public_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAESYrvEwooR33jt/8Up0lWdDNAcxmg
NZrCX23OThCPA+WxDx+dHYrjRlfPmHX0/aMTopp1PdKAtlQjRJDHSNd8XA==
-----END PUBLIC KEY-----
Loading