Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM implementation of adapters' traits on WASM types #1506

Merged
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
dbee3d7
Move identity_wasm package into new folder bindings/wasm/identity_wasm
chrisgitiota Dec 4, 2024
5d77eaa
Reorganize tsconfig and typedoc files
chrisgitiota Dec 4, 2024
cdf0129
Extend build scripts to handle multiple artifacts and add new binding…
chrisgitiota Dec 4, 2024
e7cc8eb
Merge branch 'feat/identity-rebased-alpha' into feat/wasm32-develop-a…
chrisgitiota Dec 4, 2024
9a9415a
Update identity_wasm/package.json to use shared build scripts
chrisgitiota Dec 4, 2024
2c21ec7
Initial version of the identity_iota_interaction crate
chrisgitiota Dec 5, 2024
4f9d0d6
Provide identity_iota_interaction crate types as `use identity_iota::…
chrisgitiota Dec 5, 2024
189481e
Initial version of iota_interactions_ts
chrisgitiota Dec 9, 2024
6445ddb
Prepare identity_iota_core/rebased for iota_interaction usage
chrisgitiota Dec 9, 2024
bdc03d3
Merge branch 'feat/identity-rebased-alpha' into feat/wasm32-develop-a…
chrisgitiota Dec 9, 2024
c393acb
Minor README fixes
chrisgitiota Dec 9, 2024
fe8376a
Updated identity_interaction_rust MoveCalls to the latest identity_io…
chrisgitiota Dec 9, 2024
f31eda4
First compilable but not successfully testable version of identity_io…
chrisgitiota Dec 12, 2024
0dfb752
add stubs for `ProgrammableTransaction` type chain
wulfraem Dec 13, 2024
7fea4db
re-add changes from `feat/add-iota_client_ts_sdk-impls` as closely as…
wulfraem Dec 13, 2024
e1c9814
ts move calls
UMR1352 Dec 27, 2024
d8627e5
Merge branch 'feat/identity-rebased-alpha' into feat/wasm32-develop-a…
chrisgitiota Jan 6, 2025
f348ff7
Use cloned native IotaTransactionBlockResponse instead of a BCS deser…
chrisgitiota Jan 7, 2025
c1e4cbf
Fix build warnings and fix MoveType implementation for IotaVerifiable…
chrisgitiota Jan 7, 2025
f46876f
Fix & allow clippy errors
chrisgitiota Jan 7, 2025
f4e7a99
Fix even more clippy errors
chrisgitiota Jan 7, 2025
57968c2
Elide superfluous explicit lifetimes
chrisgitiota Jan 7, 2025
4ed173c
Use rustfmt ignore to exclude identity_iota_interaction/src/sdk_types…
chrisgitiota Jan 8, 2025
1cc7e25
Fix rustfmt issues for identity_iota_core/src/iota_interaction_rust a…
chrisgitiota Jan 8, 2025
59f02b9
Fix rustfmt issues for bindings/wasm/iota_interaction_ts and identity…
chrisgitiota Jan 8, 2025
db8fe86
Update all paths for bindings/wasm/identity_wasm in al GH workflows f…
chrisgitiota Jan 8, 2025
425739a
Rollback removing bindings/wasm/iota_interaction_ts from the workspac…
chrisgitiota Jan 8, 2025
a22dd33
Fix format issue for step "wasm fmt check identity_wasm"
chrisgitiota Jan 8, 2025
59be0ac
Fix issue "identity_iota_core not compilable using --no-default-featu…
chrisgitiota Jan 9, 2025
e43ea51
Remove iota_interaction_ts related steps from github workflows as thi…
chrisgitiota Jan 9, 2025
ffff17f
Fix several dprint issues
chrisgitiota Jan 9, 2025
fb0857f
scratch
UMR1352 Jan 9, 2025
f60f348
Merge remote-tracking branch 'origin/feat/wasm32-develop-alpha' into …
UMR1352 Jan 9, 2025
5dc7ff3
Add iota_interaction_ts build products as 'excludes' to the dprint co…
chrisgitiota Jan 9, 2025
806243e
Fixing paths to the bindings/wasm/identity_wasm crate in several READ…
chrisgitiota Jan 9, 2025
fa94623
fix dprint issue missing empty line at end of file
chrisgitiota Jan 9, 2025
f8e2435
Update licence_template file to allow optional "Modifications", "(c)"…
chrisgitiota Jan 9, 2025
8d993b3
Add missing copyright license comments
chrisgitiota Jan 9, 2025
3c75dc2
Narrowed the dockerignore filter down from "bindings/wasm" to "bindin…
chrisgitiota Jan 9, 2025
e75e6a5
implement TsMoveCalls
UMR1352 Jan 14, 2025
db5ec09
bindings/wasm projects identity_wasm and iota_interaction_ts can be b…
chrisgitiota Jan 14, 2025
59c335a
dprint refomated
chrisgitiota Jan 14, 2025
e413789
assets move calls
UMR1352 Jan 14, 2025
21978e2
Merge branch 'feat/identity-rebased-alpha' into feat/wasm32-develop-a…
chrisgitiota Jan 14, 2025
f1bd28b
avoid unsafe
UMR1352 Jan 15, 2025
8c5a879
clippy
UMR1352 Jan 16, 2025
a1c72de
Removed IntentFn adapters and fixed several issues reulting from last…
chrisgitiota Jan 16, 2025
09e5094
Merge branch 'feat/wasm32-develop-alpha' into feat/ts-move-calls
UMR1352 Jan 16, 2025
bf0e64b
implement missing bindings
UMR1352 Jan 17, 2025
e76dba5
make iota_interaction_ts a workspace member again
UMR1352 Jan 17, 2025
e74ed7a
Merge remote-tracking branch 'origin/feat/ts-move-calls' into feat/pl…
UMR1352 Jan 21, 2025
53f964e
TransactionBuilder adaptor
UMR1352 Jan 21, 2025
629e5fc
TransactionBlockResponseAdapter
UMR1352 Jan 22, 2025
a2a70fd
Merge remote-tracking branch 'origin/feat/identity-rebased-alpha' int…
UMR1352 Jan 24, 2025
b17ef0b
fix merge issues
UMR1352 Jan 24, 2025
1b032ce
fmt
UMR1352 Jan 24, 2025
245b8b9
Update package.json
chrisgitiota Jan 24, 2025
8c244e3
fix formatting and re-add TS ProgrammableTransaction
UMR1352 Jan 24, 2025
397e382
identity_wasm fmt
UMR1352 Jan 24, 2025
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
10 changes: 6 additions & 4 deletions bindings/wasm/build/node.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const path = require("path");
const fs = require("fs");
const {lintAll} = require("./lints");
const { lintAll } = require("./lints");
const generatePackage = require("./utils/generatePackage");

const artifact = process.argv[2];

const RELEASE_FOLDER = path.join(__dirname, "..", artifact, "node");
const entryFilePathNode = path.join(RELEASE_FOLDER, `${artifact}.js`);
const entryFileNode = fs.readFileSync(entryFilePathNode).toString();
console.log(`[build/node.js] Processing entryFile '${entryFilePathNode}' for artifact '${artifact}'`,)
console.log(`[build/node.js] Processing entryFile '${entryFilePathNode}' for artifact '${artifact}'`);

lintAll(entryFileNode);

Expand All @@ -29,7 +29,9 @@ fs.writeFileSync(
entryFilePathNode,
changedFileNode,
);
console.log(`[build/node.js] Added node-fetch polyfill to entryFile '${entryFilePathNode}'. Starting generatePackage().`,)
console.log(
`[build/node.js] Added node-fetch polyfill to entryFile '${entryFilePathNode}'. Starting generatePackage().`,
);

// Generate `package.json`.
const newPackage = generatePackage({
Expand All @@ -38,4 +40,4 @@ const newPackage = generatePackage({
artifact,
});
fs.writeFileSync(path.join(RELEASE_FOLDER, "package.json"), JSON.stringify(newPackage, null, 2));
console.log(`[build/node.js] Finished processing entryFile '${entryFilePathNode}' for artifact '${artifact}'`,)
console.log(`[build/node.js] Finished processing entryFile '${entryFilePathNode}' for artifact '${artifact}'`);
10 changes: 5 additions & 5 deletions bindings/wasm/build/web.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const path = require("path");
const fs = require("fs");
const fse = require("fs-extra");
const {lintAll} = require("./lints");
const { lintAll } = require("./lints");
const generatePackage = require("./utils/generatePackage");

const artifact = process.argv[2];

const RELEASE_FOLDER = path.join(__dirname, "..", artifact, "web");
const entryFilePath = path.join(RELEASE_FOLDER, `${artifact}.js`);
const entryFile = fs.readFileSync(entryFilePath).toString();
console.log(`[build/web.js] Processing entryFile '${entryFilePath}' for artifact '${artifact}'`,)
console.log(`[build/web.js] Processing entryFile '${entryFilePath}' for artifact '${artifact}'`);

lintAll(entryFile);

Expand All @@ -29,7 +29,7 @@ fs.writeFileSync(
entryFilePath,
changedFile,
);
console.log(`[build/web.js] Commented out webpack workaround for '${entryFilePath}'.`,)
console.log(`[build/web.js] Commented out webpack workaround for '${entryFilePath}'.`);

const entryFilePathTs = path.join(RELEASE_FOLDER, `${artifact}.d.ts`);
const entryFileTs = fs.readFileSync(entryFilePathTs).toString();
Expand All @@ -47,7 +47,7 @@ fs.writeFileSync(
entryFilePathTs,
changedFileTs,
);
console.log(`[build/web.js] Created init function for '${entryFilePathTs}'. Starting generatePackage().`,)
console.log(`[build/web.js] Created init function for '${entryFilePathTs}'. Starting generatePackage().`);

// Generate `package.json`.
const newPackage = generatePackage({
Expand All @@ -56,4 +56,4 @@ const newPackage = generatePackage({
artifact,
});
fs.writeFileSync(path.join(RELEASE_FOLDER, "package.json"), JSON.stringify(newPackage, null, 2));
console.log(`[build/web.js] Finished processing entryFile '${entryFilePathNode}' for artifact '${artifact}'`,)
console.log(`[build/web.js] Finished processing entryFile '${entryFilePathNode}' for artifact '${artifact}'`);
2 changes: 1 addition & 1 deletion bindings/wasm/identity_wasm/src/sd_jwt/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl WasmSdObjectEncoder {
/// "claim2": ["val_1", "val_2"]
/// }
/// ```
///
///
/// Path "/id" conceals `"id": "did:value"`
/// Path "/claim1/abc" conceals `"abc": true`
/// Path "/claim2/0" conceals `val_1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl WasmMethodData {
Cow::Borrowed("PrivateKeyMaterialExposed"),
Cow::Borrowed("jwk with private key components is not permitted"),
))
.wasm_result();
.wasm_result();
};

Ok(Self(MethodData::PublicKeyJwk(key.0.clone())))
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/iota_interaction_ts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ js-sys = { version = "0.3.61" }
secret-storage = { git = "https://github.com/iotaledger/secret-storage.git", default-features = false, tag = "v0.1.0" }
serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.6.5"
serde_json = { version = "1.0", default-features = false }
serde_json.workspace = true
thiserror.workspace = true
tsify = "0.4.5"
wasm-bindgen = { version = "=0.2.93", features = ["serde-serialize"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class IotaTransactionBlockResponseAdapter {
? this.response.effects.created
: null;
}

get_response(): IotaTransactionBlockResponse {
return this.response;
}
}

async function signTransactionData(
Expand Down
1 change: 0 additions & 1 deletion bindings/wasm/iota_interaction_ts/package-lock.json

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

40 changes: 26 additions & 14 deletions bindings/wasm/iota_interaction_ts/src/bindings/wasm_types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2020-2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::net::AddrParseError;

use identity_iota_interaction::rpc_types::IotaExecutionStatus;
use identity_iota_interaction::rpc_types::OwnedObjectRef;
use identity_iota_interaction::types::base_types::IotaAddress;
use identity_iota_interaction::types::base_types::ObjectID;
Expand All @@ -9,8 +12,10 @@ use identity_iota_interaction::types::base_types::SequenceNumber;
use identity_iota_interaction::types::execution_status::CommandArgumentError;
use identity_iota_interaction::types::execution_status::ExecutionStatus;
use identity_iota_interaction::types::object::Owner;
use identity_iota_interaction::IotaTransactionBlockResponseT;
use identity_iota_interaction::ProgrammableTransactionBcs;
use js_sys::Promise;
use js_sys::Uint8Array;
use serde::Deserialize;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsCast;
Expand All @@ -21,6 +26,7 @@ use crate::bindings::WasmIotaClient;
use crate::common::into_sdk_type;
use crate::console_log;
use crate::error::TsSdkError;
use crate::error::WasmError;

// TODO: fix/add
// not available anymore
Expand Down Expand Up @@ -58,9 +64,6 @@ const TS_SDK_TYPES: &'static str = r#"
executeTransaction,
IotaTransactionBlockResponseAdapter,
} from "./iota_client_helpers"

// TODO: decide if we use this or replace it with an adapter written in TypeScript type if needed
type ProgrammableTransaction = ReturnType<typeof bcs.ProgrammableTransaction.parse>;
"#;

#[wasm_bindgen(module = "@iota/iota.js/client")]
Expand All @@ -71,6 +74,12 @@ extern "C" {
#[wasm_bindgen(typescript_type = "Transaction")]
pub type WasmTransactionBuilder;

#[wasm_bindgen(js_name = "from", static_method_of = WasmTransactionBuilder, catch)]
pub fn from_bcs_bytes(bytes: &[u8]) -> Result<WasmTransactionBuilder, JsValue>;

#[wasm_bindgen(method, structural, catch)]
pub async fn build(this: &WasmTransactionBuilder) -> Result<Uint8Array, JsValue>;

#[wasm_bindgen(typescript_type = "TransactionArgument")]
pub type WasmTransactionArgument;

Expand Down Expand Up @@ -238,6 +247,9 @@ extern "C" {
#[wasm_bindgen(method)]
fn effects_created_inner(this: &IotaTransactionBlockResponseAdapter) -> Option<Vec<WasmOwnedObjectRef>>;

#[wasm_bindgen(method, js_name = "get_response")]
fn response(this: &IotaTransactionBlockResponseAdapter) -> WasmIotaTransactionBlockResponse;

#[wasm_bindgen(js_name = executeTransaction)]
fn execute_transaction_inner(
iotaClient: &WasmIotaClient, // --> TypeScript: IotaClient
Expand All @@ -249,12 +261,6 @@ extern "C" {
) -> PromiseIotaTransactionBlockResponseAdapter;
}

#[wasm_bindgen] // no module here, as imported via custom section above
extern "C" {
#[wasm_bindgen(typescript_type = "ProgrammableTransaction")]
pub type WasmProgrammableTransaction;
}

#[derive(Deserialize)]
struct WasmExecutionStatusAdapter {
status: ExecutionStatus,
Expand Down Expand Up @@ -306,9 +312,15 @@ pub async fn execute_transaction(
}

chrisgitiota marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Deserialize)]
// TODO: add manual deserialization later on (must be deserializable, but WasmPT is not)
// pub struct ProgrammableTransaction(WasmProgrammableTransaction);
pub struct ProgrammableTransaction(());
#[serde(try_from = "Vec<u8>")]
pub struct ProgrammableTransaction(WasmTransactionBuilder);

// TODO: fill in required functions and data handling here
impl ProgrammableTransaction {}
impl TryFrom<Vec<u8>> for ProgrammableTransaction {
type Error = TsSdkError;
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
WasmTransactionBuilder::from_bcs_bytes(&value)
.map(Self)
.map_err(WasmError::from)
.map_err(TsSdkError::from)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use identity_iota_interaction::rpc_types::OwnedObjectRef;
use identity_iota_interaction::types::base_types::IotaAddress;
use identity_iota_interaction::types::base_types::ObjectID;
use identity_iota_interaction::types::base_types::ObjectRef;
use identity_iota_interaction::types::base_types::SequenceNumber;
use identity_iota_interaction::types::transaction::Argument;
use identity_iota_interaction::types::TypeTag;
use identity_iota_interaction::BorrowIntentFnInternalT;
use identity_iota_interaction::ControllerIntentFnInternalT;
Expand Down
3 changes: 1 addition & 2 deletions bindings/wasm/iota_interaction_ts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ cfg_if::cfg_if! {

#[allow(unused_imports)] pub use error::TsSdkError as AdapterError;
#[allow(unused_imports)] pub use bindings::IotaTransactionBlockResponseAdapter as AdapterNativeResponse;
#[allow(unused_imports)] pub use bindings::ProgrammableTransaction;

#[allow(unused_imports)] pub use transaction_builder::NativeTsTransactionBuilderBindingWrapper;

#[allow(unused_imports)] pub use bindings::ProgrammableTransaction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use identity_iota_interaction::ident_str;
use identity_iota_interaction::rpc_types::OwnedObjectRef;
use identity_iota_interaction::types::base_types::ObjectID;
use identity_iota_interaction::types::base_types::ObjectRef;
use identity_iota_interaction::types::transaction::ObjectArg;
use identity_iota_interaction::types::IOTA_FRAMEWORK_PACKAGE_ID;
use identity_iota_interaction::MigrationMoveCalls;
use identity_iota_interaction::ProgrammableTransactionBcs;
use js_sys::Uint8Array;
Expand Down
10 changes: 7 additions & 3 deletions bindings/wasm/iota_interaction_ts/src/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::ops::DerefMut;

use crate::bindings::WasmTransactionBuilder;
use crate::error::TsSdkError;
use crate::error::WasmError;
use identity_iota_interaction::ProgrammableTransactionBcs;
use identity_iota_interaction::TransactionBuilderT;

Expand All @@ -26,15 +27,18 @@ impl TransactionBuilderT for TransactionBuilderTsSdk {
type NativeTxBuilder = NativeTsTransactionBuilderBindingWrapper;

fn finish(self) -> Result<ProgrammableTransactionBcs, TsSdkError> {
unimplemented!();
futures::executor::block_on(self.builder.build())
.map(|js_arr| js_arr.to_vec())
.map_err(WasmError::from)
.map_err(Self::Error::from)
}

fn as_native_tx_builder(&mut self) -> &mut Self::NativeTxBuilder {
todo!()
&mut self.builder
}

fn into_native_tx_builder(self) -> Self::NativeTxBuilder {
todo!()
self.builder
}
}

Expand Down
Loading