Skip to content

Commit

Permalink
Chore/change to non dir imports (#24)
Browse files Browse the repository at this point in the history
* chore: change to non dir imports

* chore: bump version

* chore: fix dir imports

* chore: bump version
  • Loading branch information
coodos authored Jan 9, 2025
1 parent 6ffcb72 commit 7f3eab3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanglelabs/iota-identity-adapter",
"version": "0.4.2",
"version": "0.4.3",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Module from "node:module";
const require = Module.createRequire(import.meta.url);
import { getPublicKeyAsync } from "@noble/ed25519";
import { IotaJwkStore, IotaKidStore } from "./iota-store";
import { Client, SecretManager, Utils } from "@iota/sdk-wasm/node";
import { Client, SecretManager, Utils } from "@iota/sdk-wasm/node/lib/index.js";
import {
IotaDID,
IotaDocument,
Expand Down
2 changes: 1 addition & 1 deletion src/iota-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "@iota/sdk-wasm/node";
import { Client } from "@iota/sdk-wasm/node/lib/index.js";
import {
type DIDResolutionOptions,
type DIDDocument,
Expand Down
68 changes: 24 additions & 44 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,39 @@
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import {
IotaDID,
IotaDocument,
IotaIdentityClient,
JwkMemStore,
JwsAlgorithm,
KeyIdMemStore,
MethodScope,
Storage,
Credential,
JwsSignatureOptions,
} from "@iota/identity-wasm/node";
import {
AliasOutput,
Client,
IOutputsResponse,
MnemonicSecretManager,
SecretManager,
SeedSecretManager,
Utils,
} from "@iota/sdk-wasm/node";
import { Client, IOutputsResponse } from "@iota/sdk-wasm/node/lib/index.js";
import { InsufficientBalanceError } from "./errors/BalanceErorr";

export async function ensureAddressHasFunds(
client: Client,
addressBech32: string,
amount: string,
seed: string
client: Client,
addressBech32: string,
amount: string,
seed: string
) {
let balance = await getAddressBalance(client, addressBech32);
if (balance >= BigInt(amount)) {
return;
}
throw new InsufficientBalanceError(addressBech32, parseInt(amount), seed);
let balance = await getAddressBalance(client, addressBech32);
if (balance >= BigInt(amount)) {
return;
}
throw new InsufficientBalanceError(addressBech32, parseInt(amount), seed);
}

/** Returns the balance of the given Bech32-encoded address. */
async function getAddressBalance(
client: Client,
addressBech32: string
client: Client,
addressBech32: string
): Promise<bigint> {
const outputIds: IOutputsResponse = await client.basicOutputIds([
{ address: addressBech32 },
{ hasExpiration: false },
{ hasTimelock: false },
{ hasStorageDepositReturn: false },
]);
const outputs = await client.getOutputs(outputIds.items);
const outputIds: IOutputsResponse = await client.basicOutputIds([
{ address: addressBech32 },
{ hasExpiration: false },
{ hasTimelock: false },
{ hasStorageDepositReturn: false },
]);
const outputs = await client.getOutputs(outputIds.items);

let totalAmount = BigInt(0);
for (const output of outputs) {
totalAmount += output.output.getAmount();
}
let totalAmount = BigInt(0);
for (const output of outputs) {
totalAmount += output.output.getAmount();
}

return totalAmount;
return totalAmount;
}

0 comments on commit 7f3eab3

Please sign in to comment.