├── sdk ├── README.md ├── src │ ├── types │ │ ├── fuzz │ │ │ ├── .gitignore │ │ │ └── fuzz_targets │ │ │ │ ├── fuzz_block.rs │ │ │ │ ├── fuzz_input.rs │ │ │ │ ├── fuzz_feature.rs │ │ │ │ ├── fuzz_output.rs │ │ │ │ ├── fuzz_unlock.rs │ │ │ │ ├── fuzz_address.rs │ │ │ │ ├── fuzz_payload.rs │ │ │ │ ├── fuzz_signature.rs │ │ │ │ └── fuzz_unlock_condition.rs │ │ ├── api │ │ │ ├── core │ │ │ │ ├── mod.rs │ │ │ │ └── error.rs │ │ │ ├── plugins │ │ │ │ ├── mod.rs │ │ │ │ ├── participation │ │ │ │ │ ├── mod.rs │ │ │ │ │ └── error.rs │ │ │ │ └── indexer.rs │ │ │ └── mod.rs │ │ └── block │ │ │ ├── rand │ │ │ ├── bool.rs │ │ │ ├── option.rs │ │ │ ├── transaction.rs │ │ │ ├── parents.rs │ │ │ ├── bytes.rs │ │ │ ├── number.rs │ │ │ ├── milestone.rs │ │ │ ├── string.rs │ │ │ ├── milestone_option.rs │ │ │ ├── output │ │ │ │ └── metadata.rs │ │ │ ├── input.rs │ │ │ ├── address.rs │ │ │ ├── signature.rs │ │ │ └── block.rs │ │ │ ├── block_id.rs │ │ │ ├── payload │ │ │ ├── milestone │ │ │ │ └── milestone_id.rs │ │ │ └── transaction │ │ │ │ └── transaction_id.rs │ │ │ ├── output │ │ │ ├── token_id.rs │ │ │ ├── nft_id.rs │ │ │ └── alias_id.rs │ │ │ ├── helper.rs │ │ │ └── convert.rs │ ├── wallet │ │ ├── account │ │ │ ├── operations │ │ │ │ ├── helpers │ │ │ │ │ └── mod.rs │ │ │ │ ├── transaction │ │ │ │ │ └── high_level │ │ │ │ │ │ ├── minting │ │ │ │ │ │ └── mod.rs │ │ │ │ │ │ └── mod.rs │ │ │ │ ├── syncing │ │ │ │ │ └── addresses │ │ │ │ │ │ └── output_ids │ │ │ │ │ │ └── nft.rs │ │ │ │ └── mod.rs │ │ │ ├── types │ │ │ │ └── participation.rs │ │ │ └── constants.rs │ │ ├── task.rs │ │ ├── core │ │ │ └── operations │ │ │ │ ├── mod.rs │ │ │ │ └── ledger_nano.rs │ │ └── storage │ │ │ ├── kind.rs │ │ │ └── adapter │ │ │ └── memory.rs │ ├── client │ │ ├── api │ │ │ ├── mod.rs │ │ │ └── block_builder │ │ │ │ └── input_selection │ │ │ │ ├── mod.rs │ │ │ │ └── core │ │ │ │ └── requirement │ │ │ │ └── issuer.rs │ │ ├── storage │ │ │ └── stronghold.rs │ │ ├── secret │ │ │ └── stronghold.rs │ │ └── node_api │ │ │ ├── mod.rs │ │ │ ├── mqtt │ │ │ └── error.rs │ │ │ └── error.rs │ ├── utils │ │ └── mod.rs │ └── pow │ │ └── mod.rs ├── tests │ ├── wallet │ │ ├── fixtures │ │ │ ├── chrysalis-db │ │ │ │ ├── db │ │ │ │ │ ├── CURRENT │ │ │ │ │ ├── 000051.sst │ │ │ │ │ ├── 000054.sst │ │ │ │ │ └── MANIFEST-000056 │ │ │ │ └── wallet.stronghold │ │ │ ├── check_existing_1_db_test │ │ │ │ ├── CURRENT │ │ │ │ ├── IDENTITY │ │ │ │ ├── 000071.sst │ │ │ │ ├── 000074.sst │ │ │ │ ├── 000079.sst │ │ │ │ └── MANIFEST-000081 │ │ │ ├── check_existing_2_db_test │ │ │ │ ├── CURRENT │ │ │ │ ├── IDENTITY │ │ │ │ ├── 000086.sst │ │ │ │ ├── 000089.sst │ │ │ │ ├── MANIFEST-000155 │ │ │ │ └── walletstronghold │ │ │ ├── check_existing_3_db_test │ │ │ │ ├── CURRENT │ │ │ │ ├── IDENTITY │ │ │ │ ├── 000120.sst │ │ │ │ ├── 000123.sst │ │ │ │ ├── 000128.sst │ │ │ │ ├── MANIFEST-000130 │ │ │ │ └── walletstronghold │ │ │ ├── check_existing_4_db_test │ │ │ │ ├── CURRENT │ │ │ │ ├── IDENTITY │ │ │ │ ├── 000008.sst │ │ │ │ ├── 000013.sst │ │ │ │ ├── 000018.sst │ │ │ │ ├── MANIFEST-000020 │ │ │ │ └── walletstronghold │ │ │ ├── check_existing_5_db_test │ │ │ │ ├── CURRENT │ │ │ │ ├── IDENTITY │ │ │ │ ├── 000008.sst │ │ │ │ ├── MANIFEST-000130 │ │ │ │ └── walletstronghold │ │ │ ├── check_existing_db_test │ │ │ │ ├── CURRENT │ │ │ │ ├── IDENTITY │ │ │ │ ├── 000097.sst │ │ │ │ ├── 000100.sst │ │ │ │ ├── 000105.sst │ │ │ │ ├── MANIFEST-000107 │ │ │ │ └── strongholdfile │ │ │ ├── chrysalis-db-ledger │ │ │ │ └── db │ │ │ │ │ ├── CURRENT │ │ │ │ │ ├── IDENTITY │ │ │ │ │ ├── 000008.sst │ │ │ │ │ └── MANIFEST-000010 │ │ │ ├── chrysalis-db-encrypted │ │ │ │ ├── db │ │ │ │ │ ├── CURRENT │ │ │ │ │ ├── IDENTITY │ │ │ │ │ ├── 000097.sst │ │ │ │ │ ├── 000100.sst │ │ │ │ │ ├── 000105.sst │ │ │ │ │ ├── 000110.sst │ │ │ │ │ └── MANIFEST-000112 │ │ │ │ └── wallet.stronghold │ │ │ ├── v2.stronghold │ │ │ ├── already_v3.stronghold │ │ │ ├── v2_with_backup.stronghold │ │ │ ├── no_secret_manager_data.stronghold │ │ │ └── chrysalis-backup-work-factor-0.stronghold │ │ ├── common │ │ │ └── constants.rs │ │ ├── mod.rs │ │ └── error.rs │ ├── utils │ │ └── mod.rs │ ├── client │ │ ├── mqtt │ │ │ └── mod.rs │ │ ├── common │ │ │ └── constants.rs │ │ ├── secret_manager │ │ │ ├── mod.rs │ │ │ └── mnemonic.rs │ │ ├── input_selection │ │ │ └── mod.rs │ │ └── mnemonic.rs │ ├── types │ │ ├── api │ │ │ └── mod.rs │ │ ├── input │ │ │ └── mod.rs │ │ ├── mod.rs │ │ └── foundry_id.rs │ ├── pow │ │ └── mod.rs │ └── mod.rs └── examples │ ├── how_tos │ ├── accounts_and_addresses │ │ ├── create_mnemonic.rs │ │ ├── list_addresses.rs │ │ └── list_accounts.rs │ └── client │ │ ├── get_info.rs │ │ └── get_health.rs │ └── client │ ├── getting_started.rs │ ├── tagged_data_to_utf8.rs │ └── node_api_core │ ├── 03_get_tips.rs │ ├── 12_get_receipts.rs │ ├── 14_get_treasury.rs │ └── 01_get_routes.rs ├── bindings ├── python │ ├── iota_sdk │ │ ├── py.typed │ │ ├── external.py │ │ ├── types │ │ │ ├── network_info.py │ │ │ ├── native_token.py │ │ │ ├── utxo_changes.py │ │ │ ├── filter_options.py │ │ │ ├── consolidation_params.py │ │ │ ├── event.py │ │ │ ├── signature.py │ │ │ └── input.py │ │ └── prefix_hex.py │ ├── .gitignore │ ├── MANIFEST.in │ ├── requirements-dev.txt │ ├── examples │ │ ├── how_tos │ │ │ ├── accounts_and_addresses │ │ │ │ ├── create_mnemonic.py │ │ │ │ ├── list_accounts.py │ │ │ │ ├── list_addresses.py │ │ │ │ ├── create_address.py │ │ │ │ ├── check_balance.py │ │ │ │ ├── list_outputs.py │ │ │ │ ├── list_transactions.py │ │ │ │ └── create_account.py │ │ │ ├── client │ │ │ │ ├── get_health.py │ │ │ │ ├── get_info.py │ │ │ │ └── get_outputs.py │ │ │ ├── simple_transaction │ │ │ │ ├── request_funds.py │ │ │ │ └── simple_transaction.py │ │ │ ├── alias │ │ │ │ ├── create.py │ │ │ │ └── destroy.py │ │ │ ├── nfts │ │ │ │ ├── burn_nft.py │ │ │ │ ├── mint_nft.py │ │ │ │ └── send_nft.py │ │ │ ├── sign_and_verify_ed25519 │ │ │ │ └── verify_ed25519_signature.py │ │ │ └── advanced_transactions │ │ │ │ ├── send_micro_transaction.py │ │ │ │ └── claim_transaction.py │ │ ├── client │ │ │ ├── getting_started.py │ │ │ ├── 06_simple_block.py │ │ │ ├── 04_get_output.py │ │ │ ├── get_raw_block.py │ │ │ ├── post_raw_block.py │ │ │ ├── logger.py │ │ │ ├── 07_get_block_data.py │ │ │ ├── 09_transaction.py │ │ │ ├── 08_data_block.py │ │ │ ├── custom_plugin.py │ │ │ ├── build_foundry.py │ │ │ └── mqtt.py │ │ ├── wallet │ │ │ ├── get_client.py │ │ │ ├── create_alias.py │ │ │ ├── restore_backup.py │ │ │ ├── 12-prepare_output.py │ │ │ ├── backup.py │ │ │ └── 13-check-unlock-conditions.py │ │ ├── exchange │ │ │ ├── 0_generate_mnemonic.py │ │ │ ├── 2_generate_address.py │ │ │ └── 3_check_balance.py │ │ └── secret_manager │ │ │ ├── stronghold.py │ │ │ ├── generate_addresses.py │ │ │ └── ledger_nano.py │ ├── pyproject.toml │ ├── .pylintrc │ ├── pydoc-markdown.yml │ └── pydoc_markdown_iota.py ├── nodejs │ ├── tests │ │ ├── webpack │ │ │ ├── index.js │ │ │ └── webpack.config.js │ │ └── fixtures │ │ │ └── offlineSigningAddresses.ts │ ├── .eslintignore │ ├── .npmignore │ ├── .cargo │ │ └── config.toml │ ├── examples │ │ ├── client │ │ │ ├── offline_signing │ │ │ │ └── example-address.json │ │ │ ├── getting-started.ts │ │ │ ├── 12-get-raw-block.ts │ │ │ └── 04-get-output.ts │ │ ├── tsconfig.json │ │ ├── how_tos │ │ │ ├── accounts_and_addresses │ │ │ │ ├── create-mnemonic.ts │ │ │ │ └── list-accounts.ts │ │ │ └── client │ │ │ │ ├── get-info.ts │ │ │ │ └── get-health.ts │ │ ├── exchange │ │ │ └── 0-generate-mnemonic.ts │ │ └── package.json │ ├── lib │ │ ├── types │ │ │ ├── block │ │ │ │ ├── input │ │ │ │ │ └── index.ts │ │ │ │ ├── payload │ │ │ │ │ ├── tagged │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ └── tagged.ts │ │ │ │ │ ├── treasury │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ └── treasury.ts │ │ │ │ │ ├── milestone │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── transaction │ │ │ │ │ │ └── index.ts │ │ │ │ │ └── payload.ts │ │ │ │ ├── output │ │ │ │ │ └── index.ts │ │ │ │ ├── index.ts │ │ │ │ ├── id.ts │ │ │ │ └── block.ts │ │ │ ├── models │ │ │ │ ├── api │ │ │ │ │ ├── plugins │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ └── indexer │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ └── output-response.ts │ │ │ │ │ ├── block-id-response.ts │ │ │ │ │ ├── tips-response.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── response.ts │ │ │ │ │ ├── output-response.ts │ │ │ │ │ ├── milestone-utxo-changes-response.ts │ │ │ │ │ └── receipts-response.ts │ │ │ │ ├── ledger-inclusion-state.ts │ │ │ │ ├── info │ │ │ │ │ ├── routes-response.ts │ │ │ │ │ ├── node-info-protocol-params-milestone-opt.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── node-info-metrics.ts │ │ │ │ │ ├── node-info-milestone.ts │ │ │ │ │ ├── node-info-status.ts │ │ │ │ │ ├── node-info-base-token.ts │ │ │ │ │ └── node-info-protocol.ts │ │ │ │ ├── index.ts │ │ │ │ ├── rent.ts │ │ │ │ ├── native-token.ts │ │ │ │ ├── gossip-heartbeat.ts │ │ │ │ ├── migrated-funds.ts │ │ │ │ ├── milestone_options │ │ │ │ │ ├── milestone-options.ts │ │ │ │ │ └── index.ts │ │ │ │ └── peer.ts │ │ │ ├── secret_manager │ │ │ │ ├── index.ts │ │ │ │ └── bridge │ │ │ │ │ └── index.ts │ │ │ ├── utils │ │ │ │ ├── index.ts │ │ │ │ ├── numeric.ts │ │ │ │ └── hex-encoding.ts │ │ │ ├── client │ │ │ │ ├── range.ts │ │ │ │ ├── nodeInfo.ts │ │ │ │ ├── burn.ts │ │ │ │ ├── index.ts │ │ │ │ ├── constants.ts │ │ │ │ ├── output_builder_params │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── nft-output-params.ts │ │ │ │ │ ├── basic-output-params.ts │ │ │ │ │ ├── foundry-output-params.ts │ │ │ │ │ └── alias-output-params.ts │ │ │ │ ├── generate-addresses-options.ts │ │ │ │ └── ledger-nano-status.ts │ │ │ ├── index.ts │ │ │ ├── wallet │ │ │ │ ├── consolidation-params.ts │ │ │ │ ├── wallet.ts │ │ │ │ ├── signed-transaction-essence.ts │ │ │ │ ├── index.ts │ │ │ │ └── prepared-create-token-transaction-data.ts │ │ │ └── logger-config.ts │ │ ├── client │ │ │ └── index.ts │ │ ├── secret_manager │ │ │ └── index.ts │ │ ├── wallet │ │ │ └── index.ts │ │ ├── logger.ts │ │ └── utils │ │ │ └── utf8.ts │ ├── .gitignore │ ├── .prettierrc.js │ ├── binding.gyp │ ├── gon-config.json │ ├── jest.config.js │ ├── scripts │ │ ├── strip.js │ │ ├── move-artifact.js │ │ └── neon-build.js │ ├── tsconfig.json │ └── .eslintrc.js ├── wasm │ ├── .cargo │ │ └── config.toml │ ├── .eslintignore │ ├── tsconfig.web.json │ ├── .gitignore │ ├── tsconfig.node.json │ ├── .prettierrc.js │ ├── jest.config.js │ ├── tsconfig.base.json │ ├── build_scripts │ │ ├── utils │ │ │ └── generatePackage.js │ │ └── copyNodejsDefs.js │ ├── .eslintrc.js │ └── src │ │ ├── utils.rs │ │ └── lib.rs ├── package-lock.json └── core │ ├── src │ ├── method │ │ └── mod.rs │ └── method_handler │ │ └── mod.rs │ └── tests │ └── serialize_error.rs ├── .license_template ├── cli ├── .gitignore ├── src │ └── command │ │ └── mod.rs └── gon-config.json ├── rustfmt.toml ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ └── feature_request.md ├── actions │ ├── private-tangle │ │ └── tear-down │ │ │ └── action.yml │ ├── ledger-nano │ │ └── action.yml │ └── setup-clang │ │ └── action.yml └── workflows │ └── cancel-jobs.yml ├── .config └── nextest.toml ├── CHANGELOG.md ├── Cargo.toml ├── .gitignore └── .patches ├── macos_cargo_toml.patch └── rocksdb_faligned_allocation.patch /sdk/README.md: -------------------------------------------------------------------------------- 1 | ../README.md -------------------------------------------------------------------------------- /bindings/python/iota_sdk/py.typed: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/.gitignore: -------------------------------------------------------------------------------- 1 | artifacts 2 | corpus 3 | target 4 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db/db/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000056 2 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_1_db_test/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000081 2 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_2_db_test/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000155 2 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_3_db_test/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000130 2 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_4_db_test/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000020 2 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_5_db_test/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000130 2 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_db_test/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000107 2 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-ledger/db/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000010 2 | -------------------------------------------------------------------------------- /bindings/nodejs/tests/webpack/index.js: -------------------------------------------------------------------------------- 1 | import * as types from '../../out/types'; -------------------------------------------------------------------------------- /bindings/python/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | dist 3 | iota_sdk.egg-info 4 | .tox 5 | env -------------------------------------------------------------------------------- /bindings/wasm/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | target = "wasm32-unknown-unknown" 3 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000112 2 | -------------------------------------------------------------------------------- /bindings/python/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include pyproject.toml Cargo.toml 2 | recursive-include src * -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_db_test/IDENTITY: -------------------------------------------------------------------------------- 1 | 0033d7da-ea2f-4755-b332-c02d9240c886 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-ledger/db/IDENTITY: -------------------------------------------------------------------------------- 1 | c68fb305-90e8-4a23-ab09-793fd35b2dad -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_1_db_test/IDENTITY: -------------------------------------------------------------------------------- 1 | 3ebbd3ee-87c9-49db-ba0d-460f89bae548 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_2_db_test/IDENTITY: -------------------------------------------------------------------------------- 1 | d85ecfeb-d0ee-4e44-96f6-c6a4077b6b5d -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_3_db_test/IDENTITY: -------------------------------------------------------------------------------- 1 | dfde6630-6a9f-46f3-adef-bc8698c7d996 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_4_db_test/IDENTITY: -------------------------------------------------------------------------------- 1 | 41fe5963-0593-46bb-ba7c-b8fe31b655cf -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_5_db_test/IDENTITY: -------------------------------------------------------------------------------- 1 | 005b9a4a-311b-4093-8947-6d1a92f14e53 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/IDENTITY: -------------------------------------------------------------------------------- 1 | 42953950-2698-4d2b-b2a1-9e405c72280e -------------------------------------------------------------------------------- /.license_template: -------------------------------------------------------------------------------- 1 | // Copyright {20\d{2}(-20\d{2})?} IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 -------------------------------------------------------------------------------- /bindings/nodejs/.eslintignore: -------------------------------------------------------------------------------- 1 | scripts 2 | target 3 | **/node_modules/ 4 | **/out/ 5 | **/tests/ 6 | **/dist -------------------------------------------------------------------------------- /bindings/nodejs/.npmignore: -------------------------------------------------------------------------------- 1 | target 2 | index.node 3 | **/node_modules 4 | **/.DS_Store 5 | npm-debug.log* 6 | -------------------------------------------------------------------------------- /cli/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /stardust-cli-wallet-db 3 | *.stronghold 4 | archive.log 5 | mnemonic.txt 6 | wallet -------------------------------------------------------------------------------- /bindings/nodejs/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [target.x86_64-pc-windows-msvc] 2 | rustflags = ["-C", "target-feature=+crt-static"] 3 | -------------------------------------------------------------------------------- /sdk/tests/utils/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod serde; 5 | -------------------------------------------------------------------------------- /sdk/tests/client/mqtt/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod topic; 5 | -------------------------------------------------------------------------------- /sdk/tests/types/api/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod participation; 5 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/v2.stronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/v2.stronghold -------------------------------------------------------------------------------- /bindings/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bindings", 3 | "lockfileVersion": 2, 4 | "requires": true, 5 | "packages": {} 6 | } 7 | -------------------------------------------------------------------------------- /bindings/wasm/.eslintignore: -------------------------------------------------------------------------------- 1 | build_scripts/ 2 | target/ 3 | **/node_modules/ 4 | **/out/ 5 | **/tests/ 6 | **/dist 7 | node/ 8 | web/ 9 | -------------------------------------------------------------------------------- /sdk/tests/pow/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod miner; 5 | mod score; 6 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/client/offline_signing/example-address.json: -------------------------------------------------------------------------------- 1 | ["rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy"] 2 | -------------------------------------------------------------------------------- /sdk/tests/types/input/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod treasury; 5 | mod utxo; 6 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/already_v3.stronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/already_v3.stronghold -------------------------------------------------------------------------------- /bindings/wasm/tsconfig.web.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "ES2020" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/v2_with_backup.stronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/v2_with_backup.stronghold -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/input/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './input'; 5 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db/db/000051.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db/db/000051.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db/db/000054.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db/db/000054.sst -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/plugins/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './indexer'; 5 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db/wallet.stronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db/wallet.stronghold -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/payload/tagged/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './tagged'; 5 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/payload/treasury/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './treasury'; 5 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_db_test/000097.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_db_test/000097.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_db_test/000100.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_db_test/000100.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_db_test/000105.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_db_test/000105.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-ledger/db/000008.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db-ledger/db/000008.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db/db/MANIFEST-000056: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db/db/MANIFEST-000056 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/no_secret_manager_data.stronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/no_secret_manager_data.stronghold -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_1_db_test/000071.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_1_db_test/000071.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_1_db_test/000074.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_1_db_test/000074.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_1_db_test/000079.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_1_db_test/000079.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_2_db_test/000086.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_2_db_test/000086.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_2_db_test/000089.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_2_db_test/000089.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_3_db_test/000120.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_3_db_test/000120.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_3_db_test/000123.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_3_db_test/000123.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_3_db_test/000128.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_3_db_test/000128.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_4_db_test/000008.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_4_db_test/000008.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_4_db_test/000013.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_4_db_test/000013.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_4_db_test/000018.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_4_db_test/000018.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_5_db_test/000008.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_5_db_test/000008.sst -------------------------------------------------------------------------------- /bindings/nodejs/.gitignore: -------------------------------------------------------------------------------- 1 | index.node 2 | **/node_modules 3 | **/.DS_Store 4 | *.log 5 | build/ 6 | prebuilds/ 7 | out/ 8 | **/dist 9 | offline_signing*.json 10 | docs 11 | -------------------------------------------------------------------------------- /bindings/python/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | pytest>=7.2.1 2 | setuptools-rust>=1.5.2 3 | wheel>=0.38.4 4 | pyhumps>=3.8.0 5 | python-dotenv>=1.0.0 6 | pydoc-markdown>=4.8.0 7 | dacite>=1.8.1 -------------------------------------------------------------------------------- /bindings/wasm/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | **/*~ 3 | **/node_modules 4 | **/.DS_Store 5 | build/ 6 | out/ 7 | **/dist 8 | stronghold 9 | web/ 10 | node/ 11 | lib/bindings.js 12 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_db_test/MANIFEST-000107: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_db_test/MANIFEST-000107 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_db_test/strongholdfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_db_test/strongholdfile -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/000097.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/000097.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/000100.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/000100.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/000105.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/000105.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/000110.sst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/000110.sst -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-ledger/db/MANIFEST-000010: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db-ledger/db/MANIFEST-000010 -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/plugins/indexer/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './output-response'; 5 | -------------------------------------------------------------------------------- /cli/src/command/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | pub mod account; 5 | pub mod account_completion; 6 | pub mod wallet; 7 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_1_db_test/MANIFEST-000081: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_1_db_test/MANIFEST-000081 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_2_db_test/MANIFEST-000155: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_2_db_test/MANIFEST-000155 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_3_db_test/MANIFEST-000130: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_3_db_test/MANIFEST-000130 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_4_db_test/MANIFEST-000020: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_4_db_test/MANIFEST-000020 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_5_db_test/MANIFEST-000130: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_5_db_test/MANIFEST-000130 -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-encrypted/wallet.stronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db-encrypted/wallet.stronghold -------------------------------------------------------------------------------- /bindings/wasm/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "target": "ES2020", 5 | "module": "commonjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_2_db_test/walletstronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_2_db_test/walletstronghold -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_3_db_test/walletstronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_3_db_test/walletstronghold -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_4_db_test/walletstronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_4_db_test/walletstronghold -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/check_existing_5_db_test/walletstronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/check_existing_5_db_test/walletstronghold -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-backup-work-factor-0.stronghold: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-backup-work-factor-0.stronghold -------------------------------------------------------------------------------- /sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/MANIFEST-000112: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iotaledger/iota-sdk/HEAD/sdk/tests/wallet/fixtures/chrysalis-db-encrypted/db/MANIFEST-000112 -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/secret_manager/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './bridge'; 5 | export * from './secret-manager'; 6 | -------------------------------------------------------------------------------- /sdk/src/wallet/account/operations/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /// The module for time related functions 5 | pub(crate) mod time; 6 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/payload/milestone/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './milestone'; 5 | 6 | export type MilestoneId = string; 7 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/utils/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './bridge'; 5 | export * from './hex-encoding'; 6 | export * from './numeric'; 7 | -------------------------------------------------------------------------------- /sdk/src/types/api/core/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Core API-related types like responses and DTOs. 5 | 6 | pub mod error; 7 | pub mod response; 8 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/accounts_and_addresses/create_mnemonic.py: -------------------------------------------------------------------------------- 1 | from iota_sdk import Utils 2 | 3 | # Generate a random BIP39 mnemonic 4 | mnemonic = Utils.generate_mnemonic() 5 | print(f'Mnemonic: {mnemonic}') 6 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/utils/numeric.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * Used for serialised numeric strings 6 | */ 7 | export declare type NumericString = string; 8 | -------------------------------------------------------------------------------- /sdk/src/types/api/plugins/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! INX plugin API-related types like responses and DTOs. 5 | 6 | pub mod indexer; 7 | pub mod participation; 8 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/client/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './client'; 5 | export * from './client-method-handler'; 6 | export * from '../types/client'; 7 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/payload/transaction/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './essence'; 5 | export * from './unlock'; 6 | export * from './transaction'; 7 | -------------------------------------------------------------------------------- /sdk/src/types/api/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! API-related types like responses and DTOs. 5 | 6 | #![allow(missing_docs)] 7 | 8 | pub mod core; 9 | pub mod plugins; 10 | -------------------------------------------------------------------------------- /bindings/nodejs/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: true, 3 | singleQuote: true, 4 | tabWidth: 4, 5 | useTabs: false, 6 | trailingComma: 'all', 7 | bracketSpacing: true, 8 | arrowParens: 'always', 9 | }; 10 | -------------------------------------------------------------------------------- /bindings/nodejs/binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "index", 5 | 'defines': [ 6 | "NAPI_VERSION=<(napi_build_version)", 7 | ], 8 | "win_delay_load_hook": "true", 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /bindings/wasm/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: true, 3 | singleQuote: true, 4 | tabWidth: 4, 5 | useTabs: false, 6 | trailingComma: 'all', 7 | bracketSpacing: true, 8 | arrowParens: 'always', 9 | }; 10 | -------------------------------------------------------------------------------- /sdk/tests/client/common/constants.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | pub static NODE_LOCAL: &str = "http://localhost:14265"; 5 | 6 | pub static FAUCET_URL: &str = "http://localhost:8091/api/enqueue"; 7 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/secret_manager/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './secret-manager'; 5 | export * from './secret-manager-method-handler'; 6 | export * from '../types/secret_manager'; 7 | -------------------------------------------------------------------------------- /sdk/src/wallet/account/operations/transaction/high_level/minting/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | pub(crate) mod create_native_token; 5 | pub(crate) mod mint_native_token; 6 | pub(crate) mod mint_nfts; 7 | -------------------------------------------------------------------------------- /sdk/tests/client/secret_manager/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod mnemonic; 5 | #[cfg(feature = "private_key_secret_manager")] 6 | mod private_key; 7 | #[cfg(feature = "stronghold")] 8 | mod stronghold; 9 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/bool.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use rand::Rng; 5 | 6 | /// Generates a random boolean. 7 | pub fn rand_bool() -> bool { 8 | rand::thread_rng().gen::() 9 | } 10 | -------------------------------------------------------------------------------- /bindings/python/examples/client/getting_started.py: -------------------------------------------------------------------------------- 1 | from iota_sdk import Client 2 | 3 | # Create a Client instance 4 | client = Client(nodes=['https://api.testnet.shimmer.network']) 5 | 6 | # Get the node info 7 | node_info = client.get_info() 8 | print(f'{node_info}') 9 | -------------------------------------------------------------------------------- /sdk/tests/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #[cfg(feature = "client")] 5 | mod client; 6 | #[cfg(feature = "pow")] 7 | mod pow; 8 | mod types; 9 | mod utils; 10 | #[cfg(feature = "wallet")] 11 | mod wallet; 12 | -------------------------------------------------------------------------------- /bindings/python/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["maturin>=1.0.0b4"] 3 | build-backend = "maturin" 4 | 5 | [project] 6 | name = "iota-sdk" 7 | dependencies = ["dacite >= 1.8.1", "pyhumps >= 3.8.0"] 8 | 9 | [tool.maturin] 10 | python-packages = ["iota_sdk"] -------------------------------------------------------------------------------- /bindings/nodejs/tests/webpack/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | entry: './index.js', 5 | mode: 'development', 6 | output: { 7 | path: path.resolve(__dirname, 'dist'), 8 | filename: 'bundle.js', 9 | } 10 | }; -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | comment_width = 120 2 | edition = "2021" 3 | style_edition = "2024" 4 | format_code_in_doc_comments = true 5 | group_imports = "StdExternalCrate" 6 | imports_granularity = "Crate" 7 | max_width = 120 8 | normalize_comments = true 9 | normalize_doc_attributes = true 10 | wrap_comments = true 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Discord 4 | url: https://discord.iota.org/ 5 | about: Please ask and answer questions here. 6 | - name: Security vulnerabilities 7 | url: security@iota.org 8 | about: Please report security vulnerabilities here. 9 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/wallet/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './account'; 5 | export * from './wallet'; 6 | export * from './wallet-method-handler'; 7 | export * from '../types/wallet'; 8 | export { migrateDbChrysalisToStardust } from '../bindings'; 9 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/range.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** A range with start and end values. */ 5 | export interface IRange { 6 | /** The start index. */ 7 | start: number; 8 | /** The end index. */ 9 | end: number; 10 | } 11 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/output/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './feature'; 5 | export * from './unlock-condition'; 6 | export * from './output'; 7 | export * from './token-scheme'; 8 | export * from './irc-27'; 9 | export * from './irc-30'; 10 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/ledger-inclusion-state.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * The different states of ledger inclusion. 6 | */ 7 | export declare type LedgerInclusionState = 8 | | 'noTransaction' 9 | | 'included' 10 | | 'conflicting'; 11 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/option.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::rand::bool::rand_bool; 5 | 6 | /// Generates a random generic option. 7 | pub fn rand_option(inner: T) -> Option { 8 | if rand_bool() { Some(inner) } else { None } 9 | } 10 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/info/routes-response.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * Response from the /routes endpoint. 6 | */ 7 | export interface IRoutesResponse { 8 | /** 9 | * The routes the node exposes. 10 | */ 11 | routes: string[]; 12 | } 13 | -------------------------------------------------------------------------------- /bindings/wasm/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | testMatch: ['/test/**/*.(test|spec).ts'], 6 | moduleNameMapper: { 7 | 'index.node': '/index.node', 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /sdk/src/types/api/plugins/participation/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Node participation API. 5 | //! 6 | 7 | pub mod error; 8 | pub mod responses; 9 | pub mod types; 10 | -------------------------------------------------------------------------------- /sdk/src/wallet/account/operations/transaction/high_level/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | pub(crate) mod burning_melting; 5 | pub(crate) mod create_alias; 6 | pub(crate) mod minting; 7 | pub(crate) mod send; 8 | pub(crate) mod send_native_tokens; 9 | pub(crate) mod send_nft; 10 | -------------------------------------------------------------------------------- /sdk/tests/client/input_selection/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod alias_outputs; 5 | mod basic_outputs; 6 | mod burn; 7 | mod expiration; 8 | mod foundry_outputs; 9 | mod native_tokens; 10 | mod nft_outputs; 11 | mod outputs; 12 | mod storage_deposit_return; 13 | mod timelock; 14 | -------------------------------------------------------------------------------- /sdk/src/client/api/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! High level APIs 5 | 6 | mod address; 7 | mod block_builder; 8 | mod consolidation; 9 | mod high_level; 10 | mod types; 11 | 12 | pub use self::{address::*, block_builder::*, types::*}; 13 | 14 | const ADDRESS_GAP_RANGE: u32 = 20; 15 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './input/index'; 5 | export * from './output/index'; 6 | export * from './payload/index'; 7 | 8 | export * from './address'; 9 | export * from './id'; 10 | export * from './block'; 11 | export * from './signature'; 12 | -------------------------------------------------------------------------------- /cli/gon-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": ["../target/production/wallet"], 3 | "bundle_id": "org.iota.cli-wallet", 4 | "apple_id": { 5 | "provider": "UG77RJKZHH" 6 | }, 7 | "sign": { 8 | "application_identity": "Developer ID Application: IOTA Stiftung (UG77RJKZHH)" 9 | }, 10 | "zip": { 11 | "output_path": "./wallet.zip" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sdk/src/types/block/block_id.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | impl_id!( 5 | pub BlockId, 6 | 32, 7 | "A block identifier, the BLAKE2b-256 hash of the block bytes. See for more information." 8 | ); 9 | 10 | #[cfg(feature = "serde")] 11 | string_serde_impl!(BlockId); 12 | -------------------------------------------------------------------------------- /bindings/python/examples/wallet/get_client.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | load_dotenv() 8 | 9 | # This example gets a client from the wallet. 10 | 11 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 12 | 13 | client = wallet.get_client() 14 | 15 | info = client.get_info() 16 | print(f'{info}') 17 | -------------------------------------------------------------------------------- /bindings/core/src/method/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod account; 5 | mod client; 6 | mod secret_manager; 7 | mod utils; 8 | mod wallet; 9 | 10 | pub use self::{ 11 | account::AccountMethod, client::ClientMethod, secret_manager::SecretManagerMethod, utils::UtilsMethod, 12 | wallet::WalletMethod, 13 | }; 14 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/transaction.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::{payload::transaction::TransactionId, rand::bytes::rand_bytes_array}; 5 | 6 | /// Generates a random transaction id. 7 | pub fn rand_transaction_id() -> TransactionId { 8 | TransactionId::new(rand_bytes_array()) 9 | } 10 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/fuzz_targets/fuzz_block.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![no_main] 5 | 6 | use crate::types::block::Block; 7 | 8 | use libfuzzer_sys::fuzz_target; 9 | use packable::PackableExt; 10 | 11 | fuzz_target!(|data: &[u8]| { 12 | let _ = Block::unpack_strict(data.to_vec().as_slice(), &()); 13 | }); 14 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/block-id-response.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import type { HexEncodedString } from '../../utils/hex-encoding'; 5 | /** 6 | * Block id response. 7 | */ 8 | export interface IBlockIdResponse { 9 | /** 10 | * The block id. 11 | */ 12 | blockId: HexEncodedString; 13 | } 14 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/fuzz_targets/fuzz_input.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![no_main] 5 | 6 | use crate::types::block::input::Input; 7 | 8 | use libfuzzer_sys::fuzz_target; 9 | use packable::PackableExt; 10 | 11 | fuzz_target!(|data: &[u8]| { 12 | let _ = Input::unpack_verified(data.to_vec().as_slice()); 13 | }); 14 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/fuzz_targets/fuzz_feature.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![no_main] 5 | 6 | use crate::types::block::output::Feature; 7 | 8 | use libfuzzer_sys::fuzz_target; 9 | use packable::PackableExt; 10 | 11 | fuzz_target!(|data: &[u8]| { 12 | let _ = Feature::unpack_verified(data.to_vec().as_slice()); 13 | }); 14 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/fuzz_targets/fuzz_output.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![no_main] 5 | 6 | use crate::types::block::output::Output; 7 | 8 | use libfuzzer_sys::fuzz_target; 9 | use packable::PackableExt; 10 | 11 | fuzz_target!(|data: &[u8]| { 12 | let _ = Output::unpack_verified(data.to_vec().as_slice()); 13 | }); 14 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/fuzz_targets/fuzz_unlock.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![no_main] 5 | 6 | use crate::types::block::unlock::Unlock; 7 | 8 | use libfuzzer_sys::fuzz_target; 9 | use packable::PackableExt; 10 | 11 | fuzz_target!(|data: &[u8]| { 12 | let _ = Unlock::unpack_verified(data.to_vec().as_slice()); 13 | }); 14 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/fuzz_targets/fuzz_address.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![no_main] 5 | 6 | use crate::types::block::address::Address; 7 | 8 | use libfuzzer_sys::fuzz_target; 9 | use packable::PackableExt; 10 | 11 | fuzz_target!(|data: &[u8]| { 12 | let _ = Address::unpack_verified(data.to_vec().as_slice()); 13 | }); 14 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/fuzz_targets/fuzz_payload.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![no_main] 5 | 6 | use crate::types::block::payload::Payload; 7 | 8 | use libfuzzer_sys::fuzz_target; 9 | use packable::PackableExt; 10 | 11 | fuzz_target!(|data: &[u8]| { 12 | let _ = Payload::unpack_verified(data.to_vec().as_slice()); 13 | }); 14 | -------------------------------------------------------------------------------- /sdk/src/utils/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #[cfg(feature = "serde")] 5 | pub mod serde; 6 | 7 | #[cfg(feature = "instant")] 8 | pub fn unix_timestamp_now() -> core::time::Duration { 9 | instant::SystemTime::now() 10 | .duration_since(instant::SystemTime::UNIX_EPOCH) 11 | .expect("time went backwards") 12 | } 13 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/fuzz_targets/fuzz_signature.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![no_main] 5 | 6 | use crate::types::block::signature::Signature; 7 | 8 | use libfuzzer_sys::fuzz_target; 9 | use packable::PackableExt; 10 | 11 | fuzz_target!(|data: &[u8]| { 12 | let _ = Signature::unpack_verified(data.to_vec().as_slice()); 13 | }); 14 | -------------------------------------------------------------------------------- /bindings/nodejs/gon-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": ["./build/Release/index.node"], 3 | "bundle_id": "org.iota.sdk-nodejs", 4 | "apple_id": { 5 | "password": "@env:AC_PASSWORD" 6 | }, 7 | "sign": { 8 | "application_identity": "Developer ID Application: IOTA Stiftung (UG77RJKZHH)" 9 | }, 10 | "zip": { 11 | "output_path": "./binary.zip" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/tips-response.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import type { HexEncodedString } from '../../utils/hex-encoding'; 5 | /** 6 | * Response from the tips endpoint. 7 | */ 8 | export interface ITipsResponse { 9 | /** 10 | * The block ids of the tip. 11 | */ 12 | tips: HexEncodedString[]; 13 | } 14 | -------------------------------------------------------------------------------- /sdk/src/types/block/payload/milestone/milestone_id.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | impl_id!( 5 | pub MilestoneId, 6 | 32, 7 | "A milestone identifier, the BLAKE2b-256 hash of the milestone bytes. See for more information." 8 | ); 9 | 10 | #[cfg(feature = "serde")] 11 | string_serde_impl!(MilestoneId); 12 | -------------------------------------------------------------------------------- /bindings/python/examples/exchange/0_generate_mnemonic.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | # This example generates a new random mnemonic. 5 | 6 | from iota_sdk import Utils 7 | 8 | # Set the generated mnemonic as env variable MNEMONIC so it can be used in 9 | # the next examples. 10 | mnemonic = Utils.generate_mnemonic() 11 | print(f'Mnemonic: {mnemonic}') 12 | -------------------------------------------------------------------------------- /sdk/src/client/storage/stronghold.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Stronghold-as-a-Database implementation. 5 | 6 | use crate::client::stronghold::StrongholdAdapter; 7 | 8 | /// Stronghold as a database provider. 9 | /// 10 | /// This is just an alias to the all-in-one [StrongholdAdapter]. 11 | pub type StrongholdStorageAdapter = StrongholdAdapter; 12 | -------------------------------------------------------------------------------- /sdk/src/types/fuzz/fuzz_targets/fuzz_unlock_condition.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![no_main] 5 | 6 | use crate::types::block::output::UnlockCondition; 7 | 8 | use libfuzzer_sys::fuzz_target; 9 | use packable::PackableExt; 10 | 11 | fuzz_target!(|data: &[u8]| { 12 | let _ = UnlockCondition::unpack_verified(data.to_vec().as_slice()); 13 | }); 14 | -------------------------------------------------------------------------------- /.config/nextest.toml: -------------------------------------------------------------------------------- 1 | [profile.ci] 2 | # Print out output for failing tests as soon as they fail, and also at the end 3 | # of the run (for easy scrollability). 4 | failure-output = "immediate-final" 5 | fail-fast = false 6 | retries = 2 7 | test-threads = "num-cpus" 8 | slow-timeout = { period = "60s", terminate-after = 2 } 9 | 10 | [[profile.ci.overrides]] 11 | filter = 'test(/^pow::/)' 12 | slow-timeout = "5m" 13 | -------------------------------------------------------------------------------- /sdk/src/client/api/block_builder/input_selection/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Input selection for transactions 5 | 6 | mod automatic; 7 | mod core; 8 | mod manual; 9 | mod sender_issuer; 10 | mod utxo_chains; 11 | 12 | pub(crate) use self::core::is_alias_transition; 13 | pub use self::core::{Burn, BurnDto, Error, InputSelection, Requirement, Selected}; 14 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/info/node-info-protocol-params-milestone-opt.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { ProtocolParamsMilestoneOption } from '../milestone_options/protocol-params-milestone-option'; 5 | /** 6 | * Defines changing protocol parameters in a milestone. 7 | */ 8 | export class NodeInfoProtocolParamsMilestoneOpt extends ProtocolParamsMilestoneOption {} 9 | -------------------------------------------------------------------------------- /bindings/nodejs/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | testMatch: ['/tests/**/*.(test|spec).ts'], 6 | verbose: false, 7 | detectOpenHandles: true, 8 | forceExit: true, 9 | moduleNameMapper: { 10 | 'index.node': '/build/Release/index.node', 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /bindings/python/iota_sdk/external.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | # pylint: disable=import-error, unused-import 5 | from .iota_sdk import call_utils_method, call_secret_manager_method, create_secret_manager, destroy_wallet, create_client, create_wallet, listen_wallet, get_client_from_wallet, get_secret_manager_from_wallet, call_wallet_method, call_client_method, init_logger, listen_mqtt 6 | -------------------------------------------------------------------------------- /sdk/src/client/secret/stronghold.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Stronghold-as-a-Secret-Manager. 5 | 6 | use crate::client::stronghold::StrongholdAdapter; 7 | 8 | /// Secret manager that uses [`iota_stronghold`] as the backing storage. 9 | /// 10 | /// This is just an alias to the all-in-one [StrongholdAdapter]. 11 | pub type StrongholdSecretManager = StrongholdAdapter; 12 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/parents.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::{ 5 | parent::Parents, 6 | rand::{block::rand_block_ids, number::rand_number_range}, 7 | }; 8 | 9 | /// Generates random parents. 10 | pub fn rand_parents() -> Parents { 11 | Parents::from_vec(rand_block_ids(rand_number_range(Parents::COUNT_RANGE).into())).unwrap() 12 | } 13 | -------------------------------------------------------------------------------- /bindings/core/src/method_handler/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod account; 5 | mod call_method; 6 | mod client; 7 | mod secret_manager; 8 | mod utils; 9 | mod wallet; 10 | 11 | pub use call_method::{ 12 | CallMethod, call_client_method, call_secret_manager_method, call_utils_method, call_wallet_method, 13 | }; 14 | #[cfg(feature = "mqtt")] 15 | pub use client::listen_mqtt; 16 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/client/get_health.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Client 6 | 7 | load_dotenv() 8 | 9 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 10 | 11 | # Create a Client instance 12 | client = Client(nodes=[node_url]) 13 | 14 | # Get the node health 15 | is_healthy = client.get_health(node_url) 16 | print(f'Healthy: {is_healthy}') 17 | -------------------------------------------------------------------------------- /sdk/src/client/node_api/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! node API modules 5 | 6 | pub mod core; 7 | pub mod error; 8 | pub mod indexer; 9 | #[cfg(feature = "mqtt")] 10 | #[cfg_attr(docsrs, doc(cfg(feature = "mqtt")))] 11 | pub mod mqtt; 12 | #[cfg(feature = "participation")] 13 | #[cfg_attr(docsrs, doc(cfg(feature = "participation")))] 14 | pub mod participation; 15 | pub mod plugin; 16 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2019", 4 | "module": "commonjs", 5 | "sourceMap": true, 6 | "strict": true, 7 | "moduleResolution": "node", 8 | "types": ["node"], 9 | "esModuleInterop": true, 10 | "noImplicitAny": true, 11 | "removeComments": true, 12 | "skipLibCheck": true, 13 | "outDir": "dist" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './plugins'; 5 | 6 | export * from './block-id-response'; 7 | export * from './milestone-utxo-changes-response'; 8 | export * from './output-metadata-response'; 9 | export * from './output-response'; 10 | export * from './receipts-response'; 11 | export * from './response'; 12 | export * from './tips-response'; 13 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/nodeInfo.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { INodeInfo } from '../models/info'; 5 | 6 | /** NodeInfo wrapper which contains the node info and the url from the node (useful when multiple nodes are used) */ 7 | export interface INodeInfoWrapper { 8 | /** The node info */ 9 | nodeInfo: INodeInfo; 10 | /** The url of the node */ 11 | url: string; 12 | } 13 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/info/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './node-info'; 5 | export * from './node-info-base-token'; 6 | export * from './node-info-metrics'; 7 | export * from './node-info-milestone'; 8 | export * from './node-info-protocol'; 9 | export * from './node-info-protocol-params-milestone-opt'; 10 | export * from './node-info-status'; 11 | export * from './routes-response'; 12 | -------------------------------------------------------------------------------- /bindings/python/iota_sdk/types/network_info.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from __future__ import annotations 5 | from dataclasses import dataclass 6 | from iota_sdk.types.node_info import NodeInfoProtocol 7 | 8 | 9 | @dataclass 10 | class NetworkInfo: 11 | """Network and PoW related information. 12 | """ 13 | 14 | protocolParameters: NodeInfoProtocol 15 | localPow: bool 16 | tipsInterval: int 17 | -------------------------------------------------------------------------------- /bindings/python/iota_sdk/types/native_token.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from dataclasses import dataclass 5 | from iota_sdk.types.common import HexStr 6 | 7 | 8 | @dataclass 9 | class NativeToken(): 10 | """A native token. 11 | 12 | Attributes: 13 | id: The unique identifier of the native token. 14 | amount: The amount of native tokens. 15 | """ 16 | id: HexStr 17 | amount: HexStr 18 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './block'; 5 | export * from './client'; 6 | export * from './models'; 7 | export * from './secret_manager'; 8 | export * from './utils'; 9 | export * from './wallet'; 10 | export * from './logger-config'; 11 | 12 | /** 13 | * Response from the message interface 14 | */ 15 | export interface Response { 16 | type: string; 17 | payload: T; 18 | } 19 | -------------------------------------------------------------------------------- /bindings/python/examples/client/06_simple_block.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Client 6 | 7 | load_dotenv() 8 | 9 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 10 | 11 | # Create a Client instance 12 | client = Client(nodes=[node_url]) 13 | 14 | # Create and post a block without payload 15 | block = client.build_and_post_block() 16 | print(f'Empty block sent: {os.environ["EXPLORER_URL"]}/block/{block[0]}') 17 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/accounts_and_addresses/list_accounts.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | # This example lists all accounts in the wallet. 8 | 9 | # This example uses secrets in environment variables for simplicity which 10 | # should not be done in production. 11 | load_dotenv() 12 | 13 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 14 | 15 | for account in wallet.get_accounts(): 16 | print(account.get_metadata()) 17 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/client/get_info.py: -------------------------------------------------------------------------------- 1 | import dataclasses 2 | import json 3 | import os 4 | 5 | from dotenv import load_dotenv 6 | 7 | from iota_sdk import Client 8 | 9 | load_dotenv() 10 | 11 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 12 | 13 | # Create a Client instance 14 | client = Client(nodes=[node_url]) 15 | 16 | # Get the node info 17 | node_info = client.get_info().nodeInfo 18 | print(f'{json.dumps(dataclasses.asdict(node_info), indent=4)}') 19 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Rust 2 | 3 | https://github.com/iotaledger/iota-sdk/blob/develop/sdk/CHANGELOG.md 4 | 5 | # Nodejs 6 | 7 | https://github.com/iotaledger/iota-sdk/blob/develop/bindings/nodejs/CHANGELOG.md 8 | 9 | # Wasm 10 | 11 | https://github.com/iotaledger/iota-sdk/blob/develop/bindings/wasm/CHANGELOG.md 12 | 13 | # Python 14 | 15 | https://github.com/iotaledger/iota-sdk/blob/develop/bindings/python/CHANGELOG.md 16 | 17 | # CLI 18 | 19 | https://github.com/iotaledger/iota-sdk/blob/develop/cli/CHANGELOG.md -------------------------------------------------------------------------------- /bindings/python/.pylintrc: -------------------------------------------------------------------------------- 1 | [MESSAGES CONTROL] 2 | disable=missing-module-docstring, 3 | line-too-long, # enforced by PEP8 format checker 4 | broad-exception-raised, 5 | invalid-name, # files that starts with number 6 | duplicate-code, 7 | consider-using-with, 8 | fixme, # TODOS 9 | too-many-instance-attributes, 10 | too-many-arguments, 11 | too-many-public-methods, 12 | too-few-public-methods, 13 | too-many-locals 14 | 15 | [TYPECHECK] 16 | generated-members=from_dict,to_dict,to_json # Made from @json 17 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/bytes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use alloc::vec::Vec; 5 | 6 | use rand::Rng; 7 | 8 | /// Generates a [`Vec`] of random bytes with a given length. 9 | pub fn rand_bytes(len: usize) -> Vec { 10 | (0..len).map(|_| rand::random::()).collect() 11 | } 12 | 13 | /// Generates an array of random bytes of length N. 14 | pub fn rand_bytes_array() -> [u8; N] { 15 | rand::thread_rng().gen::<[u8; N]>() 16 | } 17 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/wallet/consolidation-params.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** Parameters for consolidation */ 5 | export interface ConsolidationParams { 6 | /** Ignores the output threshold if set to `true`. */ 7 | force: boolean; 8 | /** Consolidates if the output number is >= the output_threshold. */ 9 | outputThreshold?: number; 10 | /** Address to which the consolidated output should be sent. */ 11 | targetAddress?: string; 12 | } 13 | -------------------------------------------------------------------------------- /bindings/nodejs/scripts/strip.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require('path'); 2 | const { spawnSync } = require('child_process'); 3 | 4 | // Based on https://github.com/prebuild/prebuild/blob/master/strip.js 5 | // Prebuild requires that the binary is in `build/Release` as though it was built with node-gyp 6 | 7 | const binaryPath = resolve(__dirname, '../build/Release/index.node'); 8 | const stripArgs = process.platform === 'darwin' ? '-Sx' : '--strip-all'; 9 | spawnSync('strip', [stripArgs, binaryPath], { stdio: 'inherit' }); 10 | -------------------------------------------------------------------------------- /bindings/python/pydoc-markdown.yml: -------------------------------------------------------------------------------- 1 | loaders: 2 | - type: python 3 | processors: 4 | - type: filter 5 | skip_empty_modules: true 6 | - type: smart 7 | - type: pydoc_markdown_iota.IotaProcessor 8 | - type: crossref 9 | renderer: 10 | type: docusaurus 11 | docs_base_path: ../../docs/ 12 | relative_output_path: python 13 | 14 | markdown: 15 | use_fixed_header_levels: true 16 | header_level_by_type: 17 | Module: 1 18 | Class: 2 19 | Method: 3 20 | Function: 3 21 | Data: 3 -------------------------------------------------------------------------------- /bindings/python/iota_sdk/prefix_hex.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from iota_sdk.types.common import HexStr 5 | 6 | 7 | def utf8_to_hex(utf8_data: str) -> HexStr: 8 | """Convert a UTF-8 string to a hex string. 9 | """ 10 | return HexStr('0x' + utf8_data.encode('utf-8').hex()) 11 | 12 | 13 | def hex_to_utf8(hex_data: HexStr) -> str: 14 | """Convert a given hex string to a UTF-8 string. 15 | """ 16 | return bytes.fromhex(hex_data[2:]).decode('utf-8') 17 | -------------------------------------------------------------------------------- /sdk/src/pow/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Provides proof of work implementations and scoring for the IOTA protocol. 5 | //! TIP . 6 | 7 | pub mod miner; 8 | pub mod score; 9 | #[cfg(target_family = "wasm")] 10 | pub mod wasm_miner; 11 | 12 | // Precomputed natural logarithm of 3 for performance reasons. 13 | // See https://oeis.org/A002391. 14 | const LN_3: f64 = 1.098_612_288_668_109; 15 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/burn.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { AliasId, FoundryId, NftId, TokenId } from '../block/id'; 5 | 6 | /** A DTO for [`Burn`] */ 7 | export interface Burn { 8 | /** Aliases to burn */ 9 | aliases?: AliasId[]; 10 | /** NFTs to burn */ 11 | nfts?: NftId[]; 12 | /** Foundries to burn */ 13 | foundries?: FoundryId[]; 14 | /** Amounts of native tokens to burn */ 15 | nativeTokens?: Map; 16 | } 17 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/index.ts: -------------------------------------------------------------------------------- 1 | export * from './output_builder_params'; 2 | 3 | export * from './bridge'; 4 | export * from './build-block-options'; 5 | export * from './burn'; 6 | export * from './client-options'; 7 | export * from './constants'; 8 | export * from './generate-addresses-options'; 9 | export * from './ledger-nano-status'; 10 | export * from './network'; 11 | export * from './nodeInfo'; 12 | export * from './prepared-transaction-data'; 13 | export * from './query-parameters'; 14 | export * from './range'; 15 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/response.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * Base response data. 6 | */ 7 | export interface IResponse { 8 | /** 9 | * Optional error in the response. 10 | */ 11 | error?: { 12 | /** 13 | * The code for the error response. 14 | */ 15 | code: string; 16 | /** 17 | * A more descriptive version of the error. 18 | */ 19 | message: string; 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /.github/actions/private-tangle/tear-down/action.yml: -------------------------------------------------------------------------------- 1 | name: 'private-tangle-tear-down' 2 | description: 'tear-down a private tangle' 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Tear down private tangle 7 | shell: bash 8 | run: | 9 | # TODO: use next line when a working hornet release is published 10 | #cd private_tangle 11 | 12 | # TODO: remove next line when a working hornet release is published 13 | sudo ./cleanup.sh 14 | working-directory: hornet/private_tangle 15 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | members = [ 4 | "bindings/core", 5 | "bindings/nodejs", 6 | "bindings/python", 7 | "bindings/wasm", 8 | "cli", 9 | "sdk", 10 | ] 11 | 12 | # Necessary to get coverage to work as for some reason using a custom profile breaks it 13 | [profile.test] 14 | debug = 0 15 | incremental = false 16 | 17 | [profile.ci] 18 | inherits = "dev" 19 | debug = 0 20 | incremental = false 21 | 22 | [profile.production] 23 | codegen-units = 1 24 | inherits = "release" 25 | lto = true 26 | strip = "symbols" 27 | -------------------------------------------------------------------------------- /sdk/src/types/block/output/token_id.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::output::FoundryId; 5 | 6 | impl_id!(pub TokenId, 38, "Unique identifiers of native tokens. The TokenId of native tokens minted by a specific foundry is the same as the FoundryId."); 7 | 8 | #[cfg(feature = "serde")] 9 | string_serde_impl!(TokenId); 10 | 11 | impl From for TokenId { 12 | fn from(foundry_id: FoundryId) -> Self { 13 | Self::new(*foundry_id) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Build files 3 | **/target 4 | *.pyc 5 | **/*.rs.bk 6 | 7 | # IDE files 8 | .vscode 9 | .idea 10 | *.ipynb 11 | 12 | # Storages/databases 13 | /storage 14 | test-storage 15 | wallet/test-storage 16 | **/*walletdb 17 | backup 18 | 19 | # JSON files 20 | address.json 21 | *addresses.json 22 | *prepared_transaction.json 23 | *signed_transaction.json 24 | 25 | # Miscellaneous 26 | *.log 27 | .env 28 | *.stronghold 29 | !**/tests/**/**.stronghold 30 | .DS_Store 31 | book 32 | .venv* 33 | 34 | # Temporary documentation 35 | docs 36 | -------------------------------------------------------------------------------- /bindings/python/iota_sdk/types/utxo_changes.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from typing import List 5 | from dataclasses import dataclass 6 | from iota_sdk.types.common import HexStr 7 | 8 | 9 | @dataclass 10 | class UtxoChanges(): 11 | """Response of GET /api/core/v2/milestone/{milestone_index}/utxo-changes. 12 | Returns all UTXO changes that happened at a specific milestone. 13 | """ 14 | index: int 15 | createdOutputs: List[HexStr] 16 | consumedOutputs: List[HexStr] 17 | -------------------------------------------------------------------------------- /bindings/wasm/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["ES2020", "DOM"], 4 | "declaration": true, 5 | "sourceMap": true, 6 | "strict": true, 7 | "moduleResolution": "node", 8 | "noImplicitAny": true, 9 | "preserveConstEnums": true, 10 | "resolveJsonModule": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "experimentalDecorators": true 13 | }, 14 | "include": ["out/**/*"], 15 | "exclude": ["node_modules", "out/test/*"] 16 | } 17 | -------------------------------------------------------------------------------- /.github/workflows/cancel-jobs.yml: -------------------------------------------------------------------------------- 1 | name: Cancel jobs from merged/closed pull request 2 | 3 | on: 4 | pull_request_target: 5 | types: [closed] 6 | # workflow_run: 7 | # workflows: ["*"] 8 | # types: [requested] 9 | 10 | 11 | jobs: 12 | merge_job: 13 | runs-on: ubuntu-latest 14 | permissions: 15 | actions: write 16 | steps: 17 | - uses: styfle/cancel-workflow-action@0.11.0 18 | with: 19 | ignore_sha: true 20 | access_token: ${{ secrets.GITHUB_TOKEN }} 21 | workflow_id: all 22 | -------------------------------------------------------------------------------- /.patches/macos_cargo_toml.patch: -------------------------------------------------------------------------------- 1 | diff --git a/Cargo.toml b/Cargo.toml 2 | index e00fa5df9..209f94d6c 100644 3 | --- a/Cargo.toml 4 | +++ b/Cargo.toml 5 | @@ -25,3 +25,12 @@ codegen-units = 1 6 | inherits = "release" 7 | lto = true 8 | strip = "symbols" 9 | + 10 | +[workspace.metadata.patch.librocksdb-sys] 11 | +version = "0.11.0+8.1.1" 12 | +patches = [ 13 | + { path = "rocksdb_faligned_allocation.patch", source = "GithubPrDiff" }, 14 | +] 15 | + 16 | +[patch.crates-io] 17 | +librocksdb-sys = { path = "./target/patch/librocksdb-sys-0.11.0+8.1.1"} 18 | -------------------------------------------------------------------------------- /sdk/tests/wallet/common/constants.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![allow(dead_code)] 5 | 6 | pub static NODE_LOCAL: &str = "http://localhost:14265"; 7 | pub static NODE_OTHER: &str = "http://some.not.default.node:14265"; 8 | 9 | pub static DEFAULT_MNEMONIC: &str = "inhale gorilla deny three celery song category owner lottery rent author wealth penalty crawl hobby obtain glad warm early rain clutch slab august bleak"; 10 | 11 | pub static FAUCET_URL: &str = "http://localhost:8091/api/enqueue"; 12 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './api'; 5 | export * from './milestone_options'; 6 | export * from './info'; 7 | 8 | export * from './conflict-reason'; 9 | export * from './block-metadata'; 10 | export * from './gossip-metrics'; 11 | export * from './gossip-heartbeat'; 12 | export * from './migrated-funds'; 13 | export * from './native-token'; 14 | export * from './peer'; 15 | export * from './rent'; 16 | export * from './ledger-inclusion-state'; 17 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/info/node-info-metrics.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * Response from the /info endpoint. 6 | */ 7 | export interface INodeInfoMetrics { 8 | /** 9 | * Blocks per second. 10 | */ 11 | blocksPerSecond: number; 12 | /** 13 | * Referenced blocks per second. 14 | */ 15 | referencedBlocksPerSecond: number; 16 | /** 17 | * The rate at which rates are being referenced. 18 | */ 19 | referencedRate: number; 20 | } 21 | -------------------------------------------------------------------------------- /sdk/src/types/block/helper.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crypto::hashes::{Digest, blake2b::Blake2b256}; 5 | 6 | /// Hashes a string network name to a digit network ID. 7 | pub fn network_name_to_id(network_name: &str) -> u64 { 8 | // PANIC: indexing and unwrapping is fine as a Blake2b256 digest has 32 bytes, we ask for 8 of them and we convert 9 | // that slice to an array of 8 bytes. 10 | u64::from_le_bytes(Blake2b256::digest(network_name.as_bytes())[0..8].try_into().unwrap()) 11 | } 12 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/constants.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | export const IOTA_BECH32_HRP = 'iota'; 4 | export const IOTA_TESTNET_BECH32_HRP = 'atoi'; 5 | export const SHIMMER_BECH32_HRP = 'smr'; 6 | export const SHIMMER_TESTNET_BECH32_HRP = 'rms'; 7 | 8 | /** BIP44 Coin Types for IOTA and Shimmer. */ 9 | export enum CoinType { 10 | /** The IOTA coin. */ 11 | IOTA = 4218, 12 | /** The Shimmer coin. */ 13 | Shimmer = 4219, 14 | /** The Ether coin. */ 15 | Ether = 60, 16 | } 17 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/info/node-info-milestone.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import type { HexEncodedString } from '../../utils/hex-encoding'; 5 | /** 6 | * The milestone info. 7 | */ 8 | export interface INodeInfoMilestone { 9 | /** 10 | * The milestone index. 11 | */ 12 | index: number; 13 | /** 14 | * The milestone timestamp. 15 | */ 16 | timestamp?: number; 17 | /** 18 | * The milestone id. 19 | */ 20 | milestoneId?: HexEncodedString; 21 | } 22 | -------------------------------------------------------------------------------- /bindings/python/examples/client/04_get_output.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from dotenv import load_dotenv 5 | 6 | from iota_sdk import Client 7 | 8 | load_dotenv() 9 | 10 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 11 | 12 | # Create a Client instance 13 | client = Client(nodes=[node_url]) 14 | 15 | # Get an outputs by its id 16 | output_with_metadata = client.get_output( 17 | '0x022aefa73dff09b35b21ab5493412b0d354ad07a970a12b71e8087c6f3a7b8660000') 18 | print(json.dumps(output_with_metadata.as_dict(), indent=4)) 19 | -------------------------------------------------------------------------------- /sdk/examples/how_tos/accounts_and_addresses/create_mnemonic.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! In this example we will create a random mnemonic. 5 | //! 6 | //! ```sh 7 | //! `cargo run --release --all-features --example create_mnemonic` 8 | //! ``` 9 | 10 | use iota_sdk::client::{Client, Result}; 11 | 12 | #[tokio::main] 13 | async fn main() -> Result<()> { 14 | let mnemonic = Client::generate_mnemonic()?; 15 | 16 | println!("Generated mnemonic:\n{}", mnemonic.as_ref()); 17 | 18 | Ok(()) 19 | } 20 | -------------------------------------------------------------------------------- /.patches/rocksdb_faligned_allocation.patch: -------------------------------------------------------------------------------- 1 | diff --git a/build.rs b/build.rs 2 | index dccaf29..582aa32 100644 3 | --- a/build.rs 4 | +++ b/build.rs 5 | @@ -155,6 +155,7 @@ fn build_rocksdb() { 6 | config.define("OS_MACOSX", None); 7 | config.define("ROCKSDB_PLATFORM_POSIX", None); 8 | config.define("ROCKSDB_LIB_IO_POSIX", None); 9 | + config.flag_if_supported("-faligned-allocation"); 10 | } else if target.contains("android") { 11 | config.define("OS_ANDROID", None); 12 | config.define("ROCKSDB_PLATFORM_POSIX", None); 13 | -------------------------------------------------------------------------------- /bindings/nodejs/scripts/move-artifact.js: -------------------------------------------------------------------------------- 1 | const { existsSync, mkdirSync, renameSync } = require('fs'); 2 | const { resolve } = require('path'); 3 | 4 | // Prebuild requires that the binary be in `build/Release` as though it was built with node-gyp 5 | 6 | const moveArtifact = () => { 7 | const path = resolve(__dirname, '../build/Release'); 8 | 9 | if (!existsSync(path)) { 10 | mkdirSync(path, { recursive: true }); 11 | } 12 | renameSync(resolve(__dirname, '../index.node'), resolve(path, 'index.node')); 13 | }; 14 | 15 | module.exports = moveArtifact; 16 | -------------------------------------------------------------------------------- /bindings/python/examples/client/get_raw_block.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Client 6 | 7 | load_dotenv() 8 | 9 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 10 | 11 | # Create a Client instance 12 | client = Client(nodes=[node_url]) 13 | 14 | # Fetch a block ID from the node 15 | block_id = client.get_tips()[0] 16 | print(f'Block id: {block_id}') 17 | 18 | # Get block raw 19 | block_raw = client.get_block_raw(block_id) 20 | 21 | # Print block raw 22 | print(f'Block bytes: {block_raw}') 23 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/accounts_and_addresses/list_addresses.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | # This example lists all addresses in the account. 8 | 9 | # This example uses secrets in environment variables for simplicity which 10 | # should not be done in production. 11 | load_dotenv() 12 | 13 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 14 | 15 | account = wallet.get_account('Alice') 16 | 17 | addresses = account.addresses() 18 | 19 | for address in addresses: 20 | print(address.address) 21 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/wallet/wallet.ts: -------------------------------------------------------------------------------- 1 | import { IClientOptions, CoinType } from '../client'; 2 | import { SecretManagerType } from '../secret_manager/secret-manager'; 3 | 4 | /** Options for the Wallet builder. */ 5 | export interface WalletOptions { 6 | /** The path to the wallet database. */ 7 | storagePath?: string; 8 | /** The node client options. */ 9 | clientOptions?: IClientOptions; 10 | /** The type of coin stored with the wallet. */ 11 | coinType?: CoinType; 12 | /** The secret manager to use. */ 13 | secretManager?: SecretManagerType; 14 | } 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Request a feature 3 | about: Request a feature 4 | --- 5 | 6 | ## Description 7 | 8 | Briefly describe the feature that you are requesting. 9 | 10 | ## Motivation 11 | 12 | Explain why this feature is needed. 13 | 14 | ## Requirements 15 | 16 | Write a list of what you want this feature to do. 17 | 18 | 1. 19 | 2. 20 | 3. 21 | 22 | ## Open questions (optional) 23 | 24 | Use this section to ask any questions that are related to the feature. 25 | 26 | ## Are you planning to do it yourself in a pull request? 27 | 28 | Yes/No. 29 | -------------------------------------------------------------------------------- /sdk/src/wallet/task.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #[cfg(not(target_family = "wasm"))] 5 | pub(crate) fn spawn(future: F) -> tokio::task::JoinHandle 6 | where 7 | F: futures::Future + Send + 'static, 8 | F::Output: Send + 'static, 9 | { 10 | tokio::task::spawn(future) 11 | } 12 | 13 | #[cfg(target_family = "wasm")] 14 | pub(crate) async fn spawn(future: F) -> crate::wallet::Result 15 | where 16 | F: futures::Future + 'static, 17 | F::Output: 'static, 18 | { 19 | Ok(future.await) 20 | } 21 | -------------------------------------------------------------------------------- /sdk/src/wallet/core/operations/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | pub(crate) mod account_recovery; 5 | pub(crate) mod address_generation; 6 | pub(crate) mod background_syncing; 7 | pub(crate) mod client; 8 | pub(crate) mod get_account; 9 | #[cfg(feature = "ledger_nano")] 10 | pub(crate) mod ledger_nano; 11 | pub(crate) mod storage; 12 | #[cfg(feature = "stronghold")] 13 | pub(crate) mod stronghold; 14 | #[cfg(feature = "stronghold")] 15 | pub(crate) mod stronghold_backup; 16 | #[cfg(debug_assertions)] 17 | pub(crate) mod verify_integrity; 18 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/output_builder_params/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import type { BasicOutputBuilderParams } from './basic-output-params'; 5 | import type { AliasOutputBuilderParams } from './alias-output-params'; 6 | import type { FoundryOutputBuilderParams } from './foundry-output-params'; 7 | import type { NftOutputBuilderParams } from './nft-output-params'; 8 | 9 | export { 10 | BasicOutputBuilderParams, 11 | AliasOutputBuilderParams, 12 | FoundryOutputBuilderParams, 13 | NftOutputBuilderParams, 14 | }; 15 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/logger.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import type { ILoggerConfig } from './types/logger-config'; 5 | import { initLogger as initLoggerBinding } from './bindings'; 6 | 7 | const defaultLoggerConfig: ILoggerConfig = { 8 | colorEnabled: true, 9 | name: './iota-sdk.log', 10 | levelFilter: 'debug', 11 | }; 12 | 13 | /** Initialize logger, if no arguments are provided a default config will be used. */ 14 | export const initLogger = (config: ILoggerConfig = defaultLoggerConfig) => 15 | initLoggerBinding(JSON.stringify(config)); 16 | -------------------------------------------------------------------------------- /sdk/src/client/node_api/mqtt/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /// MQTT related errors. 5 | #[derive(Debug, thiserror::Error)] 6 | pub enum Error { 7 | /// Client error. 8 | #[error("client error {0}")] 9 | Client(#[from] rumqttc::ClientError), 10 | /// Connection not found. 11 | #[error("connection not found")] 12 | ConnectionNotFound, 13 | /// Crypto error. 14 | #[error("crypto error {0}")] 15 | Crypto(#[from] crypto::Error), 16 | /// Invalid topic. 17 | #[error("invalid topic {0}")] 18 | InvalidTopic(String), 19 | } 20 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/rent.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * Defines the parameters of rent cost calculations on objects which take node resources. 6 | */ 7 | export interface IRent { 8 | /** 9 | * Defines the rent of a single virtual byte denoted in IOTA token. 10 | */ 11 | vByteCost: number; 12 | /** 13 | * The factor to be used for data only fields. 14 | */ 15 | vByteFactorData: number; 16 | /** 17 | * The factor to be used for key/lookup generating fields. 18 | */ 19 | vByteFactorKey: number; 20 | } 21 | -------------------------------------------------------------------------------- /bindings/nodejs/scripts/neon-build.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require('path'); 2 | const { spawnSync } = require('child_process'); 3 | const moveArtifact = require('./move-artifact'); 4 | 5 | // Passing "--prepack 'yarn build:neon'" causes problems on Windows, so this is a workaround 6 | 7 | const { status } = spawnSync(process.platform === 'win32' ? 'yarn.cmd' : 'yarn', ['build:neon'], { 8 | stdio: 'inherit', 9 | cwd: resolve(__dirname, '../'), 10 | shell: true 11 | }); 12 | 13 | if (status === null) { 14 | process.exit(1); 15 | } else if (status > 0) { 16 | process.exit(status); 17 | } 18 | 19 | moveArtifact(); 20 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/how_tos/accounts_and_addresses/create-mnemonic.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Utils } from '@iota/sdk'; 5 | 6 | // Run with command: 7 | // yarn run-example ./how_tos/accounts_and_addresses/create-mnemonic.ts 8 | 9 | // In this example we will generate a random BIP39 mnemonic 10 | async function run() { 11 | try { 12 | const mnemonic = Utils.generateMnemonic(); 13 | console.log('Mnemonic: ' + mnemonic); 14 | } catch (error) { 15 | console.error('Error: ', error); 16 | } 17 | } 18 | 19 | run().then(() => process.exit()); 20 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/native-token.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Transform } from 'class-transformer'; 5 | import type { HexEncodedString } from '../utils/hex-encoding'; 6 | import { hexToBigInt } from '../utils/hex-encoding'; 7 | /** 8 | * Native token. 9 | */ 10 | export class INativeToken { 11 | /** 12 | * Identifier of the native token. 13 | */ 14 | id!: HexEncodedString; 15 | /** 16 | * Amount of native tokens of the given Token ID. 17 | */ 18 | @Transform((value) => hexToBigInt(value.value)) 19 | amount!: bigint; 20 | } 21 | -------------------------------------------------------------------------------- /bindings/python/iota_sdk/types/filter_options.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from __future__ import annotations 5 | from dataclasses import dataclass 6 | from typing import List, Optional 7 | 8 | 9 | @dataclass 10 | class FilterOptions: 11 | """Options to filter outputs. 12 | """ 13 | 14 | lowerBoundBookedTimestamp: Optional[int] = None 15 | upperBoundBookedTimestamp: Optional[int] = None 16 | outputTypes: Optional[List[int]] = None 17 | aliasIds: Optional[List[str]] = None 18 | foundryIds: Optional[List[str]] = None 19 | nftIds: Optional[List[str]] = None 20 | -------------------------------------------------------------------------------- /bindings/python/examples/client/post_raw_block.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Client 6 | 7 | load_dotenv() 8 | 9 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 10 | 11 | # Create a Client instance 12 | client = Client(nodes=[node_url]) 13 | 14 | # Create and post a block without payload 15 | block_id = client.build_and_post_block()[0] 16 | blockBytes = client.get_block_raw(block_id) 17 | 18 | # Post raw block 19 | result = client.post_block_raw(blockBytes) 20 | 21 | # Print block raw 22 | print(f'Posted raw block: {os.environ["EXPLORER_URL"]}/block/{result}') 23 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/simple_transaction/request_funds.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | # This example requests funds from the faucet 8 | 9 | load_dotenv() 10 | 11 | FAUCET_URL = os.environ.get( 12 | 'FAUCET_URL', 13 | 'https://faucet.testnet.shimmer.network/api/enqueue') 14 | 15 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 16 | 17 | account = wallet.get_account('Alice') 18 | 19 | address = account.addresses()[0].address 20 | print(address) 21 | 22 | response = wallet.get_client().request_funds_from_faucet(FAUCET_URL, address=address) 23 | print(response) 24 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/exchange/0-generate-mnemonic.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // This example generates a new random mnemonic. 5 | // Run with command: 6 | // yarn run-example ./exchange/0-generate-mnemonic.ts 7 | 8 | import { Utils } from '@iota/sdk'; 9 | 10 | async function run() { 11 | try { 12 | // Set the generated mnemonic as env variable MNEMONIC so it can be used in the next examples. 13 | console.log('Mnemonic:', Utils.generateMnemonic()); 14 | } catch (error) { 15 | console.error(error); 16 | } 17 | } 18 | 19 | run().then(() => process.exit()); 20 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/wallet/signed-transaction-essence.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Type } from 'class-transformer'; 5 | import { TransactionPayload } from '../block/payload/transaction'; 6 | import { InputSigningData } from '../client'; 7 | 8 | /** The signed transaction with inputs data */ 9 | export class SignedTransactionEssence { 10 | /** A transaction payload. */ 11 | @Type(() => TransactionPayload) 12 | transactionPayload!: TransactionPayload; 13 | /** Signed inputs data. */ 14 | @Type(() => InputSigningData) 15 | inputsData!: InputSigningData; 16 | } 17 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/accounts_and_addresses/create_address.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | load_dotenv() 8 | 9 | # This example generates a new address. 10 | 11 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 12 | 13 | if 'STRONGHOLD_PASSWORD' not in os.environ: 14 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 15 | 16 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 17 | 18 | account = wallet.get_account('Alice') 19 | 20 | address = account.generate_ed25519_addresses(1) 21 | print('Generated address:', address[0].address) 22 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/logger-config.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** Logger output configuration. */ 5 | export interface ILoggerConfig { 6 | /** Name of an output file, or `stdout` for standard output.*/ 7 | name?: string; 8 | /** Log level filter of an output.*/ 9 | levelFilter?: 'off' | 'error' | 'warn' | 'info' | 'debug' | 'trace'; 10 | /** Log target filters of an output.*/ 11 | targetFilter?: string[]; 12 | /** Log target exclusions of an output.*/ 13 | targetExclusions?: string[]; 14 | /** Color flag of an output.*/ 15 | colorEnabled?: boolean; 16 | } 17 | -------------------------------------------------------------------------------- /sdk/examples/client/getting_started.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! This examples shows how to get the node info. 5 | //! 6 | //! ```sh 7 | //! cargo run --release --example client_getting_started 8 | //! ``` 9 | 10 | use iota_sdk::client::{Client, Result}; 11 | 12 | #[tokio::main] 13 | async fn main() -> Result<()> { 14 | let client = Client::builder() 15 | .with_node("https://api.testnet.shimmer.network")? // Insert your node URL here 16 | .finish() 17 | .await?; 18 | 19 | let info = client.get_info().await?; 20 | println!("Node Info: {info:?}"); 21 | 22 | Ok(()) 23 | } 24 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/gossip-heartbeat.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * Gossip heartbeat. 6 | */ 7 | export interface IGossipHeartbeat { 8 | /** 9 | * Solid milestone index. 10 | */ 11 | solidMilestoneIndex: number; 12 | /** 13 | * Pruned milestone index. 14 | */ 15 | prunedMilestoneIndex: number; 16 | /** 17 | * Latest milestone index. 18 | */ 19 | latestMilestoneIndex: number; 20 | /** 21 | * Connected peers. 22 | */ 23 | connectedPeers: number; 24 | /** 25 | * Synced peers. 26 | */ 27 | syncedPeers: number; 28 | } 29 | -------------------------------------------------------------------------------- /sdk/src/types/block/payload/transaction/transaction_id.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use core::ops::Deref; 5 | 6 | use crate::types::block::payload::milestone::MilestoneId; 7 | 8 | impl_id!( 9 | pub TransactionId, 10 | 32, 11 | "A transaction identifier, the BLAKE2b-256 hash of the transaction bytes. See for more information." 12 | ); 13 | 14 | #[cfg(feature = "serde")] 15 | string_serde_impl!(TransactionId); 16 | 17 | impl From for TransactionId { 18 | fn from(milestone_id: MilestoneId) -> Self { 19 | Self::new(*milestone_id.deref()) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.github/actions/ledger-nano/action.yml: -------------------------------------------------------------------------------- 1 | name: "ledger-nano-setup" 2 | description: "Setup a simulated ledger nano instance" 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Checkout ledger shimmer app files 7 | uses: actions/checkout@v3 8 | with: 9 | repository: iotaledger/ledger-iota-app 10 | ref: develop 11 | path: ledger-iota-app 12 | 13 | - name: Update submodules 14 | shell: bash 15 | run: git submodule update --init --recursive 16 | working-directory: ledger-iota-app 17 | 18 | - name: Run the simulator 19 | shell: bash 20 | run: ./build.sh -s -v shimmer -b 21 | working-directory: ledger-iota-app 22 | -------------------------------------------------------------------------------- /bindings/nodejs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es2019", "DOM"], 4 | "declaration": true, 5 | "declarationMap": true, 6 | "target": "es2019", 7 | "module": "commonjs", 8 | "sourceMap": true, 9 | "strict": true, 10 | "moduleResolution": "node", 11 | "noImplicitAny": true, 12 | "removeComments": false, 13 | "preserveConstEnums": true, 14 | "outDir": "out", 15 | "resolveJsonModule": true, 16 | "esModuleInterop": true, 17 | "experimentalDecorators": true, 18 | "emitDecoratorMetadata": true 19 | }, 20 | "include": ["lib/**/*", "test"] 21 | } 22 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/number.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use rand::{ 5 | Rng, 6 | distributions::{ 7 | Distribution, Standard, 8 | uniform::{SampleRange, SampleUniform}, 9 | }, 10 | }; 11 | 12 | /// Generates a random number. 13 | pub fn rand_number() -> T 14 | where 15 | Standard: Distribution, 16 | { 17 | rand::thread_rng().gen() 18 | } 19 | 20 | /// Generates a random number within a given range. 21 | pub fn rand_number_range(range: R) -> T 22 | where 23 | T: SampleUniform + PartialOrd, 24 | R: SampleRange, 25 | { 26 | rand::thread_rng().gen_range(range) 27 | } 28 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/output-response.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | import { Output, OutputDiscriminator } from '../../block/output'; 4 | import type { IOutputMetadataResponse } from './output-metadata-response'; 5 | 6 | import { Type } from 'class-transformer'; 7 | 8 | /** 9 | * Details of an output. 10 | */ 11 | export class OutputResponse { 12 | /** 13 | * The metadata about the output. 14 | */ 15 | metadata!: IOutputMetadataResponse; 16 | /** 17 | * The output. 18 | */ 19 | @Type(() => Output, { 20 | discriminator: OutputDiscriminator, 21 | }) 22 | output!: Output; 23 | } 24 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/info/node-info-status.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import type { INodeInfoMilestone } from './node-info-milestone'; 5 | /** 6 | * Response from the /info endpoint. 7 | */ 8 | export interface INodeInfoStatus { 9 | /** 10 | * Is the node healthy. 11 | */ 12 | isHealthy: boolean; 13 | /** 14 | * The latest milestone info. 15 | */ 16 | latestMilestone: INodeInfoMilestone; 17 | /** 18 | * The confirmed milestone info. 19 | */ 20 | confirmedMilestone: INodeInfoMilestone; 21 | /** 22 | * The pruning index. 23 | */ 24 | pruningIndex: number; 25 | } 26 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/client/getting-started.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Client } from '@iota/sdk'; 5 | 6 | // Run with command: 7 | // yarn run-example ./client/getting-started.ts 8 | 9 | // In this example we will get information about the node 10 | async function run() { 11 | const client = new Client({ 12 | nodes: ['https://api.testnet.shimmer.network'], 13 | }); 14 | 15 | try { 16 | const nodeInfo = (await client.getInfo()).nodeInfo; 17 | console.log(nodeInfo); 18 | } catch (error) { 19 | console.error('Error: ', error); 20 | } 21 | } 22 | 23 | run().then(() => process.exit()); 24 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/accounts_and_addresses/check_balance.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from dotenv import load_dotenv 5 | 6 | from iota_sdk import Wallet 7 | 8 | # This example checks the balance of an account. 9 | 10 | # This example uses secrets in environment variables for simplicity which 11 | # should not be done in production. 12 | load_dotenv() 13 | 14 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 15 | 16 | account = wallet.get_account('Alice') 17 | 18 | # Sync account with the node 19 | _balance = account.sync() 20 | 21 | # Just calculate the balance with the known state 22 | balance = account.get_balance() 23 | print(f'Balance {json.dumps(balance.as_dict(), indent=4)}') 24 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/milestone-utxo-changes-response.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import type { HexEncodedString } from '../../utils/hex-encoding'; 5 | /** 6 | * Milestone. 7 | */ 8 | export interface IMilestoneUtxoChangesResponse { 9 | /** 10 | * The milestone index. 11 | */ 12 | index: number; 13 | /** 14 | * The output IDs (transaction hash + output index) of the newly created outputs. 15 | */ 16 | createdOutputs: HexEncodedString[]; 17 | /** 18 | * The output IDs (transaction hash + output index) of the consumed (spent) outputs. 19 | */ 20 | consumedOutputs: HexEncodedString[]; 21 | } 22 | -------------------------------------------------------------------------------- /bindings/wasm/build_scripts/utils/generatePackage.js: -------------------------------------------------------------------------------- 1 | const rootPackage = require('../../package.json') 2 | 3 | module.exports = (options) => { 4 | 5 | const newPackage = { 6 | name: rootPackage.name, 7 | description: rootPackage.description, 8 | version: rootPackage.version, 9 | license: rootPackage.license, 10 | repository: rootPackage.repository, 11 | main: options.main, 12 | module: options.module, 13 | homepage: rootPackage.homepage, 14 | types: options.types, 15 | } 16 | 17 | // remove empty keys 18 | Object.keys(newPackage).forEach(key => newPackage[key] === undefined && delete newPackage[key]) 19 | 20 | return newPackage; 21 | 22 | } -------------------------------------------------------------------------------- /sdk/src/types/block/rand/milestone.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::{ 5 | payload::milestone::{MerkleRoot, MilestoneId, MilestoneIndex}, 6 | rand::{bytes::rand_bytes_array, number::rand_number}, 7 | }; 8 | 9 | /// Generates a random milestone index. 10 | pub fn rand_milestone_index() -> MilestoneIndex { 11 | MilestoneIndex::from(rand_number::()) 12 | } 13 | 14 | /// Generates a random milestone id. 15 | pub fn rand_milestone_id() -> MilestoneId { 16 | MilestoneId::new(rand_bytes_array()) 17 | } 18 | 19 | /// Generates a random merkle root. 20 | pub fn rand_merkle_root() -> MerkleRoot { 21 | MerkleRoot::from(rand_bytes_array()) 22 | } 23 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/receipts-response.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Type } from 'class-transformer'; 5 | import { ReceiptMilestoneOption } from '../milestone_options'; 6 | /** 7 | * Receipts response details. 8 | */ 9 | export class ReceiptsResponse { 10 | /** 11 | * The receipts. 12 | */ 13 | @Type(() => MilestoneReceipt) 14 | receipts!: MilestoneReceipt[]; 15 | } 16 | 17 | export class MilestoneReceipt { 18 | /** 19 | * The milestone index. 20 | */ 21 | milestoneIndex!: number; 22 | /** 23 | * The receipt. 24 | */ 25 | @Type(() => ReceiptMilestoneOption) 26 | receipt!: ReceiptMilestoneOption; 27 | } 28 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/string.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use alloc::string::String; 5 | 6 | use rand::{Rng, distributions::Alphanumeric, thread_rng}; 7 | 8 | /// Generates a random string with a given charset. 9 | pub fn rand_string_charset(charset: &str, len: usize) -> String { 10 | let charset = charset.as_bytes(); 11 | let mut rng = rand::thread_rng(); 12 | 13 | (0..len) 14 | .map(|_| charset[rng.gen_range(0..charset.len())] as char) 15 | .collect() 16 | } 17 | 18 | /// Generates a random string. 19 | pub fn rand_string(len: usize) -> String { 20 | String::from_utf8(thread_rng().sample_iter(&Alphanumeric).take(len).collect()).unwrap() 21 | } 22 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/wallet/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export * from './account'; 5 | export * from './wallet'; 6 | export * from './address'; 7 | export * from './bridge'; 8 | export * from './build-output-data'; 9 | export * from './event'; 10 | export * from './output'; 11 | export * from './output-params'; 12 | export * from './participation'; 13 | export * from './prepared-create-token-transaction'; 14 | export * from './prepared-transaction'; 15 | export * from './signed-transaction-essence'; 16 | export * from './transaction'; 17 | export * from './transaction-options'; 18 | export * from './prepared-create-token-transaction-data'; 19 | export * from './consolidation-params'; 20 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/utils/utf8.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { HexEncodedString } from '../types/utils/hex-encoding'; 5 | 6 | /** Convert UTF8 string to an array of bytes */ 7 | export const utf8ToBytes = (utf8: string) => { 8 | const utf8Encode = new TextEncoder(); 9 | return Array.from(utf8Encode.encode(utf8)); 10 | }; 11 | 12 | /** Convert hex encoded string to UTF8 string */ 13 | export const hexToUtf8 = (hex: HexEncodedString) => 14 | decodeURIComponent(hex.replace(/^0x/, '').replace(/[0-9a-f]{2}/g, '%$&')); 15 | 16 | /** Convert UTF8 string to hex encoded string */ 17 | export const utf8ToHex = (utf8: string) => 18 | '0x' + Buffer.from(utf8, 'utf8').toString('hex'); 19 | -------------------------------------------------------------------------------- /bindings/wasm/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | commonjs: true, 4 | es2019: true, 5 | }, 6 | plugins: ['@typescript-eslint'], 7 | extends: [ 8 | 'eslint:recommended', 9 | 'plugin:@typescript-eslint/recommended', 10 | 'prettier', 11 | ], 12 | parser: '@typescript-eslint/parser', 13 | parserOptions: { 14 | ecmaVersion: 12, 15 | sourceType: 'module', 16 | }, 17 | rules: { 18 | '@typescript-eslint/no-var-requires': 0, 19 | '@typescript-eslint/ban-ts-comment': [ 20 | 'error', 21 | { 'ts-ignore': 'allow-with-description' }, 22 | ], 23 | '@typescript-eslint/no-explicit-any': 'off', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/alias/create.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | load_dotenv() 8 | 9 | # In this example we will create an alias output 10 | 11 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 12 | 13 | account = wallet.get_account('Alice') 14 | 15 | # Sync account with the node 16 | account.sync() 17 | 18 | if 'STRONGHOLD_PASSWORD' not in os.environ: 19 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 20 | 21 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 22 | 23 | # Send transaction. 24 | transaction = account.create_alias_output(None, None) 25 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}') 26 | -------------------------------------------------------------------------------- /bindings/python/examples/wallet/create_alias.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | load_dotenv() 8 | 9 | # In this example we will create an alias output 10 | 11 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 12 | 13 | account = wallet.get_account('Alice') 14 | 15 | # Sync account with the node 16 | account.sync() 17 | 18 | if 'STRONGHOLD_PASSWORD' not in os.environ: 19 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 20 | 21 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 22 | 23 | # Send transaction. 24 | transaction = account.create_alias_output(None, None) 25 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}') 26 | -------------------------------------------------------------------------------- /sdk/tests/types/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod address; 5 | mod api; 6 | #[cfg(feature = "pow")] 7 | mod block; 8 | mod block_id; 9 | mod ed25519_signature; 10 | mod foundry_id; 11 | mod input; 12 | mod migrated_funds_entry; 13 | mod milestone_id; 14 | mod milestone_index; 15 | mod milestone_payload; 16 | mod milestone_payload_essence; 17 | mod output_id; 18 | mod parents; 19 | mod payload; 20 | mod receipt_milestone_option; 21 | mod rent; 22 | mod tagged_data_payload; 23 | mod tail_transaction_hash; 24 | mod transaction_essence; 25 | mod transaction_id; 26 | mod transaction_payload; 27 | mod transaction_regular_essence; 28 | mod treasury_output; 29 | mod treasury_transaction_payload; 30 | mod unlock; 31 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/id.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { HexEncodedString } from '../utils'; 5 | 6 | /** 7 | * An Alias ID represented as hex-encoded string. 8 | */ 9 | export type AliasId = HexEncodedString; 10 | 11 | /** 12 | * An NFT ID represented as hex-encoded string. 13 | */ 14 | export type NftId = HexEncodedString; 15 | 16 | /** 17 | * A Block ID represented as hex-encoded string. 18 | */ 19 | export type BlockId = HexEncodedString; 20 | 21 | /** 22 | * A Token ID represented as hex-encoded string. 23 | */ 24 | export type TokenId = HexEncodedString; 25 | 26 | /** 27 | * A Foundry ID represented as hex-encoded string. 28 | */ 29 | export type FoundryId = HexEncodedString; 30 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/info/node-info-base-token.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * The base token info of the node. 6 | */ 7 | export interface INodeInfoBaseToken { 8 | /** 9 | * The base token name. 10 | */ 11 | name: string; 12 | /** 13 | * The base token ticker symbol. 14 | */ 15 | tickerSymbol: string; 16 | /** 17 | * The base token unit. 18 | */ 19 | unit: string; 20 | /** 21 | * The base token sub-unit. 22 | */ 23 | subunit?: string; 24 | /** 25 | * The base token decimals. 26 | */ 27 | decimals: number; 28 | /** 29 | * The use metric prefix flag. 30 | */ 31 | useMetricPrefix: boolean; 32 | } 33 | -------------------------------------------------------------------------------- /sdk/src/wallet/account/types/participation.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use serde::{Deserialize, Serialize}; 5 | 6 | use crate::{client::node_manager::node::Node, types::api::plugins::participation::types::ParticipationEventId}; 7 | 8 | /// Options when registering participation events. 9 | /// If `events_to_register` is an empty `Vec` or `None`, then every event being tracked by the node will be registered. 10 | #[derive(Debug, Clone, Serialize, Deserialize)] 11 | #[serde(rename_all = "camelCase")] 12 | pub struct ParticipationEventRegistrationOptions { 13 | pub node: Node, 14 | pub events_to_register: Option>, 15 | pub events_to_ignore: Option>, 16 | } 17 | -------------------------------------------------------------------------------- /bindings/python/examples/client/logger.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from dotenv import load_dotenv 5 | 6 | # pylint: disable=no-name-in-module 7 | from iota_sdk import Client, init_logger 8 | 9 | load_dotenv() 10 | 11 | # Create the log configuration, the log will be outputted in 'client.log' 12 | log_config = { 13 | 'name': 'client.log', 14 | 'levelFilter': 'debug', 15 | 'targetExclusions': ["h2", "hyper", "rustls"] 16 | } 17 | 18 | log_config_str = json.dumps(log_config) 19 | 20 | init_logger(log_config_str) 21 | 22 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 23 | 24 | # Create a Client instance 25 | client = Client(nodes=[node_url]) 26 | 27 | # Get the node info 28 | node_info = client.get_info() 29 | print(f'{node_info}') 30 | -------------------------------------------------------------------------------- /bindings/python/iota_sdk/types/consolidation_params.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from dataclasses import dataclass 5 | from typing import Optional 6 | 7 | 8 | @dataclass 9 | class ConsolidationParams: 10 | """Parameters for consolidation. 11 | 12 | Attributes: 13 | force (bool): 14 | Ignores the output_threshold if set to `true`. 15 | outputThreshold (Optional[int]): 16 | Consolidates if the output number is >= the output_threshold. 17 | targetAddress (Optional[str]): 18 | Address to which the consolidated output should be sent. 19 | """ 20 | 21 | force: bool 22 | outputThreshold: Optional[int] = None 23 | targetAddress: Optional[str] = None 24 | -------------------------------------------------------------------------------- /sdk/src/types/block/convert.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::Error; 5 | 6 | pub trait ConvertTo: Send + Sized { 7 | fn convert(self) -> Result; 8 | 9 | fn convert_unchecked(self) -> T { 10 | self.convert().unwrap() 11 | } 12 | } 13 | 14 | impl ConvertTo for T { 15 | fn convert(self) -> Result { 16 | Ok(self) 17 | } 18 | 19 | fn convert_unchecked(self) -> T { 20 | self 21 | } 22 | } 23 | 24 | impl ConvertTo for &T { 25 | fn convert(self) -> Result { 26 | Ok(*self) 27 | } 28 | 29 | fn convert_unchecked(self) -> T { 30 | *self 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/nfts/burn_nft.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | load_dotenv() 8 | 9 | # In this example we will burn an NFT 10 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 11 | 12 | if 'STRONGHOLD_PASSWORD' not in os.environ: 13 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 14 | 15 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 16 | 17 | account = wallet.get_account('Alice') 18 | 19 | # Sync account with the node 20 | balance = account.sync() 21 | 22 | nftId = balance.nfts[0] 23 | 24 | # Send transaction. 25 | transaction = account.prepare_burn_nft(nftId).send() 26 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}') 27 | -------------------------------------------------------------------------------- /bindings/core/tests/serialize_error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use iota_sdk::{client::Error as ClientError, wallet::Error as WalletError}; 5 | use iota_sdk_bindings_core::Error; 6 | use pretty_assertions::assert_eq; 7 | 8 | #[test] 9 | fn custom_error_serialization() { 10 | let error = Error::Client(ClientError::HealthyNodePoolEmpty); 11 | assert_eq!( 12 | serde_json::to_string(&error).unwrap(), 13 | "{\"type\":\"client\",\"error\":\"no healthy node available\"}" 14 | ); 15 | let error = Error::Wallet(WalletError::AccountNotFound("Alice".to_string())); 16 | assert_eq!( 17 | serde_json::to_string(&error).unwrap(), 18 | "{\"type\":\"wallet\",\"error\":\"account Alice not found\"}" 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/secret_manager/bridge/index.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | __GenerateEd25519AddressesMethod__, 3 | __GenerateEvmAddressesMethod__, 4 | __GetLedgerNanoStatusMethod__, 5 | __SignTransactionMethod__, 6 | __StoreMnemonicMethod__, 7 | __GetSeedMethod__, 8 | __SignatureUnlockMethod__, 9 | __SignEd25519Method__, 10 | __SignSecp256k1EcdsaMethod__, 11 | } from './secret-manager'; 12 | 13 | export type __SecretManagerMethods__ = 14 | | __GenerateEd25519AddressesMethod__ 15 | | __GenerateEvmAddressesMethod__ 16 | | __GetLedgerNanoStatusMethod__ 17 | | __SignTransactionMethod__ 18 | | __SignatureUnlockMethod__ 19 | | __StoreMnemonicMethod__ 20 | | __GetSeedMethod__ 21 | | __SignEd25519Method__ 22 | | __SignSecp256k1EcdsaMethod__; 23 | -------------------------------------------------------------------------------- /bindings/python/examples/client/07_get_block_data.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | from dataclasses import asdict 4 | 5 | from dotenv import load_dotenv 6 | 7 | from iota_sdk import Client 8 | 9 | load_dotenv() 10 | 11 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 12 | 13 | # Create a Client instance 14 | client = Client(nodes=[node_url]) 15 | 16 | # Fetch a block ID from the node 17 | block_ids = client.get_tips() 18 | print(f'Block id: {block_ids[0]}') 19 | 20 | # Get the metadata for the block 21 | metadata = client.get_block_metadata(block_ids[0]) 22 | print(f'Block metadata: {json.dumps(asdict(metadata), indent=4)}') 23 | 24 | # Request the block by its id 25 | block = client.get_block_data(block_ids[0]) 26 | print(f'Block: {json.dumps(asdict(block), indent=4)}') 27 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/output_builder_params/nft-output-params.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Feature, NftId } from '../..'; 5 | import type { BasicOutputBuilderParams } from './basic-output-params'; 6 | 7 | /** 8 | * Options for building an Nft Output 9 | */ 10 | export interface NftOutputBuilderParams extends BasicOutputBuilderParams { 11 | /** 12 | * Unique identifier of an NFT, which is the BLAKE2b-256 hash of the Output ID that created it. 13 | */ 14 | nftId: NftId; 15 | /** 16 | * Features that add utility to the output but do not impose unlocking conditions. 17 | * These features need to be kept in future transitions of the UTXO state machine. 18 | */ 19 | immutableFeatures?: Feature[]; 20 | } 21 | -------------------------------------------------------------------------------- /sdk/src/types/api/core/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::Error as BlockError; 5 | 6 | #[derive(Debug)] 7 | pub enum Error { 8 | InvalidField(&'static str), 9 | Block(BlockError), 10 | } 11 | 12 | impl core::fmt::Display for Error { 13 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 14 | match self { 15 | Self::InvalidField(field) => write!(f, "invalid field \"{field}\""), 16 | Self::Block(error) => write!(f, "{error}"), 17 | } 18 | } 19 | } 20 | 21 | impl From for Error { 22 | fn from(error: BlockError) -> Self { 23 | Self::Block(error) 24 | } 25 | } 26 | 27 | #[cfg(feature = "std")] 28 | impl std::error::Error for Error {} 29 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/milestone_option.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::{ 5 | payload::milestone::ReceiptMilestoneOption, 6 | rand::{ 7 | bool::rand_bool, milestone::rand_milestone_index, payload::rand_treasury_transaction_payload, 8 | receipt::rand_migrated_funds_entry, 9 | }, 10 | }; 11 | 12 | /// Generates a random receipt milestone option. 13 | pub fn rand_receipt_milestone_option(token_supply: u64) -> ReceiptMilestoneOption { 14 | ReceiptMilestoneOption::new( 15 | rand_milestone_index(), 16 | rand_bool(), 17 | [rand_migrated_funds_entry(token_supply)], 18 | rand_treasury_transaction_payload(token_supply), 19 | token_supply, 20 | ) 21 | .unwrap() 22 | } 23 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/migrated-funds.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Type } from 'class-transformer'; 5 | import { Address, AddressDiscriminator } from '../block/address'; 6 | import type { HexEncodedString } from '../utils/hex-encoding'; 7 | /** 8 | * The migrated funds for receipts. 9 | */ 10 | export class MigratedFunds { 11 | /** 12 | * The tail transaction hash of the migration bundle. 13 | */ 14 | tailTransactionHash!: HexEncodedString; 15 | /** 16 | * The target address of the migrated funds. 17 | */ 18 | @Type(() => Address, { 19 | discriminator: AddressDiscriminator, 20 | }) 21 | address!: Address; 22 | /** 23 | * The amount of the deposit. 24 | */ 25 | deposit!: string; 26 | } 27 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/utils/hex-encoding.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * Hex encoded bytes. 6 | */ 7 | export declare type HexEncodedString = string; 8 | /** 9 | * Hex encoded U256. 10 | */ 11 | export declare type HexEncodedAmount = string; 12 | 13 | /** 14 | * Converts `bigint` value to hexadecimal string representation prefixed with "0x". 15 | */ 16 | export function bigIntToHex(value: bigint): string { 17 | return '0x' + value.toString(16); 18 | } 19 | 20 | /** 21 | * Converts hex encoded string to `bigint` value. 22 | */ 23 | export function hexToBigInt( 24 | value: HexEncodedAmount | HexEncodedString, 25 | ): bigint { 26 | if (!value.startsWith('0x')) { 27 | value = '0x' + value; 28 | } 29 | return BigInt(value); 30 | } 31 | -------------------------------------------------------------------------------- /bindings/nodejs/tests/fixtures/offlineSigningAddresses.ts: -------------------------------------------------------------------------------- 1 | export const addresses = [ 2 | 'rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy', 3 | 'rms1qzzk86qv30l4e85ljtccxa0ruy8y7u8zn2dle3g8dv2tl2m4cu227a7n2wj', 4 | 'rms1qqjrtmslm36l3lyd8086w9qdxd9mudu2z2qyywlltpycn2ftxsdmu9ulj47', 5 | 'rms1qzz75j5h7vd5melxwersz49jja36m2vvnawedu0l6rlhg70ylzqp52lx8zf', 6 | 'rms1qzvs2rvq5ef79vhuel354mnvzfz049gyyf808zmjculuatt56u92vc4v4p3', 7 | 'rms1qpk0dj5lmv5r8d64f3x0qwx3jccredwa42xscdreqma73f3dxymaqdy645t', 8 | 'rms1qqlp6nurrz459jvvvuhv6t965v6cmlata57kf6auv6955uyp77uyw0egzgn', 9 | 'rms1qq2tu523zqzjxgdl69au8a9yewmd9ztctssv40dsv7lfd0tp36w4xdfzcyr', 10 | 'rms1qpw904c253cc9yn2dkhxx89u6r5j9vzezfatchrlugrkcvvhed3hckx6h2u', 11 | 'rms1qpa646cegkqsx9eht793nmux2vjwa63jrenqe87xq8j5wysfhu4l28k4ep9', 12 | ]; 13 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/output/metadata.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::{ 5 | output::OutputMetadata, 6 | rand::{ 7 | block::rand_block_id, bool::rand_bool, number::rand_number, option::rand_option, output::rand_output_id, 8 | transaction::rand_transaction_id, 9 | }, 10 | }; 11 | 12 | /// Generates a random [`OutputMetadata`]. 13 | pub fn rand_output_metadata() -> OutputMetadata { 14 | OutputMetadata::new( 15 | rand_block_id(), 16 | rand_output_id(), 17 | rand_bool(), 18 | rand_option(rand_number()), 19 | rand_option(rand_number()), 20 | rand_option(rand_transaction_id()), 21 | rand_number(), 22 | rand_number(), 23 | rand_number(), 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /bindings/wasm/src/utils.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use iota_sdk_bindings_core::{UtilsMethod, call_utils_method as rust_call_utils_method}; 5 | use wasm_bindgen::{JsValue, prelude::wasm_bindgen}; 6 | 7 | /// Handles a method, returns the response as a JSON-encoded string. 8 | /// 9 | /// Returns an error if the response itself is an error or panic. 10 | #[wasm_bindgen(js_name = callUtilsMethodRust)] 11 | #[allow(non_snake_case)] 12 | pub fn call_utils_method(method: String) -> Result { 13 | let method: UtilsMethod = serde_json::from_str(&method).map_err(|err| err.to_string())?; 14 | let response = rust_call_utils_method(method); 15 | Ok(JsValue::from( 16 | serde_json::to_string(&response).map_err(|err| err.to_string())?, 17 | )) 18 | } 19 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/input.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::{ 5 | input::{Input, TreasuryInput, UtxoInput}, 6 | rand::{milestone::rand_milestone_id, number::rand_number, output::rand_output_id}, 7 | }; 8 | 9 | /// Generates a random Utxo input. 10 | pub fn rand_utxo_input() -> UtxoInput { 11 | rand_output_id().into() 12 | } 13 | 14 | /// Generates a random treasury input. 15 | pub fn rand_treasury_input() -> TreasuryInput { 16 | TreasuryInput::new(rand_milestone_id()) 17 | } 18 | 19 | /// Generates a random input. 20 | pub fn rand_input() -> Input { 21 | match rand_number::() % 2 { 22 | 0 => rand_utxo_input().into(), 23 | 1 => rand_treasury_input().into(), 24 | _ => unreachable!(), 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/output_builder_params/basic-output-params.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { UnlockCondition, Feature, INativeToken, NumericString } from '../..'; 5 | 6 | /** 7 | * Options for building a Basic Output 8 | */ 9 | export interface BasicOutputBuilderParams { 10 | /** 11 | * If not provided, minimum storage deposit will be used 12 | */ 13 | amount?: bigint | NumericString; 14 | /** 15 | * The native tokens to be held by the output. 16 | */ 17 | nativeTokens?: INativeToken[]; 18 | /** 19 | * The unlock conditions for the output. 20 | */ 21 | unlockConditions: UnlockCondition[]; 22 | /** 23 | * Features to be contained by the output. 24 | */ 25 | features?: Feature[]; 26 | } 27 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/sign_and_verify_ed25519/verify_ed25519_signature.py: -------------------------------------------------------------------------------- 1 | from iota_sdk import Ed25519Signature, Utils, utf8_to_hex 2 | 3 | # In this example we will verify an Ed25519 signature. 4 | 5 | FOUNDRY_METADATA = '{"standard":"IRC30","name":"NativeToken","description":"A native token","symbol":"NT","decimals":6,"logoUrl":"https://my.website/nativeToken.png"}' 6 | PUBLIC_KEY = "0x67b7fc3f78763c9394fc4fcdb52cf3a973b6e064bdc3defb40a6cb2c880e6f5c" 7 | ED25519_SIGNATURE = "0x5437ee671f182507103c6ae2f6649083475019f2cc372e674be164577dd123edd7a76291ba88732bbe1fae39688b50a3678bce05c9ef32c9494b3968f4f07a01" 8 | 9 | message = utf8_to_hex(FOUNDRY_METADATA) 10 | validSignature = Utils.verify_ed25519_signature( 11 | Ed25519Signature(PUBLIC_KEY, ED25519_SIGNATURE), 12 | message, 13 | ) 14 | print(f'Valid signature: {validSignature}') 15 | -------------------------------------------------------------------------------- /.github/actions/setup-clang/action.yml: -------------------------------------------------------------------------------- 1 | name: Set Up Clang/LLVM 2 | description: "This composite action installs Clang/LLVM to the runner's temporary directory and sets LIBCLANG_PATH for the following steps, which is required for bindgen to work on Windows. See: https://github.com/rust-lang/rust-bindgen/issues/1797." 3 | inputs: 4 | version: 5 | description: The version of Clang/LLVM to install. 6 | type: string 7 | required: false 8 | default: '13' 9 | 10 | runs: 11 | using: composite 12 | steps: 13 | - name: Install Clang/LLVM 14 | uses: KyleMayes/install-llvm-action@v1 15 | with: 16 | version: ${{ inputs.version }} 17 | directory: ${{ runner.temp }}/llvm/ 18 | 19 | - name: Set LIBCLANG_PATH 20 | shell: pwsh 21 | run: Add-Content -Path "$Env:GITHUB_ENV" -Value "LIBCLANG_PATH=$Env:LLVM_PATH\bin" 22 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/nfts/mint_nft.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import MintNftParams, Wallet, utf8_to_hex 6 | 7 | load_dotenv() 8 | 9 | # In this example we will mint an nft 10 | 11 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 12 | 13 | if 'STRONGHOLD_PASSWORD' not in os.environ: 14 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 15 | 16 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 17 | 18 | account = wallet.get_account('Alice') 19 | 20 | # Sync account with the node 21 | response = account.sync() 22 | 23 | outputs = [MintNftParams( 24 | immutableMetadata=utf8_to_hex("some immutable nft metadata"), 25 | )] 26 | 27 | transaction = account.mint_nfts(outputs) 28 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}') 29 | -------------------------------------------------------------------------------- /bindings/python/iota_sdk/types/event.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from enum import IntEnum 5 | 6 | 7 | class WalletEventType(IntEnum): 8 | """Types of wallet events. 9 | 10 | Attributes: 11 | ConsolidationRequired (0): Consolidation is required. 12 | LedgerAddressGeneration (1): Nano Ledger has generated an address. 13 | NewOutput (2): A new output was created. 14 | SpentOutput (3): An output was spent. 15 | TransactionInclusion (4): A transaction was included into the ledger. 16 | TransactionProgress (5): A progress update while submitting a transaction. 17 | """ 18 | ConsolidationRequired = 0 19 | LedgerAddressGeneration = 1 20 | NewOutput = 2 21 | SpentOutput = 3 22 | TransactionInclusion = 4 23 | TransactionProgress = 5 24 | -------------------------------------------------------------------------------- /sdk/tests/wallet/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | mod account_recovery; 5 | mod accounts; 6 | mod address_generation; 7 | #[cfg(all(feature = "stronghold", feature = "storage"))] 8 | mod backup_restore; 9 | mod balance; 10 | mod bech32_hrp_validation; 11 | mod burn_outputs; 12 | #[cfg(not(target_os = "windows"))] 13 | #[cfg(all(feature = "stronghold", feature = "storage"))] 14 | mod chrysalis_migration; 15 | mod claim_outputs; 16 | mod common; 17 | mod consolidation; 18 | mod core; 19 | mod error; 20 | #[cfg(feature = "events")] 21 | mod events; 22 | #[cfg(feature = "stronghold")] 23 | mod migrate_stronghold_snapshot_v2_to_v3; 24 | mod native_tokens; 25 | mod output_preparation; 26 | mod syncing; 27 | mod transactions; 28 | #[cfg(not(target_os = "windows"))] 29 | #[cfg(feature = "rocksdb")] 30 | mod wallet_storage; 31 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/alias/destroy.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | load_dotenv() 8 | 9 | # In this example we will destroy an alias output 10 | 11 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 12 | 13 | account = wallet.get_account('Alice') 14 | 15 | # Sync account with the node 16 | balance = account.sync() 17 | 18 | # We try to destroy the first alias in the account 19 | alias_id = balance.aliases[0] 20 | 21 | if 'STRONGHOLD_PASSWORD' not in os.environ: 22 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 23 | 24 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 25 | 26 | # Send transaction. 27 | transaction = account.prepare_destroy_alias(alias_id).send() 28 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}') 29 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/milestone_options/milestone-options.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * All of the milestone option types. 6 | */ 7 | enum MilestoneOptionType { 8 | /** The Receipt milestone option. */ 9 | Receipt = 0, 10 | /** The ProtocolParams milestone option. */ 11 | ProtocolParams = 1, 12 | } 13 | 14 | abstract class MilestoneOption { 15 | readonly type: MilestoneOptionType; 16 | 17 | /** 18 | * @param type The type of milestone option. 19 | */ 20 | constructor(type: MilestoneOptionType) { 21 | this.type = type; 22 | } 23 | 24 | /** 25 | * Get the type of milestone option. 26 | */ 27 | getType(): MilestoneOptionType { 28 | return this.type; 29 | } 30 | } 31 | 32 | export { MilestoneOptionType, MilestoneOption }; 33 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examples", 3 | "version": "1.0.0", 4 | "main": "dist/index.js", 5 | "private": true, 6 | "scripts": { 7 | "preinstall": "cd ../ && yarn && yarn link && cd examples && yarn link @iota/sdk", 8 | "build": "tsc", 9 | "run-example": "ts-node" 10 | }, 11 | "dependencies": { 12 | "class-transformer": "^0.5.1", 13 | "dotenv": "^16.0.0", 14 | "ts-node": "^10.9.1" 15 | }, 16 | "devDependencies": { 17 | "@ethereumjs/common": "^3.1.2", 18 | "@ethereumjs/rlp": "^4.0.1", 19 | "@ethereumjs/tx": "^4.1.2", 20 | "@ethereumjs/util": "^8.0.6", 21 | "typescript": "^4.6.3", 22 | "undici-types": "^6.0.1", 23 | "web3": "^1.10.0" 24 | }, 25 | "resolutions": { 26 | "tough-cookie": "^4.1.3" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /bindings/wasm/build_scripts/copyNodejsDefs.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fse = require('fs-extra'); 3 | 4 | // Copy the TypeScript definitions from the Node.js bindings. 5 | const nodejsBindingsDir = path.join(__dirname, '..', '..', 'nodejs'); 6 | const outDir = path.join(__dirname, '..', 'out'); 7 | const folders = ['lib']; 8 | for (const folder of folders) { 9 | const sourceDir = path.join(nodejsBindingsDir, folder); 10 | const destDir = path.join(outDir, folder); 11 | fse.copySync(sourceDir, destDir, { 'overwrite': true }); 12 | } 13 | 14 | // Overwrite the Node.js `bindings.ts` file with one which links to Wasm functions instead. 15 | const bindingsSrc = path.join(__dirname, '..', 'lib', 'bindings.ts'); 16 | const bindingsDest = path.join(__dirname, '..', 'out', 'lib', 'bindings.ts'); 17 | fse.copySync(bindingsSrc, bindingsDest, { 'overwrite': true }); 18 | -------------------------------------------------------------------------------- /sdk/src/wallet/storage/kind.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use serde::{Deserialize, Serialize}; 5 | 6 | /// The kind of storage used by the manager. 7 | #[derive(Debug, Clone, Copy, Serialize, Deserialize)] 8 | #[non_exhaustive] 9 | pub enum StorageKind { 10 | /// RocksDB storage. 11 | #[cfg(feature = "rocksdb")] 12 | Rocksdb, 13 | /// Storage backed by a Map in memory. 14 | Memory, 15 | /// Wasm storage. 16 | #[cfg(target_family = "wasm")] 17 | Wasm, 18 | } 19 | 20 | impl Default for StorageKind { 21 | fn default() -> Self { 22 | #[cfg(feature = "rocksdb")] 23 | return Self::Rocksdb; 24 | #[cfg(target_family = "wasm")] 25 | return Self::Wasm; 26 | #[cfg(not(any(feature = "rocksdb", target_family = "wasm")))] 27 | Self::Memory 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/generate-addresses-options.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | import type { CoinType } from './constants'; 4 | import type { IRange } from './range'; 5 | 6 | /** 7 | * Input options for GenerateAddresses 8 | */ 9 | export interface IGenerateAddressesOptions { 10 | coinType?: CoinType; 11 | accountIndex?: number; 12 | range?: IRange; 13 | /** 14 | * Bech32 human readable part 15 | */ 16 | bech32Hrp?: string; 17 | options?: IGenerateAddressOptions; 18 | } 19 | 20 | /** 21 | * Options provided to Generate Address 22 | */ 23 | export interface IGenerateAddressOptions { 24 | /** 25 | * Internal addresses 26 | */ 27 | internal?: boolean; 28 | /** 29 | * Display the address on ledger devices. 30 | */ 31 | ledgerNanoPrompt?: boolean; 32 | } 33 | -------------------------------------------------------------------------------- /bindings/python/examples/exchange/2_generate_address.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | # This example generates an address for an account. 5 | 6 | import os 7 | 8 | from dotenv import load_dotenv 9 | 10 | from iota_sdk import Wallet 11 | 12 | # This example uses secrets in environment variables for simplicity which 13 | # should not be done in production. 14 | load_dotenv() 15 | 16 | for env_var in ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD']: 17 | if env_var not in os.environ: 18 | raise Exception(f'.env {env_var} is undefined, see .env.example') 19 | 20 | wallet = Wallet(os.environ.get('WALLET_DB_PATH')) 21 | 22 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 23 | 24 | account = wallet.get_account('Alice') 25 | 26 | address = account.generate_ed25519_addresses(1)[0] 27 | print('Address:', address.address) 28 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/nfts/send_nft.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import SendNftParams, Wallet 6 | 7 | load_dotenv() 8 | 9 | # In this example we will send an nft 10 | 11 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 12 | 13 | if 'STRONGHOLD_PASSWORD' not in os.environ: 14 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 15 | 16 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 17 | 18 | account = wallet.get_account('Alice') 19 | 20 | # Sync account with the node 21 | balance = account.sync() 22 | 23 | outputs = [SendNftParams( 24 | address="rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu", 25 | nftId=balance.nfts[0], 26 | )] 27 | 28 | transaction = account.send_nft(outputs) 29 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}') 30 | -------------------------------------------------------------------------------- /sdk/src/types/block/output/nft_id.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::{ 5 | address::{Address, NftAddress}, 6 | output::OutputId, 7 | }; 8 | 9 | impl_id!(pub NftId, 32, "Unique identifier of an NFT, which is the BLAKE2b-256 hash of the Output ID that created it."); 10 | 11 | #[cfg(feature = "serde")] 12 | string_serde_impl!(NftId); 13 | 14 | impl From<&OutputId> for NftId { 15 | fn from(output_id: &OutputId) -> Self { 16 | Self::from(output_id.hash()) 17 | } 18 | } 19 | 20 | impl NftId { 21 | /// 22 | pub fn or_from_output_id(self, output_id: &OutputId) -> Self { 23 | if self.is_null() { Self::from(output_id) } else { self } 24 | } 25 | } 26 | 27 | impl From for Address { 28 | fn from(value: NftId) -> Self { 29 | Self::Nft(NftAddress::new(value)) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /bindings/nodejs/.eslintrc.js: -------------------------------------------------------------------------------- 1 | const typescriptEslintRules = { 2 | '@typescript-eslint/ban-ts-comment': [ 3 | 'error', 4 | { 'ts-ignore': 'allow-with-description' }, 5 | ], 6 | '@typescript-eslint/no-empty-interface': 'off', 7 | '@typescript-eslint/no-var-requires': 'off', // cleanest way to set dotenv path 8 | '@typescript-eslint/no-explicit-any': 'off', 9 | }; 10 | 11 | module.exports = { 12 | env: { 13 | node: true, 14 | commonjs: true, 15 | es2019: true, 16 | }, 17 | plugins: ['@typescript-eslint'], 18 | extends: [ 19 | 'eslint:recommended', 20 | 'plugin:@typescript-eslint/recommended', 21 | 'prettier', 22 | ], 23 | parser: '@typescript-eslint/parser', 24 | parserOptions: { 25 | ecmaVersion: 12, 26 | sourceType: 'module', 27 | }, 28 | rules: typescriptEslintRules, 29 | }; 30 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/payload/tagged/tagged.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { HexEncodedString } from '../../../utils/hex-encoding'; 5 | import { Payload, PayloadType } from '../payload'; 6 | 7 | /** 8 | * A Tagged Data payload. 9 | */ 10 | class TaggedDataPayload extends Payload { 11 | /** 12 | * The tag to use to categorize the data. 13 | */ 14 | tag: HexEncodedString; 15 | /** 16 | * The index data. 17 | */ 18 | data: HexEncodedString; 19 | /** 20 | * @param tag A tag as hex-encoded string. 21 | * @param data Index data as hex-encoded string. 22 | */ 23 | constructor(tag: HexEncodedString, data: HexEncodedString) { 24 | super(PayloadType.TaggedData); 25 | this.tag = tag; 26 | this.data = data; 27 | } 28 | } 29 | 30 | export { TaggedDataPayload }; 31 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/milestone_options/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { MilestoneOptionType } from './milestone-options'; 5 | import { ProtocolParamsMilestoneOption } from './protocol-params-milestone-option'; 6 | import { ReceiptMilestoneOption } from './receipt-milestone-option'; 7 | 8 | export * from './protocol-params-milestone-option'; 9 | export * from './receipt-milestone-option'; 10 | export * from './milestone-options'; 11 | 12 | export const MilestoneOptionDiscriminator = { 13 | property: 'type', 14 | subTypes: [ 15 | { 16 | value: ReceiptMilestoneOption, 17 | name: MilestoneOptionType.Receipt as any, 18 | }, 19 | { 20 | value: ProtocolParamsMilestoneOption, 21 | name: MilestoneOptionType.ProtocolParams as any, 22 | }, 23 | ], 24 | }; 25 | -------------------------------------------------------------------------------- /bindings/python/examples/client/09_transaction.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import AddressAndAmount, Client, MnemonicSecretManager 6 | 7 | load_dotenv() 8 | 9 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 10 | 11 | # Create a Client instance 12 | client = Client(nodes=[node_url]) 13 | 14 | if 'MNEMONIC' not in os.environ: 15 | raise Exception(".env MNEMONIC is undefined, see .env.example") 16 | 17 | secret_manager = MnemonicSecretManager( 18 | os.environ['MNEMONIC']) 19 | 20 | address_and_amount = AddressAndAmount( 21 | 1000000, 22 | 'rms1qzpf0tzpf8yqej5zyhjl9k3km7y6j0xjnxxh7m2g3jtj2z5grej67sl6l46', 23 | ) 24 | 25 | # Create and post a block with a transaction 26 | block = client.build_and_post_block(secret_manager, output=address_and_amount) 27 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{block[0]}') 28 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/accounts_and_addresses/list_outputs.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | # In this example we will get outputs stored in the account 8 | 9 | # This example uses secrets in environment variables for simplicity which 10 | # should not be done in production. 11 | load_dotenv() 12 | 13 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 14 | 15 | account = wallet.get_account('Alice') 16 | account.sync() 17 | 18 | # All outputs stored in the account 19 | outputs = account.outputs() 20 | 21 | # Print all output ids 22 | print('Output ids:') 23 | for output in outputs: 24 | print(output.outputId) 25 | 26 | # All unspent outputs stored in the account 27 | outputs = account.unspent_outputs() 28 | 29 | # Print all unspent output ids 30 | print('Unspent output ids:') 31 | for output in outputs: 32 | print(output.outputId) 33 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/simple_transaction/simple_transaction.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import SendParams, Wallet 6 | 7 | load_dotenv() 8 | 9 | # This example sends a transaction. 10 | 11 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 12 | 13 | account = wallet.get_account('Alice') 14 | 15 | # Sync account with the node 16 | response = account.sync() 17 | 18 | if 'STRONGHOLD_PASSWORD' not in os.environ: 19 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 20 | 21 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 22 | 23 | params = [SendParams( 24 | address="rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu", 25 | amount=1000000, 26 | )] 27 | 28 | transaction = account.send_with_params(params) 29 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}') 30 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/block.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import type { HexEncodedString } from '../utils/hex-encoding'; 5 | import { Payload, PayloadDiscriminator } from './payload'; 6 | import { Type } from 'class-transformer'; 7 | import { NumericString } from '../utils/numeric'; 8 | 9 | /** 10 | * Block layout. 11 | */ 12 | export class Block { 13 | /** 14 | * The protocol version under which this block operates. 15 | */ 16 | protocolVersion!: number; 17 | /** 18 | * The parent block ids. 19 | */ 20 | parents!: HexEncodedString[]; 21 | /** 22 | * The payload contents. 23 | */ 24 | @Type(() => Payload, { 25 | discriminator: PayloadDiscriminator, 26 | }) 27 | payload?: Payload; 28 | /** 29 | * The nonce for the block. 30 | */ 31 | nonce!: NumericString; 32 | } 33 | -------------------------------------------------------------------------------- /bindings/python/examples/client/08_data_block.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | from dataclasses import asdict 4 | 5 | from dotenv import load_dotenv 6 | 7 | from iota_sdk import Client, hex_to_utf8, utf8_to_hex 8 | 9 | load_dotenv() 10 | 11 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 12 | 13 | # Create a Client instance 14 | client = Client(nodes=[node_url]) 15 | 16 | # Create and post a block with a tagged data payload 17 | block = client.build_and_post_block( 18 | tag=utf8_to_hex('hello'), data=utf8_to_hex('hello')) 19 | 20 | print(f'Data block sent: {os.environ["EXPLORER_URL"]}/block/{block[0]}') 21 | 22 | block = client.get_block_data(block[0]) 23 | print(f'Block data: {json.dumps(asdict(block), indent=4)}') 24 | 25 | payload = block.payload 26 | 27 | if payload and 'data' in payload and payload['data']: 28 | print(f'Decoded data: { hex_to_utf8(payload["data"]) }') 29 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/api/plugins/indexer/output-response.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { NumericString } from '../../../../utils'; 5 | import type { HexEncodedString } from '../../../../utils/hex-encoding'; 6 | 7 | /** 8 | * Details of an outputs response from the indexer plugin. 9 | */ 10 | export interface IOutputsResponse { 11 | /** 12 | * The ledger index at which these outputs where available at. 13 | */ 14 | ledgerIndex: number; 15 | /** 16 | * The maximum count of results that are returned by the node. 17 | */ 18 | pageSize: NumericString; 19 | /** 20 | * The cursor to use for getting the next results. 21 | */ 22 | cursor?: string; 23 | /** 24 | * The output IDs (transaction hash + output index) of the outputs on this address. 25 | */ 26 | items: HexEncodedString[]; 27 | } 28 | -------------------------------------------------------------------------------- /sdk/src/types/block/output/alias_id.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::{ 5 | address::{Address, AliasAddress}, 6 | output::OutputId, 7 | }; 8 | 9 | impl_id!(pub AliasId, 32, "Unique identifier of an alias, which is the BLAKE2b-256 hash of the Output ID that created it."); 10 | 11 | #[cfg(feature = "serde")] 12 | string_serde_impl!(AliasId); 13 | 14 | impl From<&OutputId> for AliasId { 15 | fn from(output_id: &OutputId) -> Self { 16 | Self::from(output_id.hash()) 17 | } 18 | } 19 | 20 | impl AliasId { 21 | /// 22 | pub fn or_from_output_id(self, output_id: &OutputId) -> Self { 23 | if self.is_null() { Self::from(output_id) } else { self } 24 | } 25 | } 26 | 27 | impl From for Address { 28 | fn from(value: AliasId) -> Self { 29 | Self::Alias(AliasAddress::new(value)) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sdk/src/types/api/plugins/participation/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #[derive(Debug)] 5 | pub enum Error { 6 | /// Invalid participations error 7 | InvalidParticipations, 8 | /// IO error 9 | #[cfg(feature = "std")] 10 | Io(std::io::Error), 11 | } 12 | 13 | impl core::fmt::Display for Error { 14 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 15 | match self { 16 | Self::InvalidParticipations => write!(f, "invalid participations"), 17 | #[cfg(feature = "std")] 18 | Self::Io(error) => write!(f, "{error}"), 19 | } 20 | } 21 | } 22 | 23 | #[cfg(feature = "std")] 24 | impl From for Error { 25 | fn from(error: std::io::Error) -> Self { 26 | Self::Io(error) 27 | } 28 | } 29 | 30 | #[cfg(feature = "std")] 31 | impl std::error::Error for Error {} 32 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/accounts_and_addresses/list_transactions.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | # In this example we will list transactions 8 | 9 | # This example uses secrets in environment variables for simplicity which 10 | # should not be done in production. 11 | load_dotenv() 12 | 13 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 14 | 15 | account = wallet.get_account('Alice') 16 | account.sync({'syncIncomingTransactions': True}) 17 | 18 | # All transactions sent from the the account 19 | transactions = account.transactions() 20 | print('Sent transactions:') 21 | for transaction in transactions: 22 | print(transaction.transactionId) 23 | 24 | 25 | # Incoming transactions 26 | incoming_transactions = account.incoming_transactions() 27 | print('Received transactions:') 28 | for transaction in incoming_transactions: 29 | print(transaction.transactionId) 30 | -------------------------------------------------------------------------------- /bindings/python/pydoc_markdown_iota.py: -------------------------------------------------------------------------------- 1 | # Inspired by 2 | # https://github.com/tqdm/tqdm.github.io/blob/main/pydoc_markdown_tqdm.py 3 | # as reference 4 | 5 | from pydoc_markdown.contrib.processors.pydocmd import PydocmdProcessor 6 | import re 7 | from functools import partial 8 | 9 | sub = partial(re.sub, flags=re.M) 10 | 11 | 12 | class IotaProcessor(PydocmdProcessor): 13 | def _process(self, node): 14 | if not getattr(node, "docstring", None): 15 | return 16 | 17 | c = node.docstring.content 18 | # join long lines ending in escape (\) 19 | c = sub(r"\\\n\s*", "", c) 20 | # convert parameter lists to markdown list 21 | c = sub(r"^(\w+)\s{1,}(:.*?)$", r"* __\1__*\2* ", c) 22 | # Convert "Parameters" and "Returns" to

23 | c = sub(r"^(.+?)\n[-]{4,}$", r"#### \1\n", c) 24 | node.docstring.content = c 25 | 26 | return super()._process(node) 27 | -------------------------------------------------------------------------------- /sdk/examples/client/tagged_data_to_utf8.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! In this example we will UTF-8 encode the tag and the data of an `TaggedDataPayload`. 5 | //! 6 | //! Rename `.env.example` to `.env` first, then run the command: 7 | //! ```sh 8 | //! cargo run --release --example tagged_data_to_utf8 9 | //! ``` 10 | 11 | use iota_sdk::{ 12 | client::{Client, Result}, 13 | types::block::payload::TaggedDataPayload, 14 | }; 15 | 16 | #[tokio::main] 17 | async fn main() -> Result<()> { 18 | // `hello` in hexadecimal. 19 | let tag = prefix_hex::decode::>("0x68656c6c6f")?; 20 | // `world` in hexadecimal. 21 | let data = prefix_hex::decode::>("0x776f726c64")?; 22 | 23 | let (tag_utf8, data_utf8) = Client::tagged_data_to_utf8(&TaggedDataPayload::new(tag, data)?)?; 24 | 25 | println!("tag: {tag_utf8}\ndata: {data_utf8}"); 26 | 27 | Ok(()) 28 | } 29 | -------------------------------------------------------------------------------- /bindings/python/examples/wallet/restore_backup.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | from dataclasses import asdict 4 | 5 | from dotenv import load_dotenv 6 | 7 | from iota_sdk import ClientOptions, CoinType, Wallet 8 | 9 | load_dotenv() 10 | 11 | # This example restores the wallet from a stronghold. 12 | 13 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 14 | client_options = ClientOptions(nodes=[node_url]) 15 | 16 | # Shimmer coin type 17 | coin_type = CoinType.SHIMMER 18 | 19 | wallet = Wallet('./restore-backup-database', client_options, 20 | coin_type, 'Placeholder') 21 | 22 | if 'STRONGHOLD_PASSWORD' not in os.environ: 23 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 24 | 25 | wallet.restore_backup("backup.stronghold", os.environ['STRONGHOLD_PASSWORD']) 26 | 27 | accounts = wallet.get_accounts() 28 | print(f'Restored accounts: {json.dumps(asdict(accounts), indent=4)}') 29 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/payload/payload.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /** 5 | * All of the block payload types. 6 | */ 7 | enum PayloadType { 8 | /** A milestone payload. */ 9 | Milestone = 7, 10 | /** A tagged data payload. */ 11 | TaggedData = 5, 12 | /** A transaction payload. */ 13 | Transaction = 6, 14 | /** A treasury transaction payload. */ 15 | TreasuryTransaction = 4, 16 | } 17 | 18 | /** 19 | * The base class for block payloads. 20 | */ 21 | abstract class Payload { 22 | readonly type: PayloadType; 23 | 24 | /** 25 | * @param type The type of payload. 26 | */ 27 | constructor(type: PayloadType) { 28 | this.type = type; 29 | } 30 | 31 | /** 32 | * Get the type of payload. 33 | */ 34 | getType(): PayloadType { 35 | return this.type; 36 | } 37 | } 38 | 39 | export { PayloadType, Payload }; 40 | -------------------------------------------------------------------------------- /sdk/tests/client/mnemonic.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crypto::keys::bip39::Mnemonic; 5 | use iota_sdk::client::{Client, Result}; 6 | 7 | #[tokio::test] 8 | async fn mnemonic() -> Result<()> { 9 | let mnemonic = Client::generate_mnemonic()?; 10 | assert!(Client::mnemonic_to_hex_seed(mnemonic).is_ok()); 11 | assert!(Client::mnemonic_to_hex_seed(Mnemonic::from("until fire hat mountain zoo grocery real deny advance change marble taste goat ivory wheat bubble panic banner tattoo client ticket action race rocket".to_owned())).is_ok()); 12 | assert!(Client::mnemonic_to_hex_seed(Mnemonic::from("fire until hat mountain zoo grocery real deny advance change marble taste goat ivory wheat bubble panic banner tattoo client ticket action race rocket".to_owned())).is_err()); 13 | assert!(Client::mnemonic_to_hex_seed(Mnemonic::from("invalid mnemonic".to_owned())).is_err()); 14 | Ok(()) 15 | } 16 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/info/node-info-protocol.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { NumericString } from '../../utils/numeric'; 5 | import type { IRent } from '../rent'; 6 | 7 | /** 8 | * The Protocol Info. 9 | */ 10 | export interface INodeInfoProtocol { 11 | /** 12 | * The human friendly name of the network on which the node operates on. 13 | */ 14 | networkName: string; 15 | /** 16 | * The human readable part of bech32 addresses. 17 | */ 18 | bech32Hrp: string; 19 | /** 20 | * The token supply. 21 | */ 22 | tokenSupply: NumericString; 23 | /** 24 | * The protocol version. 25 | */ 26 | version: number; 27 | /** 28 | * The minimum score required for PoW. 29 | */ 30 | minPowScore: number; 31 | /** 32 | * The rent structure used by given node/network. 33 | */ 34 | rentStructure: IRent; 35 | } 36 | -------------------------------------------------------------------------------- /bindings/python/examples/client/custom_plugin.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from dotenv import load_dotenv 5 | 6 | # pylint: disable=no-name-in-module 7 | from iota_sdk import Client, init_logger 8 | 9 | load_dotenv() 10 | log_config = { 11 | 'name': 'client.log', 12 | 'levelFilter': 'debug', 13 | 'targetExclusions': ["h2", "hyper", "rustls"] 14 | } 15 | 16 | log_config_str = json.dumps(log_config) 17 | 18 | init_logger(log_config_str) 19 | 20 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 21 | 22 | # Create a Client instance 23 | client = Client(nodes=[node_url]) 24 | 25 | # Get an nft ID from ./10_mint_nft.py 26 | nft_id = "0x0000000000000000000000000000000000000000000000000000000000000000" 27 | route = "outputs/nft/" + nft_id 28 | 29 | # Call our "custom" indexer plugin 30 | output_id = client.call_plugin_route( 31 | "api/indexer/v1/", "GET", route, None, None) 32 | print(json.dumps(output_id, indent=4)) 33 | -------------------------------------------------------------------------------- /sdk/src/wallet/core/operations/ledger_nano.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::{ 5 | client::secret::{LedgerNanoStatus, SecretManager, ledger_nano::LedgerSecretManager}, 6 | wallet::Wallet, 7 | }; 8 | 9 | impl Wallet { 10 | /// Get the ledger nano status 11 | pub async fn get_ledger_nano_status(&self) -> crate::wallet::Result { 12 | Ok(self.secret_manager.read().await.get_ledger_nano_status().await) 13 | } 14 | } 15 | 16 | impl Wallet { 17 | /// Get the ledger nano status 18 | pub async fn get_ledger_nano_status(&self) -> crate::wallet::Result { 19 | if let SecretManager::LedgerNano(ledger) = &*self.secret_manager.read().await { 20 | Ok(ledger.get_ledger_nano_status().await) 21 | } else { 22 | Err(crate::client::Error::SecretManagerMismatch.into()) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bindings/python/examples/secret_manager/stronghold.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import SecretManager, StrongholdSecretManager 6 | 7 | load_dotenv() 8 | 9 | for env_var in ['MNEMONIC', 'STRONGHOLD_PASSWORD']: 10 | if env_var not in os.environ: 11 | raise Exception(f'.env {env_var} is undefined, see .env.example') 12 | 13 | 14 | secret_manager = SecretManager(StrongholdSecretManager( 15 | "example.stronghold", os.environ['STRONGHOLD_PASSWORD'])) 16 | 17 | # Store the mnemonic in the Stronghold snapshot, this needs to be done only the first time. 18 | # The mnemonic can't be retrieved from the Stronghold file, so make a 19 | # backup in a secure place! 20 | secret_manager.store_mnemonic( 21 | os.environ['MNEMONIC']) 22 | 23 | # Generate public address with custom account index and range. 24 | address = secret_manager.generate_ed25519_addresses( 25 | account_index=0, start=0, end=1) 26 | 27 | print(f'Address: {address[0]}') 28 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/block/payload/treasury/treasury.ts: -------------------------------------------------------------------------------- 1 | import { Type } from 'class-transformer'; 2 | import { TreasuryInput } from '../../input'; 3 | import { TreasuryOutput } from '../../output'; 4 | import { Payload, PayloadType } from '../payload'; 5 | 6 | /** 7 | * A treasury transaction payload. 8 | */ 9 | class TreasuryTransactionPayload extends Payload { 10 | /** 11 | * The input of this transaction. 12 | */ 13 | @Type(() => TreasuryInput) 14 | input: TreasuryInput; 15 | /** 16 | * The output of this transaction. 17 | */ 18 | @Type(() => TreasuryOutput) 19 | output: TreasuryOutput; 20 | 21 | /** 22 | * @param input A Treasury input. 23 | * @param output A Treasury output. 24 | */ 25 | constructor(input: TreasuryInput, output: TreasuryOutput) { 26 | super(PayloadType.Transaction); 27 | this.input = input; 28 | this.output = output; 29 | } 30 | } 31 | 32 | export { TreasuryTransactionPayload }; 33 | -------------------------------------------------------------------------------- /bindings/python/examples/secret_manager/generate_addresses.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import CoinType, MnemonicSecretManager, SecretManager 6 | 7 | load_dotenv() 8 | 9 | if 'MNEMONIC' not in os.environ: 10 | raise Exception(".env MNEMONIC is undefined, see .env.example") 11 | 12 | # In this example we will create addresses from a mnemonic 13 | 14 | secret_manager = SecretManager(MnemonicSecretManager(os.environ['MNEMONIC'])) 15 | 16 | # Generate public address with default account index and range. 17 | addresses = secret_manager.generate_ed25519_addresses() 18 | 19 | print('List of generated public addresses:', *addresses, sep='\n', end='\n\n') 20 | 21 | addresses = secret_manager.generate_ed25519_addresses( 22 | coin_type=CoinType.SHIMMER, 23 | account_index=0, 24 | start=0, 25 | end=4, 26 | internal=False, 27 | bech32_hrp='rms') 28 | 29 | print('List of generated public addresses:', *addresses, sep='\n', end='\n\n') 30 | -------------------------------------------------------------------------------- /bindings/python/examples/client/build_foundry.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from dotenv import load_dotenv 5 | 6 | from iota_sdk import (AliasAddress, Client, 7 | ImmutableAliasAddressUnlockCondition, SimpleTokenScheme) 8 | 9 | load_dotenv() 10 | 11 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 12 | 13 | # Create a Client instance 14 | client = Client(nodes=[node_url]) 15 | 16 | # Configure foundry output 17 | # Replace with your own values 18 | serial_number = 1 19 | token_scheme = SimpleTokenScheme(32, 0, 64) 20 | unlock_conditions = [ 21 | ImmutableAliasAddressUnlockCondition( 22 | AliasAddress( 23 | '0xa5c28d5baa951de05e375fb19134ea51a918f03acc2d0cee011a42b298d3effa') 24 | ) 25 | ] 26 | 27 | # Configure and build and foundry output 28 | output = client.build_foundry_output( 29 | 1, 30 | token_scheme, 31 | unlock_conditions, 32 | ) 33 | 34 | # Print the output 35 | print(json.dumps(output.as_dict(), indent=4)) 36 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/output_builder_params/foundry-output-params.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | import { Feature, SimpleTokenScheme } from '../..'; 4 | import type { BasicOutputBuilderParams } from './basic-output-params'; 5 | 6 | /** 7 | * Options for building a Foundry Output. 8 | */ 9 | export interface FoundryOutputBuilderParams extends BasicOutputBuilderParams { 10 | /** 11 | * The serial number of the foundry with respect to the controlling alias. 12 | */ 13 | serialNumber: number; 14 | /** 15 | * Defines the supply control scheme of the tokens controlled by the foundry. 16 | * Currently only a simple scheme is supported. 17 | */ 18 | tokenScheme: SimpleTokenScheme; 19 | /** 20 | * Features that add utility to the output but do not impose unlocking conditions. 21 | * These features need to be kept in future transitions of the UTXO state machine. 22 | */ 23 | immutableFeatures?: Feature[]; 24 | } 25 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/wallet/prepared-create-token-transaction-data.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Type } from 'class-transformer'; 5 | import { Transaction } from './transaction'; 6 | import { PreparedTransactionData } from '../client/prepared-transaction-data'; 7 | 8 | /** The result of preparing an operation to create a native token. */ 9 | export class PreparedCreateNativeTokenTransactionData { 10 | /** The token id of the minted token */ 11 | tokenId!: string; 12 | /** The prepared transaction which will mint the token */ 13 | @Type(() => PreparedTransactionData) 14 | transaction!: PreparedTransactionData; 15 | } 16 | 17 | /** The result of an operation to create a native token. */ 18 | export class CreateNativeTokenTransaction { 19 | /** The token id of the minted token */ 20 | tokenId!: string; 21 | /** The transaction which minted the token */ 22 | @Type(() => Transaction) 23 | transaction!: Transaction; 24 | } 25 | -------------------------------------------------------------------------------- /sdk/src/types/api/plugins/indexer.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Node indexer responses. 5 | 6 | use alloc::{string::String, vec::Vec}; 7 | use core::ops::Deref; 8 | 9 | use crate::types::block::output::OutputId; 10 | 11 | /// Response of GET /api/indexer/v1/* 12 | /// Returns the output_ids for the provided query parameters. 13 | #[derive(Clone, Debug, Eq, PartialEq)] 14 | #[cfg_attr( 15 | feature = "serde", 16 | derive(serde::Serialize, serde::Deserialize), 17 | serde(rename_all = "camelCase") 18 | )] 19 | pub struct OutputIdsResponse { 20 | /// The ledger index at which the outputs were collected 21 | pub ledger_index: u32, 22 | /// Cursor confirmationMS+outputId.pageSize 23 | pub cursor: Option, 24 | /// The output ids 25 | pub items: Vec, 26 | } 27 | 28 | impl Deref for OutputIdsResponse { 29 | type Target = Vec; 30 | 31 | fn deref(&self) -> &Self::Target { 32 | &self.items 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sdk/src/wallet/account/operations/syncing/addresses/output_ids/nft.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::{ 5 | client::{node_api::indexer::query_parameters::QueryParameter, secret::SecretManage}, 6 | types::block::{ConvertTo, address::Bech32Address, output::OutputId}, 7 | wallet::Account, 8 | }; 9 | 10 | impl Account 11 | where 12 | crate::wallet::Error: From, 13 | { 14 | /// Returns output ids of nft outputs that have the address in any unlock condition 15 | pub(crate) async fn get_nft_output_ids_with_any_unlock_condition( 16 | &self, 17 | bech32_address: impl ConvertTo, 18 | ) -> crate::wallet::Result> { 19 | let bech32_address = bech32_address.convert()?; 20 | 21 | Ok(self 22 | .client() 23 | .nft_output_ids([QueryParameter::UnlockableByAddress(bech32_address)]) 24 | .await? 25 | .items) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/tests/wallet/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use iota_sdk::wallet::Error; 5 | use pretty_assertions::assert_eq; 6 | 7 | #[test] 8 | fn stringified_error() { 9 | let error = Error::AccountNotFound("0".into()); 10 | assert_eq!( 11 | &serde_json::to_string(&error).unwrap(), 12 | "{\"type\":\"accountNotFound\",\"error\":\"account 0 not found\"}" 13 | ); 14 | 15 | let error = Error::NoOutputsToConsolidate { 16 | available_outputs: 0, 17 | consolidation_threshold: 0, 18 | }; 19 | assert_eq!( 20 | &serde_json::to_string(&error).unwrap(), 21 | "{\"type\":\"noOutputsToConsolidate\",\"error\":\"nothing to consolidate: available outputs: 0, consolidation threshold: 0\"}" 22 | ); 23 | 24 | let error = Error::FailedToGetRemainder; 25 | assert_eq!( 26 | &serde_json::to_string(&error).unwrap(), 27 | "{\"type\":\"failedToGetRemainder\",\"error\":\"failed to get remainder address\"}" 28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/models/peer.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import type { IGossipHeartbeat } from './gossip-heartbeat'; 5 | import type { IGossipMetrics } from './gossip-metrics'; 6 | /** 7 | * Peer details. 8 | */ 9 | export interface IPeer { 10 | /** 11 | * The id of the peer. 12 | */ 13 | id: string; 14 | /** 15 | * The addresses of the peer. 16 | */ 17 | multiAddresses: string[]; 18 | /** 19 | * The alias of the peer. 20 | */ 21 | alias?: string; 22 | /** 23 | * The relation of the peer. 24 | */ 25 | relation: string; 26 | /** 27 | * Is it connected. 28 | */ 29 | connected: boolean; 30 | /** 31 | * Gossip metrics for the peer. 32 | */ 33 | gossip?: { 34 | /** 35 | * The peer heartbeat. 36 | */ 37 | heartbeat: IGossipHeartbeat; 38 | /** 39 | * The peer metrics. 40 | */ 41 | metrics: IGossipMetrics; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /bindings/python/examples/secret_manager/ledger_nano.py: -------------------------------------------------------------------------------- 1 | from dotenv import load_dotenv 2 | 3 | from iota_sdk import LedgerNanoSecretManager, SecretManager 4 | 5 | load_dotenv() 6 | 7 | # In this example we will get the ledger status and generate an address 8 | # To use the ledger nano simulator clone https://github.com/iotaledger/ledger-iota-app, run `git submodule init && git submodule update --recursive`, 9 | # then `./build.sh -m nanos|nanox|nanosplus -s` and use `True` in 10 | # `LedgerNanoSecretManager(True)`. 11 | 12 | is_simulator = True 13 | 14 | ledger_secret_manager = LedgerNanoSecretManager(is_simulator) 15 | secret_manager = SecretManager(ledger_secret_manager) 16 | 17 | # Get the Ledger Nano status. 18 | ledger_nano_status = secret_manager.get_ledger_nano_status() 19 | 20 | print(f'Ledger Nano status: {ledger_nano_status}') 21 | 22 | # Generate public address with custom account index and range. 23 | address = secret_manager.generate_ed25519_addresses( 24 | account_index=0, start=0, end=1) 25 | 26 | print(f'Address: {address[0]}') 27 | -------------------------------------------------------------------------------- /sdk/src/wallet/storage/adapter/memory.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use alloc::sync::Arc; 5 | use std::collections::HashMap; 6 | 7 | use tokio::sync::RwLock; 8 | 9 | use crate::client::storage::StorageAdapter; 10 | 11 | /// A storage adapter that stores data in memory. 12 | #[derive(Debug, Default)] 13 | pub struct Memory(Arc>>>); 14 | 15 | #[async_trait::async_trait] 16 | impl StorageAdapter for Memory { 17 | type Error = crate::wallet::Error; 18 | 19 | async fn get_bytes(&self, key: &str) -> crate::wallet::Result>> { 20 | Ok(self.0.read().await.get(key).cloned()) 21 | } 22 | 23 | async fn set_bytes(&self, key: &str, record: &[u8]) -> crate::wallet::Result<()> { 24 | self.0.write().await.insert(key.to_string(), record.to_owned()); 25 | Ok(()) 26 | } 27 | 28 | async fn delete(&self, key: &str) -> crate::wallet::Result<()> { 29 | self.0.write().await.remove(key); 30 | Ok(()) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/how_tos/client/get-info.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Client, initLogger } from '@iota/sdk'; 5 | require('dotenv').config({ path: '.env' }); 6 | 7 | // Run with command: 8 | // yarn run-example ./how_tos/client/get-info.ts 9 | 10 | // In this example we will get information about the node 11 | async function run() { 12 | initLogger(); 13 | for (const envVar of ['NODE_URL']) { 14 | if (!(envVar in process.env)) { 15 | throw new Error(`.env ${envVar} is undefined, see .env.example`); 16 | } 17 | } 18 | 19 | const client = new Client({ 20 | // Insert your node URL in the .env. 21 | nodes: [process.env.NODE_URL as string], 22 | localPow: true, 23 | }); 24 | 25 | try { 26 | const nodeInfo = (await client.getInfo()).nodeInfo; 27 | console.log(nodeInfo); 28 | } catch (error) { 29 | console.error('Error: ', error); 30 | } 31 | } 32 | 33 | run().then(() => process.exit()); 34 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/client/get_outputs.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from dotenv import load_dotenv 5 | 6 | from iota_sdk import Client, NodeIndexerAPI 7 | 8 | load_dotenv() 9 | 10 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 11 | 12 | # Create a Client instance 13 | client = Client(nodes=[node_url]) 14 | 15 | query_parameters = NodeIndexerAPI.QueryParameters( 16 | address='rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy', 17 | has_expiration=False, 18 | has_timelock=False, 19 | has_storage_deposit_return=False 20 | ) 21 | 22 | # Get output ids of basic outputs that can be controlled by this address 23 | # without further unlock constraints. 24 | output_ids_response = client.basic_output_ids(query_parameters) 25 | print('First output of query:') 26 | print(f'ID: {output_ids_response.items[0]}') 27 | 28 | # Get the outputs by their id 29 | outputs_with_metadata = client.get_outputs(output_ids_response.items) 30 | print(f'{json.dumps(outputs_with_metadata[0].as_dict(), indent=4)}') 31 | -------------------------------------------------------------------------------- /bindings/python/examples/wallet/12-prepare_output.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from dotenv import load_dotenv 5 | 6 | from iota_sdk import OutputParams, Unlocks, Wallet 7 | 8 | load_dotenv() 9 | 10 | # In this example we will prepare an output with an address and expiration 11 | # unlock condition and send it. 12 | 13 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 14 | 15 | account = wallet.get_account("Alice") 16 | 17 | if 'STRONGHOLD_PASSWORD' not in os.environ: 18 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 19 | 20 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 21 | 22 | # using prepare_output 23 | output = account.prepare_output(OutputParams( 24 | "rms1qprutadk4uc9rp6h7wh7sech42sl0z40ztpgyygr5tf0cn5jrqshgm8y43d", "1000000", unlocks=Unlocks(expirationUnixTime=1676570528))) 25 | print(f"Output: {json.dumps(output.as_dict(), indent=4)}") 26 | 27 | account.sync() 28 | 29 | transaction = account.send_outputs([output]) 30 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}') 31 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/address.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crate::types::block::{ 5 | address::{Address, AliasAddress, Ed25519Address, NftAddress}, 6 | output::{AliasId, NftId}, 7 | rand::{bytes::rand_bytes_array, number::rand_number}, 8 | }; 9 | 10 | /// Generates a random Ed25519 address. 11 | pub fn rand_ed25519_address() -> Ed25519Address { 12 | Ed25519Address::new(rand_bytes_array()) 13 | } 14 | 15 | /// Generates a random alias address. 16 | pub fn rand_alias_address() -> AliasAddress { 17 | AliasAddress::new(AliasId::from(rand_bytes_array())) 18 | } 19 | 20 | /// Generates a random NFT address. 21 | pub fn rand_nft_address() -> NftAddress { 22 | NftAddress::new(NftId::from(rand_bytes_array())) 23 | } 24 | 25 | /// Generates a random address. 26 | pub fn rand_address() -> Address { 27 | match rand_number::() % 3 { 28 | 0 => rand_ed25519_address().into(), 29 | 1 => rand_alias_address().into(), 30 | 2 => rand_nft_address().into(), 31 | _ => unreachable!(), 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/ledger-nano-status.ts: -------------------------------------------------------------------------------- 1 | /** The status of a Ledger Nano */ 2 | export interface LedgerNanoStatus { 3 | /** Ledger is available and ready to be used. */ 4 | connected: boolean; 5 | /** Ledger is connected and locked, true/false for IOTA/Shimmer, undefined for the rest. */ 6 | locked?: boolean; 7 | /** Ledger blind signing enabled */ 8 | blindSigningEnabled: boolean; 9 | /** Ledger opened app. */ 10 | app?: LedgerApp; 11 | /** Ledger device */ 12 | device?: LedgerDeviceType; 13 | /** Buffer size on device */ 14 | bufferSize?: number; 15 | } 16 | 17 | /** The current opened app */ 18 | export interface LedgerApp { 19 | /** Opened app name. */ 20 | name: string; 21 | /** Opened app version. */ 22 | version: string; 23 | } 24 | 25 | /** The Ledger Device Type */ 26 | export enum LedgerDeviceType { 27 | /** Device Type Nano S */ 28 | LedgerNanoS = 'ledgerNanoS', 29 | /** Device Type Nano X */ 30 | LedgerNanoX = 'ledgerNanoX', 31 | /** Device Type Nano S Plus */ 32 | LedgerNanoSPlus = 'ledgerNanoSPlus', 33 | } 34 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/advanced_transactions/send_micro_transaction.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | load_dotenv() 8 | 9 | # In this example we will send an amount below the minimum storage deposit 10 | 11 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 12 | 13 | account = wallet.get_account('Alice') 14 | 15 | # Sync account with the node 16 | response = account.sync() 17 | 18 | if 'STRONGHOLD_PASSWORD' not in os.environ: 19 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 20 | 21 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 22 | 23 | params = [{ 24 | "address": "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu", 25 | "amount": "1", 26 | }] 27 | 28 | transaction = account.send_with_params(params, {"allowMicroAmount": True}) 29 | print(f'Transaction sent: {transaction.transactionId}') 30 | 31 | block_id = account.retry_transaction_until_included(transaction.transactionId) 32 | 33 | print( 34 | f'Block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') 35 | -------------------------------------------------------------------------------- /sdk/examples/client/node_api_core/03_get_tips.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Returns tips that are ideal for attaching a block by querying its `/api/core/v2/tips` endpoint. 5 | //! 6 | //! Rename `.env.example` to `.env` first, then run the command: 7 | //! ```sh 8 | //! cargo run --release --example node_api_core_get_tips [NODE URL] 9 | //! ``` 10 | 11 | use iota_sdk::client::{Client, Result}; 12 | 13 | #[tokio::main] 14 | async fn main() -> Result<()> { 15 | // If not provided we use the default node from the `.env` file. 16 | dotenvy::dotenv().ok(); 17 | 18 | // Take the node URL from command line argument or use one from env as default. 19 | let node_url = std::env::args() 20 | .nth(1) 21 | .unwrap_or_else(|| std::env::var("NODE_URL").expect("NODE_URL not set")); 22 | 23 | // Create a node client. 24 | let client = Client::builder().with_node(&node_url)?.finish().await?; 25 | 26 | // Get tips. 27 | let tips = client.get_tips().await?; 28 | 29 | println!("Tips:\n{tips:#?}"); 30 | 31 | Ok(()) 32 | } 33 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/signature.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use crypto::{ 5 | keys::{ 6 | bip39::{Passphrase, mnemonic_to_seed, wordlist}, 7 | slip10::{Seed, Segment}, 8 | }, 9 | signatures::ed25519, 10 | }; 11 | 12 | use super::bytes::{rand_bytes, rand_bytes_array}; 13 | use crate::types::block::signature::{Ed25519Signature, Signature}; 14 | 15 | pub fn rand_ed25519_signature() -> Ed25519Signature { 16 | let mnemonic = wordlist::encode(&rand_bytes_array::<32>(), &wordlist::ENGLISH).unwrap(); 17 | let seed = Seed::from(mnemonic_to_seed(&mnemonic, &Passphrase::default())); 18 | let chain = [0; 5]; 19 | let private_key = seed 20 | .derive::(chain.into_iter().map(Segment::harden)) 21 | .secret_key(); 22 | let public_key = private_key.public_key(); 23 | let signature = private_key.sign(&rand_bytes(64)); 24 | 25 | Ed25519Signature::new(public_key, signature) 26 | } 27 | 28 | pub fn rand_signature() -> Signature { 29 | Signature::from(rand_ed25519_signature()) 30 | } 31 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/how_tos/client/get-health.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Client, initLogger } from '@iota/sdk'; 5 | require('dotenv').config({ path: '.env' }); 6 | 7 | // Run with command: 8 | // yarn run-example ./how_tos/client/get-health.ts 9 | 10 | // In this example we will get the node health 11 | async function run() { 12 | initLogger(); 13 | for (const envVar of ['NODE_URL']) { 14 | if (!(envVar in process.env)) { 15 | throw new Error(`.env ${envVar} is undefined, see .env.example`); 16 | } 17 | } 18 | 19 | const client = new Client({ 20 | // Insert your node URL in the .env. 21 | nodes: [process.env.NODE_URL as string], 22 | localPow: true, 23 | }); 24 | 25 | try { 26 | const isHealthy = await client.getHealth( 27 | process.env.NODE_URL as string, 28 | ); 29 | console.log('Healthy: ', isHealthy); 30 | } catch (error) { 31 | console.error('Error: ', error); 32 | } 33 | } 34 | 35 | run().then(() => process.exit()); 36 | -------------------------------------------------------------------------------- /bindings/wasm/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #![forbid(unsafe_code)] 5 | 6 | pub mod client; 7 | pub mod secret_manager; 8 | pub mod utils; 9 | pub mod wallet; 10 | 11 | use wasm_bindgen::{JsValue, prelude::wasm_bindgen}; 12 | 13 | /// Initializes the console error panic hook for better panic messages. 14 | /// Gets automatically called when using wasm 15 | #[wasm_bindgen(start)] 16 | pub fn start() -> Result<(), JsValue> { 17 | console_error_panic_hook::set_once(); 18 | Ok(()) 19 | } 20 | 21 | /// The Wasm bindings do not support internal logging configuration yet. 22 | /// 23 | /// Calling this will enable all rust logs to be show 24 | #[wasm_bindgen(js_name = initLogger)] 25 | pub async fn init_logger(_config: String) -> Result<(), JsValue> { 26 | wasm_logger::init(wasm_logger::Config::default()); 27 | Ok(()) 28 | } 29 | 30 | #[wasm_bindgen] 31 | extern "C" { 32 | #[wasm_bindgen(typescript_type = "string[]")] 33 | pub type ArrayString; 34 | 35 | #[wasm_bindgen(typescript_type = "Promise")] 36 | pub type PromiseString; 37 | } 38 | -------------------------------------------------------------------------------- /sdk/tests/types/foundry_id.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use core::str::FromStr; 5 | 6 | use iota_sdk::types::block::{ 7 | address::AliasAddress, 8 | output::{AliasId, FoundryId, SimpleTokenScheme, TokenScheme}, 9 | }; 10 | use pretty_assertions::assert_eq; 11 | 12 | #[test] 13 | fn getters() { 14 | let alias_address = AliasAddress::from( 15 | AliasId::from_str("0x52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649").unwrap(), 16 | ); 17 | let serial_number = 42; 18 | let token_scheme = TokenScheme::from(SimpleTokenScheme::new(100, 0, 100).unwrap()); 19 | let foundry_id = FoundryId::build(&alias_address, serial_number, token_scheme.kind()); 20 | 21 | assert_eq!(foundry_id.alias_address(), alias_address); 22 | assert_eq!(foundry_id.serial_number(), serial_number); 23 | assert_eq!(foundry_id.token_scheme_kind(), token_scheme.kind()); 24 | assert_eq!( 25 | foundry_id, 26 | FoundryId::from_str("0x0852fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c6492a00000000").unwrap() 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /sdk/examples/client/node_api_core/12_get_receipts.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Returns all stored receipts by querying the `/api/core/v2/receipts` node endpoint. 5 | //! 6 | //! Rename `.env.example` to `.env` first, then run the command: 7 | //! ```sh 8 | //! cargo run --release --example node_api_core_get_receipts [NODE URL] 9 | //! ``` 10 | 11 | use iota_sdk::client::{Client, Result}; 12 | 13 | #[tokio::main] 14 | async fn main() -> Result<()> { 15 | // If not provided we use the default node from the `.env` file. 16 | dotenvy::dotenv().ok(); 17 | 18 | // Take the node URL from command line argument or use one from env as default. 19 | let node_url = std::env::args() 20 | .nth(1) 21 | .unwrap_or_else(|| std::env::var("NODE_URL").expect("NODE_URL not set")); 22 | 23 | // Create a node client. 24 | let client = Client::builder().with_node(&node_url)?.finish().await?; 25 | 26 | // Send the request. 27 | let receipts = client.get_receipts().await?; 28 | 29 | println!("Receipts:\n{receipts:#?}"); 30 | 31 | Ok(()) 32 | } 33 | -------------------------------------------------------------------------------- /sdk/examples/client/node_api_core/14_get_treasury.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Returns information about the treasury by querying the `/api/core/v2/treasury` node endpoint. 5 | //! 6 | //! Rename `.env.example` to `.env` first, then run the command: 7 | //! ```sh 8 | //! cargo run --release --example node_api_core_get_treasury [NODE URL] 9 | //! ``` 10 | 11 | use iota_sdk::client::{Client, Result}; 12 | 13 | #[tokio::main] 14 | async fn main() -> Result<()> { 15 | // If not provided we use the default node from the `.env` file. 16 | dotenvy::dotenv().ok(); 17 | 18 | // Take the node URL from command line argument or use one from env as default. 19 | let node_url = std::env::args() 20 | .nth(1) 21 | .unwrap_or_else(|| std::env::var("NODE_URL").expect("NODE_URL not set")); 22 | 23 | // Create a node client. 24 | let client = Client::builder().with_node(&node_url)?.finish().await?; 25 | 26 | // Send the request. 27 | let treasury = client.get_treasury().await?; 28 | 29 | println!("{treasury:#?}"); 30 | 31 | Ok(()) 32 | } 33 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/types/client/output_builder_params/alias-output-params.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { AliasId, Feature, HexEncodedString } from '../..'; 5 | import type { BasicOutputBuilderParams } from './basic-output-params'; 6 | 7 | /** 8 | * Options for building an Alias Output. 9 | */ 10 | export interface AliasOutputBuilderParams extends BasicOutputBuilderParams { 11 | /** 12 | * Unique identifier of an alias, which is the BLAKE2b-256 hash of the Output ID that created it. 13 | */ 14 | aliasId: AliasId; 15 | /** 16 | * A counter that must increase by 1 every time the alias is state transitioned. 17 | */ 18 | stateIndex?: number; 19 | /** 20 | * Metadata that can only be changed by the state controller. 21 | */ 22 | stateMetadata?: HexEncodedString; 23 | /** 24 | * A counter that denotes the number of foundries created by this alias account. 25 | */ 26 | foundryCounter?: number; 27 | /** 28 | * A list of immutable features. 29 | */ 30 | immutableFeatures?: Feature[]; 31 | } 32 | -------------------------------------------------------------------------------- /sdk/src/wallet/account/operations/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /// The module for the address generation 5 | pub(crate) mod address_generation; 6 | /// The module to get the accounts balance 7 | pub(crate) mod balance; 8 | /// Helper functions 9 | pub(crate) mod helpers; 10 | /// The module for claiming of outputs with 11 | /// [`UnlockCondition`](crate::types::block::output::UnlockCondition)s that aren't only 12 | /// [`AddressUnlockCondition`](crate::types::block::output::unlock_condition::AddressUnlockCondition) 13 | pub(crate) mod output_claiming; 14 | /// The module for the output consolidation 15 | pub(crate) mod output_consolidation; 16 | /// The module to find additional addresses with unspent outputs 17 | pub(crate) mod output_finder; 18 | /// The module for participation 19 | #[cfg(feature = "participation")] 20 | pub(crate) mod participation; 21 | /// The module for retrying blocks or transactions 22 | pub(crate) mod retry; 23 | /// The module for synchronization of an account 24 | pub(crate) mod syncing; 25 | /// The module for transactions 26 | pub(crate) mod transaction; 27 | -------------------------------------------------------------------------------- /sdk/tests/client/secret_manager/mnemonic.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use iota_sdk::client::{ 5 | Result, api::GetAddressesOptions, constants::SHIMMER_TESTNET_BECH32_HRP, secret::SecretManager, 6 | }; 7 | use pretty_assertions::assert_eq; 8 | 9 | #[tokio::test] 10 | async fn mnemonic_secret_manager() -> Result<()> { 11 | let dto = r#"{"mnemonic": "acoustic trophy damage hint search taste love bicycle foster cradle brown govern endless depend situate athlete pudding blame question genius transfer van random vast"}"#; 12 | let secret_manager: SecretManager = dto.parse()?; 13 | 14 | let addresses = secret_manager 15 | .generate_ed25519_addresses( 16 | GetAddressesOptions::default() 17 | .with_bech32_hrp(SHIMMER_TESTNET_BECH32_HRP) 18 | .with_account_index(0) 19 | .with_range(0..1), 20 | ) 21 | .await 22 | .unwrap(); 23 | 24 | assert_eq!( 25 | addresses[0], 26 | "rms1qzev36lk0gzld0k28fd2fauz26qqzh4hd4cwymlqlv96x7phjxcw6v3ea5a" 27 | ); 28 | 29 | Ok(()) 30 | } 31 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/client/12-get-raw-block.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Client, initLogger } from '@iota/sdk'; 5 | require('dotenv').config({ path: '.env' }); 6 | 7 | // Run with command: 8 | // yarn run-example ./client/12-get-raw-block.ts 9 | 10 | // In this example we will get the raw bytes of a block. 11 | async function run() { 12 | initLogger(); 13 | for (const envVar of ['NODE_URL']) { 14 | if (!(envVar in process.env)) { 15 | throw new Error(`.env ${envVar} is undefined, see .env.example`); 16 | } 17 | } 18 | 19 | const client = new Client({ 20 | // Insert your node URL in the .env. 21 | nodes: [process.env.NODE_URL as string], 22 | }); 23 | 24 | try { 25 | // Get a random block ID. 26 | const blockId = (await client.getTips())[0]; 27 | 28 | const rawBytes = await client.getBlockRaw(blockId); 29 | console.log('Block bytes: ', rawBytes); 30 | } catch (error) { 31 | console.error('Error: ', error); 32 | } 33 | } 34 | 35 | run().then(() => process.exit()); 36 | -------------------------------------------------------------------------------- /sdk/examples/how_tos/accounts_and_addresses/list_addresses.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! In this example we will list all addresses of an account. 5 | //! 6 | //! Rename `.env.example` to `.env` first, then run the command: 7 | //! ```sh 8 | //! cargo run --release --all-features --example list_addresses 9 | //! ``` 10 | 11 | use iota_sdk::{Wallet, wallet::Result}; 12 | 13 | #[tokio::main] 14 | async fn main() -> Result<()> { 15 | // This example uses secrets in environment variables for simplicity which should not be done in production. 16 | dotenvy::dotenv().ok(); 17 | 18 | for var in ["WALLET_DB_PATH"] { 19 | std::env::var(var).expect(&format!(".env variable '{var}' is undefined, see .env.example")); 20 | } 21 | 22 | let wallet = Wallet::builder() 23 | .with_storage_path(std::env::var("WALLET_DB_PATH").unwrap()) 24 | .finish() 25 | .await?; 26 | let account = wallet.get_account("Alice").await?; 27 | 28 | for address in account.addresses().await? { 29 | println!("{}", address.address()); 30 | } 31 | 32 | Ok(()) 33 | } 34 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/client/04-get-output.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Client, initLogger } from '@iota/sdk'; 5 | require('dotenv').config({ path: '.env' }); 6 | 7 | // Run with command: 8 | // yarn run-example ./client/04-get-output.ts 9 | 10 | // In this example we will get output from a known outputId. 11 | async function run() { 12 | initLogger(); 13 | for (const envVar of ['NODE_URL']) { 14 | if (!(envVar in process.env)) { 15 | throw new Error(`.env ${envVar} is undefined, see .env.example`); 16 | } 17 | } 18 | 19 | const client = new Client({ 20 | // Insert your node URL in the .env. 21 | nodes: [process.env.NODE_URL as string], 22 | localPow: true, 23 | }); 24 | try { 25 | const output = await client.getOutput( 26 | '0x022aefa73dff09b35b21ab5493412b0d354ad07a970a12b71e8087c6f3a7b8660000', 27 | ); 28 | console.log('Output: ', output); 29 | } catch (error) { 30 | console.error('Error: ', error); 31 | } 32 | } 33 | 34 | run().then(() => process.exit()); 35 | -------------------------------------------------------------------------------- /bindings/python/iota_sdk/types/signature.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from dataclasses import dataclass, field 5 | from iota_sdk.types.common import HexStr, CoinType 6 | 7 | 8 | @dataclass 9 | class Signature(): 10 | """Base class of a signature. 11 | """ 12 | type: int 13 | 14 | 15 | @dataclass 16 | class Ed25519Signature(Signature): 17 | """An Ed25519 signature. 18 | 19 | Attributes: 20 | publicKey: The Ed25519 public key. 21 | signature: The Ed25519 signature of some message. 22 | type: The Ed25519 signature type. 23 | """ 24 | publicKey: HexStr 25 | signature: HexStr 26 | type: int = field(default_factory=lambda: 0, init=False) 27 | 28 | 29 | @dataclass 30 | class Bip44(): 31 | """A BIP44 chain. 32 | 33 | Attributes: 34 | coinType: The coin type segment. 35 | account: The account segment. 36 | change: The change segment. 37 | addressIndex: The address index segment. 38 | """ 39 | coinType: int = CoinType.IOTA 40 | account: int = 0 41 | change: int = 0 42 | addressIndex: int = 0 43 | -------------------------------------------------------------------------------- /sdk/src/client/api/block_builder/input_selection/core/requirement/issuer.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use super::{Error, InputSelection, Requirement}; 5 | use crate::{ 6 | client::secret::types::InputSigningData, 7 | types::block::{address::Address, output::AliasTransition}, 8 | }; 9 | 10 | impl InputSelection { 11 | /// Fulfills an issuer requirement by fulfilling the equivalent sender requirement. 12 | /// Potentially converts the error for a more accurate one. 13 | pub(crate) fn fulfill_issuer_requirement( 14 | &mut self, 15 | address: Address, 16 | ) -> Result)>, Error> { 17 | log::debug!("Treating {address:?} issuer requirement as a sender requirement"); 18 | 19 | match self.fulfill_sender_requirement(address) { 20 | Ok(res) => Ok(res), 21 | Err(Error::UnfulfillableRequirement(Requirement::Sender(_))) => { 22 | Err(Error::UnfulfillableRequirement(Requirement::Issuer(address))) 23 | } 24 | Err(e) => Err(e), 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/examples/how_tos/accounts_and_addresses/list_accounts.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! In this example we will list all accounts in the wallet. 5 | //! 6 | //! Rename `.env.example` to `.env` first, then run the command: 7 | //! ```sh 8 | //! cargo run --release --all-features --example list_accounts 9 | //! ``` 10 | 11 | use iota_sdk::{Wallet, wallet::Result}; 12 | 13 | #[tokio::main] 14 | async fn main() -> Result<()> { 15 | // This example uses secrets in environment variables for simplicity which should not be done in production. 16 | dotenvy::dotenv().ok(); 17 | 18 | for var in ["WALLET_DB_PATH"] { 19 | std::env::var(var).expect(&format!(".env variable '{var}' is undefined, see .env.example")); 20 | } 21 | 22 | let wallet = Wallet::builder() 23 | .with_storage_path(std::env::var("WALLET_DB_PATH").unwrap()) 24 | .finish() 25 | .await?; 26 | 27 | // Get the accounts and print the alias of each account 28 | for account in wallet.get_accounts().await? { 29 | println!("{}", account.alias().await); 30 | } 31 | 32 | Ok(()) 33 | } 34 | -------------------------------------------------------------------------------- /bindings/python/iota_sdk/types/input.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from __future__ import annotations 5 | from dataclasses import dataclass 6 | from enum import IntEnum 7 | from iota_sdk.types.common import HexStr 8 | 9 | 10 | class InputType(IntEnum): 11 | """Input types. 12 | 13 | Attributes: 14 | Utxo: An unspent transaction output. 15 | Treasury: The treasury output. 16 | """ 17 | Utxo = 0 18 | Treasury = 1 19 | 20 | 21 | @dataclass 22 | class UtxoInput: 23 | """Represents an input referencing an output. 24 | 25 | Attributes: 26 | type: The type of input. 27 | transactionId: The transaction id that created the output. 28 | transactionOutputIndex: The output index. 29 | """ 30 | type: int 31 | transactionId: HexStr 32 | transactionOutputIndex: int 33 | 34 | 35 | @dataclass 36 | class TreasuryInput: 37 | """A treasury input. 38 | 39 | Attributes: 40 | type: The type of input. 41 | milestoneId: The milestone id that created the treasury output. 42 | """ 43 | type: int 44 | milestoneId: HexStr 45 | -------------------------------------------------------------------------------- /bindings/python/examples/exchange/3_check_balance.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | # This example gets the balance of an account. 5 | 6 | import os 7 | 8 | from dotenv import load_dotenv 9 | 10 | from iota_sdk import SyncOptions, Wallet 11 | 12 | # This example uses secrets in environment variables for simplicity which 13 | # should not be done in production. 14 | load_dotenv() 15 | 16 | if 'WALLET_DB_PATH' not in os.environ: 17 | raise Exception(".env WALLET_DB_PATH is undefined, see .env.example") 18 | 19 | wallet = Wallet(os.environ.get('WALLET_DB_PATH')) 20 | 21 | account = wallet.get_account('Alice') 22 | 23 | addresses = account.addresses() 24 | print('Addresses:', addresses) 25 | 26 | # Set sync_only_most_basic_outputs to True if not interested in outputs that are timelocked, 27 | # have a storage deposit return, expiration or are nft/alias/foundry outputs. 28 | balance = account.sync(SyncOptions(sync_only_most_basic_outputs=True)) 29 | print('Balance', balance) 30 | 31 | # Use the faucet to send tokens to your address. 32 | print('Fill your address with the Faucet: https://faucet.testnet.shimmer.network/') 33 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/accounts_and_addresses/create_account.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import ClientOptions, CoinType, StrongholdSecretManager, Wallet 6 | 7 | load_dotenv() 8 | 9 | # This example creates a new database and account 10 | 11 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 12 | client_options = ClientOptions(nodes=[node_url]) 13 | 14 | # Shimmer coin type 15 | coin_type = CoinType.SHIMMER 16 | 17 | for env_var in ['STRONGHOLD_PASSWORD', 'MNEMONIC']: 18 | if env_var not in os.environ: 19 | raise Exception(f".env {env_var} is undefined, see .env.example") 20 | 21 | secret_manager = StrongholdSecretManager( 22 | os.environ['STRONGHOLD_SNAPSHOT_PATH'], os.environ['STRONGHOLD_PASSWORD']) 23 | 24 | wallet = Wallet( 25 | os.environ['WALLET_DB_PATH'], 26 | client_options, 27 | coin_type, 28 | secret_manager) 29 | 30 | # Store the mnemonic in the Stronghold snapshot, this only needs to be 31 | # done once. 32 | wallet.store_mnemonic(os.environ['MNEMONIC']) 33 | 34 | account = wallet.create_account('Alice') 35 | print("Account created:", account.get_metadata()) 36 | -------------------------------------------------------------------------------- /bindings/python/examples/how_tos/advanced_transactions/claim_transaction.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import Wallet 6 | 7 | load_dotenv() 8 | 9 | # In this example we will claim outputs that have additional unlock 10 | # conditions as expiration or storage deposit return. 11 | 12 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 13 | 14 | account = wallet.get_account('Alice') 15 | 16 | if 'STRONGHOLD_PASSWORD' not in os.environ: 17 | raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") 18 | 19 | wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) 20 | 21 | # Sync account with the node 22 | response = account.sync() 23 | 24 | # Only the unspent outputs in the account 25 | output_ids = account.claimable_outputs('All') 26 | 27 | print('Available outputs to claim:') 28 | for output_id in output_ids: 29 | print(f'{output_id}') 30 | 31 | transaction = account.claim_outputs(output_ids) 32 | print(f'Transaction sent: {transaction.transactionId}') 33 | 34 | block_id = account.retry_transaction_until_included(transaction.transactionId) 35 | print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') 36 | -------------------------------------------------------------------------------- /sdk/examples/how_tos/client/get_info.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Returns general information about the node by querying its `/api/core/v2/info` endpoint. 5 | //! 6 | //! Rename `.env.example` to `.env` first, then run the command: 7 | //! ```sh 8 | //! cargo run --release --all-features --example get_info [NODE URL] 9 | //! ``` 10 | 11 | use iota_sdk::client::{Client, Result}; 12 | 13 | #[tokio::main] 14 | async fn main() -> Result<()> { 15 | // If not provided we use the default node from the `.env` file. 16 | dotenvy::dotenv().ok(); 17 | 18 | // Take the node URL from command line argument or use one from env as default. 19 | let node_url = std::env::args() 20 | .nth(1) 21 | .unwrap_or_else(|| std::env::var("NODE_URL").expect("NODE_URL not set")); 22 | 23 | // Create a node client. 24 | let client = Client::builder() 25 | .with_node(&node_url)? 26 | .with_ignore_node_health() 27 | .finish() 28 | .await?; 29 | 30 | // Get node info. 31 | let info = client.get_info().await?.node_info; 32 | 33 | println!("{info}"); 34 | 35 | Ok(()) 36 | } 37 | -------------------------------------------------------------------------------- /sdk/src/wallet/account/constants.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /// Amount at which outputs on a single addresses will get consolidated by default if consolidatioin is enabled 5 | pub(crate) const DEFAULT_OUTPUT_CONSOLIDATION_THRESHOLD: usize = 100; 6 | /// Amount at which outputs on a single addresses will get consolidated by default with a ledger secret_manager if 7 | /// consolidatioin is enabled, needs to be smaller because the memory of the ledger nano s is limited 8 | #[cfg(feature = "ledger_nano")] 9 | pub(crate) const DEFAULT_LEDGER_OUTPUT_CONSOLIDATION_THRESHOLD: usize = 15; 10 | 11 | /// Amount of API request that can be sent in parallel during syncing 12 | pub(crate) const PARALLEL_REQUESTS_AMOUNT: usize = 500; 13 | 14 | /// ms before an account actually syncs with the network, before it just returns the previous syncing result 15 | /// this is done to prevent unnecessary simultaneous synchronizations 16 | pub(crate) const MIN_SYNC_INTERVAL: u128 = 5; 17 | 18 | // Default expiration time for [ExpirationUnlockCondition] when sending native tokens, one day in seconds 19 | pub(crate) const DEFAULT_EXPIRATION_TIME: u32 = 86400; 20 | -------------------------------------------------------------------------------- /bindings/python/examples/wallet/backup.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import ClientOptions, CoinType, StrongholdSecretManager, Wallet 6 | 7 | load_dotenv() 8 | 9 | # This example creates a new database and account 10 | 11 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 12 | client_options = ClientOptions(nodes=[node_url]) 13 | 14 | # Shimmer coin type 15 | coin_type = CoinType.SHIMMER 16 | 17 | for env_var in ['STRONGHOLD_PASSWORD', 'MNEMONIC']: 18 | if env_var not in os.environ: 19 | raise Exception(f'.env {env_var} is undefined, see .env.example') 20 | 21 | secret_manager = StrongholdSecretManager( 22 | os.environ['STRONGHOLD_SNAPSHOT_PATH'], os.environ['STRONGHOLD_PASSWORD']) 23 | 24 | wallet = Wallet('./backup-database', client_options, 25 | coin_type, secret_manager) 26 | 27 | # Store the mnemonic in the Stronghold snapshot, this only needs to be 28 | # done once. 29 | account = wallet.store_mnemonic(os.environ['MNEMONIC']) 30 | 31 | accounts = wallet.create_account('Alice') 32 | 33 | wallet.backup("backup.stronghold", os.environ['STRONGHOLD_PASSWORD']) 34 | print('Created backup') 35 | -------------------------------------------------------------------------------- /sdk/examples/client/node_api_core/01_get_routes.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! Returns the available API route groups of the node by querying its `/api/routes` endpoint. 5 | //! 6 | //! Rename `.env.example` to `.env` first, then run the command: 7 | //! ```sh 8 | //! cargo run --release --example node_api_core_get_routes [NODE URL] 9 | //! ``` 10 | 11 | use iota_sdk::client::{Client, Result}; 12 | 13 | #[tokio::main] 14 | async fn main() -> Result<()> { 15 | // If not provided we use the default node from the `.env` file. 16 | dotenvy::dotenv().ok(); 17 | // Take the node URL from command line argument or use one from env as default. 18 | let node_url = std::env::args() 19 | .nth(1) 20 | .unwrap_or_else(|| std::env::var("NODE_URL").expect("NODE_URL not set")); 21 | 22 | // Create a node client. 23 | let client = Client::builder() 24 | .with_node(&node_url)? 25 | .with_ignore_node_health() 26 | .finish() 27 | .await?; 28 | 29 | // Get routes. 30 | let routes = client.get_routes().await?; 31 | 32 | println!("Routes:\n{routes:#?}"); 33 | 34 | Ok(()) 35 | } 36 | -------------------------------------------------------------------------------- /sdk/src/client/node_api/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /// Type alias of `Result` in Node errors 5 | pub type Result = std::result::Result; 6 | 7 | /// Node errors. 8 | #[derive(Debug, thiserror::Error)] 9 | pub enum Error { 10 | /// The requested data was not found. (404) 11 | #[error("The requested data {0} was not found.")] 12 | NotFound(String), 13 | /// Reqwest error 14 | #[error("{0}")] 15 | Reqwest(#[from] reqwest::Error), 16 | /// Error from RestAPI calls with unexpected status code response 17 | #[error("Response error with status code {code}: {text}, URL: {url}")] 18 | ResponseError { 19 | /// The status code. 20 | code: u16, 21 | /// The text from the response. 22 | text: String, 23 | /// The url of the API. 24 | url: String, 25 | }, 26 | /// None of our nodes have remote Pow enabled 27 | #[error("No node available for remote Pow")] 28 | UnavailablePow, 29 | /// We made a call to the node but the protocol was unsupported 30 | #[error("Call to {0} is not supported on this node")] 31 | NotSupported(String), 32 | } 33 | -------------------------------------------------------------------------------- /bindings/nodejs/examples/how_tos/accounts_and_addresses/list-accounts.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Wallet, initLogger } from '@iota/sdk'; 5 | 6 | // This example uses secrets in environment variables for simplicity which should not be done in production. 7 | require('dotenv').config({ path: '.env' }); 8 | 9 | // Run with command: 10 | // yarn run-example ./how_tos/accounts_and_addresses/list-accounts.ts 11 | 12 | // This example lists all accounts in the wallet. 13 | async function run() { 14 | initLogger(); 15 | for (const envVar of ['WALLET_DB_PATH']) { 16 | if (!(envVar in process.env)) { 17 | throw new Error(`.env ${envVar} is undefined, see .env.example`); 18 | } 19 | } 20 | try { 21 | const wallet = new Wallet({ 22 | storagePath: process.env.WALLET_DB_PATH, 23 | }); 24 | 25 | const accounts = await wallet.getAccounts(); 26 | 27 | for (const account of accounts) 28 | console.log(account.getMetadata().alias); 29 | } catch (error) { 30 | console.error('Error: ', error); 31 | } 32 | } 33 | 34 | run().then(() => process.exit()); 35 | -------------------------------------------------------------------------------- /sdk/examples/how_tos/client/get_health.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //! This example returns the health of the node by querying its `/health` endpoint. 5 | //! 6 | //! Rename `.env.example` to `.env` first, then run the command: 7 | //! ```sh 8 | //! cargo run --release --all-features --example get_health [NODE_URL] 9 | //! ``` 10 | 11 | use iota_sdk::client::{Client, Result}; 12 | 13 | #[tokio::main] 14 | async fn main() -> Result<()> { 15 | // If not provided we use the default node from the `.env` file. 16 | dotenvy::dotenv().ok(); 17 | 18 | // Take the node URL from command line argument or use one from env as default. 19 | let node_url = std::env::args() 20 | .nth(1) 21 | .unwrap_or_else(|| std::env::var("NODE_URL").expect("NODE_URL not set")); 22 | 23 | // Create a node client. 24 | let client = Client::builder() 25 | .with_node(&node_url)? 26 | .with_ignore_node_health() 27 | .finish() 28 | .await?; 29 | 30 | // Get node health. 31 | let is_healthy = client.get_health(&node_url).await?; 32 | 33 | println!("Healthy: {is_healthy}"); 34 | 35 | Ok(()) 36 | } 37 | -------------------------------------------------------------------------------- /bindings/python/examples/wallet/13-check-unlock-conditions.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | from iota_sdk import OutputParams, Utils, Wallet 6 | 7 | load_dotenv() 8 | 9 | # In this example we check if an output has only an address unlock 10 | # condition and that the address is from the account. 11 | 12 | wallet = Wallet(os.environ['WALLET_DB_PATH']) 13 | 14 | account = wallet.get_account("Alice") 15 | 16 | accountAddresses = account.addresses() 17 | 18 | # using prepare_output 19 | output = account.prepare_output(OutputParams( 20 | accountAddresses[0].address, "1000000")) 21 | 22 | 23 | def hexAddress(address): 24 | """Converts an address to hex""" 25 | return Utils.bech32_to_hex(address.address) 26 | 27 | 28 | hexEncodedAccountAddresses = map(hexAddress, accountAddresses) 29 | 30 | controlled_by_account = False 31 | 32 | if len(output.unlockConditions) == 1 and output.unlockConditions[0].type == 0: 33 | if output.unlockConditions[0].address.pubKeyHash in hexEncodedAccountAddresses: 34 | controlled_by_account = True 35 | 36 | print( 37 | f'The output has only an address unlock condition and the address is from the account: {controlled_by_account}') 38 | -------------------------------------------------------------------------------- /sdk/src/types/block/rand/block.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 IOTA Stiftung 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | use alloc::vec::Vec; 5 | 6 | use crate::types::block::{ 7 | Block, BlockBuilder, BlockId, 8 | parent::Parents, 9 | rand::{bytes::rand_bytes_array, number::rand_number, parents::rand_parents, payload::rand_payload_for_block}, 10 | }; 11 | 12 | /// Generates a random block id. 13 | pub fn rand_block_id() -> BlockId { 14 | BlockId::new(rand_bytes_array()) 15 | } 16 | 17 | /// Generates a vector of random block ids of a given length. 18 | pub fn rand_block_ids(len: usize) -> Vec { 19 | let mut parents = (0..len).map(|_| rand_block_id()).collect::>(); 20 | parents.sort_by(|a, b| a.as_ref().cmp(b.as_ref())); 21 | parents 22 | } 23 | 24 | /// Generates a random block with given parents. 25 | pub fn rand_block_with_parents(parents: Parents) -> Block { 26 | BlockBuilder::new(parents) 27 | .with_payload(rand_payload_for_block()) 28 | .with_nonce(rand_number::()) 29 | .finish() 30 | .unwrap() 31 | } 32 | 33 | /// Generates a random block. 34 | pub fn rand_block() -> Block { 35 | rand_block_with_parents(rand_parents()) 36 | } 37 | -------------------------------------------------------------------------------- /bindings/python/examples/client/mqtt.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 IOTA Stiftung 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | # This example shows how to listen to MQTT events of a node. 5 | 6 | import json 7 | import os 8 | import threading 9 | 10 | from dotenv import load_dotenv 11 | 12 | from iota_sdk import Client 13 | 14 | load_dotenv() 15 | 16 | node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') 17 | 18 | # Create a Client instance 19 | client = Client(nodes=[node_url]) 20 | 21 | received_events = 0 22 | 23 | received_10_events = threading.Event() 24 | 25 | 26 | def callback(event): 27 | """Callback function for the MQTT listener""" 28 | event_dict = json.loads(event) 29 | print(event_dict) 30 | # pylint: disable=global-statement 31 | global received_events 32 | received_events += 1 33 | if received_events > 10: 34 | received_10_events.set() 35 | 36 | 37 | # Topics can be found here 38 | # https://studio.asyncapi.com/?url=https://raw.githubusercontent.com/iotaledger/tips/main/tips/TIP-0028/event-api.yml 39 | client.listen_mqtt(["blocks"], callback) 40 | 41 | # Exit after 10 received events 42 | received_10_events.wait() 43 | client.clear_mqtt_listeners(["blocks"]) 44 | --------------------------------------------------------------------------------