@twin.org/nft-cli 0.0.2-next.8 → 0.0.3-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // SPDX-License-Identifier: Apache-2.0.
4
4
  process.title = 'TWIN Identity';
5
5
 
6
- import { CLI } from '../dist/esm/index.mjs';
6
+ import { CLI } from '../dist/es/index.js';
7
7
 
8
8
  const cli = new CLI();
9
9
  const result = await cli.run(process.argv);
package/dist/es/cli.js ADDED
@@ -0,0 +1,52 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { CLIBase } from "@twin.org/cli-core";
6
+ import { buildCommandAddress, buildCommandMnemonic } from "@twin.org/crypto-cli";
7
+ import { buildCommandFaucet } from "@twin.org/wallet-cli";
8
+ import { buildCommandNftBurn } from "./commands/nftBurn.js";
9
+ import { buildCommandNftMint } from "./commands/nftMint.js";
10
+ import { buildCommandNftResolve } from "./commands/nftResolve.js";
11
+ import { buildCommandNftTransfer } from "./commands/nftTransfer.js";
12
+ /**
13
+ * The main entry point for the CLI.
14
+ */
15
+ export class CLI extends CLIBase {
16
+ /**
17
+ * Run the app.
18
+ * @param argv The process arguments.
19
+ * @param localesDirectory The directory for the locales, default to relative to the script.
20
+ * @param options Additional options for the CLI.
21
+ * @param options.overrideOutputWidth Override the output width.
22
+ * @returns The exit code.
23
+ */
24
+ async run(argv, localesDirectory, options) {
25
+ return this.execute({
26
+ title: "TWIN NFT",
27
+ appName: "twin-nft",
28
+ version: "0.0.3-next.2", // x-release-please-version
29
+ icon: "🌍",
30
+ supportsEnvFiles: true,
31
+ overrideOutputWidth: options?.overrideOutputWidth,
32
+ showDevToolWarning: true
33
+ }, localesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), "../locales"), argv);
34
+ }
35
+ /**
36
+ * Get the commands for the CLI.
37
+ * @param program The main program to add the commands to.
38
+ * @internal
39
+ */
40
+ getCommands(program) {
41
+ return [
42
+ buildCommandMnemonic(),
43
+ buildCommandAddress(),
44
+ buildCommandFaucet(),
45
+ buildCommandNftMint(),
46
+ buildCommandNftResolve(),
47
+ buildCommandNftBurn(),
48
+ buildCommandNftTransfer()
49
+ ];
50
+ }
51
+ }
52
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;GAEG;AACH,MAAM,OAAO,GAAI,SAAQ,OAAO;IAC/B;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,CACf,IAAc,EACd,gBAAyB,EACzB,OAA0C;QAE1C,OAAO,IAAI,CAAC,OAAO,CAClB;YACC,KAAK,EAAE,UAAU;YACjB,OAAO,EAAE,UAAU;YACnB,OAAO,EAAE,cAAc,EAAE,2BAA2B;YACpD,IAAI,EAAE,IAAI;YACV,gBAAgB,EAAE,IAAI;YACtB,mBAAmB,EAAE,OAAO,EAAE,mBAAmB;YACjD,kBAAkB,EAAE,IAAI;SACxB,EACD,gBAAgB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,EACzF,IAAI,CACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACO,WAAW,CAAC,OAAgB;QACrC,OAAO;YACN,oBAAoB,EAAE;YACtB,mBAAmB,EAAE;YACrB,kBAAkB,EAAE;YACpB,mBAAmB,EAAE;YACrB,sBAAsB,EAAE;YACxB,mBAAmB,EAAE;YACrB,uBAAuB,EAAE;SACzB,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { CLIBase } from \"@twin.org/cli-core\";\nimport { buildCommandAddress, buildCommandMnemonic } from \"@twin.org/crypto-cli\";\nimport { buildCommandFaucet } from \"@twin.org/wallet-cli\";\nimport type { Command } from \"commander\";\nimport { buildCommandNftBurn } from \"./commands/nftBurn.js\";\nimport { buildCommandNftMint } from \"./commands/nftMint.js\";\nimport { buildCommandNftResolve } from \"./commands/nftResolve.js\";\nimport { buildCommandNftTransfer } from \"./commands/nftTransfer.js\";\n\n/**\n * The main entry point for the CLI.\n */\nexport class CLI extends CLIBase {\n\t/**\n\t * Run the app.\n\t * @param argv The process arguments.\n\t * @param localesDirectory The directory for the locales, default to relative to the script.\n\t * @param options Additional options for the CLI.\n\t * @param options.overrideOutputWidth Override the output width.\n\t * @returns The exit code.\n\t */\n\tpublic async run(\n\t\targv: string[],\n\t\tlocalesDirectory?: string,\n\t\toptions?: { overrideOutputWidth?: number }\n\t): Promise<number> {\n\t\treturn this.execute(\n\t\t\t{\n\t\t\t\ttitle: \"TWIN NFT\",\n\t\t\t\tappName: \"twin-nft\",\n\t\t\t\tversion: \"0.0.3-next.2\", // x-release-please-version\n\t\t\t\ticon: \"🌍\",\n\t\t\t\tsupportsEnvFiles: true,\n\t\t\t\toverrideOutputWidth: options?.overrideOutputWidth,\n\t\t\t\tshowDevToolWarning: true\n\t\t\t},\n\t\t\tlocalesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), \"../locales\"),\n\t\t\targv\n\t\t);\n\t}\n\n\t/**\n\t * Get the commands for the CLI.\n\t * @param program The main program to add the commands to.\n\t * @internal\n\t */\n\tprotected getCommands(program: Command): Command[] {\n\t\treturn [\n\t\t\tbuildCommandMnemonic(),\n\t\t\tbuildCommandAddress(),\n\t\t\tbuildCommandFaucet(),\n\t\t\tbuildCommandNftMint(),\n\t\t\tbuildCommandNftResolve(),\n\t\t\tbuildCommandNftBurn(),\n\t\t\tbuildCommandNftTransfer()\n\t\t];\n\t}\n}\n"]}
@@ -0,0 +1,72 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay, CLIParam } from "@twin.org/cli-core";
4
+ import { Converter, I18n, Is, StringHelper } from "@twin.org/core";
5
+ import { IotaNftUtils } from "@twin.org/nft-connector-iota";
6
+ import { VaultConnectorFactory } from "@twin.org/vault-models";
7
+ import { setupWalletConnector, WalletConnectorTypes } from "@twin.org/wallet-cli";
8
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
9
+ import { Command } from "commander";
10
+ import { setupNftConnector, setupVault } from "./setupCommands.js";
11
+ /**
12
+ * Build the nft burn command for the CLI.
13
+ * @returns The command.
14
+ */
15
+ export function buildCommandNftBurn() {
16
+ const command = new Command();
17
+ command
18
+ .name("nft-burn")
19
+ .summary(I18n.formatMessage("commands.nft-burn.summary"))
20
+ .description(I18n.formatMessage("commands.nft-burn.description"))
21
+ .requiredOption(I18n.formatMessage("commands.nft-burn.options.seed.param"), I18n.formatMessage("commands.nft-burn.options.seed.description"))
22
+ .requiredOption(I18n.formatMessage("commands.nft-burn.options.id.param"), I18n.formatMessage("commands.nft-burn.options.id.description"));
23
+ command
24
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
25
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
26
+ .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
27
+ .action(actionCommandNftBurn);
28
+ return command;
29
+ }
30
+ /**
31
+ * Action the nft burn command.
32
+ * @param opts The options for the command.
33
+ * @param opts.seed The seed required for signing by the issuer.
34
+ * @param opts.id The id of the NFT to burn in urn format.
35
+ * @param opts.node The node URL.
36
+ * @param opts.network The network to use for connector.
37
+ * @param opts.explorer The explorer URL.
38
+ */
39
+ export async function actionCommandNftBurn(opts) {
40
+ const seed = CLIParam.hexBase64("seed", opts.seed);
41
+ const id = CLIParam.stringValue("id", opts.id);
42
+ const nodeEndpoint = CLIParam.url("node", opts.node);
43
+ const network = CLIParam.stringValue("network", opts.network);
44
+ const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
45
+ CLIDisplay.value(I18n.formatMessage("commands.nft-burn.labels.nftId"), id);
46
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
47
+ if (Is.stringValue(network)) {
48
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
49
+ }
50
+ CLIDisplay.break();
51
+ setupVault();
52
+ const localIdentity = "local";
53
+ const vaultSeedId = "local-seed";
54
+ const vaultConnector = VaultConnectorFactory.get("vault");
55
+ await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
56
+ const walletConnector = setupWalletConnector({ nodeEndpoint, network, vaultSeedId }, WalletConnectorTypes.Iota);
57
+ WalletConnectorFactory.register("wallet", () => walletConnector);
58
+ const nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId });
59
+ const boundStart = nftConnector.start?.bind(nftConnector);
60
+ if (Is.function(boundStart)) {
61
+ await boundStart();
62
+ }
63
+ CLIDisplay.task(I18n.formatMessage("commands.nft-burn.progress.burningNft"));
64
+ CLIDisplay.break();
65
+ CLIDisplay.spinnerStart();
66
+ await nftConnector.burn(localIdentity, id);
67
+ CLIDisplay.spinnerStop();
68
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${IotaNftUtils.nftIdToObjectId(id)}?network=${network}`);
69
+ CLIDisplay.break();
70
+ CLIDisplay.done();
71
+ }
72
+ //# sourceMappingURL=nftBurn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nftBurn.js","sourceRoot":"","sources":["../../../src/commands/nftBurn.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEnE;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IAClC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,UAAU,CAAC;SAChB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,2BAA2B,CAAC,CAAC;SACxD,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,+BAA+B,CAAC,CAAC;SAChE,cAAc,CACd,IAAI,CAAC,aA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,CAAC;IAE1B,MAAM,YAAY,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IAE3C,UAAU,CAAC,WAAW,EAAE,CAAC;IAEzB,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,EACpD,GAAG,YAAY,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,WAAW,YAAY,CAAC,eAAe,CAAC,EAAE,CAAC,YAAY,OAAO,EAAE,CACrH,CAAC;IACF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIParam } from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper } from \"@twin.org/core\";\nimport { IotaNftUtils } from \"@twin.org/nft-connector-iota\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { setupWalletConnector, WalletConnectorTypes } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Command } from \"commander\";\nimport { setupNftConnector, setupVault } from \"./setupCommands.js\";\n\n/**\n * Build the nft burn command for the CLI.\n * @returns The command.\n */\nexport function buildCommandNftBurn(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"nft-burn\")\n\t\t.summary(I18n.formatMessage(\"commands.nft-burn.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.nft-burn.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-burn.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-burn.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-burn.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-burn.options.id.description\")\n\t\t);\n\n\tcommand\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.action(actionCommandNftBurn);\n\n\treturn command;\n}\n\n/**\n * Action the nft burn command.\n * @param opts The options for the command.\n * @param opts.seed The seed required for signing by the issuer.\n * @param opts.id The id of the NFT to burn in urn format.\n * @param opts.node The node URL.\n * @param opts.network The network to use for connector.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandNftBurn(opts: {\n\tseed: string;\n\tid: string;\n\tnode: string;\n\tnetwork?: string;\n\texplorer: string;\n}): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string = CLIParam.stringValue(\"network\", opts.network);\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.nft-burn.labels.nftId\"), id);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst localIdentity = \"local\";\n\tconst vaultSeedId = \"local-seed\";\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, network, vaultSeedId },\n\t\tWalletConnectorTypes.Iota\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId });\n\tconst boundStart = nftConnector.start?.bind(nftConnector);\n\tif (Is.function(boundStart)) {\n\t\tawait boundStart();\n\t}\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.nft-burn.progress.burningNft\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait nftConnector.burn(localIdentity, id);\n\n\tCLIDisplay.spinnerStop();\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${IotaNftUtils.nftIdToObjectId(id)}?network=${network}`\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,139 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import path from "node:path";
4
+ import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
5
+ import { Converter, I18n, Is, StringHelper } from "@twin.org/core";
6
+ import { IotaNftUtils } from "@twin.org/nft-connector-iota";
7
+ import { VaultConnectorFactory } from "@twin.org/vault-models";
8
+ import { setupWalletConnector, WalletConnectorTypes } from "@twin.org/wallet-cli";
9
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
10
+ import { Command } from "commander";
11
+ import { setupNftConnector, setupVault } from "./setupCommands.js";
12
+ /**
13
+ * Build the nft mint command for the CLI.
14
+ * @returns The command.
15
+ */
16
+ export function buildCommandNftMint() {
17
+ const command = new Command();
18
+ command
19
+ .name("nft-mint")
20
+ .summary(I18n.formatMessage("commands.nft-mint.summary"))
21
+ .description(I18n.formatMessage("commands.nft-mint.description"))
22
+ .requiredOption(I18n.formatMessage("commands.nft-mint.options.seed.param"), I18n.formatMessage("commands.nft-mint.options.seed.description"))
23
+ .requiredOption(I18n.formatMessage("commands.nft-mint.options.issuer.param"), I18n.formatMessage("commands.nft-mint.options.issuer.description"))
24
+ .option(I18n.formatMessage("commands.nft-mint.options.wallet-address-index.param"), I18n.formatMessage("commands.nft-mint.options.wallet-address-index.description"), "0")
25
+ .requiredOption(I18n.formatMessage("commands.nft-mint.options.tag.param"), I18n.formatMessage("commands.nft-mint.options.tag.description"))
26
+ .option(I18n.formatMessage("commands.nft-mint.options.immutable-json.param"), I18n.formatMessage("commands.nft-mint.options.immutable-json.description"))
27
+ .option(I18n.formatMessage("commands.nft-mint.options.mutable-json.param"), I18n.formatMessage("commands.nft-mint.options.mutable-json.description"));
28
+ CLIOptions.output(command, {
29
+ noConsole: true,
30
+ json: true,
31
+ env: true,
32
+ mergeJson: true,
33
+ mergeEnv: true
34
+ });
35
+ command
36
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
37
+ .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
38
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
39
+ .action(actionCommandNftMint);
40
+ return command;
41
+ }
42
+ /**
43
+ * Action the nft mint command.
44
+ * @param opts The options for the command.
45
+ * @param opts.seed The seed required for signing by the issuer.
46
+ * @param opts.issuer The identity of the issuer.
47
+ * @param opts.walletAddressIndex The wallet address index.
48
+ * @param opts.tag The tag for the NFT.
49
+ * @param opts.immutableJson Filename of the immutable JSON data.
50
+ * @param opts.mutableJson Filename of the mutable JSON data.
51
+ * @param opts.node The node URL.
52
+ * @param opts.network The network to use for connector.
53
+ * @param opts.explorer The explorer URL.
54
+ */
55
+ export async function actionCommandNftMint(opts) {
56
+ const seed = CLIParam.hexBase64("seed", opts.seed);
57
+ const issuer = CLIParam.stringValue("issuer", opts.issuer);
58
+ const walletAddressIndex = Is.empty(opts.walletAddressIndex)
59
+ ? undefined
60
+ : CLIParam.integer("wallet-address-index", opts.walletAddressIndex);
61
+ const tag = CLIParam.stringValue("tag", opts.tag);
62
+ const immutableJson = opts.immutableJson
63
+ ? path.resolve(opts.immutableJson)
64
+ : undefined;
65
+ const mutableJson = opts.mutableJson
66
+ ? path.resolve(opts.mutableJson)
67
+ : undefined;
68
+ const nodeEndpoint = CLIParam.url("node", opts.node);
69
+ const network = CLIParam.stringValue("network", opts.network);
70
+ const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
71
+ CLIDisplay.value(I18n.formatMessage("commands.nft-mint.labels.issuer"), issuer);
72
+ if (Is.integer(walletAddressIndex)) {
73
+ CLIDisplay.value(I18n.formatMessage("commands.nft-mint.labels.walletAddressIndex"), walletAddressIndex);
74
+ }
75
+ CLIDisplay.value(I18n.formatMessage("commands.nft-mint.labels.tag"), tag);
76
+ if (Is.stringValue(immutableJson)) {
77
+ CLIDisplay.value(I18n.formatMessage("commands.nft-mint.labels.immutableJsonFilename"), immutableJson);
78
+ }
79
+ if (Is.stringValue(mutableJson)) {
80
+ CLIDisplay.value(I18n.formatMessage("commands.nft-mint.labels.mutableJsonFilename"), mutableJson);
81
+ }
82
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
83
+ if (Is.stringValue(network)) {
84
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
85
+ }
86
+ CLIDisplay.break();
87
+ setupVault();
88
+ const localIdentity = issuer;
89
+ const vaultSeedId = "local-seed";
90
+ const vaultConnector = VaultConnectorFactory.get("vault");
91
+ await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
92
+ const walletConnector = setupWalletConnector({ nodeEndpoint, network, vaultSeedId }, WalletConnectorTypes.Iota);
93
+ WalletConnectorFactory.register("wallet", () => walletConnector);
94
+ const nftConnector = setupNftConnector({
95
+ nodeEndpoint,
96
+ network,
97
+ vaultSeedId,
98
+ walletAddressIndex
99
+ });
100
+ const boundStart = nftConnector.start?.bind(nftConnector);
101
+ if (Is.function(boundStart)) {
102
+ await boundStart();
103
+ }
104
+ const immutableJsonData = Is.stringValue(immutableJson)
105
+ ? await CLIUtils.readJsonFile(immutableJson)
106
+ : undefined;
107
+ const mutableJsonData = Is.stringValue(mutableJson)
108
+ ? await CLIUtils.readJsonFile(mutableJson)
109
+ : undefined;
110
+ if (Is.object(immutableJsonData)) {
111
+ CLIDisplay.section(I18n.formatMessage("commands.nft-mint.labels.immutableJson"));
112
+ CLIDisplay.json(immutableJsonData);
113
+ CLIDisplay.break();
114
+ }
115
+ if (Is.object(mutableJsonData)) {
116
+ CLIDisplay.section(I18n.formatMessage("commands.nft-mint.labels.mutableJson"));
117
+ CLIDisplay.json(mutableJsonData);
118
+ CLIDisplay.break();
119
+ }
120
+ CLIDisplay.task(I18n.formatMessage("commands.nft-mint.progress.mintingNft"));
121
+ CLIDisplay.break();
122
+ CLIDisplay.spinnerStart();
123
+ const nftId = await nftConnector.mint(localIdentity, tag, immutableJsonData, mutableJsonData);
124
+ CLIDisplay.spinnerStop();
125
+ if (opts.console) {
126
+ CLIDisplay.value(I18n.formatMessage("commands.nft-mint.labels.nftId"), nftId);
127
+ CLIDisplay.break();
128
+ }
129
+ if (Is.stringValue(opts?.json)) {
130
+ await CLIUtils.writeJsonFile(opts.json, { nftId }, opts.mergeJson);
131
+ }
132
+ if (Is.stringValue(opts?.env)) {
133
+ await CLIUtils.writeEnvFile(opts.env, [`NFT_ID="${nftId}"`], opts.mergeEnv);
134
+ }
135
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${IotaNftUtils.nftIdToObjectId(nftId)}?network=${network}`);
136
+ CLIDisplay.break();
137
+ CLIDisplay.done();
138
+ }
139
+ //# sourceMappingURL=nftMint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nftMint.js","sourceRoot":"","sources":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AAa,CAAC,gCAAgC,CAAC,EAAE,KAAK,CAAC,CAAC;QAC9E,UAAU,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACpE,CAAC;IACD,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7E,CAAC;IAED,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,EAEpD,GAAG,YAAY,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,WAAW,YAAY,CAAC,eAAe,CAAC,KAAK,CAAC,YAAY,OAAO,EAAE,CACxH,CAAC;IACF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper } from \"@twin.org/core\";\nimport { IotaNftUtils } from \"@twin.org/nft-connector-iota\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { setupWalletConnector, WalletConnectorTypes } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Command } from \"commander\";\nimport { setupNftConnector, setupVault } from \"./setupCommands.js\";\n\n/**\n * Build the nft mint command for the CLI.\n * @returns The command.\n */\nexport function buildCommandNftMint(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"nft-mint\")\n\t\t.summary(I18n.formatMessage(\"commands.nft-mint.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.nft-mint.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.issuer.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.issuer.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.wallet-address-index.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.wallet-address-index.description\"),\n\t\t\t\"0\"\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.tag.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.tag.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.immutable-json.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.immutable-json.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.mutable-json.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-mint.options.mutable-json.description\")\n\t\t);\n\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: true,\n\t\tmergeJson: true,\n\t\tmergeEnv: true\n\t});\n\n\tcommand\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.action(actionCommandNftMint);\n\n\treturn command;\n}\n\n/**\n * Action the nft mint command.\n * @param opts The options for the command.\n * @param opts.seed The seed required for signing by the issuer.\n * @param opts.issuer The identity of the issuer.\n * @param opts.walletAddressIndex The wallet address index.\n * @param opts.tag The tag for the NFT.\n * @param opts.immutableJson Filename of the immutable JSON data.\n * @param opts.mutableJson Filename of the mutable JSON data.\n * @param opts.node The node URL.\n * @param opts.network The network to use for connector.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandNftMint(\n\topts: {\n\t\tseed: string;\n\t\tissuer: string;\n\t\twalletAddressIndex?: string;\n\t\ttag: string;\n\t\timmutableJson?: string;\n\t\tmutableJson?: string;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t\texplorer: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst issuer: string = CLIParam.stringValue(\"issuer\", opts.issuer);\n\tconst walletAddressIndex = Is.empty(opts.walletAddressIndex)\n\t\t? undefined\n\t\t: CLIParam.integer(\"wallet-address-index\", opts.walletAddressIndex);\n\tconst tag: string = CLIParam.stringValue(\"tag\", opts.tag);\n\tconst immutableJson: string | undefined = opts.immutableJson\n\t\t? path.resolve(opts.immutableJson)\n\t\t: undefined;\n\tconst mutableJson: string | undefined = opts.mutableJson\n\t\t? path.resolve(opts.mutableJson)\n\t\t: undefined;\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string = CLIParam.stringValue(\"network\", opts.network);\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.nft-mint.labels.issuer\"), issuer);\n\tif (Is.integer(walletAddressIndex)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.nft-mint.labels.walletAddressIndex\"),\n\t\t\twalletAddressIndex\n\t\t);\n\t}\n\tCLIDisplay.value(I18n.formatMessage(\"commands.nft-mint.labels.tag\"), tag);\n\tif (Is.stringValue(immutableJson)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.nft-mint.labels.immutableJsonFilename\"),\n\t\t\timmutableJson\n\t\t);\n\t}\n\tif (Is.stringValue(mutableJson)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.nft-mint.labels.mutableJsonFilename\"),\n\t\t\tmutableJson\n\t\t);\n\t}\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst localIdentity = issuer;\n\tconst vaultSeedId = \"local-seed\";\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, network, vaultSeedId },\n\t\tWalletConnectorTypes.Iota\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst nftConnector = setupNftConnector({\n\t\tnodeEndpoint,\n\t\tnetwork,\n\t\tvaultSeedId,\n\t\twalletAddressIndex\n\t});\n\tconst boundStart = nftConnector.start?.bind(nftConnector);\n\tif (Is.function(boundStart)) {\n\t\tawait boundStart();\n\t}\n\n\tconst immutableJsonData = Is.stringValue(immutableJson)\n\t\t? await CLIUtils.readJsonFile(immutableJson)\n\t\t: undefined;\n\tconst mutableJsonData = Is.stringValue(mutableJson)\n\t\t? await CLIUtils.readJsonFile(mutableJson)\n\t\t: undefined;\n\n\tif (Is.object(immutableJsonData)) {\n\t\tCLIDisplay.section(I18n.formatMessage(\"commands.nft-mint.labels.immutableJson\"));\n\t\tCLIDisplay.json(immutableJsonData);\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.object(mutableJsonData)) {\n\t\tCLIDisplay.section(I18n.formatMessage(\"commands.nft-mint.labels.mutableJson\"));\n\t\tCLIDisplay.json(mutableJsonData);\n\t\tCLIDisplay.break();\n\t}\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.nft-mint.progress.mintingNft\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst nftId = await nftConnector.mint(localIdentity, tag, immutableJsonData, mutableJsonData);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.nft-mint.labels.nftId\"), nftId);\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, { nftId }, opts.mergeJson);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(opts.env, [`NFT_ID=\"${nftId}\"`], opts.mergeEnv);\n\t}\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\n\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${IotaNftUtils.nftIdToObjectId(nftId)}?network=${network}`\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,75 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
4
+ import { I18n, Is, StringHelper } from "@twin.org/core";
5
+ import { IotaNftUtils } from "@twin.org/nft-connector-iota";
6
+ import { setupWalletConnector, WalletConnectorTypes } from "@twin.org/wallet-cli";
7
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
8
+ import { Command } from "commander";
9
+ import { setupNftConnector, setupVault } from "./setupCommands.js";
10
+ /**
11
+ * Build the nft resolve command for the CLI.
12
+ * @returns The command.
13
+ */
14
+ export function buildCommandNftResolve() {
15
+ const command = new Command();
16
+ command
17
+ .name("nft-resolve")
18
+ .summary(I18n.formatMessage("commands.nft-resolve.summary"))
19
+ .description(I18n.formatMessage("commands.nft-resolve.description"))
20
+ .requiredOption(I18n.formatMessage("commands.nft-resolve.options.id.param"), I18n.formatMessage("commands.nft-resolve.options.id.description"));
21
+ CLIOptions.output(command, {
22
+ noConsole: true,
23
+ json: true,
24
+ env: false,
25
+ mergeJson: true,
26
+ mergeEnv: false
27
+ });
28
+ command
29
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
30
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
31
+ .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
32
+ .action(actionCommandNftResolve);
33
+ return command;
34
+ }
35
+ /**
36
+ * Action the nft resolve command.
37
+ * @param opts The options for the command.
38
+ * @param opts.id The id of the NFT to resolve in urn format.
39
+ * @param opts.node The node URL.
40
+ * @param opts.network The network to use for connector.
41
+ * @param opts.explorer The explorer URL.
42
+ */
43
+ export async function actionCommandNftResolve(opts) {
44
+ const id = CLIParam.stringValue("id", opts.id);
45
+ const nodeEndpoint = CLIParam.url("node", opts.node);
46
+ const network = CLIParam.stringValue("network", opts.network);
47
+ const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
48
+ CLIDisplay.value(I18n.formatMessage("commands.nft-resolve.labels.nftId"), id);
49
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
50
+ if (Is.stringValue(network)) {
51
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
52
+ }
53
+ CLIDisplay.break();
54
+ setupVault();
55
+ const walletConnector = setupWalletConnector({ nodeEndpoint, network }, WalletConnectorTypes.Iota);
56
+ WalletConnectorFactory.register("wallet", () => walletConnector);
57
+ const nftConnector = setupNftConnector({ nodeEndpoint, network });
58
+ CLIDisplay.task(I18n.formatMessage("commands.nft-resolve.progress.resolvingNft"));
59
+ CLIDisplay.break();
60
+ CLIDisplay.spinnerStart();
61
+ const nft = await nftConnector.resolve(id);
62
+ CLIDisplay.spinnerStop();
63
+ if (opts.console) {
64
+ CLIDisplay.section(I18n.formatMessage("commands.nft-resolve.labels.nft"));
65
+ CLIDisplay.json(nft);
66
+ CLIDisplay.break();
67
+ }
68
+ if (Is.stringValue(opts?.json)) {
69
+ await CLIUtils.writeJsonFile(opts.json, nft, opts.mergeJson);
70
+ }
71
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${IotaNftUtils.nftIdToObjectId(id)}?network=${network}`);
72
+ CLIDisplay.break();
73
+ CLIDisplay.done();
74
+ }
75
+ //# sourceMappingURL=nftResolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nftResolve.js","sourceRoot":"","sources":["../../../src/commands/nftResolve.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,M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AC,IAAI,CAAC,aAAa,CAAC,iCAAiC,CAAC,CAAC,CAAC;QAC1E,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrB,UAAU,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;IAED,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,EACpD,GAAG,YAAY,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,WAAW,YAAY,CAAC,eAAe,CAAC,EAAE,CAAC,YAAY,OAAO,EAAE,CACrH,CAAC;IACF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { I18n, Is, StringHelper } from \"@twin.org/core\";\nimport { IotaNftUtils } from \"@twin.org/nft-connector-iota\";\nimport { setupWalletConnector, WalletConnectorTypes } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Command } from \"commander\";\nimport { setupNftConnector, setupVault } from \"./setupCommands.js\";\n\n/**\n * Build the nft resolve command for the CLI.\n * @returns The command.\n */\nexport function buildCommandNftResolve(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"nft-resolve\")\n\t\t.summary(I18n.formatMessage(\"commands.nft-resolve.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.nft-resolve.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-resolve.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-resolve.options.id.description\")\n\t\t);\n\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: false,\n\t\tmergeJson: true,\n\t\tmergeEnv: false\n\t});\n\n\tcommand\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.action(actionCommandNftResolve);\n\n\treturn command;\n}\n\n/**\n * Action the nft resolve command.\n * @param opts The options for the command.\n * @param opts.id The id of the NFT to resolve in urn format.\n * @param opts.node The node URL.\n * @param opts.network The network to use for connector.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandNftResolve(\n\topts: {\n\t\tid: string;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t\texplorer: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string = CLIParam.stringValue(\"network\", opts.network);\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.nft-resolve.labels.nftId\"), id);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, network },\n\t\tWalletConnectorTypes.Iota\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst nftConnector = setupNftConnector({ nodeEndpoint, network });\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.nft-resolve.progress.resolvingNft\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst nft = await nftConnector.resolve(id);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.section(I18n.formatMessage(\"commands.nft-resolve.labels.nft\"));\n\t\tCLIDisplay.json(nft);\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, nft, opts.mergeJson);\n\t}\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${IotaNftUtils.nftIdToObjectId(id)}?network=${network}`\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,80 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay, CLIParam } from "@twin.org/cli-core";
4
+ import { Converter, I18n, Is, StringHelper } from "@twin.org/core";
5
+ import { IotaNftUtils } from "@twin.org/nft-connector-iota";
6
+ import { VaultConnectorFactory } from "@twin.org/vault-models";
7
+ import { setupWalletConnector, WalletConnectorTypes } from "@twin.org/wallet-cli";
8
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
9
+ import { Command } from "commander";
10
+ import { setupNftConnector, setupVault } from "./setupCommands.js";
11
+ /**
12
+ * Build the nft transfer command for the CLI.
13
+ * @returns The command.
14
+ */
15
+ export function buildCommandNftTransfer() {
16
+ const command = new Command();
17
+ command
18
+ .name("nft-transfer")
19
+ .summary(I18n.formatMessage("commands.nft-transfer.summary"))
20
+ .description(I18n.formatMessage("commands.nft-transfer.description"))
21
+ .requiredOption(I18n.formatMessage("commands.nft-transfer.options.seed.param"), I18n.formatMessage("commands.nft-transfer.options.seed.description"))
22
+ .requiredOption(I18n.formatMessage("commands.nft-transfer.options.id.param"), I18n.formatMessage("commands.nft-transfer.options.id.description"))
23
+ .requiredOption(I18n.formatMessage("commands.nft-transfer.options.recipient-identity.param"), I18n.formatMessage("commands.nft-transfer.options.recipient-identity.description"))
24
+ .requiredOption(I18n.formatMessage("commands.nft-transfer.options.recipient-address.param"), I18n.formatMessage("commands.nft-transfer.options.recipient-address.description"));
25
+ command
26
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
27
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
28
+ .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
29
+ .action(actionCommandNftTransfer);
30
+ return command;
31
+ }
32
+ /**
33
+ * Action the nft transfer command.
34
+ * @param opts The options for the command.
35
+ * @param opts.seed The seed required for signing by the issuer.
36
+ * @param opts.id The id of the NFT to transfer in urn format.
37
+ * @param opts.recipientIdentity The recipient address of the NFT.
38
+ * @param opts.recipientAddress The recipient address of the NFT.
39
+ * @param opts.node The node URL.
40
+ * @param opts.network The network to use for connector.
41
+ * @param opts.explorer The explorer URL.
42
+ */
43
+ export async function actionCommandNftTransfer(opts) {
44
+ const seed = CLIParam.hexBase64("seed", opts.seed);
45
+ const id = CLIParam.stringValue("id", opts.id);
46
+ const recipientIdentity = CLIParam.stringValue("recipientIdentity", opts.recipientIdentity);
47
+ const recipientAddress = Converter.bytesToHex(CLIParam.hex("recipientAddress", opts.recipientAddress), true);
48
+ const nodeEndpoint = CLIParam.url("node", opts.node);
49
+ const network = CLIParam.stringValue("network", opts.network);
50
+ const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
51
+ CLIDisplay.value(I18n.formatMessage("commands.nft-transfer.labels.nftId"), id);
52
+ CLIDisplay.value(I18n.formatMessage("commands.nft-transfer.labels.recipientIdentity"), recipientIdentity);
53
+ CLIDisplay.value(I18n.formatMessage("commands.nft-transfer.labels.recipientAddress"), recipientAddress);
54
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
55
+ if (Is.stringValue(network)) {
56
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
57
+ }
58
+ CLIDisplay.break();
59
+ setupVault();
60
+ const walletConnector = setupWalletConnector({ nodeEndpoint, network }, WalletConnectorTypes.Iota);
61
+ WalletConnectorFactory.register("wallet", () => walletConnector);
62
+ const localIdentity = "local";
63
+ const vaultSeedId = "local-seed";
64
+ const vaultConnector = VaultConnectorFactory.get("vault");
65
+ await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
66
+ const nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId });
67
+ const boundStart = nftConnector.start?.bind(nftConnector);
68
+ if (Is.function(boundStart)) {
69
+ await boundStart();
70
+ }
71
+ CLIDisplay.task(I18n.formatMessage("commands.nft-transfer.progress.transferringNft"));
72
+ CLIDisplay.break();
73
+ CLIDisplay.spinnerStart();
74
+ await nftConnector.transfer(localIdentity, id, recipientIdentity, recipientAddress);
75
+ CLIDisplay.spinnerStop();
76
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${IotaNftUtils.nftIdToObjectId(id)}?network=${network}`);
77
+ CLIDisplay.break();
78
+ CLIDisplay.done();
79
+ }
80
+ //# sourceMappingURL=nftTransfer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nftTransfer.js","sourceRoot":"","sources":["../../../src/commands/nftTransfer.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EA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;IACpB,CAAC;IAED,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC,CAAC,CAAC;IACtF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,YAAY,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,EAAE,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;IAEpF,UAAU,CAAC,WAAW,EAAE,CAAC;IAEzB,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,EACpD,GAAG,YAAY,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,WAAW,YAAY,CAAC,eAAe,CAAC,EAAE,CAAC,YAAY,OAAO,EAAE,CACrH,CAAC;IACF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIParam } from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper } from \"@twin.org/core\";\nimport { IotaNftUtils } from \"@twin.org/nft-connector-iota\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { setupWalletConnector, WalletConnectorTypes } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Command } from \"commander\";\nimport { setupNftConnector, setupVault } from \"./setupCommands.js\";\n\n/**\n * Build the nft transfer command for the CLI.\n * @returns The command.\n */\nexport function buildCommandNftTransfer(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"nft-transfer\")\n\t\t.summary(I18n.formatMessage(\"commands.nft-transfer.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.nft-transfer.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-transfer.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-transfer.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-transfer.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-transfer.options.id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-transfer.options.recipient-identity.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-transfer.options.recipient-identity.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.nft-transfer.options.recipient-address.param\"),\n\t\t\tI18n.formatMessage(\"commands.nft-transfer.options.recipient-address.description\")\n\t\t);\n\n\tcommand\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.action(actionCommandNftTransfer);\n\n\treturn command;\n}\n\n/**\n * Action the nft transfer command.\n * @param opts The options for the command.\n * @param opts.seed The seed required for signing by the issuer.\n * @param opts.id The id of the NFT to transfer in urn format.\n * @param opts.recipientIdentity The recipient address of the NFT.\n * @param opts.recipientAddress The recipient address of the NFT.\n * @param opts.node The node URL.\n * @param opts.network The network to use for connector.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandNftTransfer(opts: {\n\tseed: string;\n\tid: string;\n\trecipientIdentity: string;\n\trecipientAddress: string;\n\tnode: string;\n\tnetwork?: string;\n\texplorer: string;\n}): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst recipientIdentity: string = CLIParam.stringValue(\n\t\t\"recipientIdentity\",\n\t\topts.recipientIdentity\n\t);\n\tconst recipientAddress: string = Converter.bytesToHex(\n\t\tCLIParam.hex(\"recipientAddress\", opts.recipientAddress),\n\t\ttrue\n\t);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string = CLIParam.stringValue(\"network\", opts.network);\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.nft-transfer.labels.nftId\"), id);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.nft-transfer.labels.recipientIdentity\"),\n\t\trecipientIdentity\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.nft-transfer.labels.recipientAddress\"),\n\t\trecipientAddress\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, network },\n\t\tWalletConnectorTypes.Iota\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst localIdentity = \"local\";\n\tconst vaultSeedId = \"local-seed\";\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId });\n\tconst boundStart = nftConnector.start?.bind(nftConnector);\n\tif (Is.function(boundStart)) {\n\t\tawait boundStart();\n\t}\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.nft-transfer.progress.transferringNft\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait nftConnector.transfer(localIdentity, id, recipientIdentity, recipientAddress);\n\n\tCLIDisplay.spinnerStop();\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${IotaNftUtils.nftIdToObjectId(id)}?network=${network}`\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,43 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { MemoryEntityStorageConnector } from "@twin.org/entity-storage-connector-memory";
4
+ import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
5
+ import { IotaNftConnector } from "@twin.org/nft-connector-iota";
6
+ import { EntityStorageVaultConnector, initSchema } from "@twin.org/vault-connector-entity-storage";
7
+ import { VaultConnectorFactory } from "@twin.org/vault-models";
8
+ /**
9
+ * Setup the vault for use in the CLI commands.
10
+ */
11
+ export function setupVault() {
12
+ initSchema();
13
+ EntityStorageConnectorFactory.register("vault-key", () => new MemoryEntityStorageConnector({
14
+ entitySchema: "VaultKey"
15
+ }));
16
+ EntityStorageConnectorFactory.register("vault-secret", () => new MemoryEntityStorageConnector({
17
+ entitySchema: "VaultSecret"
18
+ }));
19
+ const vaultConnector = new EntityStorageVaultConnector();
20
+ VaultConnectorFactory.register("vault", () => vaultConnector);
21
+ }
22
+ /**
23
+ * Setup the NFT connector for use in the CLI commands.
24
+ * @param options The options for the NFT connector.
25
+ * @param options.nodeEndpoint The node endpoint.
26
+ * @param options.network The network.
27
+ * @param options.vaultSeedId The vault seed ID.
28
+ * @param options.walletAddressIndex The wallet address index.
29
+ * @returns The NFT connector.
30
+ */
31
+ export function setupNftConnector(options) {
32
+ return new IotaNftConnector({
33
+ config: {
34
+ clientOptions: {
35
+ url: options.nodeEndpoint
36
+ },
37
+ network: options.network ?? "",
38
+ vaultSeedId: options.vaultSeedId,
39
+ walletAddressIndex: options.walletAddressIndex ?? 0
40
+ }
41
+ });
42
+ }
43
+ //# sourceMappingURL=setupCommands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupCommands.js","sourceRoot":"","sources":["../../../src/commands/setupCommands.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AACzF,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EACN,2BAA2B,EAG3B,UAAU,EACV,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;GAEG;AACH,MAAM,UAAU,UAAU;IACzB,UAAU,EAAE,CAAC;IAEb,6BAA6B,CAAC,QAAQ,CACrC,WAAW,EACX,GAAG,EAAE,CACJ,IAAI,4BAA4B,CAAW;QAC1C,YAAY,YAAoB;KAChC,CAAC,CACH,CAAC;IACF,6BAA6B,CAAC,QAAQ,CACrC,cAAc,EACd,GAAG,EAAE,CACJ,IAAI,4BAA4B,CAAc;QAC7C,YAAY,eAAuB;KACnC,CAAC,CACH,CAAC;IAEF,MAAM,cAAc,GAAG,IAAI,2BAA2B,EAAE,CAAC;IACzD,qBAAqB,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAKjC;IACA,OAAO,IAAI,gBAAgB,CAAC;QAC3B,MAAM,EAAE;YACP,aAAa,EAAE;gBACd,GAAG,EAAE,OAAO,CAAC,YAAY;aACzB;YACD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,CAAC;SACnD;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { MemoryEntityStorageConnector } from \"@twin.org/entity-storage-connector-memory\";\nimport { EntityStorageConnectorFactory } from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { IotaNftConnector } from \"@twin.org/nft-connector-iota\";\nimport type { INftConnector } from \"@twin.org/nft-models\";\nimport {\n\tEntityStorageVaultConnector,\n\ttype VaultKey,\n\ttype VaultSecret,\n\tinitSchema\n} from \"@twin.org/vault-connector-entity-storage\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\n\n/**\n * Setup the vault for use in the CLI commands.\n */\nexport function setupVault(): void {\n\tinitSchema();\n\n\tEntityStorageConnectorFactory.register(\n\t\t\"vault-key\",\n\t\t() =>\n\t\t\tnew MemoryEntityStorageConnector<VaultKey>({\n\t\t\t\tentitySchema: nameof<VaultKey>()\n\t\t\t})\n\t);\n\tEntityStorageConnectorFactory.register(\n\t\t\"vault-secret\",\n\t\t() =>\n\t\t\tnew MemoryEntityStorageConnector<VaultSecret>({\n\t\t\t\tentitySchema: nameof<VaultSecret>()\n\t\t\t})\n\t);\n\n\tconst vaultConnector = new EntityStorageVaultConnector();\n\tVaultConnectorFactory.register(\"vault\", () => vaultConnector);\n}\n\n/**\n * Setup the NFT connector for use in the CLI commands.\n * @param options The options for the NFT connector.\n * @param options.nodeEndpoint The node endpoint.\n * @param options.network The network.\n * @param options.vaultSeedId The vault seed ID.\n * @param options.walletAddressIndex The wallet address index.\n * @returns The NFT connector.\n */\nexport function setupNftConnector(options: {\n\tnodeEndpoint: string;\n\tnetwork?: string;\n\tvaultSeedId?: string;\n\twalletAddressIndex?: number;\n}): INftConnector {\n\treturn new IotaNftConnector({\n\t\tconfig: {\n\t\t\tclientOptions: {\n\t\t\t\turl: options.nodeEndpoint\n\t\t\t},\n\t\t\tnetwork: options.network ?? \"\",\n\t\t\tvaultSeedId: options.vaultSeedId,\n\t\t\twalletAddressIndex: options.walletAddressIndex ?? 0\n\t\t}\n\t});\n}\n"]}
@@ -0,0 +1,9 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./cli.js";
4
+ export * from "./commands/nftBurn.js";
5
+ export * from "./commands/nftMint.js";
6
+ export * from "./commands/nftResolve.js";
7
+ export * from "./commands/nftTransfer.js";
8
+ export * from "./commands/setupCommands.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./cli.js\";\nexport * from \"./commands/nftBurn.js\";\nexport * from \"./commands/nftMint.js\";\nexport * from \"./commands/nftResolve.js\";\nexport * from \"./commands/nftTransfer.js\";\nexport * from \"./commands/setupCommands.js\";\n"]}