@twin.org/nft-cli 0.0.1-next.14 → 0.0.1-next.16
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/dist/cjs/index.cjs +145 -48
- package/dist/esm/index.mjs +145 -51
- package/dist/locales/en.json +57 -10
- package/dist/types/commands/nftBurn.d.ts +5 -0
- package/dist/types/commands/nftMint.d.ts +5 -0
- package/dist/types/commands/nftResolve.d.ts +5 -0
- package/dist/types/commands/nftTransfer.d.ts +5 -0
- package/dist/types/commands/setupCommands.d.ts +16 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/models/nftConnectorTypes.d.ts +17 -0
- package/docs/changelog.md +1 -1
- package/docs/examples.md +6 -6
- package/docs/reference/functions/actionCommandNftBurn.md +12 -0
- package/docs/reference/functions/actionCommandNftTransfer.md +12 -0
- package/docs/reference/functions/setupNftConnector.md +41 -0
- package/docs/reference/functions/setupVault.md +9 -0
- package/docs/reference/index.md +10 -0
- package/docs/reference/type-aliases/NftConnectorTypes.md +5 -0
- package/docs/reference/variables/NftConnectorTypes.md +19 -0
- package/locales/en.json +14 -4
- package/package.json +6 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@ var cryptoCli = require('@twin.org/crypto-cli');
|
|
|
7
7
|
var walletCli = require('@twin.org/wallet-cli');
|
|
8
8
|
var core = require('@twin.org/core');
|
|
9
9
|
var nftConnectorIota = require('@twin.org/nft-connector-iota');
|
|
10
|
+
var nftConnectorIotaRebased = require('@twin.org/nft-connector-iota-rebased');
|
|
10
11
|
var vaultModels = require('@twin.org/vault-models');
|
|
11
12
|
var commander = require('commander');
|
|
12
13
|
var entityStorageConnectorMemory = require('@twin.org/entity-storage-connector-memory');
|
|
@@ -14,6 +15,23 @@ var entityStorageModels = require('@twin.org/entity-storage-models');
|
|
|
14
15
|
var vaultConnectorEntityStorage = require('@twin.org/vault-connector-entity-storage');
|
|
15
16
|
|
|
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
|
+
* IOTA Rebased.
|
|
31
|
+
*/
|
|
32
|
+
IotaRebased: "iota-rebased"
|
|
33
|
+
};
|
|
34
|
+
|
|
17
35
|
// Copyright 2024 IOTA Stiftung.
|
|
18
36
|
// SPDX-License-Identifier: Apache-2.0.
|
|
19
37
|
/**
|
|
@@ -30,6 +48,42 @@ function setupVault() {
|
|
|
30
48
|
const vaultConnector = new vaultConnectorEntityStorage.EntityStorageVaultConnector();
|
|
31
49
|
vaultModels.VaultConnectorFactory.register("vault", () => vaultConnector);
|
|
32
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Setup the NFT connector for use in the CLI commands.
|
|
53
|
+
* @param options The options for the NFT connector.
|
|
54
|
+
* @param options.nodeEndpoint The node endpoint.
|
|
55
|
+
* @param options.network The network.
|
|
56
|
+
* @param options.vaultSeedId The vault seed ID.
|
|
57
|
+
* @param connector The connector to use.
|
|
58
|
+
* @returns The NFT connector.
|
|
59
|
+
*/
|
|
60
|
+
function setupNftConnector(options, connector) {
|
|
61
|
+
connector ??= NftConnectorTypes.Iota;
|
|
62
|
+
let instance;
|
|
63
|
+
if (connector === NftConnectorTypes.IotaRebased) {
|
|
64
|
+
instance = new nftConnectorIotaRebased.IotaRebasedNftConnector({
|
|
65
|
+
config: {
|
|
66
|
+
clientOptions: {
|
|
67
|
+
url: options.nodeEndpoint
|
|
68
|
+
},
|
|
69
|
+
network: options.network ?? "",
|
|
70
|
+
vaultSeedId: options.vaultSeedId
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
instance = new nftConnectorIota.IotaNftConnector({
|
|
76
|
+
config: {
|
|
77
|
+
clientOptions: {
|
|
78
|
+
nodes: [options.nodeEndpoint],
|
|
79
|
+
localPow: true
|
|
80
|
+
},
|
|
81
|
+
vaultSeedId: options.vaultSeedId
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return instance;
|
|
86
|
+
}
|
|
33
87
|
|
|
34
88
|
// Copyright 2024 IOTA Stiftung.
|
|
35
89
|
// SPDX-License-Identifier: Apache-2.0.
|
|
@@ -47,7 +101,11 @@ function buildCommandNftBurn() {
|
|
|
47
101
|
.requiredOption(core.I18n.formatMessage("commands.nft-burn.options.issuer.param"), core.I18n.formatMessage("commands.nft-burn.options.issuer.description"))
|
|
48
102
|
.requiredOption(core.I18n.formatMessage("commands.nft-burn.options.id.param"), core.I18n.formatMessage("commands.nft-burn.options.id.description"));
|
|
49
103
|
command
|
|
104
|
+
.addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
|
|
105
|
+
.choices(Object.values(NftConnectorTypes))
|
|
106
|
+
.default(NftConnectorTypes.Iota))
|
|
50
107
|
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
108
|
+
.option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
51
109
|
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
52
110
|
.action(actionCommandNftBurn);
|
|
53
111
|
return command;
|
|
@@ -58,39 +116,46 @@ function buildCommandNftBurn() {
|
|
|
58
116
|
* @param opts.seed The seed required for signing by the issuer.
|
|
59
117
|
* @param opts.issuer The issuer address of the NFT.
|
|
60
118
|
* @param opts.id The id of the NFT to burn in urn format.
|
|
119
|
+
* @param opts.connector The connector to perform the operations with.
|
|
61
120
|
* @param opts.node The node URL.
|
|
121
|
+
* @param opts.network The network to use for rebased connector.
|
|
62
122
|
* @param opts.explorer The explorer URL.
|
|
63
123
|
*/
|
|
64
124
|
async function actionCommandNftBurn(opts) {
|
|
65
125
|
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
66
|
-
const issuer =
|
|
126
|
+
const issuer = opts.connector === NftConnectorTypes.IotaRebased
|
|
127
|
+
? core.Converter.bytesToHex(cliCore.CLIParam.hex("issuer", opts.issuer), true)
|
|
128
|
+
: cliCore.CLIParam.bech32("issuer", opts.issuer);
|
|
67
129
|
const id = cliCore.CLIParam.stringValue("id", opts.id);
|
|
68
130
|
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
131
|
+
const network = opts.connector === NftConnectorTypes.IotaRebased
|
|
132
|
+
? cliCore.CLIParam.stringValue("network", opts.network)
|
|
133
|
+
: undefined;
|
|
69
134
|
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
70
135
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-burn.labels.issuer"), issuer);
|
|
71
136
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-burn.labels.nftId"), id);
|
|
72
137
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
138
|
+
if (core.Is.stringValue(network)) {
|
|
139
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
|
|
140
|
+
}
|
|
73
141
|
cliCore.CLIDisplay.break();
|
|
74
142
|
setupVault();
|
|
75
143
|
const localIdentity = "local";
|
|
76
144
|
const vaultSeedId = "local-seed";
|
|
77
145
|
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
78
146
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
localPow: true
|
|
84
|
-
},
|
|
85
|
-
vaultSeedId
|
|
86
|
-
}
|
|
87
|
-
});
|
|
147
|
+
const nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
148
|
+
if (core.Is.function(nftConnector.start)) {
|
|
149
|
+
await nftConnector.start(localIdentity);
|
|
150
|
+
}
|
|
88
151
|
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.nft-burn.progress.burningNft"));
|
|
89
152
|
cliCore.CLIDisplay.break();
|
|
90
153
|
cliCore.CLIDisplay.spinnerStart();
|
|
91
|
-
await
|
|
154
|
+
await nftConnector.burn(localIdentity, id);
|
|
92
155
|
cliCore.CLIDisplay.spinnerStop();
|
|
93
|
-
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"),
|
|
156
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), opts.connector === NftConnectorTypes.IotaRebased
|
|
157
|
+
? `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${nftConnectorIotaRebased.IotaRebasedNftUtils.nftIdToObjectId(id)}?network=${network}`
|
|
158
|
+
: `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${nftConnectorIota.IotaNftUtils.nftIdToAddress(id)}`);
|
|
94
159
|
cliCore.CLIDisplay.break();
|
|
95
160
|
cliCore.CLIDisplay.done();
|
|
96
161
|
}
|
|
@@ -120,8 +185,12 @@ function buildCommandNftMint() {
|
|
|
120
185
|
mergeEnv: true
|
|
121
186
|
});
|
|
122
187
|
command
|
|
123
|
-
.
|
|
188
|
+
.addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
|
|
189
|
+
.choices(Object.values(NftConnectorTypes))
|
|
190
|
+
.default(NftConnectorTypes.Iota))
|
|
191
|
+
.option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
124
192
|
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
193
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
125
194
|
.action(actionCommandNftMint);
|
|
126
195
|
return command;
|
|
127
196
|
}
|
|
@@ -133,12 +202,16 @@ function buildCommandNftMint() {
|
|
|
133
202
|
* @param opts.tag The tag for the NFT.
|
|
134
203
|
* @param opts.immutableJson Filename of the immutable JSON data.
|
|
135
204
|
* @param opts.mutableJson Filename of the mutable JSON data.
|
|
205
|
+
* @param opts.connector The connector to perform the operations with.
|
|
136
206
|
* @param opts.node The node URL.
|
|
207
|
+
* @param opts.network The network to use for rebased connector.
|
|
137
208
|
* @param opts.explorer The explorer URL.
|
|
138
209
|
*/
|
|
139
210
|
async function actionCommandNftMint(opts) {
|
|
140
211
|
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
141
|
-
const issuer =
|
|
212
|
+
const issuer = opts.connector === NftConnectorTypes.IotaRebased
|
|
213
|
+
? core.Converter.bytesToHex(cliCore.CLIParam.hex("issuer", opts.issuer), true)
|
|
214
|
+
: cliCore.CLIParam.bech32("issuer", opts.issuer);
|
|
142
215
|
const tag = cliCore.CLIParam.stringValue("tag", opts.tag);
|
|
143
216
|
const immutableJson = opts.immutableJson
|
|
144
217
|
? path.resolve(opts.immutableJson)
|
|
@@ -147,6 +220,9 @@ async function actionCommandNftMint(opts) {
|
|
|
147
220
|
? path.resolve(opts.mutableJson)
|
|
148
221
|
: undefined;
|
|
149
222
|
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
223
|
+
const network = opts.connector === NftConnectorTypes.IotaRebased
|
|
224
|
+
? cliCore.CLIParam.stringValue("network", opts.network)
|
|
225
|
+
: undefined;
|
|
150
226
|
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
151
227
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.issuer"), issuer);
|
|
152
228
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.tag"), tag);
|
|
@@ -157,21 +233,19 @@ async function actionCommandNftMint(opts) {
|
|
|
157
233
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.mutableJsonFilename"), mutableJson);
|
|
158
234
|
}
|
|
159
235
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
236
|
+
if (core.Is.stringValue(network)) {
|
|
237
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
|
|
238
|
+
}
|
|
160
239
|
cliCore.CLIDisplay.break();
|
|
161
240
|
setupVault();
|
|
162
241
|
const localIdentity = "local";
|
|
163
242
|
const vaultSeedId = "local-seed";
|
|
164
243
|
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
165
244
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
localPow: true
|
|
171
|
-
},
|
|
172
|
-
vaultSeedId
|
|
173
|
-
}
|
|
174
|
-
});
|
|
245
|
+
const nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
246
|
+
if (core.Is.function(nftConnector.start)) {
|
|
247
|
+
await nftConnector.start(localIdentity);
|
|
248
|
+
}
|
|
175
249
|
const immutableJsonData = core.Is.stringValue(immutableJson)
|
|
176
250
|
? await cliCore.CLIUtils.readJsonFile(immutableJson)
|
|
177
251
|
: undefined;
|
|
@@ -191,7 +265,7 @@ async function actionCommandNftMint(opts) {
|
|
|
191
265
|
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.nft-mint.progress.mintingNft"));
|
|
192
266
|
cliCore.CLIDisplay.break();
|
|
193
267
|
cliCore.CLIDisplay.spinnerStart();
|
|
194
|
-
const nftId = await
|
|
268
|
+
const nftId = await nftConnector.mint(localIdentity, issuer, tag, immutableJsonData, mutableJsonData);
|
|
195
269
|
cliCore.CLIDisplay.spinnerStop();
|
|
196
270
|
if (opts.console) {
|
|
197
271
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-mint.labels.nftId"), nftId);
|
|
@@ -203,7 +277,9 @@ async function actionCommandNftMint(opts) {
|
|
|
203
277
|
if (core.Is.stringValue(opts?.env)) {
|
|
204
278
|
await cliCore.CLIUtils.writeEnvFile(opts.env, [`NFT_ID="${nftId}"`], opts.mergeEnv);
|
|
205
279
|
}
|
|
206
|
-
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"),
|
|
280
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), opts.connector === NftConnectorTypes.IotaRebased
|
|
281
|
+
? `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${nftConnectorIotaRebased.IotaRebasedNftUtils.nftIdToObjectId(nftId)}?network=${network}`
|
|
282
|
+
: `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${nftConnectorIota.IotaNftUtils.nftIdToAddress(nftId)}`);
|
|
207
283
|
cliCore.CLIDisplay.break();
|
|
208
284
|
cliCore.CLIDisplay.done();
|
|
209
285
|
}
|
|
@@ -229,7 +305,11 @@ function buildCommandNftResolve() {
|
|
|
229
305
|
mergeEnv: false
|
|
230
306
|
});
|
|
231
307
|
command
|
|
308
|
+
.addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
|
|
309
|
+
.choices(Object.values(NftConnectorTypes))
|
|
310
|
+
.default(NftConnectorTypes.Iota))
|
|
232
311
|
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
312
|
+
.option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
233
313
|
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
234
314
|
.action(actionCommandNftResolve);
|
|
235
315
|
return command;
|
|
@@ -238,29 +318,30 @@ function buildCommandNftResolve() {
|
|
|
238
318
|
* Action the nft resolve command.
|
|
239
319
|
* @param opts The options for the command.
|
|
240
320
|
* @param opts.id The id of the NFT to resolve in urn format.
|
|
321
|
+
* @param opts.connector The connector to perform the operations with.
|
|
241
322
|
* @param opts.node The node URL.
|
|
323
|
+
* @param opts.network The network to use for rebased connector.
|
|
242
324
|
* @param opts.explorer The explorer URL.
|
|
243
325
|
*/
|
|
244
326
|
async function actionCommandNftResolve(opts) {
|
|
245
327
|
const id = cliCore.CLIParam.stringValue("id", opts.id);
|
|
246
328
|
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
329
|
+
const network = opts.connector === NftConnectorTypes.IotaRebased
|
|
330
|
+
? cliCore.CLIParam.stringValue("network", opts.network)
|
|
331
|
+
: undefined;
|
|
247
332
|
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
248
333
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-resolve.labels.nftId"), id);
|
|
249
334
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
335
|
+
if (core.Is.stringValue(network)) {
|
|
336
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
|
|
337
|
+
}
|
|
250
338
|
cliCore.CLIDisplay.break();
|
|
251
339
|
setupVault();
|
|
252
|
-
const
|
|
253
|
-
config: {
|
|
254
|
-
clientOptions: {
|
|
255
|
-
nodes: [nodeEndpoint],
|
|
256
|
-
localPow: true
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
});
|
|
340
|
+
const nftConnector = setupNftConnector({ nodeEndpoint, network }, opts.connector);
|
|
260
341
|
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.nft-resolve.progress.resolvingNft"));
|
|
261
342
|
cliCore.CLIDisplay.break();
|
|
262
343
|
cliCore.CLIDisplay.spinnerStart();
|
|
263
|
-
const nft = await
|
|
344
|
+
const nft = await nftConnector.resolve(id);
|
|
264
345
|
cliCore.CLIDisplay.spinnerStop();
|
|
265
346
|
if (opts.console) {
|
|
266
347
|
cliCore.CLIDisplay.section(core.I18n.formatMessage("commands.nft-resolve.labels.nft"));
|
|
@@ -270,7 +351,9 @@ async function actionCommandNftResolve(opts) {
|
|
|
270
351
|
if (core.Is.stringValue(opts?.json)) {
|
|
271
352
|
await cliCore.CLIUtils.writeJsonFile(opts.json, nft, opts.mergeJson);
|
|
272
353
|
}
|
|
273
|
-
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"),
|
|
354
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), opts.connector === NftConnectorTypes.IotaRebased
|
|
355
|
+
? `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${nftConnectorIotaRebased.IotaRebasedNftUtils.nftIdToObjectId(id)}?network=${network}`
|
|
356
|
+
: `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${nftConnectorIota.IotaNftUtils.nftIdToAddress(id)}`);
|
|
274
357
|
cliCore.CLIDisplay.break();
|
|
275
358
|
cliCore.CLIDisplay.done();
|
|
276
359
|
}
|
|
@@ -291,7 +374,11 @@ function buildCommandNftTransfer() {
|
|
|
291
374
|
.requiredOption(core.I18n.formatMessage("commands.nft-transfer.options.id.param"), core.I18n.formatMessage("commands.nft-transfer.options.id.description"))
|
|
292
375
|
.requiredOption(core.I18n.formatMessage("commands.nft-transfer.options.recipient.param"), core.I18n.formatMessage("commands.nft-transfer.options.recipient.description"));
|
|
293
376
|
command
|
|
377
|
+
.addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
|
|
378
|
+
.choices(Object.values(NftConnectorTypes))
|
|
379
|
+
.default(NftConnectorTypes.Iota))
|
|
294
380
|
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
381
|
+
.option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
295
382
|
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
296
383
|
.action(actionCommandNftTransfer);
|
|
297
384
|
return command;
|
|
@@ -302,39 +389,46 @@ function buildCommandNftTransfer() {
|
|
|
302
389
|
* @param opts.seed The seed required for signing by the issuer.
|
|
303
390
|
* @param opts.id The id of the NFT to transfer in urn format.
|
|
304
391
|
* @param opts.recipient The recipient address of the NFT.
|
|
392
|
+
* @param opts.connector The connector to perform the operations with.
|
|
305
393
|
* @param opts.node The node URL.
|
|
394
|
+
* @param opts.network The network to use for rebased connector.
|
|
306
395
|
* @param opts.explorer The explorer URL.
|
|
307
396
|
*/
|
|
308
397
|
async function actionCommandNftTransfer(opts) {
|
|
309
398
|
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
310
399
|
const id = cliCore.CLIParam.stringValue("id", opts.id);
|
|
311
|
-
const recipient =
|
|
400
|
+
const recipient = opts.connector === NftConnectorTypes.IotaRebased
|
|
401
|
+
? core.Converter.bytesToHex(cliCore.CLIParam.hex("recipient", opts.recipient), true)
|
|
402
|
+
: cliCore.CLIParam.bech32("recipient", opts.recipient);
|
|
312
403
|
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
404
|
+
const network = opts.connector === NftConnectorTypes.IotaRebased
|
|
405
|
+
? cliCore.CLIParam.stringValue("network", opts.network)
|
|
406
|
+
: undefined;
|
|
313
407
|
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
314
408
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-transfer.labels.nftId"), id);
|
|
315
409
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.nft-transfer.labels.recipient"), recipient);
|
|
316
410
|
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
411
|
+
if (core.Is.stringValue(network)) {
|
|
412
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
|
|
413
|
+
}
|
|
317
414
|
cliCore.CLIDisplay.break();
|
|
318
415
|
setupVault();
|
|
319
416
|
const localIdentity = "local";
|
|
320
417
|
const vaultSeedId = "local-seed";
|
|
321
418
|
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
322
419
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
localPow: true
|
|
328
|
-
},
|
|
329
|
-
vaultSeedId
|
|
330
|
-
}
|
|
331
|
-
});
|
|
420
|
+
const nftConnector = setupNftConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
421
|
+
if (core.Is.function(nftConnector.start)) {
|
|
422
|
+
await nftConnector.start(localIdentity);
|
|
423
|
+
}
|
|
332
424
|
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.nft-transfer.progress.transferringNft"));
|
|
333
425
|
cliCore.CLIDisplay.break();
|
|
334
426
|
cliCore.CLIDisplay.spinnerStart();
|
|
335
|
-
await
|
|
427
|
+
await nftConnector.transfer(localIdentity, id, recipient);
|
|
336
428
|
cliCore.CLIDisplay.spinnerStop();
|
|
337
|
-
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"),
|
|
429
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), opts.connector === NftConnectorTypes.IotaRebased
|
|
430
|
+
? `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${nftConnectorIotaRebased.IotaRebasedNftUtils.nftIdToObjectId(id)}?network=${network}`
|
|
431
|
+
: `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${nftConnectorIota.IotaNftUtils.nftIdToAddress(id)}`);
|
|
338
432
|
cliCore.CLIDisplay.break();
|
|
339
433
|
cliCore.CLIDisplay.done();
|
|
340
434
|
}
|
|
@@ -357,7 +451,7 @@ class CLI extends cliCore.CLIBase {
|
|
|
357
451
|
return this.execute({
|
|
358
452
|
title: "TWIN NFT",
|
|
359
453
|
appName: "twin-nft",
|
|
360
|
-
version: "0.0.1-next.
|
|
454
|
+
version: "0.0.1-next.16",
|
|
361
455
|
icon: "🌍",
|
|
362
456
|
supportsEnvFiles: true,
|
|
363
457
|
overrideOutputWidth: options?.overrideOutputWidth
|
|
@@ -382,6 +476,7 @@ class CLI extends cliCore.CLIBase {
|
|
|
382
476
|
}
|
|
383
477
|
|
|
384
478
|
exports.CLI = CLI;
|
|
479
|
+
exports.NftConnectorTypes = NftConnectorTypes;
|
|
385
480
|
exports.actionCommandNftBurn = actionCommandNftBurn;
|
|
386
481
|
exports.actionCommandNftMint = actionCommandNftMint;
|
|
387
482
|
exports.actionCommandNftResolve = actionCommandNftResolve;
|
|
@@ -390,3 +485,5 @@ exports.buildCommandNftBurn = buildCommandNftBurn;
|
|
|
390
485
|
exports.buildCommandNftMint = buildCommandNftMint;
|
|
391
486
|
exports.buildCommandNftResolve = buildCommandNftResolve;
|
|
392
487
|
exports.buildCommandNftTransfer = buildCommandNftTransfer;
|
|
488
|
+
exports.setupNftConnector = setupNftConnector;
|
|
489
|
+
exports.setupVault = setupVault;
|