Skip to content

Commit 397ca11

Browse files
fix: mint spendbundle
1 parent 86e95b1 commit 397ca11

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

src/js.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ pub struct BlsPair {
110110
pub puzzle_hash: Buffer,
111111
}
112112

113+
#[napi(object)]
114+
#[derive(Clone)]
115+
/// Represents the result of generating a DID proof.
116+
pub struct DidProofResult {
117+
pub proof: Proof,
118+
pub did_coin: Coin,
119+
}
120+
121+
#[napi(object)]
122+
#[derive(Clone)]
123+
/// Represents the result of creating a simple DID.
124+
pub struct CreateDidResult {
125+
pub coin_spends: Vec<CoinSpend>,
126+
pub did_coin: Coin,
127+
}
128+
113129
#[napi(object)]
114130
#[derive(Clone)]
115131
/// Represents NFT metadata.

src/lib.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,12 +1753,12 @@ pub async fn mint_nft(
17531753
/// @param {Peer} peer - The peer to query blockchain data
17541754
/// @param {Coin} didCoin - The DID coin to generate proof for
17551755
/// @param {boolean} forTestnet - Whether to use testnet or mainnet
1756-
/// @returns {Promise<Object>} An object containing the proof and the DID coin
1756+
/// @returns {Promise<DidProofResult>} An object containing the proof and the DID coin
17571757
pub async fn generate_did_proof(
17581758
peer: &Peer,
17591759
did_coin: Coin,
17601760
for_testnet: bool,
1761-
) -> napi::Result<serde_json::Value> {
1761+
) -> napi::Result<js::DidProofResult> {
17621762
let did_coin = rust::Coin::from_js(did_coin)?;
17631763
let network = if for_testnet {
17641764
wallet::TargetNetwork::Testnet11
@@ -1770,10 +1770,10 @@ pub async fn generate_did_proof(
17701770
.await
17711771
.map_err(js::err)?;
17721772

1773-
Ok(serde_json::json!({
1774-
"proof": proof.to_js()?,
1775-
"didCoin": coin.to_js()?
1776-
}))
1773+
Ok(js::DidProofResult {
1774+
proof: proof.to_js()?,
1775+
did_coin: coin.to_js()?,
1776+
})
17771777
}
17781778

17791779
#[napi]
@@ -1838,12 +1838,12 @@ pub async fn generate_did_proof_from_chain(
18381838
/// @param {Buffer} syntheticKey - The synthetic key that will control the DID
18391839
/// @param {Vec<Coin>} selectedCoins - Coins to spend for creating the DID
18401840
/// @param {BigInt} fee - Transaction fee
1841-
/// @returns {Object} An object containing coinSpends and the created DID coin
1841+
/// @returns {CreateDidResult} An object containing coinSpends and the created DID coin
18421842
pub fn create_simple_did(
18431843
synthetic_key: Buffer,
18441844
selected_coins: Vec<Coin>,
18451845
fee: BigInt,
1846-
) -> napi::Result<serde_json::Value> {
1846+
) -> napi::Result<js::CreateDidResult> {
18471847
let synthetic_key = RustPublicKey::from_js(synthetic_key)?;
18481848
let selected_coins = selected_coins
18491849
.into_iter()
@@ -1860,12 +1860,10 @@ pub fn create_simple_did(
18601860
.map(|cs| cs.to_js())
18611861
.collect::<Result<Vec<_>>>()?;
18621862

1863-
let did_coin_js = did_coin.to_js()?;
1864-
1865-
Ok(serde_json::json!({
1866-
"coinSpends": coin_spends_js,
1867-
"didCoin": did_coin_js
1868-
}))
1863+
Ok(js::CreateDidResult {
1864+
coin_spends: coin_spends_js,
1865+
did_coin: did_coin.to_js()?,
1866+
})
18691867
}
18701868

18711869
#[napi]

src/wallet.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::HashMap;
2-
use std::str::FromStr;
32
use std::time::{SystemTime, UNIX_EPOCH};
43

54
use chia::bls::{sign, verify, PublicKey, SecretKey, Signature};
@@ -28,13 +27,14 @@ use chia_wallet_sdk::client::{ClientError, Peer};
2827
use chia_wallet_sdk::driver::{
2928
get_merkle_tree, DataStore, DataStoreMetadata, DelegatedPuzzle, Did, DidInfo, DriverError,
3029
IntermediateLauncher, Launcher, Layer, NftMint, OracleLayer,
31-
Puzzle, SpendContext, SpendWithConditions, StandardLayer, WriterLayer,
30+
SpendContext, SpendWithConditions, StandardLayer, WriterLayer,
3231
};
33-
use chia_wallet_sdk::prelude::{EveProof, LineageProof, Proof};
32+
// Import proof types from our own crate's rust module
33+
use crate::rust::{EveProof, LineageProof, Proof};
3434
use chia_wallet_sdk::signer::{AggSigConstants, RequiredSignature, SignerError};
3535
use chia_wallet_sdk::types::{
3636
announcement_id,
37-
conditions::{CreateCoin, MeltSingleton, Memos, TransferNft, UpdateDataStoreMerkleRoot},
37+
conditions::{CreateCoin, MeltSingleton, Memos, UpdateDataStoreMerkleRoot},
3838
Condition, Conditions, MAINNET_CONSTANTS, TESTNET11_CONSTANTS,
3939
};
4040
use chia_wallet_sdk::utils::{self, CoinSelectionError};
@@ -1287,7 +1287,7 @@ pub async fn mint_nft(
12871287
};
12881288

12891289
// Create the DID singleton info (simplified DID structure)
1290-
let did_info = DidInfo::new(did_coin.coin_id(), None, 1, vec![], synthetic_key.derive_synthetic());
1290+
let did_info = DidInfo::new(did_coin.coin_id(), None, 1, vec![], synthetic_key.derive_synthetic().to_bytes().into());
12911291

12921292
let did = Did::new(did_coin, did_proof, did_info);
12931293

@@ -1308,7 +1308,7 @@ pub async fn mint_nft(
13081308
// Use IntermediateLauncher to mint the NFT
13091309
let (mint_conditions, _nft) = IntermediateLauncher::new(did_coin.coin_id(), 0, 1)
13101310
.create(&mut ctx)?
1311-
.mint_nft(&mut ctx, &nft_mint)?;
1311+
.mint_nft(&mut ctx, nft_mint)?;
13121312

13131313
// Update the DID with the mint conditions
13141314
let _updated_did = did.update(&mut ctx, &p2, mint_conditions)?;
@@ -1439,12 +1439,12 @@ pub async fn generate_did_proof_from_chain(
14391439
.spent_height
14401440
.ok_or(WalletError::UnknownCoin)?;
14411441

1442-
let parent_spend = peer
1442+
let _parent_spend = peer
14431443
.request_puzzle_and_solution(parent_coin_state.coin.coin_id(), parent_spend_height as u32)
14441444
.await?
14451445
.map_err(|_| WalletError::RejectPuzzleSolution)?;
14461446

1447-
let mut allocator = Allocator::new();
1447+
let _allocator = Allocator::new();
14481448

14491449
// For now, create a basic lineage proof
14501450
// This is a simplified approach - in production you'd want to properly parse the parent DID
@@ -1549,7 +1549,7 @@ pub async fn resolve_did_string_and_generate_proof(
15491549
use chia_wallet_sdk::utils::Address;
15501550
let address = Address::decode(bech32_part).map_err(|_| WalletError::Parse)?;
15511551

1552-
let did_id = address.puzzle_hash();
1552+
let did_id = address.puzzle_hash;
15531553

15541554
// First, get the launcher coin state to find the first DID coin
15551555
let launcher_states = peer
@@ -1589,7 +1589,7 @@ pub async fn resolve_did_string_and_generate_proof(
15891589
let launcher_puzzle = launcher_spend.puzzle.to_clvm(&mut allocator)?;
15901590
let launcher_solution = launcher_spend.solution.to_clvm(&mut allocator)?;
15911591

1592-
let output = clvmr::run_program(&mut allocator, launcher_puzzle, launcher_solution, u64::MAX, None)
1592+
let output = clvmr::run_program(&mut allocator, &clvmr::ChiaDialect::new(0), launcher_puzzle, launcher_solution, u64::MAX)
15931593
.map_err(|_| WalletError::Clvm)?;
15941594

15951595
let conditions =
@@ -1650,7 +1650,7 @@ pub async fn resolve_did_string_and_generate_proof(
16501650
let spend_puzzle = spend.puzzle.to_clvm(&mut allocator)?;
16511651
let spend_solution = spend.solution.to_clvm(&mut allocator)?;
16521652

1653-
let spend_output = clvmr::run_program(&mut allocator, spend_puzzle, spend_solution, u64::MAX, None)
1653+
let spend_output = clvmr::run_program(&mut allocator, &clvmr::ChiaDialect::new(0), spend_puzzle, spend_solution, u64::MAX)
16541654
.map_err(|_| WalletError::Clvm)?;
16551655

16561656
let spend_conditions = Vec::<Condition>::from_clvm(&allocator, spend_output.1)

0 commit comments

Comments
 (0)