Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: Prevent webpack loading bindings when importing UTXOInput type #990

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security -->

## 1.0.4 - 2023-MM-DD
## 1.0.5 - YYYY-MM-DD


## 1.0.4 - 2023-08-03

### Changed

- Prevent loading of bindings when importing UTXOInput type (changed UTXOInput.fromOutputId implementation)

### Fixed

Expand Down
19 changes: 19 additions & 0 deletions bindings/nodejs/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// Needed for class-transformer json deserialisation
import 'reflect-metadata';
import { callUtilsMethod } from './bindings';
import { OutputId, UTXOInput } from './types';
import { bigIntToHex } from './utils';

// Allow bigint to be serialized as hex string.
Expand All @@ -14,6 +16,23 @@ import { bigIntToHex } from './utils';
return bigIntToHex(this);
};

// Assign the util method on UTXOInput here,
// to prevent loading bindings (callUtilsMethod) when importing UTXOInput just for typing.
Object.assign(UTXOInput, {
/**
* Creates a `UTXOInput` from an output id.
*/
fromOutputId(outputId: OutputId): UTXOInput {
const input = callUtilsMethod({
name: 'outputIdToUtxoInput',
data: {
outputId,
},
});
return new UTXOInput(input.transactionId, input.transactionOutputIndex);
},
});

export * from './client';
export * from './secret_manager';
export * from './types';
Expand Down
11 changes: 3 additions & 8 deletions bindings/nodejs/lib/types/block/input/input.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { callUtilsMethod } from '../../../bindings';
import { HexEncodedString } from '../../utils';
import { OutputId } from '../output';

Expand Down Expand Up @@ -68,14 +67,10 @@ class UTXOInput extends Input {
/**
* Creates a `UTXOInput` from an output id.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
static fromOutputId(outputId: OutputId): UTXOInput {
const input = callUtilsMethod({
name: 'outputIdToUtxoInput',
data: {
outputId,
},
});
return new UTXOInput(input.transactionId, input.transactionOutputIndex);
// Implementation injected in lib/index.ts, as it uses bindings.
return null as unknown as UTXOInput;
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iota/sdk",
"version": "1.0.3",
"version": "1.0.4",
"description": "Node.js binding to the IOTA SDK library",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
Loading