Skip to content

Commit 27b2f05

Browse files
pauldeluciaclaude
andcommitted
feat(sdk): add put_from_addresses convenience method for identity creation
Add a convenience method that automatically fetches and increments nonces for identity creation from addresses, matching the pattern used by other address-based operations (top_up_from_addresses, transfer_address_funds, etc.). - Add `put_from_addresses` for automatic nonce handling - Rename `put_with_address_funding` to `put_from_addresses_with_nonce` for consistency - Update wasm-sdk to use the renamed method Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent ee57ffb commit 27b2f05

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

packages/rs-sdk/src/platform/transition/put_identity.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::platform::transition::broadcast_identity::BroadcastRequestForNewIdentity;
22
use crate::platform::transition::{
3-
address_inputs::collect_address_infos_from_proof, broadcast::BroadcastStateTransition,
3+
address_inputs::{collect_address_infos_from_proof, fetch_inputs_with_nonce, nonce_inc},
4+
broadcast::BroadcastStateTransition,
45
};
56
use crate::{Error, Sdk};
67

@@ -46,13 +47,30 @@ pub trait PutIdentity<IS: Signer<IdentityPublicKey>>: Waitable {
4647
where
4748
Self: Sized;
4849

50+
/// Creates an identity funded by Platform addresses (nonces looked up automatically).
51+
///
52+
/// Use [Identity::new_with_input_addresses_and_keys](dpp::identity::Identity::new_with_input_addresses_and_keys)
53+
/// to create an identity. Then use this method to put it to the platform.
54+
///
55+
/// This method automatically fetches the current nonces for each input address
56+
/// and increments them before submitting the transaction.
57+
async fn put_from_addresses<AS: Signer<PlatformAddress> + Send + Sync>(
58+
&self,
59+
sdk: &Sdk,
60+
inputs: BTreeMap<PlatformAddress, Credits>,
61+
output: Option<(PlatformAddress, Credits)>,
62+
identity_signer: &IS,
63+
input_address_signer: &AS,
64+
settings: Option<PutSettings>,
65+
) -> Result<(Identity, AddressInfos), Error>;
66+
4967
/// Creates an identity funded by Platform addresses using explicit nonces.
5068
///
5169
/// Use [Identity::new_with_input_addresses_and_keys](dpp::identity::Identity::new_with_input_addresses_and_keys)
5270
/// to create an identity. Then use this method to put it to the platform.
5371
///
54-
/// This is a preferred method, as you need to use the same nonces when creating the identity.
55-
async fn put_with_address_funding<AS: Signer<PlatformAddress> + Send + Sync>(
72+
/// Inputs are not pre-validated client-side (Drive enforces authoritative checks).
73+
async fn put_from_addresses_with_nonce<AS: Signer<PlatformAddress> + Send + Sync>(
5674
&self,
5775
sdk: &Sdk,
5876
inputs_with_nonce: BTreeMap<PlatformAddress, (AddressNonce, Credits)>,
@@ -105,7 +123,28 @@ impl<IS: Signer<IdentityPublicKey>> PutIdentity<IS> for Identity {
105123
Self::wait_for_response(sdk, state_transition, settings).await
106124
}
107125

108-
async fn put_with_address_funding<AS: Signer<PlatformAddress> + Send + Sync>(
126+
async fn put_from_addresses<AS: Signer<PlatformAddress> + Send + Sync>(
127+
&self,
128+
sdk: &Sdk,
129+
inputs: BTreeMap<PlatformAddress, Credits>,
130+
output: Option<(PlatformAddress, Credits)>,
131+
identity_signer: &IS,
132+
input_address_signer: &AS,
133+
settings: Option<PutSettings>,
134+
) -> Result<(Identity, AddressInfos), Error> {
135+
let inputs_with_nonce = nonce_inc(fetch_inputs_with_nonce(sdk, &inputs).await?);
136+
self.put_from_addresses_with_nonce(
137+
sdk,
138+
inputs_with_nonce,
139+
output,
140+
identity_signer,
141+
input_address_signer,
142+
settings,
143+
)
144+
.await
145+
}
146+
147+
async fn put_from_addresses_with_nonce<AS: Signer<PlatformAddress> + Send + Sync>(
109148
&self,
110149
sdk: &Sdk,
111150
inputs: BTreeMap<PlatformAddress, (AddressNonce, Credits)>,

packages/wasm-sdk/src/state_transitions/addresses.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,9 +960,9 @@ impl WasmSdk {
960960
// Extract settings from options
961961
let settings = extract_settings_from_options(&options_value)?;
962962

963-
// Use the SDK's put_with_address_funding method
963+
// Use the SDK's put_from_addresses_with_nonce method
964964
let (created_identity, address_infos) = identity
965-
.put_with_address_funding(
965+
.put_from_addresses_with_nonce(
966966
self.inner_sdk(),
967967
inputs,
968968
change_output,

0 commit comments

Comments
 (0)