dkg.js 8.0.2 → 8.0.4
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/index.cjs
CHANGED
|
@@ -586,15 +586,15 @@ class AssetOperationsManager {
|
|
|
586
586
|
|
|
587
587
|
this.validationService.validateIncreaseAllowance(blockchain);
|
|
588
588
|
|
|
589
|
-
const
|
|
590
|
-
'
|
|
589
|
+
const knowledgeCollectionAddress = await this.blockchainService.getContractAddress(
|
|
590
|
+
'KnowledgeCollection',
|
|
591
591
|
blockchain,
|
|
592
592
|
);
|
|
593
593
|
|
|
594
594
|
const receipt = await this.blockchainService.executeContractFunction(
|
|
595
595
|
'Token',
|
|
596
596
|
'increaseAllowance',
|
|
597
|
-
[
|
|
597
|
+
[knowledgeCollectionAddress, tokenAmount],
|
|
598
598
|
blockchain,
|
|
599
599
|
);
|
|
600
600
|
|
|
@@ -655,15 +655,15 @@ class AssetOperationsManager {
|
|
|
655
655
|
async getCurrentAllowance(options = {}) {
|
|
656
656
|
const blockchain = this.inputService.getBlockchain(options);
|
|
657
657
|
|
|
658
|
-
const
|
|
659
|
-
'
|
|
658
|
+
const knowledgeCollectionAddress = await this.blockchainService.getContractAddress(
|
|
659
|
+
'KnowledgeCollection',
|
|
660
660
|
blockchain,
|
|
661
661
|
);
|
|
662
662
|
|
|
663
663
|
const allowance = await this.blockchainService.callContractFunction(
|
|
664
664
|
'Token',
|
|
665
665
|
'allowance',
|
|
666
|
-
[blockchain.publicKey,
|
|
666
|
+
[blockchain.publicKey, knowledgeCollectionAddress],
|
|
667
667
|
blockchain,
|
|
668
668
|
);
|
|
669
669
|
|
|
@@ -698,6 +698,18 @@ class AssetOperationsManager {
|
|
|
698
698
|
return left;
|
|
699
699
|
}
|
|
700
700
|
|
|
701
|
+
manualJoinSignature({ r, s, v }) {
|
|
702
|
+
// Remove the "0x" prefix from r and s
|
|
703
|
+
const rNoPrefix = r.replace(/^0x/, '');
|
|
704
|
+
const sNoPrefix = s.replace(/^0x/, '');
|
|
705
|
+
|
|
706
|
+
// Convert v to a 2-digit hex string (e.g. "1b" or "1c")
|
|
707
|
+
// If v is already 27 or 28, this should work fine.
|
|
708
|
+
const vHex = Number(v).toString(16).padStart(2, '0');
|
|
709
|
+
|
|
710
|
+
return '0x' + rNoPrefix + sNoPrefix + vHex;
|
|
711
|
+
}
|
|
712
|
+
|
|
701
713
|
/**
|
|
702
714
|
* Creates a new knowledge collection.
|
|
703
715
|
* @async
|
|
@@ -849,7 +861,6 @@ class AssetOperationsManager {
|
|
|
849
861
|
hashFunctionId,
|
|
850
862
|
minimumNumberOfNodeReplications,
|
|
851
863
|
);
|
|
852
|
-
|
|
853
864
|
const publishOperationResult = await this.nodeApiService.getOperationResult(
|
|
854
865
|
endpoint,
|
|
855
866
|
port,
|
|
@@ -883,12 +894,28 @@ class AssetOperationsManager {
|
|
|
883
894
|
const identityIds = [];
|
|
884
895
|
const r = [];
|
|
885
896
|
const vs = [];
|
|
897
|
+
await Promise.all(
|
|
898
|
+
signatures.map(async (signature) => {
|
|
899
|
+
try {
|
|
900
|
+
const signerAddress = ethers.ethers.recoverAddress(
|
|
901
|
+
ethers.hashMessage(ethers.getBytes(datasetRoot)),
|
|
902
|
+
signature,
|
|
903
|
+
);
|
|
886
904
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
905
|
+
let keyIsOperationalWallet;
|
|
906
|
+
keyIsOperationalWallet = await this.blockchainService.keyIsOperationalWallet(
|
|
907
|
+
blockchain,
|
|
908
|
+
signature.identityId,
|
|
909
|
+
signerAddress,
|
|
910
|
+
);
|
|
911
|
+
if (keyIsOperationalWallet) {
|
|
912
|
+
identityIds.push(signature.identityId);
|
|
913
|
+
r.push(signature.r);
|
|
914
|
+
vs.push(signature.vs);
|
|
915
|
+
}
|
|
916
|
+
} catch {}
|
|
917
|
+
}),
|
|
918
|
+
);
|
|
892
919
|
|
|
893
920
|
let estimatedPublishingCost;
|
|
894
921
|
if (tokenAmount) {
|
|
@@ -4246,6 +4273,21 @@ class BlockchainServiceBase {
|
|
|
4246
4273
|
return this.callContractFunction('Chronos', 'epochLength', [], blockchain);
|
|
4247
4274
|
}
|
|
4248
4275
|
|
|
4276
|
+
async keyIsOperationalWallet(blockchain, identityId, signer) {
|
|
4277
|
+
const result = await this.callContractFunction(
|
|
4278
|
+
'IdentityStorage',
|
|
4279
|
+
'keyHasPurpose',
|
|
4280
|
+
[
|
|
4281
|
+
identityId,
|
|
4282
|
+
ethers.solidityPackedKeccak256(['address'], [signer]),
|
|
4283
|
+
2, // IdentityLib.OPERATIONAL_KEY
|
|
4284
|
+
],
|
|
4285
|
+
blockchain,
|
|
4286
|
+
);
|
|
4287
|
+
|
|
4288
|
+
return result;
|
|
4289
|
+
}
|
|
4290
|
+
|
|
4249
4291
|
convertToWei(ether) {
|
|
4250
4292
|
return Web3.utils.toWei(ether.toString(), 'ether');
|
|
4251
4293
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { kaTools, kcTools } from 'assertion-tools';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
2
|
+
import { ethers, hashMessage, getBytes } from 'ethers';
|
|
3
3
|
import {
|
|
4
4
|
deriveUAL,
|
|
5
5
|
getOperationStatusObject,
|
|
@@ -168,15 +168,15 @@ export default class AssetOperationsManager {
|
|
|
168
168
|
|
|
169
169
|
this.validationService.validateIncreaseAllowance(blockchain);
|
|
170
170
|
|
|
171
|
-
const
|
|
172
|
-
'
|
|
171
|
+
const knowledgeCollectionAddress = await this.blockchainService.getContractAddress(
|
|
172
|
+
'KnowledgeCollection',
|
|
173
173
|
blockchain,
|
|
174
174
|
);
|
|
175
175
|
|
|
176
176
|
const receipt = await this.blockchainService.executeContractFunction(
|
|
177
177
|
'Token',
|
|
178
178
|
'increaseAllowance',
|
|
179
|
-
[
|
|
179
|
+
[knowledgeCollectionAddress, tokenAmount],
|
|
180
180
|
blockchain,
|
|
181
181
|
);
|
|
182
182
|
|
|
@@ -237,15 +237,15 @@ export default class AssetOperationsManager {
|
|
|
237
237
|
async getCurrentAllowance(options = {}) {
|
|
238
238
|
const blockchain = this.inputService.getBlockchain(options);
|
|
239
239
|
|
|
240
|
-
const
|
|
241
|
-
'
|
|
240
|
+
const knowledgeCollectionAddress = await this.blockchainService.getContractAddress(
|
|
241
|
+
'KnowledgeCollection',
|
|
242
242
|
blockchain,
|
|
243
243
|
);
|
|
244
244
|
|
|
245
245
|
const allowance = await this.blockchainService.callContractFunction(
|
|
246
246
|
'Token',
|
|
247
247
|
'allowance',
|
|
248
|
-
[blockchain.publicKey,
|
|
248
|
+
[blockchain.publicKey, knowledgeCollectionAddress],
|
|
249
249
|
blockchain,
|
|
250
250
|
);
|
|
251
251
|
|
|
@@ -280,6 +280,18 @@ export default class AssetOperationsManager {
|
|
|
280
280
|
return left;
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
manualJoinSignature({ r, s, v }) {
|
|
284
|
+
// Remove the "0x" prefix from r and s
|
|
285
|
+
const rNoPrefix = r.replace(/^0x/, '');
|
|
286
|
+
const sNoPrefix = s.replace(/^0x/, '');
|
|
287
|
+
|
|
288
|
+
// Convert v to a 2-digit hex string (e.g. "1b" or "1c")
|
|
289
|
+
// If v is already 27 or 28, this should work fine.
|
|
290
|
+
const vHex = Number(v).toString(16).padStart(2, '0');
|
|
291
|
+
|
|
292
|
+
return '0x' + rNoPrefix + sNoPrefix + vHex;
|
|
293
|
+
}
|
|
294
|
+
|
|
283
295
|
/**
|
|
284
296
|
* Creates a new knowledge collection.
|
|
285
297
|
* @async
|
|
@@ -431,7 +443,6 @@ export default class AssetOperationsManager {
|
|
|
431
443
|
hashFunctionId,
|
|
432
444
|
minimumNumberOfNodeReplications,
|
|
433
445
|
);
|
|
434
|
-
|
|
435
446
|
const publishOperationResult = await this.nodeApiService.getOperationResult(
|
|
436
447
|
endpoint,
|
|
437
448
|
port,
|
|
@@ -465,12 +476,28 @@ export default class AssetOperationsManager {
|
|
|
465
476
|
const identityIds = [];
|
|
466
477
|
const r = [];
|
|
467
478
|
const vs = [];
|
|
479
|
+
await Promise.all(
|
|
480
|
+
signatures.map(async (signature) => {
|
|
481
|
+
try {
|
|
482
|
+
const signerAddress = ethers.recoverAddress(
|
|
483
|
+
hashMessage(getBytes(datasetRoot)),
|
|
484
|
+
signature,
|
|
485
|
+
);
|
|
468
486
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
487
|
+
let keyIsOperationalWallet;
|
|
488
|
+
keyIsOperationalWallet = await this.blockchainService.keyIsOperationalWallet(
|
|
489
|
+
blockchain,
|
|
490
|
+
signature.identityId,
|
|
491
|
+
signerAddress,
|
|
492
|
+
);
|
|
493
|
+
if (keyIsOperationalWallet) {
|
|
494
|
+
identityIds.push(signature.identityId);
|
|
495
|
+
r.push(signature.r);
|
|
496
|
+
vs.push(signature.vs);
|
|
497
|
+
}
|
|
498
|
+
} catch {}
|
|
499
|
+
}),
|
|
500
|
+
);
|
|
474
501
|
|
|
475
502
|
let estimatedPublishingCost;
|
|
476
503
|
if (tokenAmount) {
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* eslint-disable no-await-in-loop */
|
|
3
3
|
import Web3 from 'web3';
|
|
4
4
|
import axios from 'axios';
|
|
5
|
+
import { solidityPackedKeccak256 } from 'ethers';
|
|
5
6
|
import { createRequire } from 'module';
|
|
6
7
|
import {
|
|
7
8
|
OPERATIONS_STEP_STATUS,
|
|
@@ -1185,6 +1186,21 @@ export default class BlockchainServiceBase {
|
|
|
1185
1186
|
return this.callContractFunction('Chronos', 'epochLength', [], blockchain);
|
|
1186
1187
|
}
|
|
1187
1188
|
|
|
1189
|
+
async keyIsOperationalWallet(blockchain, identityId, signer) {
|
|
1190
|
+
const result = await this.callContractFunction(
|
|
1191
|
+
'IdentityStorage',
|
|
1192
|
+
'keyHasPurpose',
|
|
1193
|
+
[
|
|
1194
|
+
identityId,
|
|
1195
|
+
solidityPackedKeccak256(['address'], [signer]),
|
|
1196
|
+
2, // IdentityLib.OPERATIONAL_KEY
|
|
1197
|
+
],
|
|
1198
|
+
blockchain,
|
|
1199
|
+
);
|
|
1200
|
+
|
|
1201
|
+
return result;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1188
1204
|
convertToWei(ether) {
|
|
1189
1205
|
return Web3.utils.toWei(ether.toString(), 'ether');
|
|
1190
1206
|
}
|