Skip to content

Commit

Permalink
Merge branch '1.1' into chore/bindings-cleanup-is-alive
Browse files Browse the repository at this point in the history
  • Loading branch information
DaughterOfMars authored Sep 27, 2023
2 parents ac10b09 + d4e7d66 commit 62a7bdd
Show file tree
Hide file tree
Showing 48 changed files with 885 additions and 154 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/bindings-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ jobs:
yarn
yarn build
- name: Test types module webpack compatibility
working-directory: bindings/nodejs/
run: |
yarn run test-webpack
lint:
name: Lint
if: ${{ ! github.event.schedule }}
Expand Down
9 changes: 5 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bindings/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ participation = ["iota-sdk/participation"]
rocksdb = ["iota-sdk/rocksdb"]
storage = ["iota-sdk/storage"]
stronghold = ["iota-sdk/stronghold"]
private_key_secret_manager = ["iota-sdk/private_key_secret_manager"]
3 changes: 3 additions & 0 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,7 @@ pub enum UtilsMethod {
/// Creates a UTXOInput from outputId.
#[serde(rename_all = "camelCase")]
OutputIdToUtxoInput { output_id: OutputId },
/// Returns the hex representation of the serialized output bytes.
#[serde(rename_all = "camelCase")]
OutputHexBytes { output: OutputDto },
}
5 changes: 5 additions & 0 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use iota_sdk::{
TryFromDto,
},
};
use packable::PackableExt;

use crate::{method::UtilsMethod, response::Response, Result};

Expand Down Expand Up @@ -109,6 +110,10 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
Response::Bool(public_key.verify_keccak256(&signature, &message))
}
UtilsMethod::OutputIdToUtxoInput { output_id } => Response::Input((&UtxoInput::from(output_id)).into()),
UtilsMethod::OutputHexBytes { output } => {
let output = Output::try_from_dto(output)?;
Response::HexBytes(prefix_hex::encode(output.pack_to_vec()))
}
};
Ok(response)
}
2 changes: 2 additions & 0 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ pub enum Response {
NodeInfoWrapper(NodeInfoWrapper),
/// Response for [`Bech32ToHex`](crate::method::UtilsMethod::Bech32ToHex)
HexAddress(String),
/// Response for [`OutputHexBytes`](crate::method::UtilsMethod::OutputHexBytes)
HexBytes(String),
/// Response for [`CallPluginRoute`](crate::method::ClientMethod::CallPluginRoute)
CustomJson(serde_json::Value),

Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs-old/examples/ledger_nano.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require('dotenv').config({ path: path.resolve(__dirname, '.env') });
const { AccountManager, CoinType } = require('@iota/wallet');

// In this example we will create addresses with a ledger nano hardware wallet
// To use the ledger nano simulator clone https://github.com/iotaledger/ledger-shimmer-app, run `git submodule init && git submodule update --recursive`,
// To use the ledger nano simulator clone https://github.com/iotaledger/ledger-iota-app, run `git submodule init && git submodule update --recursive`,
// then `./build.sh -m nanos|nanox|nanosplus -s` and use `true` for `LedgerNano`.

async function run() {
Expand Down
22 changes: 21 additions & 1 deletion bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 1.1.0 - 2023-MM-DD
## 1.1.0-rc.1 - 2023-09-26

### Fixed

- Import of bindings through types;

## 1.1.0-rc.0 - 2023-09-25

### Added

- `Account::{burn(), consolidateOutputs(), createAliasOutput(), meltNativeToken(), mintNativeToken(), createNativeToken(), mintNfts(), sendTransaction(), sendNativeTokens(), sendNft()}` methods;
- `Client::outputIds()` method;
- `GenericQueryParameter, UnlockableByAddress` types;
- `Irc27Metadata` and `Irc30Metadata` helpers;
- `Utils::outputHexBytes`;
- `PrivateKeySecretManager`;

## 1.0.12 - 2023-09-25

### Changed

- Made `TransactionOptions.allowMicroAmount` optional;

### Fixed

- Parsing of `RegularTransactionEssence.payload`;
- Don't error if custom remainder address is provided with ledger nano;

## 1.0.11 - 2023-09-14

Expand Down
1 change: 1 addition & 0 deletions bindings/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ iota-sdk-bindings-core = { path = "../core", default-features = false, features
"participation",
"rocksdb",
"mqtt",
"private_key_secret_manager"
] }

log = { version = "0.4.20", default-features = false }
Expand Down
18 changes: 7 additions & 11 deletions bindings/nodejs/examples/client/15-build-nft-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SenderFeature,
Ed25519Address,
IssuerFeature,
Irc27Metadata,
} from '@iota/sdk';
require('dotenv').config({ path: '.env' });

Expand All @@ -35,14 +36,11 @@ async function run() {
'rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy',
);

// IOTA NFT Standard - IRC27: https://github.com/iotaledger/tips/blob/main/tips/TIP-0027/tip-0027.md
const tip27ImmutableMetadata = {
standard: 'IRC27',
version: 'v1.0',
type: 'image/jpeg',
uri: 'https://mywebsite.com/my-nft-files-1.jpeg',
name: 'My NFT #0001',
};
const tip27ImmutableMetadata = new Irc27Metadata(
'image/jpeg',
'https://mywebsite.com/my-nft-files-1.jpeg',
'My NFT #0001',
);

const nftOutput = await client.buildNftOutput({
// NftId needs to be null the first time
Expand All @@ -52,9 +50,7 @@ async function run() {
],
immutableFeatures: [
new IssuerFeature(new Ed25519Address(hexAddress)),
new MetadataFeature(
utf8ToHex(JSON.stringify(tip27ImmutableMetadata)),
),
tip27ImmutableMetadata.asFeature(),
],
features: [
new SenderFeature(new Ed25519Address(hexAddress)),
Expand Down
10 changes: 8 additions & 2 deletions bindings/nodejs/examples/how_tos/native_tokens/create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { CreateNativeTokenParams, utf8ToHex } from '@iota/sdk';
import { CreateNativeTokenParams, Irc30Metadata } from '@iota/sdk';

import { getUnlockedWallet } from '../../wallet/common';

Expand Down Expand Up @@ -51,11 +51,17 @@ async function run() {

console.log('Preparing transaction to create native token...');

const metadata = new Irc30Metadata(
'My Native Token',
'MNT',
10,
).withDescription('A native token to test the iota-sdk.');

// If we omit the AccountAddress field the first address of the account is used by default
const params: CreateNativeTokenParams = {
circulatingSupply: CIRCULATING_SUPPLY,
maximumSupply: MAXIMUM_SUPPLY,
foundryMetadata: utf8ToHex('Hello, World!'),
foundryMetadata: metadata.asHex(),
};

const prepared = await account.prepareCreateNativeToken(params);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { MintNftParams, NftId, utf8ToHex, Utils, Wallet } from '@iota/sdk';
import { MintNftParams, NftId, Utils, Wallet, Irc27Metadata } from '@iota/sdk';
require('dotenv').config({ path: '.env' });

// The NFT collection size
Expand Down Expand Up @@ -48,9 +48,7 @@ async function run() {
// Create the metadata with another index for each
for (let index = 0; index < NFT_COLLECTION_SIZE; index++) {
const params: MintNftParams = {
immutableMetadata: utf8ToHex(
getImmutableMetadata(index, issuerNftId),
),
immutableMetadata: getImmutableMetadata(index).asHex(),
// The NFT address from the NFT we minted in mint_issuer_nft example
issuer,
};
Expand Down Expand Up @@ -97,21 +95,18 @@ async function run() {
process.exit(0);
}

function getImmutableMetadata(index: number, issuerNftId: NftId) {
// Note: we use parse and stringify to remove all unnecessary whitespace
return JSON.stringify(
JSON.parse(`{
"standard":"IRC27",
"version":"v1.0",
"type":"video/mp4",
"uri":"ipfs://wrongcVm9fx47YXNTkhpMEYSxCD3Bqh7PJYr7eo5Ywrong",
"name":"Shimmer OG NFT ${index}",
"description":"The Shimmer OG NFT was handed out 1337 times by the IOTA Foundation to celebrate the official launch of the Shimmer Network.",
"issuerName":"IOTA Foundation",
"collectionId":"${issuerNftId}",
"collectionName":"Shimmer OG"
}`),
);
function getImmutableMetadata(index: number) {
return new Irc27Metadata(
'video/mp4',
'https://ipfs.io/ipfs/QmPoYcVm9fx47YXNTkhpMEYSxCD3Bqh7PJYr7eo5YjLgiT',
`Shimmer OG NFT ${index}`,
)
.withDescription(
'The Shimmer OG NFT was handed out 1337 times by the IOTA Foundation \
to celebrate the official launch of the Shimmer Network.',
)
.withIssuerName('IOTA Foundation')
.withCollectionName('Shimmer OG');
}

run();
11 changes: 8 additions & 3 deletions bindings/nodejs/examples/how_tos/nfts/mint_nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
utf8ToHex,
Utils,
Wallet,
Irc27Metadata,
} from '@iota/sdk';
require('dotenv').config({ path: '.env' });

Expand All @@ -18,8 +19,6 @@ const NFT1_OWNER_ADDRESS =
'rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu';
// The metadata of the first minted NFT
const NFT1_METADATA = utf8ToHex('some NFT metadata');
// The immutable metadata of the first minted NFT
const NFT1_IMMUTABLE_METADATA = utf8ToHex('some NFT immutable metadata');
// The tag of the first minted NFT
const NFT1_TAG = utf8ToHex('some NFT tag');
// The base coin amount we sent with the second NFT
Expand Down Expand Up @@ -52,13 +51,19 @@ async function run() {
// We need to unlock stronghold.
await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD);

const metadata = new Irc27Metadata(
'video/mp4',
'https://ipfs.io/ipfs/QmPoYcVm9fx47YXNTkhpMEYSxCD3Bqh7PJYr7eo5YjLgiT',
'Shimmer OG NFT',
).withDescription('The original Shimmer NFT');

const params: MintNftParams = {
address: NFT1_OWNER_ADDRESS, // Remove or change to senderAddress to send to self
sender: senderAddress,
metadata: NFT1_METADATA,
tag: NFT1_TAG,
issuer: senderAddress,
immutableMetadata: NFT1_IMMUTABLE_METADATA,
immutableMetadata: metadata.asHex(),
};
let transaction = await account.mintNfts([params]);
console.log(`Transaction sent: ${transaction.transactionId}`);
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/secret_manager/ledger-nano.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require('dotenv').config({ path: '.env' });
// yarn run-example ./secret_manager/ledger-nano.ts

// In this example we will get the ledger status and generate an address
// To use the ledger nano simulator clone https://github.com/iotaledger/ledger-shimmer-app, run `git submodule init && git submodule update --recursive`,
// To use the ledger nano simulator clone https://github.com/iotaledger/ledger-iota-app, run `git submodule init && git submodule update --recursive`,
// then `./build.sh -m nanos|nanox|nanosplus -s` and use `true` in `LedgerSecretManager::new(true)`.
async function run() {
initLogger();
Expand Down
2 changes: 2 additions & 0 deletions bindings/nodejs/lib/types/block/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export * from './feature';
export * from './unlock-condition';
export * from './output';
export * from './token-scheme';
export * from './irc-27';
export * from './irc-30';
Loading

0 comments on commit 62a7bdd

Please sign in to comment.