@twin.org/dlt-iota 0.0.3-next.14 → 0.0.3-next.15
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/es/index.js +7 -3
- package/dist/es/index.js.map +1 -1
- package/dist/es/iota.js +103 -88
- package/dist/es/iota.js.map +1 -1
- package/dist/es/models/ITransactionSigner.js +2 -0
- package/dist/es/models/ITransactionSigner.js.map +1 -0
- package/dist/es/vaultJwkStorage.js +71 -0
- package/dist/es/vaultJwkStorage.js.map +1 -0
- package/dist/es/vaultJwtSigner.js +49 -0
- package/dist/es/vaultJwtSigner.js.map +1 -0
- package/dist/es/vaultSigner.js +60 -0
- package/dist/es/vaultSigner.js.map +1 -0
- package/dist/es/vaultTransactionSigner.js +74 -0
- package/dist/es/vaultTransactionSigner.js.map +1 -0
- package/dist/types/index.d.ts +7 -3
- package/dist/types/iota.d.ts +12 -27
- package/dist/types/models/ITransactionSigner.d.ts +27 -0
- package/dist/types/vaultJwkStorage.d.ts +50 -0
- package/dist/types/vaultJwtSigner.d.ts +26 -0
- package/dist/types/vaultSigner.d.ts +32 -0
- package/dist/types/vaultTransactionSigner.d.ts +39 -0
- package/docs/changelog.md +7 -0
- package/docs/reference/classes/Iota.md +29 -81
- package/docs/reference/classes/VaultJwtSigner.md +71 -0
- package/docs/reference/classes/VaultSigner.md +106 -0
- package/docs/reference/classes/VaultTransactionSigner.md +122 -0
- package/docs/reference/index.md +4 -0
- package/docs/reference/interfaces/ITransactionSigner.md +67 -0
- package/locales/en.json +5 -1
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -11,14 +11,18 @@ export * from "./models/IGasStationExecuteResponse.js";
|
|
|
11
11
|
export * from "./models/IGasStationReserveGasResponse.js";
|
|
12
12
|
export * from "./models/IGasStationReserveGasResult.js";
|
|
13
13
|
export * from "./models/IIotaClient.js";
|
|
14
|
-
export * from "./models/IIotaControllerCapInfo.js";
|
|
15
|
-
export * from "./models/IIotaTransaction.js";
|
|
16
|
-
export * from "./models/IIotaTransactionBlockResponse.js";
|
|
17
14
|
export * from "./models/IIotaConfig.js";
|
|
15
|
+
export * from "./models/IIotaControllerCapInfo.js";
|
|
18
16
|
export * from "./models/IIotaDryRun.js";
|
|
19
17
|
export * from "./models/IIotaResponseOptions.js";
|
|
18
|
+
export * from "./models/IIotaTransaction.js";
|
|
19
|
+
export * from "./models/IIotaTransactionBlockResponse.js";
|
|
20
|
+
export * from "./models/ITransactionSigner.js";
|
|
20
21
|
export * from "./models/IMigrationStateFields.js";
|
|
21
22
|
export * from "./models/ISmartContractDeployments.js";
|
|
22
23
|
export * from "./models/ISmartContractObject.js";
|
|
23
24
|
export * from "./models/networkTypes.js";
|
|
25
|
+
export * from "./vaultJwtSigner.js";
|
|
26
|
+
export * from "./vaultSigner.js";
|
|
27
|
+
export * from "./vaultTransactionSigner.js";
|
|
24
28
|
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wCAAwC,CAAC;AACvD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wCAAwC,CAAC;AACvD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./iota.js\";\nexport * from \"./iotaIdentityUtils.js\";\nexport * from \"./iotaSmartContractUtils.js\";\nexport * from \"./models/IAdminCapFields.js\";\nexport * from \"./models/IContractData.js\";\nexport * from \"./models/IGasReservationResult.js\";\nexport * from \"./models/IGasStationConfig.js\";\nexport * from \"./models/IGasStationExecuteResponse.js\";\nexport * from \"./models/IGasStationReserveGasResponse.js\";\nexport * from \"./models/IGasStationReserveGasResult.js\";\nexport * from \"./models/IIotaClient.js\";\nexport * from \"./models/IIotaConfig.js\";\nexport * from \"./models/IIotaControllerCapInfo.js\";\nexport * from \"./models/IIotaDryRun.js\";\nexport * from \"./models/IIotaResponseOptions.js\";\nexport * from \"./models/IIotaTransaction.js\";\nexport * from \"./models/IIotaTransactionBlockResponse.js\";\nexport * from \"./models/ITransactionSigner.js\";\nexport * from \"./models/IMigrationStateFields.js\";\nexport * from \"./models/ISmartContractDeployments.js\";\nexport * from \"./models/ISmartContractObject.js\";\nexport * from \"./models/networkTypes.js\";\nexport * from \"./vaultJwtSigner.js\";\nexport * from \"./vaultSigner.js\";\nexport * from \"./vaultTransactionSigner.js\";\n"]}
|
package/dist/es/iota.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { IotaClient } from "@iota/iota-sdk/client";
|
|
4
4
|
import { requestIotaFromFaucetV0 } from "@iota/iota-sdk/faucet";
|
|
5
|
-
import { Ed25519Keypair } from "@iota/iota-sdk/keypairs/ed25519";
|
|
6
5
|
import { Transaction } from "@iota/iota-sdk/transactions";
|
|
7
6
|
import { BaseError, Coerce, Converter, GeneralError, Guards, Is, StringHelper } from "@twin.org/core";
|
|
8
7
|
import { Bip39, Bip44, Blake2b, KeyType } from "@twin.org/crypto";
|
|
8
|
+
import { VaultConnectorHelper, VaultKeyType } from "@twin.org/vault-models";
|
|
9
9
|
import { FetchHelper, HttpMethod } from "@twin.org/web";
|
|
10
|
+
import { VaultSigner } from "./vaultSigner.js";
|
|
11
|
+
import { VaultTransactionSigner } from "./vaultTransactionSigner.js";
|
|
10
12
|
/**
|
|
11
13
|
* Class for performing operations on IOTA.
|
|
12
14
|
*/
|
|
@@ -92,7 +94,7 @@ export class Iota {
|
|
|
92
94
|
await vaultConnector.setSecret(Iota.buildMnemonicKey(identity, config.vaultMnemonicId), mnemonicToStore);
|
|
93
95
|
const seed = Bip39.mnemonicToSeed(mnemonicToStore);
|
|
94
96
|
await vaultConnector.setSecret(Iota.buildSeedKey(identity, config.vaultSeedId), Converter.bytesToBase64(seed));
|
|
95
|
-
await Iota.
|
|
97
|
+
await Iota.getPublicKeys(vaultConnector, config, identity, accountIndex, false, 0, async () => seed);
|
|
96
98
|
return mnemonicToStore;
|
|
97
99
|
}
|
|
98
100
|
/**
|
|
@@ -138,10 +140,15 @@ export class Iota {
|
|
|
138
140
|
const addresses = [];
|
|
139
141
|
const internal = isInternal ?? false;
|
|
140
142
|
let currentIndex = startAddressIndex;
|
|
143
|
+
let cachedSeed;
|
|
144
|
+
const seedProvider = async () => {
|
|
145
|
+
cachedSeed ??= await Iota.getSeed(vaultConnector, config, identity);
|
|
146
|
+
return cachedSeed;
|
|
147
|
+
};
|
|
141
148
|
while (addresses.length < count) {
|
|
142
149
|
const chunkStart = Math.floor(currentIndex / Iota._PRE_CALC_CHUNK_SIZE) * Iota._PRE_CALC_CHUNK_SIZE;
|
|
143
|
-
const
|
|
144
|
-
const chunk =
|
|
150
|
+
const publicKeys = await Iota.getPublicKeys(vaultConnector, config, identity, accountIndex, internal, chunkStart, seedProvider);
|
|
151
|
+
const chunk = publicKeys.map((pk) => Iota.publicKeyToAddress(Converter.base64ToBytes(pk)));
|
|
145
152
|
const offsetInChunk = currentIndex - chunkStart;
|
|
146
153
|
const remaining = count - addresses.length;
|
|
147
154
|
addresses.push(...chunk.slice(offsetInChunk, offsetInChunk + remaining));
|
|
@@ -150,30 +157,26 @@ export class Iota {
|
|
|
150
157
|
return addresses;
|
|
151
158
|
}
|
|
152
159
|
/**
|
|
153
|
-
* Get a
|
|
160
|
+
* Get a vault-backed transaction signer for the given identity and key indices.
|
|
154
161
|
* @param vaultConnector The vault connector.
|
|
155
162
|
* @param config The configuration.
|
|
156
163
|
* @param identity The identity of the user to access the vault keys.
|
|
157
|
-
* @param accountIndex The account index
|
|
158
|
-
* @param addressIndex The address index
|
|
159
|
-
* @
|
|
160
|
-
* @returns The key pair containing private key and public key.
|
|
164
|
+
* @param accountIndex The account index.
|
|
165
|
+
* @param addressIndex The address index within the account.
|
|
166
|
+
* @returns A VaultTransactionSigner for the specified key.
|
|
161
167
|
*/
|
|
162
|
-
static async
|
|
168
|
+
static async getTransactionSigner(vaultConnector, config, identity, accountIndex, addressIndex) {
|
|
163
169
|
Guards.object(Iota.CLASS_NAME, "vaultConnector", vaultConnector);
|
|
164
170
|
Guards.object(Iota.CLASS_NAME, "config", config);
|
|
165
171
|
Guards.stringValue(Iota.CLASS_NAME, "identity", identity);
|
|
166
172
|
Guards.integer(Iota.CLASS_NAME, "accountIndex", accountIndex);
|
|
167
173
|
Guards.integer(Iota.CLASS_NAME, "addressIndex", addressIndex);
|
|
168
|
-
const
|
|
169
|
-
const chunkStart =
|
|
170
|
-
const keyPairs = await Iota.buildKeyPairRange(vaultConnector, config, identity, accountIndex, internal, chunkStart);
|
|
174
|
+
const publicKeys = await Iota.getPublicKeys(vaultConnector, config, identity, accountIndex, false, addressIndex, async () => Iota.getSeed(vaultConnector, config, identity));
|
|
175
|
+
const chunkStart = addressIndex - (addressIndex % Iota._PRE_CALC_CHUNK_SIZE);
|
|
171
176
|
const offsetInChunk = addressIndex - chunkStart;
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
publicKey: Converter.base64ToBytes(entry.publicKey)
|
|
176
|
-
};
|
|
177
|
+
const publicKey = Converter.base64ToBytes(publicKeys[offsetInChunk]);
|
|
178
|
+
const keyName = Iota.buildAddressKeyName(identity, accountIndex, false, addressIndex);
|
|
179
|
+
return new VaultTransactionSigner(vaultConnector, keyName, publicKey);
|
|
177
180
|
}
|
|
178
181
|
/**
|
|
179
182
|
* Create a new transaction instance.
|
|
@@ -233,12 +236,12 @@ export class Iota {
|
|
|
233
236
|
if (Is.stringValue(options?.dryRunLabel)) {
|
|
234
237
|
await Iota.dryRunTransaction(client, logging, transaction, owner, options.dryRunLabel);
|
|
235
238
|
}
|
|
236
|
-
const
|
|
237
|
-
const
|
|
239
|
+
const { keyName, publicKey } = await Iota.ensureOwnerKey(vaultConnector, config, identity, owner);
|
|
240
|
+
const signer = new VaultSigner(vaultConnector, keyName, publicKey);
|
|
238
241
|
try {
|
|
239
242
|
const response = await client.signAndExecuteTransaction({
|
|
240
243
|
transaction,
|
|
241
|
-
signer
|
|
244
|
+
signer,
|
|
242
245
|
requestType: "WaitForLocalExecution",
|
|
243
246
|
options: {
|
|
244
247
|
showEffects: options?.showEffects ?? true,
|
|
@@ -261,37 +264,6 @@ export class Iota {
|
|
|
261
264
|
throw new GeneralError(Iota.CLASS_NAME, "transactionFailed", undefined, Iota.extractPayloadError(error));
|
|
262
265
|
}
|
|
263
266
|
}
|
|
264
|
-
/**
|
|
265
|
-
* Find the address in the seed.
|
|
266
|
-
* @param vaultConnector The vault connector to use.
|
|
267
|
-
* @param config The configuration to use.
|
|
268
|
-
* @param identity The identity of the user to access the vault keys.
|
|
269
|
-
* @param address The address to find.
|
|
270
|
-
* @param accountIndex The account index to search.
|
|
271
|
-
* @param isInternal Whether to search internal addresses.
|
|
272
|
-
* @param startScanIndex The address index to start scanning from.
|
|
273
|
-
* @param maxScanRange The maximum range to scan.
|
|
274
|
-
* @returns The address key pair.
|
|
275
|
-
* @throws Error if the address is not found.
|
|
276
|
-
*/
|
|
277
|
-
static async findAddress(vaultConnector, config, identity, address, accountIndex, isInternal, startScanIndex, maxScanRange) {
|
|
278
|
-
const internal = isInternal ?? false;
|
|
279
|
-
const startIndex = startScanIndex ?? 0;
|
|
280
|
-
const scanRange = maxScanRange ?? config.maxAddressScanRange ?? Iota._DEFAULT_SCAN_RANGE;
|
|
281
|
-
for (let chunkStart = startIndex; chunkStart < startIndex + scanRange; chunkStart += Iota._PRE_CALC_CHUNK_SIZE) {
|
|
282
|
-
const keyPairs = await Iota.buildKeyPairRange(vaultConnector, config, identity, accountIndex, internal, chunkStart);
|
|
283
|
-
const offsetInChunk = keyPairs.findIndex(kp => Iota.publicKeyToAddress(Converter.base64ToBytes(kp.publicKey)) === address);
|
|
284
|
-
if (offsetInChunk !== -1) {
|
|
285
|
-
const entry = keyPairs[offsetInChunk];
|
|
286
|
-
return {
|
|
287
|
-
address,
|
|
288
|
-
privateKey: Converter.base64ToBytes(entry.privateKey),
|
|
289
|
-
publicKey: Converter.base64ToBytes(entry.publicKey)
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
throw new GeneralError(Iota.CLASS_NAME, "addressNotFound", { address });
|
|
294
|
-
}
|
|
295
267
|
/**
|
|
296
268
|
* Extract error from SDK payload.
|
|
297
269
|
* Errors from the IOTA SDK are usually not JSON strings but objects.
|
|
@@ -484,10 +456,9 @@ export class Iota {
|
|
|
484
456
|
transaction.setGasBudget(config.gasBudget ?? Iota._DEFAULT_GAS_BUDGET);
|
|
485
457
|
// Build and sign transaction
|
|
486
458
|
const unsignedTxBytes = await transaction.build({ client });
|
|
487
|
-
|
|
488
|
-
const
|
|
489
|
-
const
|
|
490
|
-
const signature = await keypair.signTransaction(unsignedTxBytes);
|
|
459
|
+
const { keyName, publicKey } = await Iota.ensureOwnerKey(vaultConnector, config, identity, owner);
|
|
460
|
+
const signer = new VaultSigner(vaultConnector, keyName, publicKey);
|
|
461
|
+
const signature = await signer.signTransaction(unsignedTxBytes);
|
|
491
462
|
return await Iota.executeAndConfirmGasStationTransaction(config, client, gasReservation.reservationId, unsignedTxBytes, signature.signature, options);
|
|
492
463
|
}
|
|
493
464
|
catch (error) {
|
|
@@ -672,11 +643,50 @@ export class Iota {
|
|
|
672
643
|
return BigInt(balance.totalBalance);
|
|
673
644
|
}
|
|
674
645
|
/**
|
|
675
|
-
*
|
|
646
|
+
* Create a transaction instance from the given bytes.
|
|
647
|
+
* @param bytes The transaction bytes to create the transaction from.
|
|
648
|
+
* @returns The transaction instance created from the given bytes.
|
|
649
|
+
*/
|
|
650
|
+
static transactionFromBytes(bytes) {
|
|
651
|
+
return Transaction.from(bytes);
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Find the vault key name and public key for the given owner address.
|
|
655
|
+
* Keys are individually registered in the vault by buildKeyPairRange, so no addKey is needed here.
|
|
676
656
|
* @param vaultConnector The vault connector to use.
|
|
677
657
|
* @param config The configuration to use.
|
|
678
658
|
* @param identity The identity of the user to access the vault keys.
|
|
679
|
-
* @
|
|
659
|
+
* @param owner The owner address whose key should be located.
|
|
660
|
+
* @param accountIndex The account index to search.
|
|
661
|
+
* @returns The vault key name and the public key bytes.
|
|
662
|
+
* @internal
|
|
663
|
+
*/
|
|
664
|
+
static async ensureOwnerKey(vaultConnector, config, identity, owner, accountIndex = 0) {
|
|
665
|
+
const scanRange = config.maxAddressScanRange ?? Iota._DEFAULT_SCAN_RANGE;
|
|
666
|
+
let cachedSeed;
|
|
667
|
+
const seedProvider = async () => {
|
|
668
|
+
cachedSeed ??= await Iota.getSeed(vaultConnector, config, identity);
|
|
669
|
+
return cachedSeed;
|
|
670
|
+
};
|
|
671
|
+
for (let chunkStart = 0; chunkStart < scanRange; chunkStart += Iota._PRE_CALC_CHUNK_SIZE) {
|
|
672
|
+
const publicKeys = await Iota.getPublicKeys(vaultConnector, config, identity, accountIndex, false, chunkStart, seedProvider);
|
|
673
|
+
const matchIndex = publicKeys.findIndex((pk) => Iota.publicKeyToAddress(Converter.base64ToBytes(pk)) === owner);
|
|
674
|
+
if (matchIndex >= 0) {
|
|
675
|
+
const addressIndex = chunkStart + matchIndex;
|
|
676
|
+
return {
|
|
677
|
+
keyName: Iota.buildAddressKeyName(identity, accountIndex, false, addressIndex),
|
|
678
|
+
publicKey: Converter.base64ToBytes(publicKeys[matchIndex])
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
throw new GeneralError(Iota.CLASS_NAME, "addressNotFound", { address: owner });
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Get the seed from the vault, deriving it from the mnemonic if necessary.
|
|
686
|
+
* @param vaultConnector The vault connector to use.
|
|
687
|
+
* @param config The configuration to use.
|
|
688
|
+
* @param identity The identity of the user to access the vault keys.
|
|
689
|
+
* @returns The seed bytes.
|
|
680
690
|
* @internal
|
|
681
691
|
*/
|
|
682
692
|
static async getSeed(vaultConnector, config, identity) {
|
|
@@ -700,7 +710,7 @@ export class Iota {
|
|
|
700
710
|
* @internal
|
|
701
711
|
*/
|
|
702
712
|
static buildMnemonicKey(identity, vaultMnemonicId) {
|
|
703
|
-
return
|
|
713
|
+
return VaultConnectorHelper.buildKeyName(identity, vaultMnemonicId ?? Iota.DEFAULT_MNEMONIC_SECRET_NAME);
|
|
704
714
|
}
|
|
705
715
|
/**
|
|
706
716
|
* Get the key for storing the seed.
|
|
@@ -710,54 +720,59 @@ export class Iota {
|
|
|
710
720
|
* @internal
|
|
711
721
|
*/
|
|
712
722
|
static buildSeedKey(identity, vaultSeedId) {
|
|
713
|
-
return
|
|
723
|
+
return VaultConnectorHelper.buildKeyName(identity, vaultSeedId ?? Iota.DEFAULT_SEED_SECRET_NAME);
|
|
714
724
|
}
|
|
715
725
|
/**
|
|
716
|
-
*
|
|
726
|
+
* Ensure a range of BIP44-derived keys are registered as individual vault keys and return their public keys.
|
|
727
|
+
* If the first key of the range already exists the range is considered registered and only public keys are derived.
|
|
728
|
+
* If not registered, all keys are derived and added to the vault before returning the public keys.
|
|
717
729
|
* @param vaultConnector The vault connector to use.
|
|
718
730
|
* @param config The configuration to use.
|
|
719
731
|
* @param identity The identity of the user to access the vault keys.
|
|
720
732
|
* @param accountIndex The account index.
|
|
721
733
|
* @param internal Whether the addresses are internal or external.
|
|
722
|
-
* @param addressIndex
|
|
723
|
-
* @
|
|
734
|
+
* @param addressIndex Any address index within the desired chunk; aligned internally.
|
|
735
|
+
* @param seedProvider Callback invoked at most once per call to supply the seed when a chunk is not yet registered.
|
|
736
|
+
* @returns The base64-encoded public keys for each address in the range.
|
|
724
737
|
* @internal
|
|
725
738
|
*/
|
|
726
|
-
static async
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
739
|
+
static async getPublicKeys(vaultConnector, config, identity, accountIndex, internal, addressIndex, seedProvider) {
|
|
740
|
+
const chunkStart = addressIndex - (addressIndex % Iota._PRE_CALC_CHUNK_SIZE);
|
|
741
|
+
const firstKeyName = Iota.buildAddressKeyName(identity, accountIndex, internal, chunkStart);
|
|
742
|
+
const publicKeys = [];
|
|
743
|
+
if (await vaultConnector.keyExists(firstKeyName)) {
|
|
744
|
+
for (let i = chunkStart; i < chunkStart + Iota._PRE_CALC_CHUNK_SIZE; i++) {
|
|
745
|
+
const keyName = Iota.buildAddressKeyName(identity, accountIndex, internal, i);
|
|
746
|
+
const keyData = await vaultConnector.getKey(keyName, "public");
|
|
747
|
+
if (!keyData.publicKey) {
|
|
748
|
+
throw new GeneralError(Iota.CLASS_NAME, "missingPublicKey", { keyName });
|
|
749
|
+
}
|
|
750
|
+
publicKeys.push(Converter.bytesToBase64(keyData.publicKey));
|
|
751
|
+
}
|
|
732
752
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
keyPairChunk.push({
|
|
742
|
-
privateKey: Converter.bytesToBase64(keyPair.privateKey),
|
|
743
|
-
publicKey: Converter.bytesToBase64(keyPair.publicKey)
|
|
744
|
-
});
|
|
753
|
+
else {
|
|
754
|
+
const seed = await seedProvider();
|
|
755
|
+
const coinType = config.coinType ?? Iota.DEFAULT_COIN_TYPE;
|
|
756
|
+
for (let i = chunkStart; i < chunkStart + Iota._PRE_CALC_CHUNK_SIZE; i++) {
|
|
757
|
+
const keyName = Iota.buildAddressKeyName(identity, accountIndex, internal, i);
|
|
758
|
+
const keyPair = Bip44.keyPair(seed, KeyType.Ed25519, coinType, accountIndex, internal, i);
|
|
759
|
+
await vaultConnector.addKey(keyName, VaultKeyType.Ed25519, keyPair.privateKey, keyPair.publicKey);
|
|
760
|
+
publicKeys.push(Converter.bytesToBase64(keyPair.publicKey));
|
|
745
761
|
}
|
|
746
|
-
await vaultConnector.setSecret(keyPairChunkKey, keyPairChunk);
|
|
747
762
|
}
|
|
748
|
-
return
|
|
763
|
+
return publicKeys;
|
|
749
764
|
}
|
|
750
765
|
/**
|
|
751
|
-
*
|
|
766
|
+
* Build the vault key name for a specific derived address.
|
|
752
767
|
* @param identity The identity to use.
|
|
753
768
|
* @param accountIndex The account index.
|
|
754
769
|
* @param internal Whether the address is internal or external.
|
|
755
|
-
* @param addressIndex The address index
|
|
756
|
-
* @returns The
|
|
770
|
+
* @param addressIndex The address index.
|
|
771
|
+
* @returns The vault key name.
|
|
757
772
|
* @internal
|
|
758
773
|
*/
|
|
759
|
-
static
|
|
760
|
-
return
|
|
774
|
+
static buildAddressKeyName(identity, accountIndex, internal, addressIndex) {
|
|
775
|
+
return VaultConnectorHelper.buildKeyName(identity, "account", accountIndex.toString(), internal ? "1" : "0", `${addressIndex}`);
|
|
761
776
|
}
|
|
762
777
|
}
|
|
763
778
|
//# sourceMappingURL=iota.js.map
|