@twin.org/nft-cli 0.0.2-next.7 → 0.0.3-next.1

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.
Files changed (34) hide show
  1. package/bin/index.js +1 -1
  2. package/dist/es/cli.js +52 -0
  3. package/dist/es/cli.js.map +1 -0
  4. package/dist/es/commands/nftBurn.js +72 -0
  5. package/dist/es/commands/nftBurn.js.map +1 -0
  6. package/dist/es/commands/nftMint.js +139 -0
  7. package/dist/es/commands/nftMint.js.map +1 -0
  8. package/dist/es/commands/nftResolve.js +75 -0
  9. package/dist/es/commands/nftResolve.js.map +1 -0
  10. package/dist/es/commands/nftTransfer.js +80 -0
  11. package/dist/es/commands/nftTransfer.js.map +1 -0
  12. package/dist/es/commands/setupCommands.js +43 -0
  13. package/dist/es/commands/setupCommands.js.map +1 -0
  14. package/dist/es/index.js +9 -0
  15. package/dist/es/index.js.map +1 -0
  16. package/dist/locales/en.json +27 -66
  17. package/dist/types/commands/nftBurn.d.ts +0 -3
  18. package/dist/types/commands/nftMint.d.ts +0 -3
  19. package/dist/types/commands/nftResolve.d.ts +0 -3
  20. package/dist/types/commands/nftTransfer.d.ts +0 -3
  21. package/dist/types/commands/setupCommands.d.ts +1 -3
  22. package/dist/types/index.d.ts +6 -7
  23. package/docs/changelog.md +42 -0
  24. package/docs/reference/functions/actionCommandNftBurn.md +0 -6
  25. package/docs/reference/functions/actionCommandNftTransfer.md +0 -6
  26. package/docs/reference/functions/setupNftConnector.md +1 -7
  27. package/docs/reference/index.md +0 -8
  28. package/locales/en.json +4 -8
  29. package/package.json +23 -10
  30. package/dist/cjs/index.cjs +0 -477
  31. package/dist/esm/index.mjs +0 -463
  32. package/dist/types/models/nftConnectorTypes.d.ts +0 -13
  33. package/docs/reference/type-aliases/NftConnectorTypes.md +0 -5
  34. package/docs/reference/variables/NftConnectorTypes.md +0 -13
@@ -1,477 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('node:path');
4
- var node_url = require('node:url');
5
- var cliCore = require('@twin.org/cli-core');
6
- var cryptoCli = require('@twin.org/crypto-cli');
7
- var walletCli = require('@twin.org/wallet-cli');
8
- var core = require('@twin.org/core');
9
- var nftConnectorIota = require('@twin.org/nft-connector-iota');
10
- var vaultModels = require('@twin.org/vault-models');
11
- var walletModels = require('@twin.org/wallet-models');
12
- var commander = require('commander');
13
- var entityStorageConnectorMemory = require('@twin.org/entity-storage-connector-memory');
14
- var entityStorageModels = require('@twin.org/entity-storage-models');
15
- var vaultConnectorEntityStorage = require('@twin.org/vault-connector-entity-storage');
16
-
17
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
18
- // Copyright 2024 IOTA Stiftung.
19
- // SPDX-License-Identifier: Apache-2.0.
20
- /**
21
- * The NFT connector types.
22
- */
23
- // eslint-disable-next-line @typescript-eslint/naming-convention
24
- const NftConnectorTypes = {
25
- /**
26
- * IOTA.
27
- */
28
- Iota: "iota"
29
- };
30
-
31
- // Copyright 2024 IOTA Stiftung.
32
- // SPDX-License-Identifier: Apache-2.0.
33
- /**
34
- * Setup the vault for use in the CLI commands.
35
- */
36
- function setupVault() {
37
- vaultConnectorEntityStorage.initSchema();
38
- entityStorageModels.EntityStorageConnectorFactory.register("vault-key", () => new entityStorageConnectorMemory.MemoryEntityStorageConnector({
39
- entitySchema: "VaultKey"
40
- }));
41
- entityStorageModels.EntityStorageConnectorFactory.register("vault-secret", () => new entityStorageConnectorMemory.MemoryEntityStorageConnector({
42
- entitySchema: "VaultSecret"
43
- }));
44
- const vaultConnector = new vaultConnectorEntityStorage.EntityStorageVaultConnector();
45
- vaultModels.VaultConnectorFactory.register("vault", () => vaultConnector);
46
- }
47
- /**
48
- * Setup the NFT connector for use in the CLI commands.
49
- * @param options The options for the NFT connector.
50
- * @param options.nodeEndpoint The node endpoint.
51
- * @param options.network The network.
52
- * @param options.vaultSeedId The vault seed ID.
53
- * @param options.walletAddressIndex The wallet address index.
54
- * @param connector The connector to use.
55
- * @returns The NFT connector.
56
- */
57
- function setupNftConnector(options, connector) {
58
- connector ??= NftConnectorTypes.Iota;
59
- return new nftConnectorIota.IotaNftConnector({
60
- config: {
61
- clientOptions: {
62
- url: options.nodeEndpoint
63
- },
64
- network: options.network ?? "",
65
- vaultSeedId: options.vaultSeedId,
66
- walletAddressIndex: options.walletAddressIndex ?? 0
67
- }
68
- });
69
- }
70
-
71
- // Copyright 2024 IOTA Stiftung.
72
- // SPDX-License-Identifier: Apache-2.0.
73
- /**
74
- * Build the nft burn command for the CLI.
75
- * @returns The command.
76
- */
77
- function buildCommandNftBurn() {
78
- const command = new commander.Command();
79
- command
80
- .name("nft-burn")
81
- .summary(core.I18n.formatMessage("commands.nft-burn.summary"))
82
- .description(core.I18n.formatMessage("commands.nft-burn.description"))
83
- .requiredOption(core.I18n.formatMessage("commands.nft-burn.options.seed.param"), core.I18n.formatMessage("commands.nft-burn.options.seed.description"))
84
- .requiredOption(core.I18n.formatMessage("commands.nft-burn.options.id.param"), core.I18n.formatMessage("commands.nft-burn.options.id.description"));
85
- command
86
- .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
87
- .choices(Object.values(NftConnectorTypes))
88
- .default(NftConnectorTypes.Iota))
89
- .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
90
- .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
91
- .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
92
- .action(actionCommandNftBurn);
93
- return command;
94
- }
95
- /**
96
- * Action the nft burn command.
97
- * @param opts The options for the command.
98
- * @param opts.seed The seed required for signing by the issuer.
99
- * @param opts.id The id of the NFT to burn in urn format.
100
- * @param opts.connector The connector to perform the operations with.
101
- * @param opts.node The node URL.
102
- * @param opts.network The network to use for connector.
103
- * @param opts.explorer The explorer URL.
104
- */
105
- async function actionCommandNftBurn(opts) {
106
- const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
107
- const id = cliCore.CLIParam.stringValue("id", opts.id);
108
- const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
109
- const network = opts.connector === NftConnectorTypes.Iota
110
- ? cliCore.CLIParam.stringValue("network", opts.network)
111
- : undefined;
112
- const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
113
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-burn.labels.nftId"), id);
114
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
115
- if (core.Is.stringValue(network)) {
116
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
117
- }
118
- cliCore.CLIDisplay.break();
119
- setupVault();
120
- const localIdentity = "local";
121
- const vaultSeedId = "local-seed";
122
- const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
123
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
124
- const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
125
- walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
126
- const nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
127
- if (core.Is.function(nftConnector.start)) {
128
- await nftConnector.start(localIdentity);
129
- }
130
- cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.nft-burn.progress.burningNft"));
131
- cliCore.CLIDisplay.break();
132
- cliCore.CLIDisplay.spinnerStart();
133
- await nftConnector.burn(localIdentity, id);
134
- cliCore.CLIDisplay.spinnerStop();
135
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${nftConnectorIota.IotaNftUtils.nftIdToObjectId(id)}?network=${network}`);
136
- cliCore.CLIDisplay.break();
137
- cliCore.CLIDisplay.done();
138
- }
139
-
140
- // Copyright 2024 IOTA Stiftung.
141
- // SPDX-License-Identifier: Apache-2.0.
142
- /**
143
- * Build the nft mint command for the CLI.
144
- * @returns The command.
145
- */
146
- function buildCommandNftMint() {
147
- const command = new commander.Command();
148
- command
149
- .name("nft-mint")
150
- .summary(core.I18n.formatMessage("commands.nft-mint.summary"))
151
- .description(core.I18n.formatMessage("commands.nft-mint.description"))
152
- .requiredOption(core.I18n.formatMessage("commands.nft-mint.options.seed.param"), core.I18n.formatMessage("commands.nft-mint.options.seed.description"))
153
- .requiredOption(core.I18n.formatMessage("commands.nft-mint.options.issuer.param"), core.I18n.formatMessage("commands.nft-mint.options.issuer.description"))
154
- .option(core.I18n.formatMessage("commands.nft-mint.options.wallet-address-index.param"), core.I18n.formatMessage("commands.nft-mint.options.wallet-address-index.description"), "0")
155
- .requiredOption(core.I18n.formatMessage("commands.nft-mint.options.tag.param"), core.I18n.formatMessage("commands.nft-mint.options.tag.description"))
156
- .option(core.I18n.formatMessage("commands.nft-mint.options.immutable-json.param"), core.I18n.formatMessage("commands.nft-mint.options.immutable-json.description"))
157
- .option(core.I18n.formatMessage("commands.nft-mint.options.mutable-json.param"), core.I18n.formatMessage("commands.nft-mint.options.mutable-json.description"));
158
- cliCore.CLIOptions.output(command, {
159
- noConsole: true,
160
- json: true,
161
- env: true,
162
- mergeJson: true,
163
- mergeEnv: true
164
- });
165
- command
166
- .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
167
- .choices(Object.values(NftConnectorTypes))
168
- .default(NftConnectorTypes.Iota))
169
- .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
170
- .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
171
- .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
172
- .action(actionCommandNftMint);
173
- return command;
174
- }
175
- /**
176
- * Action the nft mint command.
177
- * @param opts The options for the command.
178
- * @param opts.seed The seed required for signing by the issuer.
179
- * @param opts.issuer The identity of the issuer.
180
- * @param opts.walletAddressIndex The wallet address index.
181
- * @param opts.tag The tag for the NFT.
182
- * @param opts.immutableJson Filename of the immutable JSON data.
183
- * @param opts.mutableJson Filename of the mutable JSON data.
184
- * @param opts.connector The connector to perform the operations with.
185
- * @param opts.node The node URL.
186
- * @param opts.network The network to use for connector.
187
- * @param opts.explorer The explorer URL.
188
- */
189
- async function actionCommandNftMint(opts) {
190
- const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
191
- const issuer = cliCore.CLIParam.stringValue("issuer", opts.issuer);
192
- const walletAddressIndex = core.Is.empty(opts.walletAddressIndex)
193
- ? undefined
194
- : cliCore.CLIParam.integer("wallet-address-index", opts.walletAddressIndex);
195
- const tag = cliCore.CLIParam.stringValue("tag", opts.tag);
196
- const immutableJson = opts.immutableJson
197
- ? path.resolve(opts.immutableJson)
198
- : undefined;
199
- const mutableJson = opts.mutableJson
200
- ? path.resolve(opts.mutableJson)
201
- : undefined;
202
- const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
203
- const network = opts.connector === NftConnectorTypes.Iota
204
- ? cliCore.CLIParam.stringValue("network", opts.network)
205
- : undefined;
206
- const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
207
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.issuer"), issuer);
208
- if (core.Is.integer(walletAddressIndex)) {
209
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.walletAddressIndex"), walletAddressIndex);
210
- }
211
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.tag"), tag);
212
- if (core.Is.stringValue(immutableJson)) {
213
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.immutableJsonFilename"), immutableJson);
214
- }
215
- if (core.Is.stringValue(mutableJson)) {
216
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.mutableJsonFilename"), mutableJson);
217
- }
218
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
219
- if (core.Is.stringValue(network)) {
220
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
221
- }
222
- cliCore.CLIDisplay.break();
223
- setupVault();
224
- const localIdentity = issuer;
225
- const vaultSeedId = "local-seed";
226
- const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
227
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
228
- const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
229
- walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
230
- const nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId, walletAddressIndex }, opts.connector);
231
- if (core.Is.function(nftConnector.start)) {
232
- await nftConnector.start(localIdentity);
233
- }
234
- const immutableJsonData = core.Is.stringValue(immutableJson)
235
- ? await cliCore.CLIUtils.readJsonFile(immutableJson)
236
- : undefined;
237
- const mutableJsonData = core.Is.stringValue(mutableJson)
238
- ? await cliCore.CLIUtils.readJsonFile(mutableJson)
239
- : undefined;
240
- if (core.Is.object(immutableJsonData)) {
241
- cliCore.CLIDisplay.section(core.I18n.formatMessage("commands.nft-mint.labels.immutableJson"));
242
- cliCore.CLIDisplay.json(immutableJsonData);
243
- cliCore.CLIDisplay.break();
244
- }
245
- if (core.Is.object(mutableJsonData)) {
246
- cliCore.CLIDisplay.section(core.I18n.formatMessage("commands.nft-mint.labels.mutableJson"));
247
- cliCore.CLIDisplay.json(mutableJsonData);
248
- cliCore.CLIDisplay.break();
249
- }
250
- cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.nft-mint.progress.mintingNft"));
251
- cliCore.CLIDisplay.break();
252
- cliCore.CLIDisplay.spinnerStart();
253
- const nftId = await nftConnector.mint(localIdentity, tag, immutableJsonData, mutableJsonData);
254
- cliCore.CLIDisplay.spinnerStop();
255
- if (opts.console) {
256
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.nftId"), nftId);
257
- cliCore.CLIDisplay.break();
258
- }
259
- if (core.Is.stringValue(opts?.json)) {
260
- await cliCore.CLIUtils.writeJsonFile(opts.json, { nftId }, opts.mergeJson);
261
- }
262
- if (core.Is.stringValue(opts?.env)) {
263
- await cliCore.CLIUtils.writeEnvFile(opts.env, [`NFT_ID="${nftId}"`], opts.mergeEnv);
264
- }
265
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${nftConnectorIota.IotaNftUtils.nftIdToObjectId(nftId)}?network=${network}`);
266
- cliCore.CLIDisplay.break();
267
- cliCore.CLIDisplay.done();
268
- }
269
-
270
- // Copyright 2024 IOTA Stiftung.
271
- // SPDX-License-Identifier: Apache-2.0.
272
- /**
273
- * Build the nft resolve command for the CLI.
274
- * @returns The command.
275
- */
276
- function buildCommandNftResolve() {
277
- const command = new commander.Command();
278
- command
279
- .name("nft-resolve")
280
- .summary(core.I18n.formatMessage("commands.nft-resolve.summary"))
281
- .description(core.I18n.formatMessage("commands.nft-resolve.description"))
282
- .requiredOption(core.I18n.formatMessage("commands.nft-resolve.options.id.param"), core.I18n.formatMessage("commands.nft-resolve.options.id.description"));
283
- cliCore.CLIOptions.output(command, {
284
- noConsole: true,
285
- json: true,
286
- env: false,
287
- mergeJson: true,
288
- mergeEnv: false
289
- });
290
- command
291
- .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
292
- .choices(Object.values(NftConnectorTypes))
293
- .default(NftConnectorTypes.Iota))
294
- .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
295
- .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
296
- .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
297
- .action(actionCommandNftResolve);
298
- return command;
299
- }
300
- /**
301
- * Action the nft resolve command.
302
- * @param opts The options for the command.
303
- * @param opts.id The id of the NFT to resolve in urn format.
304
- * @param opts.connector The connector to perform the operations with.
305
- * @param opts.node The node URL.
306
- * @param opts.network The network to use for connector.
307
- * @param opts.explorer The explorer URL.
308
- */
309
- async function actionCommandNftResolve(opts) {
310
- const id = cliCore.CLIParam.stringValue("id", opts.id);
311
- const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
312
- const network = opts.connector === NftConnectorTypes.Iota
313
- ? cliCore.CLIParam.stringValue("network", opts.network)
314
- : undefined;
315
- const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
316
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-resolve.labels.nftId"), id);
317
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
318
- if (core.Is.stringValue(network)) {
319
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
320
- }
321
- cliCore.CLIDisplay.break();
322
- setupVault();
323
- const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, network }, opts.connector);
324
- walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
325
- const nftConnector = setupNftConnector({ nodeEndpoint, network }, opts.connector);
326
- cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.nft-resolve.progress.resolvingNft"));
327
- cliCore.CLIDisplay.break();
328
- cliCore.CLIDisplay.spinnerStart();
329
- const nft = await nftConnector.resolve(id);
330
- cliCore.CLIDisplay.spinnerStop();
331
- if (opts.console) {
332
- cliCore.CLIDisplay.section(core.I18n.formatMessage("commands.nft-resolve.labels.nft"));
333
- cliCore.CLIDisplay.json(nft);
334
- cliCore.CLIDisplay.break();
335
- }
336
- if (core.Is.stringValue(opts?.json)) {
337
- await cliCore.CLIUtils.writeJsonFile(opts.json, nft, opts.mergeJson);
338
- }
339
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${nftConnectorIota.IotaNftUtils.nftIdToObjectId(id)}?network=${network}`);
340
- cliCore.CLIDisplay.break();
341
- cliCore.CLIDisplay.done();
342
- }
343
-
344
- // Copyright 2024 IOTA Stiftung.
345
- // SPDX-License-Identifier: Apache-2.0.
346
- /**
347
- * Build the nft transfer command for the CLI.
348
- * @returns The command.
349
- */
350
- function buildCommandNftTransfer() {
351
- const command = new commander.Command();
352
- command
353
- .name("nft-transfer")
354
- .summary(core.I18n.formatMessage("commands.nft-transfer.summary"))
355
- .description(core.I18n.formatMessage("commands.nft-transfer.description"))
356
- .requiredOption(core.I18n.formatMessage("commands.nft-transfer.options.seed.param"), core.I18n.formatMessage("commands.nft-transfer.options.seed.description"))
357
- .requiredOption(core.I18n.formatMessage("commands.nft-transfer.options.id.param"), core.I18n.formatMessage("commands.nft-transfer.options.id.description"))
358
- .requiredOption(core.I18n.formatMessage("commands.nft-transfer.options.recipient-identity.param"), core.I18n.formatMessage("commands.nft-transfer.options.recipient-identity.description"))
359
- .requiredOption(core.I18n.formatMessage("commands.nft-transfer.options.recipient-address.param"), core.I18n.formatMessage("commands.nft-transfer.options.recipient-address.description"));
360
- command
361
- .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
362
- .choices(Object.values(NftConnectorTypes))
363
- .default(NftConnectorTypes.Iota))
364
- .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
365
- .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
366
- .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
367
- .action(actionCommandNftTransfer);
368
- return command;
369
- }
370
- /**
371
- * Action the nft transfer command.
372
- * @param opts The options for the command.
373
- * @param opts.seed The seed required for signing by the issuer.
374
- * @param opts.id The id of the NFT to transfer in urn format.
375
- * @param opts.recipientIdentity The recipient address of the NFT.
376
- * @param opts.recipientAddress The recipient address of the NFT.
377
- * @param opts.connector The connector to perform the operations with.
378
- * @param opts.node The node URL.
379
- * @param opts.network The network to use for connector.
380
- * @param opts.explorer The explorer URL.
381
- */
382
- async function actionCommandNftTransfer(opts) {
383
- const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
384
- const id = cliCore.CLIParam.stringValue("id", opts.id);
385
- const recipientIdentity = cliCore.CLIParam.stringValue("recipientIdentity", opts.recipientIdentity);
386
- const recipientAddress = opts.connector === NftConnectorTypes.Iota
387
- ? core.Converter.bytesToHex(cliCore.CLIParam.hex("recipientAddress", opts.recipientAddress), true)
388
- : cliCore.CLIParam.bech32("recipientAddress", opts.recipientAddress);
389
- const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
390
- const network = opts.connector === NftConnectorTypes.Iota
391
- ? cliCore.CLIParam.stringValue("network", opts.network)
392
- : undefined;
393
- const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
394
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-transfer.labels.nftId"), id);
395
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-transfer.labels.recipientIdentity"), recipientIdentity);
396
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-transfer.labels.recipientAddress"), recipientAddress);
397
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
398
- if (core.Is.stringValue(network)) {
399
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
400
- }
401
- cliCore.CLIDisplay.break();
402
- setupVault();
403
- const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, network }, opts.connector);
404
- walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
405
- const localIdentity = "local";
406
- const vaultSeedId = "local-seed";
407
- const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
408
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
409
- const nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
410
- if (core.Is.function(nftConnector.start)) {
411
- await nftConnector.start(localIdentity);
412
- }
413
- cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.nft-transfer.progress.transferringNft"));
414
- cliCore.CLIDisplay.break();
415
- cliCore.CLIDisplay.spinnerStart();
416
- await nftConnector.transfer(localIdentity, id, recipientIdentity, recipientAddress);
417
- cliCore.CLIDisplay.spinnerStop();
418
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${nftConnectorIota.IotaNftUtils.nftIdToObjectId(id)}?network=${network}`);
419
- cliCore.CLIDisplay.break();
420
- cliCore.CLIDisplay.done();
421
- }
422
-
423
- // Copyright 2024 IOTA Stiftung.
424
- // SPDX-License-Identifier: Apache-2.0.
425
- /**
426
- * The main entry point for the CLI.
427
- */
428
- class CLI extends cliCore.CLIBase {
429
- /**
430
- * Run the app.
431
- * @param argv The process arguments.
432
- * @param localesDirectory The directory for the locales, default to relative to the script.
433
- * @param options Additional options for the CLI.
434
- * @param options.overrideOutputWidth Override the output width.
435
- * @returns The exit code.
436
- */
437
- async run(argv, localesDirectory, options) {
438
- return this.execute({
439
- title: "TWIN NFT",
440
- appName: "twin-nft",
441
- version: "0.0.2-next.7", // x-release-please-version
442
- icon: "🌍",
443
- supportsEnvFiles: true,
444
- overrideOutputWidth: options?.overrideOutputWidth,
445
- showDevToolWarning: true
446
- }, localesDirectory ?? path.join(path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))), "../locales"), argv);
447
- }
448
- /**
449
- * Get the commands for the CLI.
450
- * @param program The main program to add the commands to.
451
- * @internal
452
- */
453
- getCommands(program) {
454
- return [
455
- cryptoCli.buildCommandMnemonic(),
456
- cryptoCli.buildCommandAddress(),
457
- walletCli.buildCommandFaucet(),
458
- buildCommandNftMint(),
459
- buildCommandNftResolve(),
460
- buildCommandNftBurn(),
461
- buildCommandNftTransfer()
462
- ];
463
- }
464
- }
465
-
466
- exports.CLI = CLI;
467
- exports.NftConnectorTypes = NftConnectorTypes;
468
- exports.actionCommandNftBurn = actionCommandNftBurn;
469
- exports.actionCommandNftMint = actionCommandNftMint;
470
- exports.actionCommandNftResolve = actionCommandNftResolve;
471
- exports.actionCommandNftTransfer = actionCommandNftTransfer;
472
- exports.buildCommandNftBurn = buildCommandNftBurn;
473
- exports.buildCommandNftMint = buildCommandNftMint;
474
- exports.buildCommandNftResolve = buildCommandNftResolve;
475
- exports.buildCommandNftTransfer = buildCommandNftTransfer;
476
- exports.setupNftConnector = setupNftConnector;
477
- exports.setupVault = setupVault;