Skip to content

Commit 5e85213

Browse files
authored
Merge pull request #38 from iotaledger/feat/notarization-api
feat: read-only notarization api
2 parents 6f9fdf3 + b4a44f2 commit 5e85213

22 files changed

Lines changed: 1455 additions & 1165 deletions

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ members = ["notarization-rs"]
1414
anyhow = "1.0"
1515
async-trait = "0.1.88"
1616
cfg-if = "1.0"
17+
bcs = { version = "0.1.6" }
1718
fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "2f502fd8570fe4e9cff36eea5bbd6fef22002898", package = "fastcrypto" }
18-
identity_iota_core = { git = "https://github.com/iotaledger/identity.rs.git", branch = "feat/identity-rebased-alpha-public-interaction-rust", default-features = false, features = [
19-
"iota-client",
20-
], package = "identity_iota_core" }
21-
identity_iota_interaction = { git = "https://github.com/iotaledger/identity.rs.git", branch = "feat/identity-rebased-alpha-public-interaction-rust", package = "identity_iota_interaction" }
19+
iota_interaction = { git = "https://github.com/iotaledger/product-core.git", branch = "feat/add-dev-inspect-tx", package = "iota_interaction" }
20+
iota_interaction_rust = { git = "https://github.com/iotaledger/product-core.git", branch = "feat/add-dev-inspect-tx", package = "iota_interaction_rust" }
2221
phf = { version = "0.11.2", features = ["macros"] }
22+
product_common = { git = "https://github.com/iotaledger/product-core.git", branch = "feat/add-dev-inspect-tx", package = "product_common" }
2323
serde = { version = "1.0", default-features = false, features = [
2424
"alloc",
2525
"derive",

notarization-move/sources/notarization.move

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,12 @@ public fun version_count<D: store + drop + copy>(self: &Notarization<D>): u64 {
350350
self.state_version_count
351351
}
352352

353-
public fun description<D: store + drop + copy>(self: &Notarization<D>): &Option<String> {
354-
&self.immutable_metadata.description
353+
public fun description<D: store + drop + copy>(self: &Notarization<D>): Option<String> {
354+
self.immutable_metadata.description
355355
}
356356

357-
public fun updateable_metadata<D: store + drop + copy>(self: &Notarization<D>): &Option<String> {
358-
&self.updateable_metadata
357+
public fun updateable_metadata<D: store + drop + copy>(self: &Notarization<D>): Option<String> {
358+
self.updateable_metadata
359359
}
360360

361361
public fun notarization_method<D: store + drop + copy>(self: &Notarization<D>): NotarizationMethod {
@@ -425,7 +425,7 @@ public fun is_destroy_allowed<D: store + drop + copy>(self: &Notarization<D>, cl
425425
/// See fun `are_locked_notarization_invariants_ok()` and
426426
/// `are_dynamic_notarization_invariants_ok()`
427427
/// for more details.
428-
public fun assert_method_specific_invariants<D: store + drop + copy>(self: &Notarization<D>) {
428+
public(package) fun assert_method_specific_invariants<D: store + drop + copy>(self: &Notarization<D>) {
429429
if (self.method.is_dynamic()) {
430430
assert!(
431431
are_dynamic_notarization_invariants_ok(&self.immutable_metadata),
@@ -443,7 +443,7 @@ public fun assert_method_specific_invariants<D: store + drop + copy>(self: &Nota
443443
///
444444
/// - `self.immutable_metadata.locking` must exist.
445445
/// - `updated_lock` and `transfer_lock` must be `TimeLock::UntilDestroyed`.
446-
public fun are_locked_notarization_invariants_ok(immutable_metadata: &ImmutableMetadata): bool {
446+
public(package) fun are_locked_notarization_invariants_ok(immutable_metadata: &ImmutableMetadata): bool {
447447
if (immutable_metadata.locking.is_some()) {
448448
let lock_metadata = option::borrow(&immutable_metadata.locking);
449449
timelock::is_until_destroyed(&lock_metadata.transfer_lock) && timelock::is_until_destroyed(&lock_metadata.update_lock)
@@ -459,7 +459,7 @@ public fun are_locked_notarization_invariants_ok(immutable_metadata: &ImmutableM
459459
/// If `immutable_metadata.locking` exists, all locks except `transfer_lock`
460460
/// must be `TimeLock::None`
461461
/// and the `transfer_lock` must not be `TimeLock::None`.
462-
public fun are_dynamic_notarization_invariants_ok(immutable_metadata: &ImmutableMetadata): bool {
462+
public(package) fun are_dynamic_notarization_invariants_ok(immutable_metadata: &ImmutableMetadata): bool {
463463
if (immutable_metadata.locking.is_some()) {
464464
let lock_metadata = option::borrow(&immutable_metadata.locking);
465465

notarization-rs/Cargo.toml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,46 @@ description = "A data notarization toolkit for the IOTA Ledger."
1515
anyhow.workspace = true
1616
cfg-if.workspace = true
1717
fastcrypto.workspace = true
18-
identity_iota_core.workspace = true
1918
phf.workspace = true
19+
product_common = { workspace = true, features = ["transaction"] }
2020
serde.workspace = true
2121
serde_json.workspace = true
2222
thiserror.workspace = true
2323
strum.workspace = true
24+
async-trait.workspace = true
25+
bcs.workspace = true
2426

2527
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
26-
identity_iota_interaction.workspace = true
28+
iota_interaction = { git = "https://github.com/iotaledger/product-core.git", branch = "feat/add-dev-inspect-tx", package = "iota_interaction", default-features = false }
29+
iota_interaction_rust = { git = "https://github.com/iotaledger/product-core.git", branch = "feat/add-dev-inspect-tx", package = "iota_interaction_rust", default-features = false }
2730
iota-config = { git = "https://github.com/iotaledger/iota.git", package = "iota-config", tag = "v0.11.6-rc" }
2831
iota-sdk = { git = "https://github.com/iotaledger/iota.git", package = "iota-sdk", tag = "v0.11.6-rc" }
2932
move-core-types = { git = "https://github.com/iotaledger/iota.git", package = "move-core-types", tag = "v0.11.6-rc" }
30-
secret-storage = { git = "https://github.com/iotaledger/secret-storage.git", tag = "v0.3.0" }
33+
secret-storage = { git = "https://github.com/iotaledger/secret-storage.git", tag = "v0.3.0", default-features = false }
3134
shared-crypto = { git = "https://github.com/iotaledger/iota.git", package = "shared-crypto", tag = "v0.11.6-rc" }
32-
tokio = { version = "1.29.0", default-features = false, features = ["macros", "sync", "rt", "process"] }
35+
tokio = { version = "1.29.0", default-features = false, features = [
36+
"macros",
37+
"sync",
38+
"rt",
39+
"process",
40+
] }
3341

3442
[target.'cfg(target_arch = "wasm32")'.dependencies]
35-
identity_iota_interaction = { git = "https://github.com/iotaledger/identity.rs.git", branch = "feat/identity-rebased-alpha-public-interaction-rust", package = "identity_iota_interaction", default-features = false }
36-
iota_interaction_ts = { git = "https://github.com/iotaledger/identity.rs.git", branch = "feat/identity-rebased-alpha-public-interaction-rust", package = "iota_interaction_ts" }
37-
secret-storage = { git = "https://github.com/iotaledger/secret-storage.git", default-features = false, tag = "v0.3.0" }
43+
iota_interaction = { git = "https://github.com/iotaledger/product-core.git", branch = "feat/add-dev-inspect-tx", package = "iota_interaction", default-features = false }
44+
iota_interaction_ts = { git = "https://github.com/iotaledger/product-core.git", branch = "feat/add-dev-inspect-tx", package = "iota_interaction_ts" }
3845

39-
[target.'cfg(target_arch = "wasm32")'.dependencies.identity_iota_core]
40-
git = "https://github.com/iotaledger/identity.rs.git"
41-
branch = "feat/identity-rebased-alpha-public-interaction-rust"
42-
package = "identity_iota_core"
43-
default-features = false
44-
features = ["iota-client", "revocation-bitmap"]
4546

4647
[dev-dependencies]
4748
async-trait.workspace = true
4849
identity_jose = { git = "https://github.com/iotaledger/identity.rs.git", branch = "feat/identity-rebased-alpha-public-interaction-rust", package = "identity_jose" }
49-
identity_storage = { git = "https://github.com/iotaledger/identity.rs.git", branch = "feat/identity-rebased-alpha-public-interaction-rust", package = "identity_storage", features = ["send-sync-storage", "storage-signer"] }
50-
identity_iota_interaction = { git = "https://github.com/iotaledger/identity.rs.git", branch = "feat/identity-rebased-alpha-public-interaction-rust", package = "identity_iota_interaction", features = ["keytool-signer"] }
50+
identity_storage = { git = "https://github.com/iotaledger/identity.rs.git", branch = "feat/identity-rebased-alpha-public-interaction-rust", package = "identity_storage", features = [
51+
"send-sync-storage",
52+
"storage-signer",
53+
] }
54+
iota_interaction = { git = "https://github.com/iotaledger/product-core.git", branch = "feat/add-dev-inspect-tx", package = "iota_interaction" }
5155
lazy_static = "1.5.0"
5256

57+
[features]
58+
send-sync = ["send-sync-storage"]
59+
# Enables `Send` + `Sync` bounds for the storage traits.
60+
send-sync-storage = ["secret-storage/send-sync-storage"]
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
use std::ops::Deref;
2+
3+
use iota_interaction::types::base_types::{IotaAddress, ObjectID};
4+
use iota_interaction::types::crypto::PublicKey;
5+
use iota_interaction::{IotaKeySignature, OptionalSync};
6+
use iota_interaction_rust::IotaClientAdapter;
7+
use product_common::core_client::{CoreClient, CoreClientReadOnly};
8+
use product_common::network_name::NetworkName;
9+
use secret_storage::Signer;
10+
11+
use super::read_only::NotarizationClientReadOnly;
12+
use crate::error::Error;
13+
14+
/// A client for interacting with the IOTA network.
15+
#[derive(Clone)]
16+
pub struct NotarizationClient<S> {
17+
/// [`NotarizationClientReadOnly`] instance, used for read-only operations.
18+
read_client: NotarizationClientReadOnly,
19+
/// The public key of the client.
20+
public_key: PublicKey,
21+
/// The signer of the client.
22+
signer: S,
23+
}
24+
25+
impl<S> Deref for NotarizationClient<S> {
26+
type Target = NotarizationClientReadOnly;
27+
fn deref(&self) -> &Self::Target {
28+
&self.read_client
29+
}
30+
}
31+
32+
impl<S> NotarizationClient<S>
33+
where
34+
S: Signer<IotaKeySignature>,
35+
{
36+
/// Create a new [`NotarizationClient`].
37+
pub async fn new(client: NotarizationClientReadOnly, signer: S) -> Result<Self, Error> {
38+
let public_key = signer
39+
.public_key()
40+
.await
41+
.map_err(|e| Error::InvalidKey(e.to_string()))?;
42+
43+
Ok(Self {
44+
public_key,
45+
read_client: client,
46+
signer,
47+
})
48+
}
49+
}
50+
51+
impl<S> CoreClientReadOnly for NotarizationClient<S>
52+
where
53+
S: OptionalSync,
54+
{
55+
fn client_adapter(&self) -> &IotaClientAdapter {
56+
&self.read_client
57+
}
58+
59+
fn package_id(&self) -> ObjectID {
60+
self.read_client.package_id()
61+
}
62+
63+
fn network_name(&self) -> &NetworkName {
64+
self.read_client.network()
65+
}
66+
}
67+
68+
impl<S> CoreClient<S> for NotarizationClient<S>
69+
where
70+
S: Signer<IotaKeySignature> + OptionalSync,
71+
{
72+
fn sender_address(&self) -> IotaAddress {
73+
IotaAddress::from(&self.public_key)
74+
}
75+
76+
fn signer(&self) -> &S {
77+
&self.signer
78+
}
79+
80+
fn sender_public_key(&self) -> &PublicKey {
81+
&self.public_key
82+
}
83+
}

notarization-rs/src/client/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod full_client;
2+
pub mod read_only;

0 commit comments

Comments
 (0)