@keetanetwork/keetanet-client 0.14.14 → 0.16.0
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/client/builder.d.ts +29 -3
- package/client/index-browser.d.ts +21 -5
- package/client/index-browser.js +3261 -2657
- package/client/index.d.ts +21 -5
- package/client/index.js +947 -457
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/KeetaNetSDK.Client.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.Account.html +13 -13
- package/docs/classes/KeetaNetSDK.Referenced.BaseSet.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BaseVoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.Block.html +33 -30
- package/docs/classes/KeetaNetSDK.Referenced.BlockBuilder.html +2 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockHash.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperation.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationCREATE_IDENTIFIER.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMANAGE_CERTIFICATE.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMODIFY_PERMISSIONS.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationRECEIVE.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSEND.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_INFO.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_REP.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_MODIFY_BALANCE.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_SUPPLY.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.Certificate.html +11 -5
- package/docs/classes/KeetaNetSDK.Referenced.CertificateBundle.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.CertificateHash.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ECDSAKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1PrivateKey.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1PublicKey.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1Signature.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PrivateKey.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PublicKey.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1Signature.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ED25519KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519PrivateKey.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ED25519PublicKey.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ED25519Signature.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.ExternalKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ExternalSet.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.IdempotentKey.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.IdentifierKey.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.IdentifierKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetError.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetErrorBase.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerError.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerIdempotentKeyError.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerVoteError.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeyInterface.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeyStorage.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.LogTargetConsole.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.Node.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.P2PSwitch.html +4 -2
- package/docs/classes/KeetaNetSDK.Referenced.PendingAccount.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.PermissionSetHolder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.PossiblyExpiredVote.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.PossiblyUnsignedBlock.html +38 -0
- package/docs/classes/KeetaNetSDK.Referenced.SignatureStorage.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.Stats.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.StatsPending.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.UnsignedBlock.html +42 -0
- package/docs/classes/KeetaNetSDK.Referenced.UserClientBuilder.html +13 -1
- package/docs/classes/KeetaNetSDK.Referenced.Vote.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.VoteBlockBundle.html +11 -9
- package/docs/classes/KeetaNetSDK.Referenced.VoteBlockHash.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.VoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteHash.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.VoteLikeBase.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.VoteQuote.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.VoteQuoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteStaple.html +10 -8
- package/docs/classes/KeetaNetSDK.Referenced.VoteStapleHash.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.src_lib_utils_buffer.BufferStorage.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.src_lib_utils_certificate.CertificateBuilder.html +4 -2
- package/docs/classes/KeetaNetSDK.UserClient.html +17 -9
- package/docs/documents/GETTING-STARTED.html +2 -2
- package/docs/enums/KeetaNetSDK.Referenced.AdjustMethod.html +4 -4
- package/docs/enums/KeetaNetSDK.Referenced.OperationType.html +10 -10
- package/docs/functions/KeetaNetSDK.Referenced.src_lib_utils_buffer.DecodeBase32.html +2 -2
- package/docs/functions/KeetaNetSDK.Referenced.src_lib_utils_buffer.DecodeBase64URL.html +1 -0
- package/docs/functions/KeetaNetSDK.Referenced.src_lib_utils_buffer.EncodeBase64URL.html +1 -0
- package/docs/functions/KeetaNetSDK.Referenced.src_lib_utils_conversion.toJSONSerializable.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ACLEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ACLUpdate.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ExplicitContextTag.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ImplicitContextTag.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ASN1Object.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseExternalKeyPairFunctions.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseGenerationConfig.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseIdentifierCreateArguments.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperation.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationCREATE_IDENTIFIER.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATE.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMODIFY_PERMISSIONS.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationRECEIVE.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSEND.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_INFO.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_REP.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_MODIFY_BALANCE.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_SUPPLY.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockOperationValidateContext.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockV1Canonical.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockV2Canonical.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.Constructor.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.DisposableTimingHandle.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsNoEncryption.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsSupportsEncryption.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.IdentifierCreateRequest.html +3 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.InitialConfigSupply.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.InstanceSet.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.KVGenericOptionsType.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.KVSetOptionsType.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.LogTarget.html +3 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.ModifyTokenBalanceEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.MultiSigIdentifierCreateArguments.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.MultisigConfig.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.NodeConfig.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.NumericValueEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerBase.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerListener.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerRepBase.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.PendingOperations.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.PendingOperationsJSON.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.PublicKeyStorage.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.PublishOptions.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.RequestTokenReceiveEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.TokenNumericEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.UserClientConfig.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.UserClientOptions.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.VoteBundleConstructor.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.VoteStapleJSON.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.WithIsInstance.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1BitString.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Date.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1OID.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Set.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1String.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Struct.html +1 -1
- package/docs/modules/KeetaNetSDK.Referenced.html +1 -1
- package/docs/modules/KeetaNetSDK.Referenced.src_lib_utils_buffer.html +1 -1
- package/docs/modules/KeetaNetSDK.Referenced.src_lib_utils_certificate.html +1 -1
- package/docs/types/KeetaNetSDK.Referenced.BlockJSONOptionalSigned.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.BlockV1JSONOptionalSigned.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.BlockV2JSONOptionalSigned.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.CertificateUpdate.html +1 -1
- package/docs/types/KeetaNetSDK.Referenced.IsTuple.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.JSONDepthLimit.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.KeyUsage.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.KeyUsageBits.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.LogTargetConsoleConfig.html +3 -2
- package/docs/types/KeetaNetSDK.Referenced.MultisigSignerFieldJSON.html +1 -1
- package/docs/types/KeetaNetSDK.Referenced.VoteOptions.html +7 -3
- package/docs/types/KeetaNetSDK.Referenced.VoteStapleInputs.html +2 -0
- package/docs/types/KeetaNetSDK.Referenced.VoteStapleOptions.html +9 -0
- package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_certificate.CertificateBundleJSONOutput.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_certificate.CertificateJSONOutput.html +1 -1
- package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_conversion.ToJSONSerializable.html +1 -1
- package/docs/variables/KeetaNetSDK.Referenced.BlockOperationASN1Schema.html +2 -2
- package/docs/variables/KeetaNetSDK.Referenced.allFullErrorCodes.html +1 -1
- package/docs/variables/KeetaNetSDK.Referenced.keyUsageBits.html +1 -0
- package/lib/block/index.d.ts +341 -46
- package/lib/block/operations.d.ts +14 -21
- package/lib/error/block.d.ts +2 -2
- package/lib/error/index.d.ts +1 -1
- package/lib/ledger/db_spanner_helper.d.ts +1 -1
- package/lib/log/common.d.ts +3 -0
- package/lib/log/internal.d.ts +22 -0
- package/lib/log/target_console.d.ts +6 -0
- package/lib/log/target_gcp.d.ts +6 -0
- package/lib/log/target_gcp.js +259 -77
- package/lib/log/target_https.d.ts +28 -0
- package/lib/log/target_https.js +6055 -0
- package/lib/p2p.d.ts +6 -2
- package/lib/utils/buffer.d.ts +7 -2
- package/lib/utils/certificate.d.ts +41 -25
- package/lib/utils/conversion.d.ts +8 -4
- package/lib/utils/external-keys/passkey-prf.d.ts +156 -0
- package/lib/utils/external-keys/passkey-prf.js +391 -0
- package/lib/vote.d.ts +230 -35
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/version.d.ts +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATESerializable.html +0 -5
- package/docs/types/KeetaNetSDK.Referenced.ExportedJSONOperation.html +0 -1
- package/docs/types/KeetaNetSDK.Referenced.MultisigSignerField.html +0 -1
package/client/index.js
CHANGED
|
@@ -57280,6 +57280,7 @@ const permissions_1 = __webpack_require__(5860);
|
|
|
57280
57280
|
const conversion_1 = __webpack_require__(2360);
|
|
57281
57281
|
const helper_1 = __webpack_require__(3208);
|
|
57282
57282
|
const certificate_1 = __webpack_require__(5661);
|
|
57283
|
+
const never_1 = __webpack_require__(8692);
|
|
57283
57284
|
class PendingAccount {
|
|
57284
57285
|
constructor() {
|
|
57285
57286
|
_PendingAccount_account.set(this, void 0);
|
|
@@ -57303,7 +57304,7 @@ class PendingAccount {
|
|
|
57303
57304
|
return (__classPrivateFieldGet(this, _PendingAccount_account, "f"));
|
|
57304
57305
|
}
|
|
57305
57306
|
toJSON() {
|
|
57306
|
-
return (this.account);
|
|
57307
|
+
return (this.account.publicKeyString.get());
|
|
57307
57308
|
}
|
|
57308
57309
|
}
|
|
57309
57310
|
exports.PendingAccount = PendingAccount;
|
|
@@ -57362,8 +57363,29 @@ class UserClientBuilder {
|
|
|
57362
57363
|
pendingOperations.tokenSupply = (0, conversion_1.parseHexBigIntString)(operations.tokenSupply);
|
|
57363
57364
|
}
|
|
57364
57365
|
if (operations.createIdentifiers !== undefined) {
|
|
57365
|
-
pendingOperations.createIdentifiers = operations.createIdentifiers.map(function ({ type }) {
|
|
57366
|
-
|
|
57366
|
+
pendingOperations.createIdentifiers = operations.createIdentifiers.map(function ({ type, createArguments }) {
|
|
57367
|
+
let createArgumentsParsed;
|
|
57368
|
+
if (createArguments !== undefined) {
|
|
57369
|
+
if (createArguments.type === account_1.AccountKeyAlgorithm.MULTISIG) {
|
|
57370
|
+
createArgumentsParsed = {
|
|
57371
|
+
type: account_1.AccountKeyAlgorithm.MULTISIG,
|
|
57372
|
+
quorum: BigInt(createArguments.quorum),
|
|
57373
|
+
signers: createArguments.signers.map(signer => {
|
|
57374
|
+
const parsed = account_1.Account.toAccount(signer);
|
|
57375
|
+
if (parsed.isAccount() || parsed.isMultisig()) {
|
|
57376
|
+
return (parsed);
|
|
57377
|
+
}
|
|
57378
|
+
else {
|
|
57379
|
+
throw (new Error('Multisig signer must be an account or multisig identifier'));
|
|
57380
|
+
}
|
|
57381
|
+
})
|
|
57382
|
+
};
|
|
57383
|
+
}
|
|
57384
|
+
else {
|
|
57385
|
+
(0, never_1.assertNever)(createArguments.type);
|
|
57386
|
+
}
|
|
57387
|
+
}
|
|
57388
|
+
return ({ type, createArguments: createArgumentsParsed });
|
|
57367
57389
|
});
|
|
57368
57390
|
}
|
|
57369
57391
|
if (operations.send !== undefined) {
|
|
@@ -57615,14 +57637,15 @@ class UserClientBuilder {
|
|
|
57615
57637
|
if (!previous) {
|
|
57616
57638
|
previous = await renderOptions.getPrevious(account) ?? block_1.Block.NO_PREVIOUS;
|
|
57617
57639
|
}
|
|
57618
|
-
for (const { type, toResolve } of (pending.createIdentifiers ?? [])) {
|
|
57640
|
+
for (const { type, toResolve, createArguments } of (pending.createIdentifiers ?? [])) {
|
|
57619
57641
|
const createdAddress = account.generateIdentifier(type, previous, operations.length);
|
|
57620
57642
|
if (PendingAccount.IsInstance(toResolve)) {
|
|
57621
57643
|
toResolve.account = createdAddress;
|
|
57622
57644
|
}
|
|
57623
57645
|
operations.push({
|
|
57624
57646
|
type: block_1.Block.OperationType.CREATE_IDENTIFIER,
|
|
57625
|
-
identifier: createdAddress
|
|
57647
|
+
identifier: createdAddress,
|
|
57648
|
+
createArguments: createArguments
|
|
57626
57649
|
});
|
|
57627
57650
|
}
|
|
57628
57651
|
const allSends = {};
|
|
@@ -57864,13 +57887,22 @@ class UserClientBuilder {
|
|
|
57864
57887
|
__classPrivateFieldGet(this, _UserClientBuilder_instances, "m", _UserClientBuilder_useOptions).call(this, options);
|
|
57865
57888
|
__classPrivateFieldGet(this, _UserClientBuilder_pendingOperations, "f").setRep = to;
|
|
57866
57889
|
}
|
|
57867
|
-
generateIdentifier(
|
|
57890
|
+
generateIdentifier(toCreate, options = {}) {
|
|
57868
57891
|
__classPrivateFieldGet(this, _UserClientBuilder_instances, "m", _UserClientBuilder_useOptions).call(this, options);
|
|
57892
|
+
let createType;
|
|
57893
|
+
let createArguments;
|
|
57894
|
+
if (typeof toCreate === 'number') {
|
|
57895
|
+
createType = toCreate;
|
|
57896
|
+
}
|
|
57897
|
+
else {
|
|
57898
|
+
createArguments = toCreate;
|
|
57899
|
+
createType = toCreate.type;
|
|
57900
|
+
}
|
|
57869
57901
|
if (!__classPrivateFieldGet(this, _UserClientBuilder_pendingOperations, "f").createIdentifiers) {
|
|
57870
57902
|
__classPrivateFieldGet(this, _UserClientBuilder_pendingOperations, "f").createIdentifiers = [];
|
|
57871
57903
|
}
|
|
57872
57904
|
const toResolve = new PendingAccount();
|
|
57873
|
-
__classPrivateFieldGet(this, _UserClientBuilder_pendingOperations, "f").createIdentifiers.push({ type, toResolve });
|
|
57905
|
+
__classPrivateFieldGet(this, _UserClientBuilder_pendingOperations, "f").createIdentifiers.push({ type: createType, toResolve, createArguments });
|
|
57874
57906
|
return (toResolve);
|
|
57875
57907
|
}
|
|
57876
57908
|
get blocks() {
|
|
@@ -60443,16 +60475,9 @@ class UserClient {
|
|
|
60443
60475
|
async getQuotes(blocks) {
|
|
60444
60476
|
return (await __classPrivateFieldGet(this, _UserClient_client, "f").getVoteQuotes(blocks));
|
|
60445
60477
|
}
|
|
60446
|
-
|
|
60447
|
-
* Generate a new identifier for the given type and publish the blocks
|
|
60448
|
-
*
|
|
60449
|
-
* @param type The type of identifier to generate
|
|
60450
|
-
* @param options The options to use for the request
|
|
60451
|
-
* @return The identifier that was generated
|
|
60452
|
-
*/
|
|
60453
|
-
async generateIdentifier(type, options = {}) {
|
|
60478
|
+
async generateIdentifier(toCreate, options = {}) {
|
|
60454
60479
|
const builder = this.initBuilder(options);
|
|
60455
|
-
const generated = builder.generateIdentifier(
|
|
60480
|
+
const generated = builder.generateIdentifier(toCreate);
|
|
60456
60481
|
await this.publishBuilder(builder);
|
|
60457
60482
|
return (generated);
|
|
60458
60483
|
}
|
|
@@ -61106,7 +61131,7 @@ exports.baseValidationConfig = {
|
|
|
61106
61131
|
}
|
|
61107
61132
|
},
|
|
61108
61133
|
idempotentKey: {
|
|
61109
|
-
maxByteLength:
|
|
61134
|
+
maxByteLength: 36
|
|
61110
61135
|
}
|
|
61111
61136
|
};
|
|
61112
61137
|
function getNetworkAlias(networkOrID) {
|
|
@@ -62849,23 +62874,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
62849
62874
|
__setModuleDefault(result, mod);
|
|
62850
62875
|
return result;
|
|
62851
62876
|
};
|
|
62852
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
62853
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
62854
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
62855
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
62856
|
-
};
|
|
62857
62877
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
62858
62878
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
62859
62879
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
62860
62880
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
62861
62881
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
62862
62882
|
};
|
|
62883
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
62884
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
62885
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
62886
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
62887
|
+
};
|
|
62863
62888
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62864
62889
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62865
62890
|
};
|
|
62866
|
-
var
|
|
62891
|
+
var _PossiblyUnsignedBlock_instances, _a, _PossiblyUnsignedBlock_valueBytes, _PossiblyUnsignedBlock_valueHash, _PossiblyUnsignedBlock_hasSignature, _PossiblyUnsignedBlock_nonNullableSignatures_get, _PossiblyUnsignedBlock_validateRecalculatedBytes, _PossiblyUnsignedBlock_validateOperationsPurpose, _PossiblyUnsignedBlock_validateSignerField, _PossiblyUnsignedBlock_validateSignatures, _PossiblyUnsignedBlock_validateIdempotent, _PossiblyUnsignedBlock_toBytesInternal, _b, _BlockBuilder_block, _BlockBuilder_ValidateInputs;
|
|
62867
62892
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
62868
|
-
exports.BlockBuilder = exports.Block = exports.BlockHash = exports.AdjustMethod = exports.BlockPurpose = void 0;
|
|
62893
|
+
exports.BlockBuilder = exports.Block = exports.UnsignedBlock = exports.BlockHash = exports.AdjustMethod = exports.BlockPurpose = void 0;
|
|
62869
62894
|
exports.toAdjustMethod = toAdjustMethod;
|
|
62870
62895
|
const account_1 = __importStar(__webpack_require__(9415));
|
|
62871
62896
|
const buffer_1 = __webpack_require__(3310);
|
|
@@ -62873,6 +62898,7 @@ const hash_1 = __webpack_require__(7908);
|
|
|
62873
62898
|
const ASN1 = __importStar(__webpack_require__(6045));
|
|
62874
62899
|
const helper_1 = __webpack_require__(3208);
|
|
62875
62900
|
const util_1 = __webpack_require__(9023);
|
|
62901
|
+
const conversion_1 = __webpack_require__(2360);
|
|
62876
62902
|
const Operations = __importStar(__webpack_require__(2778));
|
|
62877
62903
|
const block_1 = __importDefault(__webpack_require__(7412));
|
|
62878
62904
|
const common_1 = __webpack_require__(5663);
|
|
@@ -63115,6 +63141,12 @@ function _ignore_static_checks() {
|
|
|
63115
63141
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
63116
63142
|
const _ignore_check_blockasn1v2_reverse_2 = _ignore_check_blockasn1v2_reverse_1;
|
|
63117
63143
|
}
|
|
63144
|
+
function validateIdempotentKeyLength(idempotent, network) {
|
|
63145
|
+
const idempotentValidationConfig = (0, config_1.getValidation)(network).idempotentKey;
|
|
63146
|
+
if (idempotent.length > idempotentValidationConfig.maxByteLength) {
|
|
63147
|
+
throw (new block_1.default('BLOCK_INVALID_IDEMPOTENT_LENGTH', `Block idempotent key is length ${idempotent.length}, but maxByteLength is ${idempotentValidationConfig.maxByteLength}`));
|
|
63148
|
+
}
|
|
63149
|
+
}
|
|
63118
63150
|
function parseBlockIdempotent(input, network) {
|
|
63119
63151
|
let output;
|
|
63120
63152
|
if (Buffer.isBuffer(input)) {
|
|
@@ -63132,10 +63164,7 @@ function parseBlockIdempotent(input, network) {
|
|
|
63132
63164
|
throw (new block_1.default('BLOCK_INVALID_IDEMPOTENT_FORMAT', 'Could not parse Block idempotent'));
|
|
63133
63165
|
}
|
|
63134
63166
|
if (network !== undefined) {
|
|
63135
|
-
|
|
63136
|
-
if (output.length > idempotentValidationConfig.maxByteLength) {
|
|
63137
|
-
throw (new block_1.default('BLOCK_INVALID_IDEMPOTENT_LENGTH', `Block idempotent key is length ${output.length}, but maxByteLength is ${idempotentValidationConfig.maxByteLength}`));
|
|
63138
|
-
}
|
|
63167
|
+
validateIdempotentKeyLength(output, network);
|
|
63139
63168
|
}
|
|
63140
63169
|
return (output);
|
|
63141
63170
|
}
|
|
@@ -63285,11 +63314,22 @@ function assertBlockSignatureField(input) {
|
|
|
63285
63314
|
throw (new Error('Input must include 1+ signatures'));
|
|
63286
63315
|
}
|
|
63287
63316
|
}
|
|
63317
|
+
function getBlockSignatureFieldFromVersion(version) {
|
|
63318
|
+
if (version === 1) {
|
|
63319
|
+
return ('signature');
|
|
63320
|
+
}
|
|
63321
|
+
else if (version === 2) {
|
|
63322
|
+
return ('signatures');
|
|
63323
|
+
}
|
|
63324
|
+
else {
|
|
63325
|
+
throw (new Error(`Unsupported block version for signature field: ${version}`));
|
|
63326
|
+
}
|
|
63327
|
+
}
|
|
63288
63328
|
/**
|
|
63289
63329
|
* Block: An item which contains a number of operations (transactions) which
|
|
63290
63330
|
* originated from an account at a particular instant
|
|
63291
63331
|
*/
|
|
63292
|
-
class
|
|
63332
|
+
class PossiblyUnsignedBlock {
|
|
63293
63333
|
get principal() {
|
|
63294
63334
|
if (Array.isArray(this.signer)) {
|
|
63295
63335
|
return (this.signer[0]);
|
|
@@ -63298,53 +63338,44 @@ class Block {
|
|
|
63298
63338
|
return (this.signer);
|
|
63299
63339
|
}
|
|
63300
63340
|
}
|
|
63301
|
-
static
|
|
63302
|
-
const
|
|
63303
|
-
|
|
63304
|
-
|
|
63305
|
-
|
|
63341
|
+
static getSortedRequiredSigners(input) {
|
|
63342
|
+
const queue = [input];
|
|
63343
|
+
const visited = new account_1.default.Set();
|
|
63344
|
+
const out = [];
|
|
63345
|
+
while (queue.length > 0) {
|
|
63346
|
+
// We can assume that the signerFieldQueue is not empty here since the loop condition checks it
|
|
63347
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
63348
|
+
const cur = queue.shift();
|
|
63349
|
+
if (account_1.default.isInstance(cur)) {
|
|
63350
|
+
if (visited.has(cur)) {
|
|
63351
|
+
continue;
|
|
63352
|
+
}
|
|
63353
|
+
visited.add(cur);
|
|
63354
|
+
out.push(cur);
|
|
63355
|
+
}
|
|
63356
|
+
else {
|
|
63357
|
+
queue.unshift(...cur[1]);
|
|
63306
63358
|
}
|
|
63307
63359
|
}
|
|
63308
|
-
|
|
63309
|
-
// We have to ignore the type here because the ASN1.JStoASN1 function does not handle recursive types well
|
|
63310
|
-
// @ts-ignore
|
|
63311
|
-
const bytes = ASN1.JStoASN1(container).toBER(false);
|
|
63312
|
-
const hash = new BlockHash((0, hash_1.Hash)(Buffer.from(bytes)));
|
|
63313
|
-
const signers = __classPrivateFieldGet(this, _a, "m", _Block_getSortedRequiredSigners).call(this, input.signer);
|
|
63314
|
-
const signatures = await Promise.all(signers.map(async function (signer) {
|
|
63315
|
-
const signature = await signer.sign(hash.getBuffer());
|
|
63316
|
-
return (signature.getBuffer());
|
|
63317
|
-
}));
|
|
63318
|
-
let blockInput;
|
|
63319
|
-
if (input.version === 1) {
|
|
63320
|
-
blockInput = { ...input, signature: signatures[0] };
|
|
63321
|
-
}
|
|
63322
|
-
else {
|
|
63323
|
-
blockInput = { ...input, signatures };
|
|
63324
|
-
}
|
|
63325
|
-
return (new _a(blockInput));
|
|
63360
|
+
return (out);
|
|
63326
63361
|
}
|
|
63327
|
-
static
|
|
63362
|
+
static isValidJSONSignedOrUnsigned(assertSignatureIncluded, block, version) {
|
|
63328
63363
|
if (!block || typeof block !== 'object' || Array.isArray(block)) {
|
|
63329
63364
|
return (false);
|
|
63330
63365
|
}
|
|
63331
|
-
if (!('version' in block)) {
|
|
63366
|
+
if (!('version' in block) || typeof block.version !== 'number') {
|
|
63332
63367
|
return (false);
|
|
63333
63368
|
}
|
|
63334
63369
|
if (version !== undefined && block.version !== version) {
|
|
63335
63370
|
return (false);
|
|
63336
63371
|
}
|
|
63337
63372
|
const checkFields = ['date', 'previous', 'network', 'network', 'account', 'signer', 'operations'];
|
|
63338
|
-
if (
|
|
63339
|
-
checkFields.push(
|
|
63373
|
+
if (assertSignatureIncluded) {
|
|
63374
|
+
checkFields.push(getBlockSignatureFieldFromVersion(block.version));
|
|
63340
63375
|
}
|
|
63341
|
-
|
|
63342
|
-
checkFields.push('signatures');
|
|
63376
|
+
if (block.version === 2) {
|
|
63343
63377
|
checkFields.push('purpose');
|
|
63344
63378
|
}
|
|
63345
|
-
else {
|
|
63346
|
-
return (false);
|
|
63347
|
-
}
|
|
63348
63379
|
for (const checkField of checkFields) {
|
|
63349
63380
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
63350
63381
|
if (!(checkField in block) || block[checkField] === undefined) {
|
|
@@ -63353,10 +63384,11 @@ class Block {
|
|
|
63353
63384
|
}
|
|
63354
63385
|
return (true);
|
|
63355
63386
|
}
|
|
63356
|
-
constructor(input) {
|
|
63357
|
-
|
|
63358
|
-
|
|
63359
|
-
|
|
63387
|
+
constructor(input, hasSignature) {
|
|
63388
|
+
_PossiblyUnsignedBlock_instances.add(this);
|
|
63389
|
+
_PossiblyUnsignedBlock_valueBytes.set(this, void 0);
|
|
63390
|
+
_PossiblyUnsignedBlock_valueHash.set(this, void 0);
|
|
63391
|
+
_PossiblyUnsignedBlock_hasSignature.set(this, void 0);
|
|
63360
63392
|
// Extra attributes
|
|
63361
63393
|
this.$opening = false;
|
|
63362
63394
|
if (typeof input === 'string') {
|
|
@@ -63365,7 +63397,10 @@ class Block {
|
|
|
63365
63397
|
if ((0, helper_1.isBuffer)(input)) {
|
|
63366
63398
|
input = (0, helper_1.bufferToArrayBuffer)(input);
|
|
63367
63399
|
}
|
|
63400
|
+
let foundSignatureField;
|
|
63368
63401
|
if (util_1.types.isArrayBuffer(input)) {
|
|
63402
|
+
// For some reason, typescript says this is excessively deep
|
|
63403
|
+
// @ts-ignore
|
|
63369
63404
|
const data = new ASN1.BufferStorageASN1(input, BlockASN1Schema).getASN1();
|
|
63370
63405
|
if (Array.isArray(data)) {
|
|
63371
63406
|
if (data[0] !== 0n) {
|
|
@@ -63392,7 +63427,13 @@ class Block {
|
|
|
63392
63427
|
const prevHashBuf = data[7];
|
|
63393
63428
|
this.previous = new BlockHash(prevHashBuf);
|
|
63394
63429
|
this.operations = Operations.ImportOperationsASN1(data[8], this.network);
|
|
63395
|
-
|
|
63430
|
+
if (data[9]) {
|
|
63431
|
+
// @ts-ignore
|
|
63432
|
+
foundSignatureField = [data[9]];
|
|
63433
|
+
}
|
|
63434
|
+
else {
|
|
63435
|
+
foundSignatureField = null;
|
|
63436
|
+
}
|
|
63396
63437
|
}
|
|
63397
63438
|
else if (data.value === 1) {
|
|
63398
63439
|
this.version = 2;
|
|
@@ -63419,24 +63460,31 @@ class Block {
|
|
|
63419
63460
|
this.previous = new BlockHash(container[7]);
|
|
63420
63461
|
this.operations = Operations.ImportOperationsASN1(container[8], this.network);
|
|
63421
63462
|
const signatureContainer = container[9];
|
|
63422
|
-
if (
|
|
63423
|
-
|
|
63463
|
+
if (signatureContainer) {
|
|
63464
|
+
if (Buffer.isBuffer(signatureContainer)) {
|
|
63465
|
+
foundSignatureField = [signatureContainer];
|
|
63466
|
+
}
|
|
63467
|
+
else {
|
|
63468
|
+
if (signatureContainer.length <= 1) {
|
|
63469
|
+
throw (new Error('Signature field invalid, must be greater than one when using sequence of'));
|
|
63470
|
+
}
|
|
63471
|
+
assertBlockSignatureField(signatureContainer);
|
|
63472
|
+
foundSignatureField = signatureContainer;
|
|
63473
|
+
}
|
|
63424
63474
|
}
|
|
63425
63475
|
else {
|
|
63426
|
-
|
|
63427
|
-
throw (new Error('Signature field invalid, must be greater than one when using sequence of'));
|
|
63428
|
-
}
|
|
63429
|
-
assertBlockSignatureField(signatureContainer);
|
|
63430
|
-
this.signatures = signatureContainer;
|
|
63476
|
+
foundSignatureField = null;
|
|
63431
63477
|
}
|
|
63432
63478
|
}
|
|
63433
63479
|
else {
|
|
63434
63480
|
throw (new Error('Unknown block version'));
|
|
63435
63481
|
}
|
|
63436
|
-
__classPrivateFieldSet(this,
|
|
63482
|
+
__classPrivateFieldSet(this, _PossiblyUnsignedBlock_valueBytes, input, "f");
|
|
63437
63483
|
}
|
|
63438
63484
|
else {
|
|
63439
|
-
|
|
63485
|
+
// These will be loaded even though they are defined later in the file because the constructor does not get automatically called before their definitions
|
|
63486
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
63487
|
+
if (Block.isInstance(input) || UnsignedBlock.isInstance(input)) {
|
|
63440
63488
|
this.version = input.version;
|
|
63441
63489
|
this.purpose = input.purpose;
|
|
63442
63490
|
this.idempotent = input.idempotent;
|
|
@@ -63447,9 +63495,9 @@ class Block {
|
|
|
63447
63495
|
this.account = input.account;
|
|
63448
63496
|
this.operations = input.operations;
|
|
63449
63497
|
this.signer = input.signer;
|
|
63450
|
-
|
|
63498
|
+
foundSignatureField = input.signatures;
|
|
63451
63499
|
}
|
|
63452
|
-
else if (_a.
|
|
63500
|
+
else if (_a.isValidJSONSignedOrUnsigned(hasSignature, input, 1)) {
|
|
63453
63501
|
/*
|
|
63454
63502
|
* Map input to our values
|
|
63455
63503
|
*/
|
|
@@ -63469,19 +63517,24 @@ class Block {
|
|
|
63469
63517
|
* sign the hash of the block based on what has been
|
|
63470
63518
|
* processed
|
|
63471
63519
|
*/
|
|
63472
|
-
if (input.signature
|
|
63473
|
-
|
|
63474
|
-
|
|
63475
|
-
|
|
63476
|
-
|
|
63477
|
-
|
|
63520
|
+
if ('signature' in input && input.signature) {
|
|
63521
|
+
let signature;
|
|
63522
|
+
if (typeof input.signature === 'string') {
|
|
63523
|
+
signature = Buffer.from(input.signature, 'hex');
|
|
63524
|
+
}
|
|
63525
|
+
else if (Buffer.isBuffer(input.signature)) {
|
|
63526
|
+
signature = Buffer.from(input.signature);
|
|
63527
|
+
}
|
|
63528
|
+
else {
|
|
63529
|
+
throw (new Error('Invalid signature format in input'));
|
|
63530
|
+
}
|
|
63531
|
+
foundSignatureField = [signature];
|
|
63478
63532
|
}
|
|
63479
63533
|
else {
|
|
63480
|
-
|
|
63534
|
+
foundSignatureField = null;
|
|
63481
63535
|
}
|
|
63482
|
-
this.signatures = [signature];
|
|
63483
63536
|
}
|
|
63484
|
-
else if (_a.
|
|
63537
|
+
else if (_a.isValidJSONSignedOrUnsigned(hasSignature, input, 2)) {
|
|
63485
63538
|
/*
|
|
63486
63539
|
* Map input to our values
|
|
63487
63540
|
*/
|
|
@@ -63501,25 +63554,34 @@ class Block {
|
|
|
63501
63554
|
* sign the hash of the block based on what has been
|
|
63502
63555
|
* processed
|
|
63503
63556
|
*/
|
|
63504
|
-
if (input.signatures
|
|
63505
|
-
|
|
63557
|
+
if ('signatures' in input && input.signatures) {
|
|
63558
|
+
const signatures = input.signatures.map(function (signature) {
|
|
63559
|
+
if (typeof signature === 'string') {
|
|
63560
|
+
return (Buffer.from(signature, 'hex'));
|
|
63561
|
+
}
|
|
63562
|
+
else {
|
|
63563
|
+
return (Buffer.from(signature));
|
|
63564
|
+
}
|
|
63565
|
+
});
|
|
63566
|
+
assertBlockSignatureField(signatures);
|
|
63567
|
+
foundSignatureField = signatures;
|
|
63568
|
+
}
|
|
63569
|
+
else {
|
|
63570
|
+
foundSignatureField = null;
|
|
63506
63571
|
}
|
|
63507
|
-
const signatures = input.signatures.map(function (signature) {
|
|
63508
|
-
if (typeof signature === 'string') {
|
|
63509
|
-
return (Buffer.from(signature, 'hex'));
|
|
63510
|
-
}
|
|
63511
|
-
else {
|
|
63512
|
-
return (Buffer.from(signature));
|
|
63513
|
-
}
|
|
63514
|
-
});
|
|
63515
|
-
assertBlockSignatureField(signatures);
|
|
63516
|
-
this.signatures = signatures;
|
|
63517
63572
|
}
|
|
63518
63573
|
else {
|
|
63519
63574
|
throw (new Error('Cannot construct block, it is not a valid Block JSON object'));
|
|
63520
63575
|
}
|
|
63521
63576
|
/* XXX:TODO: Verify that no extra keys were passed in */
|
|
63522
63577
|
}
|
|
63578
|
+
if ((foundSignatureField === null) === hasSignature) {
|
|
63579
|
+
throw (new Error('Block signature presence does not match expected hasSignature value'));
|
|
63580
|
+
}
|
|
63581
|
+
// We can assume that the foundSignatureField is of the correct type here since we have verified the hasSignature condition
|
|
63582
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
63583
|
+
this.signatures = foundSignatureField;
|
|
63584
|
+
__classPrivateFieldSet(this, _PossiblyUnsignedBlock_hasSignature, hasSignature, "f");
|
|
63523
63585
|
if (this.previous.compareHexString(this.hash)) {
|
|
63524
63586
|
throw (new block_1.default('BLOCK_PREVIOUS_SELF', 'internal error: Block references itself'));
|
|
63525
63587
|
}
|
|
@@ -63542,84 +63604,25 @@ class Block {
|
|
|
63542
63604
|
if (this.account.isMultisig()) {
|
|
63543
63605
|
throw (new block_1.default('BLOCK_NO_MULTISIG_OP', 'Cannot create a block for a multisig account'));
|
|
63544
63606
|
}
|
|
63545
|
-
__classPrivateFieldGet(this,
|
|
63546
|
-
__classPrivateFieldGet(this,
|
|
63547
|
-
__classPrivateFieldGet(this,
|
|
63548
|
-
__classPrivateFieldGet(this,
|
|
63607
|
+
__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "m", _PossiblyUnsignedBlock_validateSignerField).call(this);
|
|
63608
|
+
__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "m", _PossiblyUnsignedBlock_validateOperationsPurpose).call(this);
|
|
63609
|
+
__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "m", _PossiblyUnsignedBlock_validateIdempotent).call(this);
|
|
63610
|
+
__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "m", _PossiblyUnsignedBlock_validateRecalculatedBytes).call(this);
|
|
63611
|
+
if (hasSignature) {
|
|
63612
|
+
__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "m", _PossiblyUnsignedBlock_validateSignatures).call(this);
|
|
63613
|
+
}
|
|
63549
63614
|
}
|
|
63550
63615
|
static getAccountOpeningHash(account) {
|
|
63551
63616
|
return (BlockHash.getAccountOpeningHash(account));
|
|
63552
63617
|
}
|
|
63553
|
-
toBytes(includeSignatures
|
|
63554
|
-
if (
|
|
63555
|
-
|
|
63556
|
-
return (__classPrivateFieldGet(this, _Block_valueBytes, "f"));
|
|
63557
|
-
}
|
|
63618
|
+
toBytes(includeSignatures) {
|
|
63619
|
+
if (includeSignatures === undefined) {
|
|
63620
|
+
includeSignatures = __classPrivateFieldGet(this, _PossiblyUnsignedBlock_hasSignature, "f");
|
|
63558
63621
|
}
|
|
63559
|
-
|
|
63560
|
-
|
|
63561
|
-
operations: this.operations,
|
|
63562
|
-
account: this.account,
|
|
63563
|
-
network: this.network,
|
|
63564
|
-
subnet: this.subnet,
|
|
63565
|
-
date: this.date,
|
|
63566
|
-
idempotent: this.idempotent
|
|
63567
|
-
};
|
|
63568
|
-
let container;
|
|
63569
|
-
if (this.version === 1) {
|
|
63570
|
-
if (Array.isArray(this.signer) || this.signatures.length !== 1) {
|
|
63571
|
-
throw (new Error('Block v1 only supports single signer'));
|
|
63572
|
-
}
|
|
63573
|
-
container = _a.getV1ASN1ContainerWithoutSignature({
|
|
63574
|
-
...sharedBlockValues,
|
|
63575
|
-
version: 1,
|
|
63576
|
-
signer: this.signer
|
|
63577
|
-
});
|
|
63578
|
-
if (includeSignatures) {
|
|
63579
|
-
container.push(this.signatures[0]);
|
|
63580
|
-
}
|
|
63581
|
-
}
|
|
63582
|
-
else {
|
|
63583
|
-
const versionTag = this.version - 1;
|
|
63584
|
-
if (versionTag !== 1) {
|
|
63585
|
-
// We only support version 2
|
|
63586
|
-
throw (new block_1.default('BLOCK_INVALID_VERSION', 'We only support version 1/2 blocks'));
|
|
63587
|
-
}
|
|
63588
|
-
const v2Container = _a.getV2ASN1ContainerWithoutSignature({
|
|
63589
|
-
...sharedBlockValues,
|
|
63590
|
-
purpose: this.purpose,
|
|
63591
|
-
version: this.version,
|
|
63592
|
-
signer: this.signer
|
|
63593
|
-
});
|
|
63594
|
-
const baseContextTag = {
|
|
63595
|
-
type: 'context',
|
|
63596
|
-
kind: 'explicit',
|
|
63597
|
-
value: versionTag
|
|
63598
|
-
};
|
|
63599
|
-
if (includeSignatures) {
|
|
63600
|
-
let signatureContainer;
|
|
63601
|
-
if (this.signatures.length > 1) {
|
|
63602
|
-
signatureContainer = this.signatures;
|
|
63603
|
-
}
|
|
63604
|
-
else if (this.signatures.length === 1) {
|
|
63605
|
-
signatureContainer = this.signatures[0];
|
|
63606
|
-
}
|
|
63607
|
-
else {
|
|
63608
|
-
throw (new Error('Block has not been signed'));
|
|
63609
|
-
}
|
|
63610
|
-
container = { ...baseContextTag, contains: [...v2Container, signatureContainer] };
|
|
63611
|
-
}
|
|
63612
|
-
else {
|
|
63613
|
-
container = { ...baseContextTag, contains: v2Container };
|
|
63614
|
-
}
|
|
63615
|
-
}
|
|
63616
|
-
// We know the container is valid because of the container type, but the ASN1.JStoASN1 function does not handle recursive types well
|
|
63617
|
-
// @ts-ignore
|
|
63618
|
-
const retval = ASN1.JStoASN1(container).toBER(false);
|
|
63619
|
-
if (includeSignatures) {
|
|
63620
|
-
__classPrivateFieldSet(this, _Block_valueBytes, retval, "f");
|
|
63622
|
+
else if (includeSignatures !== __classPrivateFieldGet(this, _PossiblyUnsignedBlock_hasSignature, "f")) {
|
|
63623
|
+
throw (new block_1.default('BLOCK_SIGNATURE_PARAMETER_DIFFERS', 'Can only include signatures in toBytes if block has signatures, and vice versa'));
|
|
63621
63624
|
}
|
|
63622
|
-
return (
|
|
63625
|
+
return (__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "m", _PossiblyUnsignedBlock_toBytesInternal).call(this, includeSignatures));
|
|
63623
63626
|
}
|
|
63624
63627
|
static getV1ASN1ContainerWithoutSignature(input) {
|
|
63625
63628
|
let outputAccount;
|
|
@@ -63691,32 +63694,32 @@ class Block {
|
|
|
63691
63694
|
if (options?.addBinary) {
|
|
63692
63695
|
additionalFields['$binary'] = Buffer.from(this.toBytes()).toString('base64');
|
|
63693
63696
|
}
|
|
63694
|
-
|
|
63695
|
-
|
|
63696
|
-
|
|
63697
|
-
|
|
63698
|
-
|
|
63699
|
-
|
|
63700
|
-
|
|
63701
|
-
|
|
63697
|
+
if (__classPrivateFieldGet(this, _PossiblyUnsignedBlock_hasSignature, "f")) {
|
|
63698
|
+
const signatures = __classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "a", _PossiblyUnsignedBlock_nonNullableSignatures_get).map(function (signature) {
|
|
63699
|
+
return (signature.toString('hex').toUpperCase());
|
|
63700
|
+
});
|
|
63701
|
+
if (this.version === 1) {
|
|
63702
|
+
additionalFields.signature = signatures[0];
|
|
63703
|
+
}
|
|
63704
|
+
else {
|
|
63705
|
+
additionalFields.signatures = signatures;
|
|
63706
|
+
}
|
|
63702
63707
|
}
|
|
63703
|
-
return ({
|
|
63708
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
63704
63709
|
version: this.version,
|
|
63705
63710
|
idempotent: this.idempotent?.toString('base64'),
|
|
63706
63711
|
date: this.date,
|
|
63707
63712
|
previous: this.previous,
|
|
63708
63713
|
account: this.account,
|
|
63709
63714
|
purpose: this.purpose,
|
|
63710
|
-
// XXX:TODO We need to use a type assertion here because toJSONSerializable does not support recursive types
|
|
63711
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
63712
63715
|
signer: this.signer,
|
|
63713
63716
|
network: this.network,
|
|
63714
63717
|
subnet: this.subnet,
|
|
63715
|
-
operations:
|
|
63718
|
+
operations: this.operations,
|
|
63716
63719
|
$hash: this.hash,
|
|
63717
63720
|
$opening: this.$opening,
|
|
63718
63721
|
...additionalFields
|
|
63719
|
-
});
|
|
63722
|
+
}));
|
|
63720
63723
|
}
|
|
63721
63724
|
/**
|
|
63722
63725
|
* Hash of the block minus the signature
|
|
@@ -63727,48 +63730,32 @@ class Block {
|
|
|
63727
63730
|
* signature (which isn't signed)
|
|
63728
63731
|
*/
|
|
63729
63732
|
get hash() {
|
|
63730
|
-
if (__classPrivateFieldGet(this,
|
|
63731
|
-
return (__classPrivateFieldGet(this,
|
|
63733
|
+
if (__classPrivateFieldGet(this, _PossiblyUnsignedBlock_valueHash, "f") !== undefined) {
|
|
63734
|
+
return (__classPrivateFieldGet(this, _PossiblyUnsignedBlock_valueHash, "f"));
|
|
63732
63735
|
}
|
|
63733
|
-
const retval = new BlockHash((0, hash_1.Hash)(Buffer.from(this.
|
|
63734
|
-
__classPrivateFieldSet(this,
|
|
63736
|
+
const retval = new BlockHash((0, hash_1.Hash)(Buffer.from(__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "m", _PossiblyUnsignedBlock_toBytesInternal).call(this, false))));
|
|
63737
|
+
__classPrivateFieldSet(this, _PossiblyUnsignedBlock_valueHash, retval, "f");
|
|
63735
63738
|
return (retval);
|
|
63736
63739
|
}
|
|
63737
63740
|
}
|
|
63738
|
-
|
|
63739
|
-
|
|
63740
|
-
|
|
63741
|
-
const visited = new account_1.default.Set();
|
|
63742
|
-
const out = [];
|
|
63743
|
-
while (queue.length > 0) {
|
|
63744
|
-
// We can assume that the signerFieldQueue is not empty here since the loop condition checks it
|
|
63745
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
63746
|
-
const cur = queue.shift();
|
|
63747
|
-
if (account_1.default.isInstance(cur)) {
|
|
63748
|
-
if (visited.has(cur)) {
|
|
63749
|
-
continue;
|
|
63750
|
-
}
|
|
63751
|
-
visited.add(cur);
|
|
63752
|
-
out.push(cur);
|
|
63753
|
-
}
|
|
63754
|
-
else {
|
|
63755
|
-
queue.unshift(...cur[1]);
|
|
63756
|
-
}
|
|
63741
|
+
_a = PossiblyUnsignedBlock, _PossiblyUnsignedBlock_valueBytes = new WeakMap(), _PossiblyUnsignedBlock_valueHash = new WeakMap(), _PossiblyUnsignedBlock_hasSignature = new WeakMap(), _PossiblyUnsignedBlock_instances = new WeakSet(), _PossiblyUnsignedBlock_nonNullableSignatures_get = function _PossiblyUnsignedBlock_nonNullableSignatures_get() {
|
|
63742
|
+
if (!this.signatures) {
|
|
63743
|
+
throw (new Error('No signature field input found on block'));
|
|
63757
63744
|
}
|
|
63758
|
-
return (
|
|
63759
|
-
},
|
|
63760
|
-
const existingBytes = __classPrivateFieldGet(this,
|
|
63745
|
+
return (this.signatures);
|
|
63746
|
+
}, _PossiblyUnsignedBlock_validateRecalculatedBytes = function _PossiblyUnsignedBlock_validateRecalculatedBytes() {
|
|
63747
|
+
const existingBytes = __classPrivateFieldGet(this, _PossiblyUnsignedBlock_valueBytes, "f");
|
|
63761
63748
|
if (existingBytes === undefined) {
|
|
63762
63749
|
return;
|
|
63763
63750
|
}
|
|
63764
|
-
const recalculatedBytesBuffer = Buffer.from(this.
|
|
63751
|
+
const recalculatedBytesBuffer = Buffer.from(__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "m", _PossiblyUnsignedBlock_toBytesInternal).call(this, __classPrivateFieldGet(this, _PossiblyUnsignedBlock_hasSignature, "f"), false));
|
|
63765
63752
|
const existingBytesBuffer = Buffer.from(existingBytes);
|
|
63766
63753
|
if (!recalculatedBytesBuffer.equals(existingBytesBuffer)) {
|
|
63767
63754
|
const existingBytesHash = Buffer.from((0, hash_1.Hash)(existingBytesBuffer)).toString('hex').toUpperCase();
|
|
63768
63755
|
const recalculatedBytesHash = Buffer.from((0, hash_1.Hash)(recalculatedBytesBuffer)).toString('hex').toUpperCase();
|
|
63769
63756
|
throw (new block_1.default('BLOCK_INVALID_SIGNATURE', `Block signed bytes (${existingBytesHash}) do not match calculated bytes (${recalculatedBytesHash})`));
|
|
63770
63757
|
}
|
|
63771
|
-
},
|
|
63758
|
+
}, _PossiblyUnsignedBlock_validateOperationsPurpose = function _PossiblyUnsignedBlock_validateOperationsPurpose() {
|
|
63772
63759
|
/**
|
|
63773
63760
|
* Do not allow blocks to contain invalid constructions
|
|
63774
63761
|
*/
|
|
@@ -63785,7 +63772,7 @@ _a = Block, _Block_valueBytes = new WeakMap(), _Block_valueHash = new WeakMap(),
|
|
|
63785
63772
|
operation.validate(context);
|
|
63786
63773
|
context.operationIndex++;
|
|
63787
63774
|
}
|
|
63788
|
-
},
|
|
63775
|
+
}, _PossiblyUnsignedBlock_validateSignerField = function _PossiblyUnsignedBlock_validateSignerField() {
|
|
63789
63776
|
if (!Array.isArray(this.signer)) {
|
|
63790
63777
|
return;
|
|
63791
63778
|
}
|
|
@@ -63814,26 +63801,172 @@ _a = Block, _Block_valueBytes = new WeakMap(), _Block_valueHash = new WeakMap(),
|
|
|
63814
63801
|
}
|
|
63815
63802
|
}
|
|
63816
63803
|
}
|
|
63817
|
-
},
|
|
63818
|
-
|
|
63819
|
-
|
|
63804
|
+
}, _PossiblyUnsignedBlock_validateSignatures = function _PossiblyUnsignedBlock_validateSignatures() {
|
|
63805
|
+
if (!__classPrivateFieldGet(this, _PossiblyUnsignedBlock_hasSignature, "f")) {
|
|
63806
|
+
throw (new block_1.default('BLOCK_SIGNATURE_REQUIRED', 'Block has not been signed'));
|
|
63807
|
+
}
|
|
63808
|
+
const signers = _a.getSortedRequiredSigners(this.signer);
|
|
63809
|
+
const signatureArray = __classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "a", _PossiblyUnsignedBlock_nonNullableSignatures_get);
|
|
63810
|
+
if (signatureArray.length !== signers.length) {
|
|
63820
63811
|
throw (new block_1.default('BLOCK_INVALID_SIGNER', 'Signer count does not match signature count'));
|
|
63821
63812
|
}
|
|
63822
63813
|
for (let i = 0; i < signers.length; i++) {
|
|
63823
|
-
const signature = new buffer_1.BufferStorage(
|
|
63814
|
+
const signature = new buffer_1.BufferStorage(signatureArray[i], 64);
|
|
63824
63815
|
const valid = signers[i].verify(this.hash.get(), signature.get());
|
|
63825
63816
|
if (valid !== true) {
|
|
63826
|
-
throw (new block_1.default('BLOCK_INVALID_SIGNATURE', `Unable to validate signature of ${this.hash.toString()} against signature ${this
|
|
63817
|
+
throw (new block_1.default('BLOCK_INVALID_SIGNATURE', `Unable to validate signature of ${this.hash.toString()} against signature ${__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "a", _PossiblyUnsignedBlock_nonNullableSignatures_get)[i].toString('hex')} for account ${signers[i].publicKeyString.get()}`));
|
|
63827
63818
|
}
|
|
63828
63819
|
}
|
|
63820
|
+
}, _PossiblyUnsignedBlock_validateIdempotent = function _PossiblyUnsignedBlock_validateIdempotent() {
|
|
63821
|
+
if (this.idempotent === undefined) {
|
|
63822
|
+
return;
|
|
63823
|
+
}
|
|
63824
|
+
validateIdempotentKeyLength(this.idempotent, this.network);
|
|
63825
|
+
}, _PossiblyUnsignedBlock_toBytesInternal = function _PossiblyUnsignedBlock_toBytesInternal(includeSignatures, useCached = true) {
|
|
63826
|
+
const isCacheable = includeSignatures || !__classPrivateFieldGet(this, _PossiblyUnsignedBlock_hasSignature, "f");
|
|
63827
|
+
if (useCached && __classPrivateFieldGet(this, _PossiblyUnsignedBlock_valueBytes, "f") !== undefined && isCacheable) {
|
|
63828
|
+
return (__classPrivateFieldGet(this, _PossiblyUnsignedBlock_valueBytes, "f"));
|
|
63829
|
+
}
|
|
63830
|
+
const sharedBlockValues = {
|
|
63831
|
+
previous: this.previous,
|
|
63832
|
+
operations: this.operations,
|
|
63833
|
+
account: this.account,
|
|
63834
|
+
network: this.network,
|
|
63835
|
+
subnet: this.subnet,
|
|
63836
|
+
date: this.date,
|
|
63837
|
+
idempotent: this.idempotent
|
|
63838
|
+
};
|
|
63839
|
+
let container;
|
|
63840
|
+
if (this.version === 1) {
|
|
63841
|
+
if (Array.isArray(this.signer)) {
|
|
63842
|
+
throw (new Error('Block v1 only supports single signer'));
|
|
63843
|
+
}
|
|
63844
|
+
container = _a.getV1ASN1ContainerWithoutSignature({
|
|
63845
|
+
...sharedBlockValues,
|
|
63846
|
+
version: 1,
|
|
63847
|
+
signer: this.signer
|
|
63848
|
+
});
|
|
63849
|
+
if (includeSignatures) {
|
|
63850
|
+
if (__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "a", _PossiblyUnsignedBlock_nonNullableSignatures_get).length !== 1) {
|
|
63851
|
+
throw (new Error('Block v1 only supports single signature'));
|
|
63852
|
+
}
|
|
63853
|
+
container.push(__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "a", _PossiblyUnsignedBlock_nonNullableSignatures_get)[0]);
|
|
63854
|
+
}
|
|
63855
|
+
}
|
|
63856
|
+
else {
|
|
63857
|
+
const versionTag = this.version - 1;
|
|
63858
|
+
if (versionTag !== 1) {
|
|
63859
|
+
// We only support version 2
|
|
63860
|
+
throw (new block_1.default('BLOCK_INVALID_VERSION', 'We only support version 1/2 blocks'));
|
|
63861
|
+
}
|
|
63862
|
+
const v2Container = _a.getV2ASN1ContainerWithoutSignature({
|
|
63863
|
+
...sharedBlockValues,
|
|
63864
|
+
purpose: this.purpose,
|
|
63865
|
+
version: this.version,
|
|
63866
|
+
signer: this.signer
|
|
63867
|
+
});
|
|
63868
|
+
const baseContextTag = {
|
|
63869
|
+
type: 'context',
|
|
63870
|
+
kind: 'explicit',
|
|
63871
|
+
value: versionTag
|
|
63872
|
+
};
|
|
63873
|
+
if (includeSignatures) {
|
|
63874
|
+
let signatureContainer;
|
|
63875
|
+
if (__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "a", _PossiblyUnsignedBlock_nonNullableSignatures_get).length > 1) {
|
|
63876
|
+
signatureContainer = __classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "a", _PossiblyUnsignedBlock_nonNullableSignatures_get);
|
|
63877
|
+
}
|
|
63878
|
+
else if (__classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "a", _PossiblyUnsignedBlock_nonNullableSignatures_get).length === 1) {
|
|
63879
|
+
signatureContainer = __classPrivateFieldGet(this, _PossiblyUnsignedBlock_instances, "a", _PossiblyUnsignedBlock_nonNullableSignatures_get)[0];
|
|
63880
|
+
}
|
|
63881
|
+
else {
|
|
63882
|
+
throw (new Error('Block has not been signed'));
|
|
63883
|
+
}
|
|
63884
|
+
container = { ...baseContextTag, contains: [...v2Container, signatureContainer] };
|
|
63885
|
+
}
|
|
63886
|
+
else {
|
|
63887
|
+
container = { ...baseContextTag, contains: v2Container };
|
|
63888
|
+
}
|
|
63889
|
+
}
|
|
63890
|
+
// We know the container is valid because of the container type, but the ASN1.JStoASN1 function does not handle recursive types well
|
|
63891
|
+
// @ts-ignore
|
|
63892
|
+
const retval = ASN1.JStoASN1(container).toBER(false);
|
|
63893
|
+
if (isCacheable) {
|
|
63894
|
+
__classPrivateFieldSet(this, _PossiblyUnsignedBlock_valueBytes, retval, "f");
|
|
63895
|
+
}
|
|
63896
|
+
return (retval);
|
|
63829
63897
|
};
|
|
63830
|
-
|
|
63831
|
-
|
|
63832
|
-
|
|
63833
|
-
|
|
63834
|
-
|
|
63835
|
-
|
|
63836
|
-
|
|
63898
|
+
PossiblyUnsignedBlock.Hash = BlockHash;
|
|
63899
|
+
PossiblyUnsignedBlock.OperationType = Operations.OperationType;
|
|
63900
|
+
PossiblyUnsignedBlock.Operation = Operations.Operation;
|
|
63901
|
+
PossiblyUnsignedBlock.NO_PREVIOUS = NO_PREVIOUS;
|
|
63902
|
+
PossiblyUnsignedBlock.AdjustMethod = AdjustMethod;
|
|
63903
|
+
PossiblyUnsignedBlock.Purpose = BlockPurpose;
|
|
63904
|
+
class UnsignedBlock extends PossiblyUnsignedBlock {
|
|
63905
|
+
constructor(input) {
|
|
63906
|
+
super(input, false);
|
|
63907
|
+
}
|
|
63908
|
+
static isValidJSON(block, version) {
|
|
63909
|
+
return (super.isValidJSONSignedOrUnsigned(false, block, version));
|
|
63910
|
+
}
|
|
63911
|
+
static async fromUnsignedJSON(input) {
|
|
63912
|
+
return (new this(input));
|
|
63913
|
+
}
|
|
63914
|
+
async seal() {
|
|
63915
|
+
const signers = UnsignedBlock.getSortedRequiredSigners(this.signer);
|
|
63916
|
+
const hash = this.hash;
|
|
63917
|
+
const signatures = await Promise.all(signers.map(async function (signer) {
|
|
63918
|
+
const signature = await signer.sign(hash.getBuffer());
|
|
63919
|
+
return (signature.getBuffer());
|
|
63920
|
+
}));
|
|
63921
|
+
const shared = {
|
|
63922
|
+
idempotent: this.idempotent,
|
|
63923
|
+
date: this.date,
|
|
63924
|
+
previous: this.previous,
|
|
63925
|
+
account: this.account,
|
|
63926
|
+
network: this.network,
|
|
63927
|
+
subnet: this.subnet,
|
|
63928
|
+
signer: this.signer,
|
|
63929
|
+
operations: this.operations
|
|
63930
|
+
};
|
|
63931
|
+
let blockInput;
|
|
63932
|
+
if (this.version === 1) {
|
|
63933
|
+
if (Array.isArray(this.signer)) {
|
|
63934
|
+
throw (new Error('Block v1 only supports single signer'));
|
|
63935
|
+
}
|
|
63936
|
+
blockInput = { ...shared, version: this.version, signer: this.signer, signature: signatures[0] };
|
|
63937
|
+
}
|
|
63938
|
+
else if (this.version === 2) {
|
|
63939
|
+
blockInput = { ...shared, version: this.version, purpose: this.purpose, signatures };
|
|
63940
|
+
}
|
|
63941
|
+
else {
|
|
63942
|
+
throw (new block_1.default('BLOCK_INVALID_VERSION', 'Invalid Version'));
|
|
63943
|
+
}
|
|
63944
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
63945
|
+
return (new Block(blockInput));
|
|
63946
|
+
}
|
|
63947
|
+
}
|
|
63948
|
+
exports.UnsignedBlock = UnsignedBlock;
|
|
63949
|
+
UnsignedBlock.isInstance = (0, helper_1.checkableGenerator)(UnsignedBlock);
|
|
63950
|
+
class Block extends PossiblyUnsignedBlock {
|
|
63951
|
+
constructor(input) {
|
|
63952
|
+
super(input, true);
|
|
63953
|
+
}
|
|
63954
|
+
static isValidJSON(block, version) {
|
|
63955
|
+
return (super.isValidJSONSignedOrUnsigned(true, block, version));
|
|
63956
|
+
}
|
|
63957
|
+
static async fromUnsignedJSON(input) {
|
|
63958
|
+
const unsigned = new UnsignedBlock(input);
|
|
63959
|
+
return (await unsigned.seal());
|
|
63960
|
+
}
|
|
63961
|
+
getUnsignedBlock() {
|
|
63962
|
+
return (new UnsignedBlock({
|
|
63963
|
+
...(this.toJSON({ addBinary: false })),
|
|
63964
|
+
signatures: undefined
|
|
63965
|
+
}));
|
|
63966
|
+
}
|
|
63967
|
+
}
|
|
63968
|
+
exports.Block = Block;
|
|
63969
|
+
Block.isInstance = (0, helper_1.checkableGenerator)(Block);
|
|
63837
63970
|
class BlockBuilder {
|
|
63838
63971
|
constructor(block) {
|
|
63839
63972
|
_BlockBuilder_block.set(this, void 0);
|
|
@@ -63855,31 +63988,16 @@ class BlockBuilder {
|
|
|
63855
63988
|
__classPrivateFieldSet(this, _BlockBuilder_block, new Block(block), "f");
|
|
63856
63989
|
}
|
|
63857
63990
|
else {
|
|
63858
|
-
|
|
63859
|
-
|
|
63860
|
-
|
|
63991
|
+
if (block === undefined) {
|
|
63992
|
+
__classPrivateFieldSet(this, _BlockBuilder_block, {}, "f");
|
|
63993
|
+
return;
|
|
63861
63994
|
}
|
|
63862
63995
|
/*
|
|
63863
|
-
*
|
|
63996
|
+
* Validate input values
|
|
63864
63997
|
*/
|
|
63865
|
-
|
|
63866
|
-
if (
|
|
63867
|
-
|
|
63868
|
-
}
|
|
63869
|
-
let newBlockJSON;
|
|
63870
|
-
if (incompleteBlockJSON.version === 1) {
|
|
63871
|
-
// We have to use a type assertion here because the MapV1InputValues function does not support recursive types
|
|
63872
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
63873
|
-
newBlockJSON = MapV1InputValues({ ...incompleteBlockJSON, version: 1 });
|
|
63874
|
-
}
|
|
63875
|
-
else if (incompleteBlockJSON.version === 2) {
|
|
63876
|
-
newBlockJSON = MapV2InputValues({ ...incompleteBlockJSON, version: 2 });
|
|
63877
|
-
}
|
|
63878
|
-
else {
|
|
63879
|
-
throw (new Error('Cannot construct block, it is not a valid Block JSON object'));
|
|
63880
|
-
}
|
|
63881
|
-
if (setPreviousNoBlock) {
|
|
63882
|
-
newBlockJSON.previous = BlockBuilder.NO_PREVIOUS;
|
|
63998
|
+
const newBlockJSON = __classPrivateFieldGet(_b, _b, "m", _BlockBuilder_ValidateInputs).call(_b, block);
|
|
63999
|
+
if (block.previous === _b.NO_PREVIOUS) {
|
|
64000
|
+
newBlockJSON.previous = _b.NO_PREVIOUS;
|
|
63883
64001
|
}
|
|
63884
64002
|
__classPrivateFieldSet(this, _BlockBuilder_block, newBlockJSON, "f");
|
|
63885
64003
|
}
|
|
@@ -63908,7 +64026,7 @@ class BlockBuilder {
|
|
|
63908
64026
|
if (opts?.addBinary) {
|
|
63909
64027
|
throw (new Error('Cannot add binary within blockBuilder.toJSON'));
|
|
63910
64028
|
}
|
|
63911
|
-
return ({
|
|
64029
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
63912
64030
|
version: this.version,
|
|
63913
64031
|
idempotent: this.idempotent,
|
|
63914
64032
|
date: this.date,
|
|
@@ -63920,23 +64038,22 @@ class BlockBuilder {
|
|
|
63920
64038
|
operations: this.operations,
|
|
63921
64039
|
purpose: this.purpose,
|
|
63922
64040
|
['$opening']: this.$opening
|
|
63923
|
-
});
|
|
64041
|
+
}));
|
|
63924
64042
|
}
|
|
63925
|
-
async
|
|
63926
|
-
|
|
64043
|
+
async getUnsignedBlock() {
|
|
64044
|
+
const input = __classPrivateFieldGet(_b, _b, "m", _BlockBuilder_ValidateInputs).call(_b, this);
|
|
64045
|
+
if (input.version === undefined) {
|
|
63927
64046
|
throw (new Error('Cannot seal block without version'));
|
|
63928
64047
|
}
|
|
63929
|
-
|
|
63930
|
-
|
|
63931
|
-
|
|
63932
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
63933
|
-
input = MapV1InputValues(this);
|
|
64048
|
+
// Date is required for a sealed block, so added it if it wasn't provided
|
|
64049
|
+
if (input.date === undefined) {
|
|
64050
|
+
input.date = new Date();
|
|
63934
64051
|
}
|
|
63935
|
-
|
|
63936
|
-
|
|
63937
|
-
|
|
63938
|
-
|
|
63939
|
-
const block = await
|
|
64052
|
+
return (new UnsignedBlock(input));
|
|
64053
|
+
}
|
|
64054
|
+
async seal() {
|
|
64055
|
+
const unsigned = await this.getUnsignedBlock();
|
|
64056
|
+
const block = await unsigned.seal();
|
|
63940
64057
|
__classPrivateFieldSet(this, _BlockBuilder_block, block, "f");
|
|
63941
64058
|
return (block);
|
|
63942
64059
|
}
|
|
@@ -64052,7 +64169,7 @@ class BlockBuilder {
|
|
|
64052
64169
|
if (BlockHash.isInstance(previous)) {
|
|
64053
64170
|
return (previous);
|
|
64054
64171
|
}
|
|
64055
|
-
if (previous ===
|
|
64172
|
+
if (previous === _b.NO_PREVIOUS) {
|
|
64056
64173
|
if (this.account !== undefined) {
|
|
64057
64174
|
return (BlockHash.getAccountOpeningHash(this.account));
|
|
64058
64175
|
}
|
|
@@ -64073,7 +64190,7 @@ class BlockBuilder {
|
|
|
64073
64190
|
if (previous === undefined) {
|
|
64074
64191
|
return (undefined);
|
|
64075
64192
|
}
|
|
64076
|
-
if (previous ===
|
|
64193
|
+
if (previous === _b.NO_PREVIOUS) {
|
|
64077
64194
|
return (true);
|
|
64078
64195
|
}
|
|
64079
64196
|
const sentinel = Block.getAccountOpeningHash(account);
|
|
@@ -64178,8 +64295,41 @@ class BlockBuilder {
|
|
|
64178
64295
|
}
|
|
64179
64296
|
}
|
|
64180
64297
|
exports.BlockBuilder = BlockBuilder;
|
|
64181
|
-
_BlockBuilder_block = new WeakMap()
|
|
64182
|
-
|
|
64298
|
+
_b = BlockBuilder, _BlockBuilder_block = new WeakMap(), _BlockBuilder_ValidateInputs = function _BlockBuilder_ValidateInputs(blockInput) {
|
|
64299
|
+
let block = blockInput;
|
|
64300
|
+
// Keep the signer as the original object so we can seal the block
|
|
64301
|
+
if (_b.isInstance(blockInput)) {
|
|
64302
|
+
block = {
|
|
64303
|
+
...blockInput.toJSON(),
|
|
64304
|
+
signer: blockInput.signer
|
|
64305
|
+
};
|
|
64306
|
+
}
|
|
64307
|
+
let validatedBlockJSON;
|
|
64308
|
+
if (block.version === undefined || block.version === 1) {
|
|
64309
|
+
if (block.signer && typeof block.signer !== 'string' && !account_1.default.isInstance(block.signer)) {
|
|
64310
|
+
throw (new block_1.default('BLOCK_INVALID_SIGNER', 'V1 Blocks Cannot use MultiSig Signers'));
|
|
64311
|
+
}
|
|
64312
|
+
if (block.purpose !== undefined && block.purpose !== BlockPurpose.GENERIC) {
|
|
64313
|
+
throw (new block_1.default('BLOCK_INVALID_PURPOSE_VALIDATION', 'V1 Block Purpose should be undefined'));
|
|
64314
|
+
}
|
|
64315
|
+
// Create narrowed block input
|
|
64316
|
+
const blockV1 = {
|
|
64317
|
+
...block,
|
|
64318
|
+
version: 1,
|
|
64319
|
+
signer: block.signer,
|
|
64320
|
+
purpose: block.purpose
|
|
64321
|
+
};
|
|
64322
|
+
validatedBlockJSON = MapV1InputValues(blockV1);
|
|
64323
|
+
}
|
|
64324
|
+
else if (block.version === 2) {
|
|
64325
|
+
validatedBlockJSON = MapV2InputValues({ ...block, version: 2 });
|
|
64326
|
+
}
|
|
64327
|
+
else {
|
|
64328
|
+
throw (new block_1.default('BLOCK_INVALID_VERSION', `Cannot construct block, expected version: 1 | 2, received: ${block.version}`));
|
|
64329
|
+
}
|
|
64330
|
+
return (validatedBlockJSON);
|
|
64331
|
+
};
|
|
64332
|
+
BlockBuilder.isInstance = (0, helper_1.checkableGenerator)(_b);
|
|
64183
64333
|
BlockBuilder.OperationType = Block.OperationType;
|
|
64184
64334
|
BlockBuilder.AdjustMethod = Block.AdjustMethod;
|
|
64185
64335
|
BlockBuilder.Operation = Block.Operation;
|
|
@@ -64247,11 +64397,11 @@ const account_1 = __importStar(__webpack_require__(9415));
|
|
|
64247
64397
|
const permissions_1 = __webpack_require__(5860);
|
|
64248
64398
|
const block_1 = __importDefault(__webpack_require__(7412));
|
|
64249
64399
|
const conversion_1 = __webpack_require__(2360);
|
|
64250
|
-
const _1 = __webpack_require__(6158);
|
|
64251
|
-
const _2 = __importStar(__webpack_require__(6158));
|
|
64400
|
+
const _1 = __importStar(__webpack_require__(6158));
|
|
64252
64401
|
const config_1 = __webpack_require__(1491);
|
|
64253
64402
|
const certificate_1 = __webpack_require__(5661);
|
|
64254
64403
|
const common_1 = __webpack_require__(5663);
|
|
64404
|
+
const util_1 = __webpack_require__(9023);
|
|
64255
64405
|
/**
|
|
64256
64406
|
* All supported operations
|
|
64257
64407
|
*/
|
|
@@ -64409,7 +64559,10 @@ class BlockOperation {
|
|
|
64409
64559
|
if (amount === undefined || amount === null) {
|
|
64410
64560
|
throw (new Error('internal error: "amount" is invalid'));
|
|
64411
64561
|
}
|
|
64412
|
-
|
|
64562
|
+
if (typeof amount === 'bigint') {
|
|
64563
|
+
return (amount);
|
|
64564
|
+
}
|
|
64565
|
+
return ((0, conversion_1.parseHexBigIntString)(amount));
|
|
64413
64566
|
}
|
|
64414
64567
|
}
|
|
64415
64568
|
BlockOperation.isInstance = (0, helper_1.checkableGenerator)(BlockOperation);
|
|
@@ -64480,13 +64633,13 @@ class BlockOperationSEND extends BlockOperation {
|
|
|
64480
64633
|
}
|
|
64481
64634
|
}
|
|
64482
64635
|
toJSON() {
|
|
64483
|
-
return ({
|
|
64636
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
64484
64637
|
type: this.type,
|
|
64485
64638
|
to: this.to,
|
|
64486
64639
|
amount: this.amount,
|
|
64487
64640
|
external: this.external,
|
|
64488
64641
|
token: this.token
|
|
64489
|
-
});
|
|
64642
|
+
}));
|
|
64490
64643
|
}
|
|
64491
64644
|
}
|
|
64492
64645
|
_BlockOperationSEND_to = new WeakMap(), _BlockOperationSEND_amount = new WeakMap(), _BlockOperationSEND_token = new WeakMap(), _BlockOperationSEND_instances = new WeakSet(), _BlockOperationSEND_computeToken = function _BlockOperationSEND_computeToken(token) {
|
|
@@ -64566,14 +64719,14 @@ class BlockOperationRECEIVE extends BlockOperation {
|
|
|
64566
64719
|
}
|
|
64567
64720
|
}
|
|
64568
64721
|
toJSON() {
|
|
64569
|
-
return ({
|
|
64722
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
64570
64723
|
type: this.type,
|
|
64571
64724
|
amount: this.amount,
|
|
64572
64725
|
token: this.token,
|
|
64573
64726
|
from: this.from,
|
|
64574
64727
|
exact: this.exact,
|
|
64575
64728
|
forward: this.forward
|
|
64576
|
-
});
|
|
64729
|
+
}));
|
|
64577
64730
|
}
|
|
64578
64731
|
}
|
|
64579
64732
|
_BlockOperationRECEIVE_amount = new WeakMap(), _BlockOperationRECEIVE_token = new WeakMap(), _BlockOperationRECEIVE_from = new WeakMap(), _BlockOperationRECEIVE_forward = new WeakMap(), _BlockOperationRECEIVE_exact = new WeakMap(), _BlockOperationRECEIVE_instances = new WeakSet(), _BlockOperationRECEIVE_computeExact = function _BlockOperationRECEIVE_computeExact(exact) {
|
|
@@ -64635,12 +64788,12 @@ class BlockOperationTOKEN_ADMIN_MODIFY_BALANCE extends BlockOperation {
|
|
|
64635
64788
|
}
|
|
64636
64789
|
}
|
|
64637
64790
|
toJSON() {
|
|
64638
|
-
return ({
|
|
64791
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
64639
64792
|
type: this.type,
|
|
64640
64793
|
token: this.token,
|
|
64641
64794
|
amount: this.amount,
|
|
64642
64795
|
method: this.method
|
|
64643
|
-
});
|
|
64796
|
+
}));
|
|
64644
64797
|
}
|
|
64645
64798
|
}
|
|
64646
64799
|
_BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_token = new WeakMap(), _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_method = new WeakMap(), _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_amount = new WeakMap(), _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_instances = new WeakSet(), _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_computeToken = function _BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_computeToken(token) {
|
|
@@ -64683,10 +64836,10 @@ class BlockOperationSET_REP extends BlockOperation {
|
|
|
64683
64836
|
}
|
|
64684
64837
|
}
|
|
64685
64838
|
toJSON() {
|
|
64686
|
-
return ({
|
|
64839
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
64687
64840
|
type: this.type,
|
|
64688
64841
|
to: this.to
|
|
64689
|
-
});
|
|
64842
|
+
}));
|
|
64690
64843
|
}
|
|
64691
64844
|
}
|
|
64692
64845
|
_BlockOperationSET_REP_to = new WeakMap();
|
|
@@ -64755,11 +64908,11 @@ class BlockOperationCREATE_IDENTIFIER extends BlockOperation {
|
|
|
64755
64908
|
}
|
|
64756
64909
|
}
|
|
64757
64910
|
toJSON() {
|
|
64758
|
-
return ({
|
|
64911
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
64759
64912
|
type: this.type,
|
|
64760
64913
|
identifier: this.identifier,
|
|
64761
64914
|
createArguments: __classPrivateFieldGet(this, _BlockOperationCREATE_IDENTIFIER_createArguments, "f")
|
|
64762
|
-
});
|
|
64915
|
+
}));
|
|
64763
64916
|
}
|
|
64764
64917
|
}
|
|
64765
64918
|
_BlockOperationCREATE_IDENTIFIER_identifier = new WeakMap(), _BlockOperationCREATE_IDENTIFIER_createArguments = new WeakMap(), _BlockOperationCREATE_IDENTIFIER_instances = new WeakSet(), _BlockOperationCREATE_IDENTIFIER_computeIdentifier = function _BlockOperationCREATE_IDENTIFIER_computeIdentifier(identifierStr) {
|
|
@@ -64874,7 +65027,7 @@ class BlockOperationSET_INFO extends BlockOperation {
|
|
|
64874
65027
|
if (this.defaultPermission !== undefined) {
|
|
64875
65028
|
val.defaultPermission = this.defaultPermission;
|
|
64876
65029
|
}
|
|
64877
|
-
return (val);
|
|
65030
|
+
return ((0, conversion_1.toJSONSerializable)(val));
|
|
64878
65031
|
}
|
|
64879
65032
|
}
|
|
64880
65033
|
_BlockOperationSET_INFO_name = new WeakMap(), _BlockOperationSET_INFO_description = new WeakMap(), _BlockOperationSET_INFO_metadata = new WeakMap(), _BlockOperationSET_INFO_defaultPermission = new WeakMap(), _BlockOperationSET_INFO_instances = new WeakSet(), _BlockOperationSET_INFO_validateNameDesc = function _BlockOperationSET_INFO_validateNameDesc(field, value, network) {
|
|
@@ -64934,7 +65087,7 @@ class BlockOperationMODIFY_PERMISSIONS extends BlockOperation {
|
|
|
64934
65087
|
validate(context) {
|
|
64935
65088
|
const { block } = context;
|
|
64936
65089
|
if (this.permissions === null) {
|
|
64937
|
-
if (this.method !==
|
|
65090
|
+
if (this.method !== _1.AdjustMethod.SET) {
|
|
64938
65091
|
throw (new Error('Method must be SET when permissions = null'));
|
|
64939
65092
|
}
|
|
64940
65093
|
}
|
|
@@ -64960,7 +65113,7 @@ class BlockOperationMODIFY_PERMISSIONS extends BlockOperation {
|
|
|
64960
65113
|
if (this.target !== undefined && settingAdminOrHigher) {
|
|
64961
65114
|
throw (new block_1.default('BLOCK_NO_ADMIN_ON_TARGET', 'Cannot set admin or higher with a target specified'));
|
|
64962
65115
|
}
|
|
64963
|
-
if (this.method !==
|
|
65116
|
+
if (this.method !== _1.default.AdjustMethod.SET && !this.permissions.canUseDelegation) {
|
|
64964
65117
|
throw (new block_1.default('BLOCK_NO_DELEGATE_ADMIN', `Cannot use delegation for ${baseFlagsString}`));
|
|
64965
65118
|
}
|
|
64966
65119
|
}
|
|
@@ -64981,19 +65134,19 @@ class BlockOperationMODIFY_PERMISSIONS extends BlockOperation {
|
|
|
64981
65134
|
if (foundMethod === undefined) {
|
|
64982
65135
|
continue;
|
|
64983
65136
|
}
|
|
64984
|
-
if (method ===
|
|
65137
|
+
if (method === _1.default.AdjustMethod.SET) {
|
|
64985
65138
|
throw (new block_1.default('BLOCK_NO_MODIFY_PERMISSION_DUPE', 'Cannot have a SET operation after any other change with the same target in MODIFY_PERMISSIONS'));
|
|
64986
65139
|
}
|
|
64987
65140
|
}
|
|
64988
65141
|
}
|
|
64989
65142
|
toJSON() {
|
|
64990
|
-
return ({
|
|
65143
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
64991
65144
|
type: this.type,
|
|
64992
65145
|
principal: this.principal,
|
|
64993
65146
|
method: this.method,
|
|
64994
65147
|
permissions: this.permissions,
|
|
64995
65148
|
target: this.target
|
|
64996
|
-
});
|
|
65149
|
+
}));
|
|
64997
65150
|
}
|
|
64998
65151
|
}
|
|
64999
65152
|
_BlockOperationMODIFY_PERMISSIONS_principal = new WeakMap(), _BlockOperationMODIFY_PERMISSIONS_target = new WeakMap(), _BlockOperationMODIFY_PERMISSIONS_method = new WeakMap(), _BlockOperationMODIFY_PERMISSIONS_permissions = new WeakMap(), _BlockOperationMODIFY_PERMISSIONS_instances = new WeakSet(), _BlockOperationMODIFY_PERMISSIONS_computePermissions = function _BlockOperationMODIFY_PERMISSIONS_computePermissions(permissions) {
|
|
@@ -65037,16 +65190,16 @@ class BlockOperationTOKEN_ADMIN_SUPPLY extends BlockOperation {
|
|
|
65037
65190
|
(0, common_1.validateSupply)(__classPrivateFieldGet(this, _BlockOperationTOKEN_ADMIN_SUPPLY_amount, "f"), block.network);
|
|
65038
65191
|
}
|
|
65039
65192
|
toJSON() {
|
|
65040
|
-
return ({
|
|
65193
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
65041
65194
|
type: this.type,
|
|
65042
65195
|
amount: this.amount,
|
|
65043
65196
|
method: this.method
|
|
65044
|
-
});
|
|
65197
|
+
}));
|
|
65045
65198
|
}
|
|
65046
65199
|
}
|
|
65047
65200
|
_BlockOperationTOKEN_ADMIN_SUPPLY_amount = new WeakMap(), _BlockOperationTOKEN_ADMIN_SUPPLY_method = new WeakMap(), _BlockOperationTOKEN_ADMIN_SUPPLY_instances = new WeakSet(), _BlockOperationTOKEN_ADMIN_SUPPLY_computeSupplyMethod = function _BlockOperationTOKEN_ADMIN_SUPPLY_computeSupplyMethod(method) {
|
|
65048
65201
|
const numericMethod = (0, _1.toAdjustMethod)(method);
|
|
65049
|
-
if (numericMethod ===
|
|
65202
|
+
if (numericMethod === _1.default.AdjustMethod.SET) {
|
|
65050
65203
|
throw (new Error('Cannot use AdjustMethod.SET on a TOKEN_ADMIN_SUPPLY operation'));
|
|
65051
65204
|
}
|
|
65052
65205
|
return (numericMethod);
|
|
@@ -65065,10 +65218,10 @@ class BlockOperationMANAGE_CERTIFICATE extends BlockOperation {
|
|
|
65065
65218
|
}
|
|
65066
65219
|
__classPrivateFieldSet(this, _BlockOperationMANAGE_CERTIFICATE_certificateOrHash, __classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_instances, "m", _BlockOperationMANAGE_CERTIFICATE_asCertificate).call(this, input.certificateOrHash), "f");
|
|
65067
65220
|
__classPrivateFieldSet(this, _BlockOperationMANAGE_CERTIFICATE_method, __classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_instances, "m", _BlockOperationMANAGE_CERTIFICATE_computeCertificateMethod).call(this, input.method), "f");
|
|
65068
|
-
if ((input.intermediateCertificates === undefined) === (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") ===
|
|
65221
|
+
if ((input.intermediateCertificates === undefined) === (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") === _1.default.AdjustMethod.ADD)) {
|
|
65069
65222
|
throw (new block_1.default('BLOCK_INTERMEDIATE_CERTIFICATES_ONLY_ADD', 'Must provide intermediate certificates with a MANAGE_CERTIFICATE operation that is an ADD operation'));
|
|
65070
65223
|
}
|
|
65071
|
-
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") ===
|
|
65224
|
+
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") === _1.default.AdjustMethod.ADD) {
|
|
65072
65225
|
__classPrivateFieldSet(this, _BlockOperationMANAGE_CERTIFICATE_intermediateCertificates, __classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_instances, "m", _BlockOperationMANAGE_CERTIFICATE_asIntermediateCertificates).call(this, input.intermediateCertificates), "f");
|
|
65073
65226
|
}
|
|
65074
65227
|
else {
|
|
@@ -65076,7 +65229,7 @@ class BlockOperationMANAGE_CERTIFICATE extends BlockOperation {
|
|
|
65076
65229
|
}
|
|
65077
65230
|
}
|
|
65078
65231
|
get intermediateCertificates() {
|
|
65079
|
-
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") ===
|
|
65232
|
+
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") === _1.default.AdjustMethod.SUBTRACT) {
|
|
65080
65233
|
return (undefined);
|
|
65081
65234
|
}
|
|
65082
65235
|
return (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_intermediateCertificates, "f"));
|
|
@@ -65086,12 +65239,12 @@ class BlockOperationMANAGE_CERTIFICATE extends BlockOperation {
|
|
|
65086
65239
|
}
|
|
65087
65240
|
get certificateOrHash() {
|
|
65088
65241
|
if (certificate_1.CertificateHash.isInstance(__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_certificateOrHash, "f"))) {
|
|
65089
|
-
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") ===
|
|
65242
|
+
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") === _1.default.AdjustMethod.ADD) {
|
|
65090
65243
|
throw (new block_1.default('BLOCK_INVALID_CERTIFICATE_VALUE', 'Cannot add a certificate by hash, you must provide the full certificate'));
|
|
65091
65244
|
}
|
|
65092
65245
|
return (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_certificateOrHash, "f"));
|
|
65093
65246
|
}
|
|
65094
|
-
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") ===
|
|
65247
|
+
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") === _1.default.AdjustMethod.SUBTRACT && !certificate_1.CertificateHash.isInstance(__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_certificateOrHash, "f"))) {
|
|
65095
65248
|
return (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_certificateOrHash, "f").hash());
|
|
65096
65249
|
}
|
|
65097
65250
|
return (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_certificateOrHash, "f"));
|
|
@@ -65106,7 +65259,7 @@ class BlockOperationMANAGE_CERTIFICATE extends BlockOperation {
|
|
|
65106
65259
|
return (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f"));
|
|
65107
65260
|
}
|
|
65108
65261
|
validate(context) {
|
|
65109
|
-
if (this.method ===
|
|
65262
|
+
if (this.method === _1.default.AdjustMethod.ADD) {
|
|
65110
65263
|
if (certificate_1.CertificateHash.isInstance(__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_certificateOrHash, "f"))) {
|
|
65111
65264
|
throw (new block_1.default('BLOCK_INVALID_CERTIFICATE_VALUE', 'Cannot add a certificate by hash, you must provide the full certificate'));
|
|
65112
65265
|
}
|
|
@@ -65142,35 +65295,12 @@ class BlockOperationMANAGE_CERTIFICATE extends BlockOperation {
|
|
|
65142
65295
|
}
|
|
65143
65296
|
}
|
|
65144
65297
|
toJSON() {
|
|
65145
|
-
|
|
65146
|
-
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") === _2.default.AdjustMethod.SUBTRACT) {
|
|
65147
|
-
intermediateCertificates = undefined;
|
|
65148
|
-
}
|
|
65149
|
-
else {
|
|
65150
|
-
intermediateCertificates = null;
|
|
65151
|
-
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_intermediateCertificates, "f") && __classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_intermediateCertificates, "f").bundleSize > 0) {
|
|
65152
|
-
intermediateCertificates = __classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_intermediateCertificates, "f").getDERBuffer().toString('base64');
|
|
65153
|
-
}
|
|
65154
|
-
}
|
|
65155
|
-
let serializedCertificate;
|
|
65156
|
-
if (__classPrivateFieldGet(this, _BlockOperationMANAGE_CERTIFICATE_method, "f") === _2.default.AdjustMethod.SUBTRACT) {
|
|
65157
|
-
if (!certificate_1.CertificateHash.isInstance(this.certificateOrHash)) {
|
|
65158
|
-
throw (new Error('Invalid response from get certificate, expected a CertificateHash'));
|
|
65159
|
-
}
|
|
65160
|
-
serializedCertificate = this.certificateOrHash.toString();
|
|
65161
|
-
}
|
|
65162
|
-
else {
|
|
65163
|
-
if (!certificate_1.Certificate.isCertificate(this.certificateOrHash)) {
|
|
65164
|
-
throw (new Error('Invalid response from get certificate, expected a Certificate'));
|
|
65165
|
-
}
|
|
65166
|
-
serializedCertificate = this.certificateOrHash.toPEM();
|
|
65167
|
-
}
|
|
65168
|
-
return ({
|
|
65298
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
65169
65299
|
type: this.type,
|
|
65170
|
-
certificateOrHash:
|
|
65300
|
+
certificateOrHash: this.certificateOrHash,
|
|
65171
65301
|
method: this.method,
|
|
65172
|
-
intermediateCertificates: intermediateCertificates
|
|
65173
|
-
});
|
|
65302
|
+
intermediateCertificates: this.intermediateCertificates
|
|
65303
|
+
}));
|
|
65174
65304
|
}
|
|
65175
65305
|
}
|
|
65176
65306
|
_BlockOperationMANAGE_CERTIFICATE_certificateOrHash = new WeakMap(), _BlockOperationMANAGE_CERTIFICATE_intermediateCertificates = new WeakMap(), _BlockOperationMANAGE_CERTIFICATE_method = new WeakMap(), _BlockOperationMANAGE_CERTIFICATE_instances = new WeakSet(), _BlockOperationMANAGE_CERTIFICATE_asCertificate = function _BlockOperationMANAGE_CERTIFICATE_asCertificate(certificate) {
|
|
@@ -65186,6 +65316,10 @@ _BlockOperationMANAGE_CERTIFICATE_certificateOrHash = new WeakMap(), _BlockOpera
|
|
|
65186
65316
|
catch {
|
|
65187
65317
|
/* Ignore Errors */
|
|
65188
65318
|
}
|
|
65319
|
+
if (!util_1.types.isArrayBuffer(certificate) && !Buffer.isBuffer(certificate) && typeof certificate === 'object') {
|
|
65320
|
+
// We still have an object that should have created a certificate but it failed
|
|
65321
|
+
throw (new Error('Could not reconstruct Certificate from JSON'));
|
|
65322
|
+
}
|
|
65189
65323
|
try {
|
|
65190
65324
|
return (new certificate_1.CertificateHash(certificate));
|
|
65191
65325
|
}
|
|
@@ -65204,7 +65338,7 @@ _BlockOperationMANAGE_CERTIFICATE_certificateOrHash = new WeakMap(), _BlockOpera
|
|
|
65204
65338
|
return (bundleObject);
|
|
65205
65339
|
}, _BlockOperationMANAGE_CERTIFICATE_computeCertificateMethod = function _BlockOperationMANAGE_CERTIFICATE_computeCertificateMethod(method) {
|
|
65206
65340
|
const numericMethod = (0, _1.toAdjustMethod)(method);
|
|
65207
|
-
if (numericMethod ===
|
|
65341
|
+
if (numericMethod === _1.default.AdjustMethod.SET) {
|
|
65208
65342
|
throw (new Error('Cannot use AdjustMethod.SET on a MANAGE_CERTIFICATE operation.'));
|
|
65209
65343
|
}
|
|
65210
65344
|
return (numericMethod);
|
|
@@ -65238,9 +65372,9 @@ function isBlockOperation(input) {
|
|
|
65238
65372
|
* serialized to JSON
|
|
65239
65373
|
*/
|
|
65240
65374
|
function ExportOperationsJSON(operations) {
|
|
65241
|
-
return (
|
|
65375
|
+
return (operations.map(function (operation) {
|
|
65242
65376
|
return (operation.toJSON());
|
|
65243
|
-
}))
|
|
65377
|
+
}));
|
|
65244
65378
|
}
|
|
65245
65379
|
function ImportOperationsJSON(operations) {
|
|
65246
65380
|
const newOperations = [];
|
|
@@ -65401,10 +65535,10 @@ function ImportOperationsASN1(input, network) {
|
|
|
65401
65535
|
else if ((0, helper_1.isBuffer)(keyValueIn)) {
|
|
65402
65536
|
if (type === OperationType.MANAGE_CERTIFICATE && key === 'certificateOrHash') {
|
|
65403
65537
|
const method = (0, _1.toAdjustMethod)(operation['method']);
|
|
65404
|
-
if (method ===
|
|
65538
|
+
if (method === _1.AdjustMethod.SUBTRACT) {
|
|
65405
65539
|
keyValueOut = new certificate_1.CertificateHash(keyValueIn);
|
|
65406
65540
|
}
|
|
65407
|
-
else if (method ===
|
|
65541
|
+
else if (method === _1.AdjustMethod.ADD) {
|
|
65408
65542
|
keyValueOut = new certificate_1.Certificate(keyValueIn);
|
|
65409
65543
|
}
|
|
65410
65544
|
else {
|
|
@@ -65596,7 +65730,9 @@ exports.BlockErrorCodes = [
|
|
|
65596
65730
|
'PERMISSIONS_INVALID_TARGET',
|
|
65597
65731
|
'PREVIOUS_SELF',
|
|
65598
65732
|
'SUPPLY_INVALID',
|
|
65599
|
-
'TOKEN_RECEIVE_DIFFERS'
|
|
65733
|
+
'TOKEN_RECEIVE_DIFFERS',
|
|
65734
|
+
'SIGNATURE_REQUIRED',
|
|
65735
|
+
'SIGNATURE_PARAMETER_DIFFERS'
|
|
65600
65736
|
];
|
|
65601
65737
|
exports.FullBlockErrorCodes = exports.BlockErrorCodes.map(code => `${BlockErrorType}_${code}`);
|
|
65602
65738
|
class KeetaNetBlockError extends base_1.KeetaNetErrorBase {
|
|
@@ -70125,6 +70261,7 @@ class LogTargetConsole {
|
|
|
70125
70261
|
this.logLevel = config?.logLevel ?? 'ALL';
|
|
70126
70262
|
__classPrivateFieldSet(this, _LogTargetConsole_console, config?.console ?? console, "f");
|
|
70127
70263
|
this.filter = config?.filter ?? null;
|
|
70264
|
+
this.context = config?.context;
|
|
70128
70265
|
}
|
|
70129
70266
|
async emitLogs(logs) {
|
|
70130
70267
|
for (const rawLog of logs) {
|
|
@@ -70150,9 +70287,10 @@ class LogTargetConsole {
|
|
|
70150
70287
|
(0, never_1.assertNever)(log.level);
|
|
70151
70288
|
}
|
|
70152
70289
|
const requestID = log.options.currentRequestInfo.id;
|
|
70153
|
-
|
|
70290
|
+
const contextPrefix = this.context ? Object.entries(this.context).map(([k, v]) => `${k}=${v}`).join(' ') + ' ' : '';
|
|
70291
|
+
__classPrivateFieldGet(this, _LogTargetConsole_console, "f")[method](`[${requestID}] ${contextPrefix}${log.level} ${log.from}:`, ...log.args);
|
|
70154
70292
|
if (log.trace !== undefined) {
|
|
70155
|
-
__classPrivateFieldGet(this, _LogTargetConsole_console, "f")[method](`[${requestID}] ${log.level} ${log.from} TRACE:`, log.trace);
|
|
70293
|
+
__classPrivateFieldGet(this, _LogTargetConsole_console, "f")[method](`[${requestID}] ${contextPrefix}${log.level} ${log.from} TRACE:`, log.trace);
|
|
70156
70294
|
}
|
|
70157
70295
|
}
|
|
70158
70296
|
}
|
|
@@ -70710,7 +70848,6 @@ const asn1_1 = __webpack_require__(6045);
|
|
|
70710
70848
|
const helper_1 = __webpack_require__(3208);
|
|
70711
70849
|
const kv_memory_1 = __importDefault(__webpack_require__(1557));
|
|
70712
70850
|
const vote_1 = __webpack_require__(1130);
|
|
70713
|
-
const effects_1 = __webpack_require__(7346);
|
|
70714
70851
|
const version_1 = __webpack_require__(5672);
|
|
70715
70852
|
const defaultP2PConfig = {
|
|
70716
70853
|
timeoutIdle: 10 /* s */ * 1000 /* ms */,
|
|
@@ -71921,12 +72058,34 @@ class P2PSwitch {
|
|
|
71921
72058
|
const seenMessageIDPromise = this.config.kv.set('seenMessageIDs', id, Date.now(), {
|
|
71922
72059
|
ttl: this.config.seenMessageTTL
|
|
71923
72060
|
});
|
|
72061
|
+
/**
|
|
72062
|
+
* For 'add' messages, parse VoteStaple for filtering.
|
|
72063
|
+
* Data can be a VoteStaple object (already parsed with trustedValues from PubSub)
|
|
72064
|
+
* or a binary string that needs parsing.
|
|
72065
|
+
*/
|
|
72066
|
+
let voteStaple;
|
|
72067
|
+
let sendData = data;
|
|
72068
|
+
if (type === 'add') {
|
|
72069
|
+
if (vote_1.VoteStaple.isInstance(data)) {
|
|
72070
|
+
voteStaple = data;
|
|
72071
|
+
// Convert back to binary for sending over the wire
|
|
72072
|
+
sendData = voteStaple.toString();
|
|
72073
|
+
}
|
|
72074
|
+
else if (typeof data === 'string') {
|
|
72075
|
+
voteStaple = new vote_1.VoteStaple(data);
|
|
72076
|
+
sendData = data;
|
|
72077
|
+
}
|
|
72078
|
+
else {
|
|
72079
|
+
this._log.error(`[${id}]`, 'Invalid data for add message, must be VoteStaple or string, received: ', typeof data);
|
|
72080
|
+
return (false);
|
|
72081
|
+
}
|
|
72082
|
+
}
|
|
71924
72083
|
/**
|
|
71925
72084
|
* Construct the message JSON
|
|
71926
72085
|
*/
|
|
71927
72086
|
const messageString = JSON.stringify({
|
|
71928
72087
|
id: id,
|
|
71929
|
-
[type]:
|
|
72088
|
+
[type]: sendData,
|
|
71930
72089
|
ttl: ttl
|
|
71931
72090
|
});
|
|
71932
72091
|
/**
|
|
@@ -71971,10 +72130,13 @@ class P2PSwitch {
|
|
|
71971
72130
|
else {
|
|
71972
72131
|
target = to;
|
|
71973
72132
|
}
|
|
71974
|
-
|
|
71975
|
-
if (
|
|
71976
|
-
__classPrivateFieldGet(this,
|
|
71977
|
-
|
|
72133
|
+
// Only apply filter for 'add' messages with a VoteStaple
|
|
72134
|
+
if (voteStaple !== undefined) {
|
|
72135
|
+
const passesFilter = await __classPrivateFieldGet(this, _P2PSwitch_instances, "m", _P2PSwitch_passesFilter).call(this, target, voteStaple);
|
|
72136
|
+
if (!passesFilter) {
|
|
72137
|
+
__classPrivateFieldGet(this, _P2PSwitch_localNode, "f").stats.incr('p2p', 'outgoingMessagesPeerFiltered');
|
|
72138
|
+
return (false);
|
|
72139
|
+
}
|
|
71978
72140
|
}
|
|
71979
72141
|
/**
|
|
71980
72142
|
* Allow greetings to be sent prior to identification of a peer
|
|
@@ -72212,18 +72374,22 @@ class P2PSwitch {
|
|
|
72212
72374
|
return (false);
|
|
72213
72375
|
}
|
|
72214
72376
|
/**
|
|
72377
|
+
* Check if any registered filter matches the VoteStaple's touched accounts.
|
|
72378
|
+
* Uses the VoteStaple's touchedAccounts getter which may be pre-computed via trustedValues.
|
|
72379
|
+
*
|
|
72215
72380
|
* TODO - make this private after refactoring websockets to handle higher load
|
|
72216
72381
|
* https://github.com/KeetaNetwork/node/issues/785
|
|
72217
72382
|
*/
|
|
72218
|
-
async haveAnyFilter(
|
|
72383
|
+
async haveAnyFilter(voteStaple) {
|
|
72219
72384
|
const kvFilters = await this.config.kv.getAll('messageFilters');
|
|
72385
|
+
const touched = voteStaple.touchedAccounts;
|
|
72220
72386
|
for (const key in kvFilters) {
|
|
72221
72387
|
const kvFilter = kvFilters[key];
|
|
72222
72388
|
if (kvFilter && typeof kvFilter === 'string') {
|
|
72223
|
-
const
|
|
72224
|
-
|
|
72225
|
-
|
|
72226
|
-
|
|
72389
|
+
const filterAccount = account_1.default.fromPublicKeyAndType(kvFilter);
|
|
72390
|
+
if (touched.has(filterAccount)) {
|
|
72391
|
+
return (true);
|
|
72392
|
+
}
|
|
72227
72393
|
}
|
|
72228
72394
|
}
|
|
72229
72395
|
return (false);
|
|
@@ -72467,7 +72633,12 @@ async function _P2PSwitch_relayActiveState(conn) {
|
|
|
72467
72633
|
* Perform peer exchange
|
|
72468
72634
|
*/
|
|
72469
72635
|
promises.push(__classPrivateFieldGet(this, _P2PSwitch_instances, "m", _P2PSwitch_relayActiveState).call(this, from));
|
|
72470
|
-
await Promise.allSettled(promises);
|
|
72636
|
+
const promiseResults = await Promise.allSettled(promises);
|
|
72637
|
+
for (const result of promiseResults) {
|
|
72638
|
+
if (result.status === 'rejected') {
|
|
72639
|
+
this._log.error('Error during greeting handling:', result.reason);
|
|
72640
|
+
}
|
|
72641
|
+
}
|
|
72471
72642
|
return (true);
|
|
72472
72643
|
}, _P2PSwitch_updateConnTimeout = function _P2PSwitch_updateConnTimeout(conn) {
|
|
72473
72644
|
if (conn.peer) {
|
|
@@ -72520,7 +72691,12 @@ async function _P2PSwitch_relayActiveState(conn) {
|
|
|
72520
72691
|
this._log.error('Failed to add peer:', addPeerError);
|
|
72521
72692
|
}
|
|
72522
72693
|
return (p2pConnection);
|
|
72523
|
-
}, _P2PSwitch_passesFilter =
|
|
72694
|
+
}, _P2PSwitch_passesFilter =
|
|
72695
|
+
/**
|
|
72696
|
+
* Check if the VoteStaple passes the filter for the target connection.
|
|
72697
|
+
* Uses the VoteStaple's touchedAccounts getter which may be pre-computed via trustedValues.
|
|
72698
|
+
*/
|
|
72699
|
+
async function _P2PSwitch_passesFilter(target, voteStaple) {
|
|
72524
72700
|
let filter = __classPrivateFieldGet(this, _P2PSwitch_messageFilterCache, "f")[target.connString];
|
|
72525
72701
|
if (filter === undefined) {
|
|
72526
72702
|
const kvFilter = await this.config.kv.get('messageFilters', target.connString);
|
|
@@ -72531,9 +72707,7 @@ async function _P2PSwitch_relayActiveState(conn) {
|
|
|
72531
72707
|
}
|
|
72532
72708
|
// If there is a filter, only send effected accounts matching the filter
|
|
72533
72709
|
if (filter) {
|
|
72534
|
-
|
|
72535
|
-
const { touched } = (0, effects_1.computeEffectOfBlocks)(voteStaple.blocks);
|
|
72536
|
-
return (touched.has(filter));
|
|
72710
|
+
return (voteStaple.touchedAccounts.has(filter));
|
|
72537
72711
|
}
|
|
72538
72712
|
return (true);
|
|
72539
72713
|
};
|
|
@@ -75538,7 +75712,9 @@ exports.Buffer = exports.BufferStorage = void 0;
|
|
|
75538
75712
|
exports.DecodeBase32 = DecodeBase32;
|
|
75539
75713
|
exports.EncodeBase32 = EncodeBase32;
|
|
75540
75714
|
exports.DecodeBase64 = DecodeBase64;
|
|
75715
|
+
exports.DecodeBase64URL = DecodeBase64URL;
|
|
75541
75716
|
exports.EncodeBase64 = EncodeBase64;
|
|
75717
|
+
exports.EncodeBase64URL = EncodeBase64URL;
|
|
75542
75718
|
exports.ZlibInflate = ZlibInflate;
|
|
75543
75719
|
exports.ZlibDeflate = ZlibDeflate;
|
|
75544
75720
|
exports.ZlibInflateAsync = ZlibInflateAsync;
|
|
@@ -75558,8 +75734,10 @@ function DecodeBase32(data, length) {
|
|
|
75558
75734
|
const retval = rfc4648_1.base32.parse(data, {
|
|
75559
75735
|
loose: true
|
|
75560
75736
|
});
|
|
75561
|
-
if (
|
|
75562
|
-
|
|
75737
|
+
if (length !== undefined) {
|
|
75738
|
+
if (retval.length !== length) {
|
|
75739
|
+
throw (new Error(`Expected ${length} bytes, got ${retval.length}`));
|
|
75740
|
+
}
|
|
75563
75741
|
}
|
|
75564
75742
|
return (retval);
|
|
75565
75743
|
}
|
|
@@ -75575,9 +75753,26 @@ function EncodeBase32(data) {
|
|
|
75575
75753
|
function DecodeBase64(data) {
|
|
75576
75754
|
return ((0, helper_1.bufferToArrayBuffer)(buffer_1.Buffer.from(data, 'base64')));
|
|
75577
75755
|
}
|
|
75756
|
+
function DecodeBase64URL(data) {
|
|
75757
|
+
switch (data.length % 4) {
|
|
75758
|
+
case 2:
|
|
75759
|
+
data += '==';
|
|
75760
|
+
break;
|
|
75761
|
+
case 3:
|
|
75762
|
+
data += '=';
|
|
75763
|
+
break;
|
|
75764
|
+
}
|
|
75765
|
+
data = data.replace(/-/g, '+').replace(/_/g, '/');
|
|
75766
|
+
return (DecodeBase64(data));
|
|
75767
|
+
}
|
|
75578
75768
|
function EncodeBase64(data) {
|
|
75579
75769
|
return (buffer_1.Buffer.from(data).toString('base64'));
|
|
75580
75770
|
}
|
|
75771
|
+
function EncodeBase64URL(data) {
|
|
75772
|
+
let output = EncodeBase64(data);
|
|
75773
|
+
output = output.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
75774
|
+
return (output);
|
|
75775
|
+
}
|
|
75581
75776
|
function ZlibInflate(data, options) {
|
|
75582
75777
|
return ((0, helper_1.bufferToArrayBuffer)(zlib_1.default.inflateSync(buffer_1.Buffer.from(data), options)));
|
|
75583
75778
|
}
|
|
@@ -75593,35 +75788,66 @@ async function ZlibDeflateAsync(data, options = {}) {
|
|
|
75593
75788
|
return ((0, helper_1.bufferToArrayBuffer)(buffer));
|
|
75594
75789
|
}
|
|
75595
75790
|
class BufferStorage {
|
|
75596
|
-
|
|
75597
|
-
|
|
75598
|
-
|
|
75791
|
+
static decodeKey(key, length) {
|
|
75792
|
+
if (key instanceof Uint8Array) {
|
|
75793
|
+
key = buffer_1.Buffer.from(key);
|
|
75794
|
+
}
|
|
75795
|
+
if (buffer_1.Buffer.isBuffer(key)) {
|
|
75796
|
+
if (length !== undefined && key.length !== length) {
|
|
75797
|
+
throw (new Error(`When decoding Buffer we got different number of bytes than expected (${key.length} expected ${length})`));
|
|
75798
|
+
}
|
|
75799
|
+
return ((0, helper_1.bufferToArrayBuffer)(key));
|
|
75800
|
+
}
|
|
75801
|
+
if (key instanceof ArrayBuffer) {
|
|
75802
|
+
if (length !== undefined && key.byteLength !== length) {
|
|
75803
|
+
throw (new Error(`When decoding ArrayBuffer we got different number of bytes than expected (${key.byteLength} expected ${length})`));
|
|
75804
|
+
}
|
|
75805
|
+
return (key);
|
|
75806
|
+
}
|
|
75599
75807
|
if (typeof (key) === 'string') {
|
|
75600
75808
|
/*
|
|
75601
75809
|
* Convert from a hex-encoded string into a buffer
|
|
75602
75810
|
*/
|
|
75603
|
-
const
|
|
75604
|
-
|
|
75605
|
-
|
|
75811
|
+
const keyBuffer = buffer_1.Buffer.from(key, 'hex');
|
|
75812
|
+
const keyUint8 = new Uint8Array(keyBuffer);
|
|
75813
|
+
const keyArrayBuffer = keyUint8.buffer;
|
|
75814
|
+
if (length !== undefined && keyBuffer.length !== length) {
|
|
75815
|
+
throw (new Error(`When decoding hex string we got different number of bytes than expected (${keyBuffer.length} expected ${length})`));
|
|
75606
75816
|
}
|
|
75607
|
-
|
|
75817
|
+
return (keyArrayBuffer);
|
|
75608
75818
|
}
|
|
75609
75819
|
else if (typeof key === 'bigint') {
|
|
75820
|
+
if (length === undefined) {
|
|
75821
|
+
throw (new Error('When decoding BigInt we need to know the expected length of the buffer'));
|
|
75822
|
+
}
|
|
75610
75823
|
let value = key.toString(16);
|
|
75824
|
+
if (value.length % 2 !== 0) {
|
|
75825
|
+
value = '0' + value;
|
|
75826
|
+
}
|
|
75827
|
+
// Pad with zeros to length specified
|
|
75611
75828
|
if (value.length > (length * 2)) {
|
|
75612
|
-
throw (new Error(`When decoding BigInt we got different number of bytes than expected (${value.length} expected ${length
|
|
75829
|
+
throw (new Error(`When decoding BigInt we got different number of bytes than expected (${value.length / 2} expected ${length})`));
|
|
75613
75830
|
}
|
|
75614
75831
|
value = '0'.repeat(length * 2) + value;
|
|
75615
75832
|
value = value.slice(length * 2 * -1);
|
|
75616
|
-
|
|
75833
|
+
const keyBuffer = buffer_1.Buffer.from(value, 'hex');
|
|
75834
|
+
const keyUint8 = new Uint8Array(keyBuffer);
|
|
75835
|
+
const keyArrayBuffer = keyUint8.buffer;
|
|
75836
|
+
return (keyArrayBuffer);
|
|
75617
75837
|
}
|
|
75618
75838
|
else {
|
|
75619
|
-
|
|
75620
|
-
throw (new Error(`When storing buffer we got different number of bytes than expected (${buffer_1.Buffer.from(key).length} expected ${length})`));
|
|
75621
|
-
}
|
|
75622
|
-
__classPrivateFieldSet(this, _BufferStorage_key, key, "f");
|
|
75839
|
+
return (key);
|
|
75623
75840
|
}
|
|
75624
75841
|
}
|
|
75842
|
+
constructor(key, length) {
|
|
75843
|
+
_BufferStorage_key.set(this, void 0);
|
|
75844
|
+
this.storageKind = 'GenericBuffer';
|
|
75845
|
+
const keyDecoded = BufferStorage.decodeKey(key, length);
|
|
75846
|
+
if (buffer_1.Buffer.from(keyDecoded).length !== length) {
|
|
75847
|
+
throw (new Error(`When storing buffer we got different number of bytes than expected (${buffer_1.Buffer.from(keyDecoded).length} expected ${length})`));
|
|
75848
|
+
}
|
|
75849
|
+
__classPrivateFieldSet(this, _BufferStorage_key, keyDecoded, "f");
|
|
75850
|
+
}
|
|
75625
75851
|
get() {
|
|
75626
75852
|
return (__classPrivateFieldGet(this, _BufferStorage_key, "f"));
|
|
75627
75853
|
}
|
|
@@ -75722,7 +75948,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
75722
75948
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
75723
75949
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
75724
75950
|
};
|
|
75725
|
-
var _CertificateBuilder_params, _CertificateBundle_raw, _CertificateBundle_contents, _Certificate_instances, _Certificate_raw, _Certificate_hash, _Certificate_extensionsRaw, _Certificate_extensionsProcessed, _Certificate_finalizeConstructionCalled, _Certificate_processExtensionsInternal, _Certificate_processBaseExtensions, _Certificate_processBaseExtension, _Certificate_assertAllCriticalExtensionsProcessed, _Certificate_checkValid, _Certificate_checkIssued;
|
|
75951
|
+
var _CertificateBuilder_params, _CertificateBuilder_caPathLen, _CertificateBundle_raw, _CertificateBundle_contents, _Certificate_instances, _Certificate_raw, _Certificate_hash, _Certificate_extensionsRaw, _Certificate_extensionsProcessed, _Certificate_finalizeConstructionCalled, _Certificate_isSelfSigned, _Certificate_processExtensionsInternal, _Certificate_processBaseExtensions, _Certificate_parseKeyUsage, _Certificate_processBaseExtension, _Certificate_assertAllCriticalExtensionsProcessed, _Certificate_checkValid, _Certificate_checkIssued;
|
|
75726
75952
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
75727
75953
|
exports.Certificate = exports.CertificateBundle = exports.CertificateHash = exports.CertificateBuilder = void 0;
|
|
75728
75954
|
const ASN1 = __importStar(__webpack_require__(6045));
|
|
@@ -75732,7 +75958,9 @@ const helper_1 = __webpack_require__(3208);
|
|
|
75732
75958
|
const HashLib = __importStar(__webpack_require__(7908));
|
|
75733
75959
|
const crypto_1 = __importDefault(__webpack_require__(6982));
|
|
75734
75960
|
const buffer_1 = __webpack_require__(3310);
|
|
75961
|
+
const conversion_1 = __webpack_require__(2360);
|
|
75735
75962
|
const certificate_1 = __importDefault(__webpack_require__(9890));
|
|
75963
|
+
const util_1 = __webpack_require__(9023);
|
|
75736
75964
|
/** @internal */
|
|
75737
75965
|
const CertificateSchemaInternal = [
|
|
75738
75966
|
/* TBS Certificate */
|
|
@@ -75860,6 +76088,7 @@ const defaultHashName = HashLib.HashFunctionName;
|
|
|
75860
76088
|
class CertificateBuilder {
|
|
75861
76089
|
constructor(params) {
|
|
75862
76090
|
_CertificateBuilder_params.set(this, void 0);
|
|
76091
|
+
_CertificateBuilder_caPathLen.set(this, void 0);
|
|
75863
76092
|
__classPrivateFieldSet(this, _CertificateBuilder_params, {
|
|
75864
76093
|
...params
|
|
75865
76094
|
}, "f");
|
|
@@ -75919,6 +76148,12 @@ class CertificateBuilder {
|
|
|
75919
76148
|
account.publicKeyAndType
|
|
75920
76149
|
]), 20)));
|
|
75921
76150
|
}
|
|
76151
|
+
/**
|
|
76152
|
+
* Set the CA path length
|
|
76153
|
+
*/
|
|
76154
|
+
setCAPathLen(pathLen) {
|
|
76155
|
+
__classPrivateFieldSet(this, _CertificateBuilder_caPathLen, pathLen, "f");
|
|
76156
|
+
}
|
|
75922
76157
|
/**
|
|
75923
76158
|
* Produce the extensions to include in this certificate
|
|
75924
76159
|
*/
|
|
@@ -75941,13 +76176,17 @@ class CertificateBuilder {
|
|
|
75941
76176
|
isCertificateAuthority = params.isCA;
|
|
75942
76177
|
}
|
|
75943
76178
|
if (isCertificateAuthority) {
|
|
76179
|
+
const basicConstraints = [true];
|
|
76180
|
+
if (__classPrivateFieldGet(this, _CertificateBuilder_caPathLen, "f") !== undefined) {
|
|
76181
|
+
basicConstraints.push(__classPrivateFieldGet(this, _CertificateBuilder_caPathLen, "f"));
|
|
76182
|
+
}
|
|
75944
76183
|
extensions.push(
|
|
75945
76184
|
/** Extension: Basic Constraints (CA) */
|
|
75946
|
-
CertificateBuilder.extension('2.5.29.19',
|
|
76185
|
+
CertificateBuilder.extension('2.5.29.19', basicConstraints, true),
|
|
75947
76186
|
/** Extension: Key Usage */
|
|
75948
76187
|
CertificateBuilder.extension('2.5.29.15', {
|
|
75949
76188
|
type: 'bitstring',
|
|
75950
|
-
value: Buffer.from([0
|
|
76189
|
+
value: Buffer.from([0 /* encipherOnly and decipherOnly */
|
|
75951
76190
|
| (1 << 1) /* CRL Sign */
|
|
75952
76191
|
| (1 << 2) /* Cert Sign */
|
|
75953
76192
|
| (0 << 3) /* Key Agreement */
|
|
@@ -75963,7 +76202,7 @@ class CertificateBuilder {
|
|
|
75963
76202
|
/** Extension: Key Usage */
|
|
75964
76203
|
CertificateBuilder.extension('2.5.29.15', {
|
|
75965
76204
|
type: 'bitstring',
|
|
75966
|
-
value: Buffer.from([0
|
|
76205
|
+
value: Buffer.from([0 /* encipherOnly and decipherOnly */
|
|
75967
76206
|
| (0 << 1) /* CRL Sign */
|
|
75968
76207
|
| (0 << 2) /* Cert Sign */
|
|
75969
76208
|
| (0 << 3) /* Key Agreement */
|
|
@@ -76164,7 +76403,7 @@ class CertificateBuilder {
|
|
|
76164
76403
|
}
|
|
76165
76404
|
}
|
|
76166
76405
|
exports.CertificateBuilder = CertificateBuilder;
|
|
76167
|
-
_CertificateBuilder_params = new WeakMap();
|
|
76406
|
+
_CertificateBuilder_params = new WeakMap(), _CertificateBuilder_caPathLen = new WeakMap();
|
|
76168
76407
|
/**
|
|
76169
76408
|
* Certificate hash
|
|
76170
76409
|
*/
|
|
@@ -76200,6 +76439,10 @@ class CertificateBundle {
|
|
|
76200
76439
|
constructor(input) {
|
|
76201
76440
|
_CertificateBundle_raw.set(this, void 0);
|
|
76202
76441
|
_CertificateBundle_contents.set(this, void 0);
|
|
76442
|
+
// If input is toJSON output
|
|
76443
|
+
if (typeof input === 'object' && 'certificates' in input) {
|
|
76444
|
+
input = input.certificates;
|
|
76445
|
+
}
|
|
76203
76446
|
if (CertificateBundle.isInstance(input)) {
|
|
76204
76447
|
__classPrivateFieldSet(this, _CertificateBundle_raw, input.getDER(), "f");
|
|
76205
76448
|
}
|
|
@@ -76271,6 +76514,17 @@ class CertificateBundle {
|
|
|
76271
76514
|
exports.CertificateBundle = CertificateBundle;
|
|
76272
76515
|
_CertificateBundle_raw = new WeakMap(), _CertificateBundle_contents = new WeakMap();
|
|
76273
76516
|
CertificateBundle.isInstance = (0, helper_1.checkableGenerator)(CertificateBundle);
|
|
76517
|
+
const keyUsageBits = [
|
|
76518
|
+
'digitalSignature',
|
|
76519
|
+
'nonRepudiation',
|
|
76520
|
+
'keyEncipherment',
|
|
76521
|
+
'dataEncipherment',
|
|
76522
|
+
'keyAgreement',
|
|
76523
|
+
'keyCertSign',
|
|
76524
|
+
'cRLSign',
|
|
76525
|
+
'encipherOnly',
|
|
76526
|
+
'decipherOnly'
|
|
76527
|
+
];
|
|
76274
76528
|
class Certificate {
|
|
76275
76529
|
/**
|
|
76276
76530
|
* Is a certificate object?
|
|
@@ -76306,6 +76560,10 @@ class Certificate {
|
|
|
76306
76560
|
* Has finalizeConstruction been called?
|
|
76307
76561
|
*/
|
|
76308
76562
|
_Certificate_finalizeConstructionCalled.set(this, false);
|
|
76563
|
+
/**
|
|
76564
|
+
* Cached value for isSelfSigned
|
|
76565
|
+
*/
|
|
76566
|
+
_Certificate_isSelfSigned.set(this, void 0);
|
|
76309
76567
|
/*
|
|
76310
76568
|
* If a certificate is provided, then extract the raw
|
|
76311
76569
|
* certificate and process it -- do not merge any of
|
|
@@ -76315,6 +76573,18 @@ class Certificate {
|
|
|
76315
76573
|
// For use in browser, have to use toDER instead of accessing #raw directly
|
|
76316
76574
|
input = input.toDER();
|
|
76317
76575
|
}
|
|
76576
|
+
else if (!util_1.types.isArrayBuffer(input) && !Buffer.isBuffer(input) && typeof input === 'object') {
|
|
76577
|
+
/**
|
|
76578
|
+
* If certificate input is output from toJSON then reconstruct from $binary
|
|
76579
|
+
* $binary is PEM format which will get parsed later
|
|
76580
|
+
*/
|
|
76581
|
+
if ('$binary' in input && input.$binary !== undefined) {
|
|
76582
|
+
input = input.$binary;
|
|
76583
|
+
}
|
|
76584
|
+
else {
|
|
76585
|
+
throw (new Error('Certificate from JSON should include $binary'));
|
|
76586
|
+
}
|
|
76587
|
+
}
|
|
76318
76588
|
/*
|
|
76319
76589
|
* Define an object type ID as an un-enumerable property to
|
|
76320
76590
|
* ensure that we can identify this object as an instance of
|
|
@@ -76481,7 +76751,11 @@ class Certificate {
|
|
|
76481
76751
|
* Verifies that a certificate is self-signed
|
|
76482
76752
|
*/
|
|
76483
76753
|
isSelfSigned() {
|
|
76484
|
-
|
|
76754
|
+
if (__classPrivateFieldGet(this, _Certificate_isSelfSigned, "f") !== undefined) {
|
|
76755
|
+
return (__classPrivateFieldGet(this, _Certificate_isSelfSigned, "f"));
|
|
76756
|
+
}
|
|
76757
|
+
__classPrivateFieldSet(this, _Certificate_isSelfSigned, this.checkIssued(this), "f");
|
|
76758
|
+
return (__classPrivateFieldGet(this, _Certificate_isSelfSigned, "f"));
|
|
76485
76759
|
}
|
|
76486
76760
|
/**
|
|
76487
76761
|
* Verifies that the certificate is was signed by the given account or certificate
|
|
@@ -76546,6 +76820,54 @@ class Certificate {
|
|
|
76546
76820
|
});
|
|
76547
76821
|
return (verified);
|
|
76548
76822
|
}
|
|
76823
|
+
/**
|
|
76824
|
+
* Verify that a given chain meets the depth requirements
|
|
76825
|
+
*/
|
|
76826
|
+
static verifyChainDepth(chain) {
|
|
76827
|
+
if (chain.length === 0) {
|
|
76828
|
+
return ({ valid: false, reason: 'Empty chain' });
|
|
76829
|
+
}
|
|
76830
|
+
const depthByIssuer = new Map();
|
|
76831
|
+
// Traverse from root to leaf
|
|
76832
|
+
for (let i = 0; i < chain.length; i++) {
|
|
76833
|
+
const certificate = chain[i];
|
|
76834
|
+
// Leaf certificates are still validated for total depth but excluded from other checks
|
|
76835
|
+
const isLeaf = i === chain.length - 1;
|
|
76836
|
+
const basicConstraints = certificate.baseExtensions?.basicConstraints;
|
|
76837
|
+
// basicConstraints are required for CA if it's not a leaf
|
|
76838
|
+
if (!isLeaf && !basicConstraints) {
|
|
76839
|
+
return ({ valid: false, reason: `Missing basicConstraints in certificate: ${certificate.subject}` });
|
|
76840
|
+
}
|
|
76841
|
+
const [isCA, pathLenConstraint] = basicConstraints ?? [false, undefined];
|
|
76842
|
+
// Root and intermediates should be a CA
|
|
76843
|
+
if (!isLeaf && !isCA) {
|
|
76844
|
+
return ({ valid: false, reason: `Non-CA certificate in chain: ${certificate.subject}` });
|
|
76845
|
+
}
|
|
76846
|
+
// CA should have usage set to be able to sign
|
|
76847
|
+
const keyUsage = certificate.baseExtensions?.keyUsage;
|
|
76848
|
+
if (!isLeaf && keyUsage && !keyUsage.keyCertSign) {
|
|
76849
|
+
return ({ valid: false, reason: `CA certificate missing keyCertSign in keyUsage: ${certificate.subject}` });
|
|
76850
|
+
}
|
|
76851
|
+
// Skip constraint checks if self-signed
|
|
76852
|
+
if (!certificate.isSelfSigned()) {
|
|
76853
|
+
// Validate against all existing constraints
|
|
76854
|
+
for (const [issuer, remainingDepth] of depthByIssuer.entries()) {
|
|
76855
|
+
if (remainingDepth < 0n) {
|
|
76856
|
+
return ({
|
|
76857
|
+
valid: false,
|
|
76858
|
+
reason: `Path length constraint exceeded for CA: ${issuer.subject} on Certificate: ${certificate.subject}`
|
|
76859
|
+
});
|
|
76860
|
+
}
|
|
76861
|
+
depthByIssuer.set(issuer, remainingDepth - 1n);
|
|
76862
|
+
}
|
|
76863
|
+
}
|
|
76864
|
+
// If this cert is a CA and has a pathLenConstraint, track it
|
|
76865
|
+
if (pathLenConstraint !== undefined) {
|
|
76866
|
+
depthByIssuer.set(certificate, pathLenConstraint);
|
|
76867
|
+
}
|
|
76868
|
+
}
|
|
76869
|
+
return ({ valid: true });
|
|
76870
|
+
}
|
|
76549
76871
|
/**
|
|
76550
76872
|
* Asserts provided certificates can construct a valid graph with no loops or orphans, and that all provided certificates can reach the root, or current certificate
|
|
76551
76873
|
* @param certificates Additional intermediate certificates to verify
|
|
@@ -76606,9 +76928,6 @@ class Certificate {
|
|
|
76606
76928
|
}
|
|
76607
76929
|
}
|
|
76608
76930
|
}
|
|
76609
|
-
/**
|
|
76610
|
-
* Verify against a given certificate store
|
|
76611
|
-
*/
|
|
76612
76931
|
verifyChain(store, _ignore_seenCerts /* XXX:TODO */) {
|
|
76613
76932
|
/*
|
|
76614
76933
|
* Check to see if the certificate is signed by any of the Root CAs
|
|
@@ -76621,10 +76940,15 @@ class Certificate {
|
|
|
76621
76940
|
if (retval !== null) {
|
|
76622
76941
|
return;
|
|
76623
76942
|
}
|
|
76624
|
-
const checkIssued = this.
|
|
76943
|
+
const checkIssued = __classPrivateFieldGet(this, _Certificate_instances, "m", _Certificate_checkIssued).call(this, rootCertificate);
|
|
76625
76944
|
if (checkIssued.issued) {
|
|
76626
76945
|
if (rootCertificate.checkValid(this.moment)) {
|
|
76627
|
-
|
|
76946
|
+
const checkRetval = [rootCertificate];
|
|
76947
|
+
const validChain = Certificate.verifyChainDepth([...checkRetval, this]);
|
|
76948
|
+
if (validChain.valid) {
|
|
76949
|
+
retval = checkRetval;
|
|
76950
|
+
return;
|
|
76951
|
+
}
|
|
76628
76952
|
}
|
|
76629
76953
|
}
|
|
76630
76954
|
});
|
|
@@ -76639,12 +76963,17 @@ class Certificate {
|
|
|
76639
76963
|
if (retval !== null) {
|
|
76640
76964
|
return;
|
|
76641
76965
|
}
|
|
76642
|
-
|
|
76966
|
+
const checkIssued = __classPrivateFieldGet(this, _Certificate_instances, "m", _Certificate_checkIssued).call(this, intermediateCertificate);
|
|
76967
|
+
if (checkIssued.issued) {
|
|
76643
76968
|
if (intermediateCertificate.checkValid(this.moment)) {
|
|
76644
|
-
const moreChain = intermediateCertificate.verifyChain(store /*
|
|
76969
|
+
const moreChain = intermediateCertificate.verifyChain(store, undefined /* seenCerts XXX:TODO */);
|
|
76645
76970
|
if (moreChain !== null) {
|
|
76646
|
-
|
|
76647
|
-
|
|
76971
|
+
const checkRetval = [...moreChain, intermediateCertificate];
|
|
76972
|
+
const validChain = Certificate.verifyChainDepth([...checkRetval, this]);
|
|
76973
|
+
if (validChain.valid) {
|
|
76974
|
+
retval = checkRetval;
|
|
76975
|
+
return;
|
|
76976
|
+
}
|
|
76648
76977
|
}
|
|
76649
76978
|
}
|
|
76650
76979
|
}
|
|
@@ -76805,7 +77134,8 @@ class Certificate {
|
|
|
76805
77134
|
this.assertConstructed();
|
|
76806
77135
|
// XXX:TODO Fix this type
|
|
76807
77136
|
const additionalFields = {};
|
|
76808
|
-
|
|
77137
|
+
// Default to including $binary so we can reconstruct this cert from PEM
|
|
77138
|
+
if (options === undefined || options.addBinary !== false) {
|
|
76809
77139
|
additionalFields['$binary'] = this.toPEM();
|
|
76810
77140
|
}
|
|
76811
77141
|
if (includeChain && this.chain !== undefined) {
|
|
@@ -76813,7 +77143,7 @@ class Certificate {
|
|
|
76813
77143
|
return (chainCert.toJSON({ ...options, addBinary: false }, false));
|
|
76814
77144
|
});
|
|
76815
77145
|
}
|
|
76816
|
-
return ({
|
|
77146
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
76817
77147
|
serial: this.serial,
|
|
76818
77148
|
notBefore: this.notBefore,
|
|
76819
77149
|
notAfter: this.notAfter,
|
|
@@ -76825,11 +77155,11 @@ class Certificate {
|
|
|
76825
77155
|
issuerDN: fromDNSequence(this.issuerDNSet),
|
|
76826
77156
|
$hash: this.hash(),
|
|
76827
77157
|
...additionalFields
|
|
76828
|
-
});
|
|
77158
|
+
}));
|
|
76829
77159
|
}
|
|
76830
77160
|
}
|
|
76831
77161
|
exports.Certificate = Certificate;
|
|
76832
|
-
_Certificate_raw = new WeakMap(), _Certificate_hash = new WeakMap(), _Certificate_extensionsRaw = new WeakMap(), _Certificate_extensionsProcessed = new WeakMap(), _Certificate_finalizeConstructionCalled = new WeakMap(), _Certificate_instances = new WeakSet(), _Certificate_processExtensionsInternal = function _Certificate_processExtensionsInternal(extensions, processedSet, handleExtension) {
|
|
77162
|
+
_Certificate_raw = new WeakMap(), _Certificate_hash = new WeakMap(), _Certificate_extensionsRaw = new WeakMap(), _Certificate_extensionsProcessed = new WeakMap(), _Certificate_finalizeConstructionCalled = new WeakMap(), _Certificate_isSelfSigned = new WeakMap(), _Certificate_instances = new WeakSet(), _Certificate_processExtensionsInternal = function _Certificate_processExtensionsInternal(extensions, processedSet, handleExtension) {
|
|
76833
77163
|
if (extensions === undefined) {
|
|
76834
77164
|
return;
|
|
76835
77165
|
}
|
|
@@ -76869,6 +77199,32 @@ _Certificate_raw = new WeakMap(), _Certificate_hash = new WeakMap(), _Certificat
|
|
|
76869
77199
|
seenExtensions.add(id);
|
|
76870
77200
|
}
|
|
76871
77201
|
__classPrivateFieldGet(this, _Certificate_instances, "m", _Certificate_processExtensionsInternal).call(this, extensions, __classPrivateFieldGet(this, _Certificate_extensionsProcessed, "f"), __classPrivateFieldGet(this, _Certificate_instances, "m", _Certificate_processBaseExtension).bind(this));
|
|
77202
|
+
}, _Certificate_parseKeyUsage = function _Certificate_parseKeyUsage(buffer, unusedBits = 0) {
|
|
77203
|
+
const result = {};
|
|
77204
|
+
let bitIndex = 0;
|
|
77205
|
+
for (let byteIndex = 0; byteIndex < buffer.length; byteIndex++) {
|
|
77206
|
+
const byte = buffer[byteIndex];
|
|
77207
|
+
let bitsToRead = 8;
|
|
77208
|
+
// If it's the last byte, subtract unused bits
|
|
77209
|
+
if (byteIndex === buffer.length - 1 && unusedBits > 0) {
|
|
77210
|
+
bitsToRead -= unusedBits;
|
|
77211
|
+
}
|
|
77212
|
+
for (let bit = 7; bit >= 8 - bitsToRead; bit--) {
|
|
77213
|
+
if (bitIndex >= keyUsageBits.length) {
|
|
77214
|
+
break;
|
|
77215
|
+
}
|
|
77216
|
+
const usageName = keyUsageBits[bitIndex];
|
|
77217
|
+
const isSet = (byte & (1 << bit)) !== 0;
|
|
77218
|
+
result[usageName] = isSet;
|
|
77219
|
+
bitIndex++;
|
|
77220
|
+
}
|
|
77221
|
+
}
|
|
77222
|
+
// Fill in remaining with false
|
|
77223
|
+
while (bitIndex < keyUsageBits.length) {
|
|
77224
|
+
result[keyUsageBits[bitIndex]] = false;
|
|
77225
|
+
bitIndex++;
|
|
77226
|
+
}
|
|
77227
|
+
return (result);
|
|
76872
77228
|
}, _Certificate_processBaseExtension = function _Certificate_processBaseExtension(id, value) {
|
|
76873
77229
|
if (this.baseExtensions === undefined) {
|
|
76874
77230
|
throw (new Error('internal error: baseExtensions not defined'));
|
|
@@ -76887,9 +77243,12 @@ _Certificate_raw = new WeakMap(), _Certificate_hash = new WeakMap(), _Certificat
|
|
|
76887
77243
|
return (true);
|
|
76888
77244
|
}
|
|
76889
77245
|
/** Extension: Key Usage */
|
|
76890
|
-
case '2.5.29.15':
|
|
77246
|
+
case '2.5.29.15': {
|
|
76891
77247
|
/* XXX:TODO */
|
|
77248
|
+
const bits = new ASN1.BufferStorageASN1(value, ASN1.ValidateASN1.IsBitString).getASN1();
|
|
77249
|
+
this.baseExtensions.keyUsage = __classPrivateFieldGet(this, _Certificate_instances, "m", _Certificate_parseKeyUsage).call(this, bits.value, bits.unusedBits);
|
|
76892
77250
|
return (true);
|
|
77251
|
+
}
|
|
76893
77252
|
/** Extension: Authority Key Identifier */
|
|
76894
77253
|
case '2.5.29.35':
|
|
76895
77254
|
this.baseExtensions.authorityKeyIdentifier = new ASN1.BufferStorageASN1(value, [{ choice: [
|
|
@@ -76981,13 +77340,22 @@ _Certificate_raw = new WeakMap(), _Certificate_hash = new WeakMap(), _Certificat
|
|
|
76981
77340
|
* Verify that the issuer has the authority to issue the
|
|
76982
77341
|
* certificate (basic constraints)
|
|
76983
77342
|
*/
|
|
76984
|
-
|
|
77343
|
+
if (issuer.baseExtensions?.basicConstraints === undefined) {
|
|
77344
|
+
return ({ issued: false, reason: 'Issuer certificate lacks the ability to sign certificates (missing basicConstraints)' });
|
|
77345
|
+
}
|
|
77346
|
+
if (!issuer.baseExtensions.basicConstraints[0]) {
|
|
77347
|
+
return ({ issued: false, reason: 'Issuer certificate lacks the ability to sign certificates (basicConstraints is false)' });
|
|
77348
|
+
}
|
|
76985
77349
|
/**
|
|
76986
77350
|
* If the key usage extension is present, then check that the
|
|
76987
77351
|
* issuer key usage is consistent with the certificate being
|
|
76988
77352
|
* a CA
|
|
76989
77353
|
*/
|
|
76990
77354
|
/* XXX:TODO */
|
|
77355
|
+
const keyUsage = issuer.baseExtensions?.keyUsage;
|
|
77356
|
+
if (keyUsage && !keyUsage.keyCertSign) {
|
|
77357
|
+
return ({ issued: false, reason: `CA certificate missing keyCertSign in keyUsage` });
|
|
77358
|
+
}
|
|
76991
77359
|
/**
|
|
76992
77360
|
* Verify the signature
|
|
76993
77361
|
*/
|
|
@@ -78301,7 +78669,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
78301
78669
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
78302
78670
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
78303
78671
|
};
|
|
78304
|
-
var _VoteBlockHashMap_instances, _VoteBlockHashMap_valueMap, _VoteBlockHashMap_keyMap, _VoteBlockHashMap_getLookupKey, _a, _VoteLikeBase_vote, _VoteLikeBase_options, _VoteLikeBase__hash, _VoteLikeBase__blocksHash, _VoteBlockBundle_value, _VoteBlockBundle_valueCompressed, _VoteBlockBundle__hash, _VoteBlockBundle__blocksHash, _BaseVoteBuilder_account, _BaseVoteBuilder_blocks, _BaseVoteBuilder_fee;
|
|
78672
|
+
var _VoteBlockHashMap_instances, _VoteBlockHashMap_valueMap, _VoteBlockHashMap_keyMap, _VoteBlockHashMap_getLookupKey, _a, _VoteLikeBase_vote, _VoteLikeBase_options, _VoteLikeBase__hash, _VoteLikeBase__blocksHash, _VoteBlockBundle_instances, _VoteBlockBundle_value, _VoteBlockBundle_valueCompressed, _VoteBlockBundle__hash, _VoteBlockBundle__blocksHash, _VoteBlockBundle__blockHashes, _VoteBlockBundle__votes, _VoteBlockBundle__blocks, _VoteBlockBundle__touchedAccounts, _VoteBlockBundle_votesRaw, _VoteBlockBundle_blocksRaw, _VoteBlockBundle_options, _VoteBlockBundle__asn1Validated, _VoteBlockBundle__blocksAndVotesRaw_get, _VoteBlockBundle__blocksRaw_get, _VoteBlockBundle__votesRaw_get, _VoteBlockBundle_blockHashes_get, _BaseVoteBuilder_account, _BaseVoteBuilder_blocks, _BaseVoteBuilder_fee;
|
|
78305
78673
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
78306
78674
|
exports.Testing = exports.VoteQuoteBuilder = exports.VoteBuilder = exports.BaseVoteBuilder = exports.VoteStaple = exports.VoteBlockBundle = exports.VoteQuote = exports.Vote = exports.PossiblyExpiredVote = exports.VoteBlockHash = exports.VoteBlockHashMap = void 0;
|
|
78307
78675
|
/*
|
|
@@ -78316,9 +78684,11 @@ const account_1 = __importStar(__webpack_require__(9415));
|
|
|
78316
78684
|
const asn1_1 = __webpack_require__(6045);
|
|
78317
78685
|
const helper_1 = __webpack_require__(3208);
|
|
78318
78686
|
const zlib_1 = __importDefault(__webpack_require__(3106));
|
|
78687
|
+
const conversion_1 = __webpack_require__(2360);
|
|
78319
78688
|
const buffer_1 = __webpack_require__(3310);
|
|
78320
78689
|
const util_1 = __webpack_require__(9023);
|
|
78321
78690
|
const vote_1 = __importDefault(__webpack_require__(3689));
|
|
78691
|
+
const effects_1 = __webpack_require__(7346);
|
|
78322
78692
|
class VoteHash extends buffer_1.BufferStorage {
|
|
78323
78693
|
constructor(blockhash) {
|
|
78324
78694
|
super(blockhash, 32);
|
|
@@ -79051,7 +79421,7 @@ class VoteLikeBase {
|
|
|
79051
79421
|
if (this.quote !== undefined) {
|
|
79052
79422
|
additionalFields['quote'] = this.quote;
|
|
79053
79423
|
}
|
|
79054
|
-
return ({
|
|
79424
|
+
return ((0, conversion_1.toJSONSerializable)({
|
|
79055
79425
|
issuer: this.issuer,
|
|
79056
79426
|
serial: this.serial,
|
|
79057
79427
|
blocks: this.blocks,
|
|
@@ -79063,7 +79433,7 @@ class VoteLikeBase {
|
|
|
79063
79433
|
$uid: this.$uid,
|
|
79064
79434
|
$id: this.$id,
|
|
79065
79435
|
...additionalFields
|
|
79066
|
-
});
|
|
79436
|
+
}));
|
|
79067
79437
|
}
|
|
79068
79438
|
expirationCheckMoment() {
|
|
79069
79439
|
let now;
|
|
@@ -79209,7 +79579,16 @@ class VoteBlockBundle {
|
|
|
79209
79579
|
]);
|
|
79210
79580
|
const buffer = Buffer.from(encoded.toBER(false));
|
|
79211
79581
|
const compressedBuffer = zlib_1.default.deflateSync(buffer);
|
|
79212
|
-
return (new this(compressedBuffer,
|
|
79582
|
+
return (new this(compressedBuffer, {
|
|
79583
|
+
trustedValues: {
|
|
79584
|
+
blocksMap: Object.fromEntries(blocks.map(function (block) {
|
|
79585
|
+
return ([block.hash.toString(), block]);
|
|
79586
|
+
})),
|
|
79587
|
+
blocks: blocksOrdered,
|
|
79588
|
+
votes: votesOrdered
|
|
79589
|
+
},
|
|
79590
|
+
...voteOptions
|
|
79591
|
+
}));
|
|
79213
79592
|
}
|
|
79214
79593
|
/**
|
|
79215
79594
|
* Convert a list of Votes and Blocks into a VoteStaple
|
|
@@ -79341,10 +79720,39 @@ class VoteBlockBundle {
|
|
|
79341
79720
|
* Construct a new staple from a message buffer
|
|
79342
79721
|
*/
|
|
79343
79722
|
constructor(votesStapled, voteOptions = {}) {
|
|
79723
|
+
_VoteBlockBundle_instances.add(this);
|
|
79344
79724
|
_VoteBlockBundle_value.set(this, void 0);
|
|
79345
79725
|
_VoteBlockBundle_valueCompressed.set(this, void 0);
|
|
79346
79726
|
_VoteBlockBundle__hash.set(this, void 0);
|
|
79347
79727
|
_VoteBlockBundle__blocksHash.set(this, void 0);
|
|
79728
|
+
_VoteBlockBundle__blockHashes.set(this, void 0);
|
|
79729
|
+
_VoteBlockBundle__votes.set(this, void 0);
|
|
79730
|
+
_VoteBlockBundle__blocks.set(this, void 0);
|
|
79731
|
+
_VoteBlockBundle__touchedAccounts.set(this, void 0);
|
|
79732
|
+
_VoteBlockBundle_votesRaw.set(this, void 0);
|
|
79733
|
+
_VoteBlockBundle_blocksRaw.set(this, void 0);
|
|
79734
|
+
_VoteBlockBundle_options.set(this, void 0);
|
|
79735
|
+
_VoteBlockBundle__asn1Validated.set(this, false);
|
|
79736
|
+
this._votesValidated = false;
|
|
79737
|
+
if (voteOptions.trustedValues?.blocksMap) {
|
|
79738
|
+
__classPrivateFieldSet(this, _VoteBlockBundle__blockHashes, voteOptions.trustedValues.blocksMap, "f");
|
|
79739
|
+
}
|
|
79740
|
+
if (voteOptions.trustedValues?.blocks) {
|
|
79741
|
+
__classPrivateFieldSet(this, _VoteBlockBundle__blocks, voteOptions.trustedValues.blocks, "f");
|
|
79742
|
+
if (__classPrivateFieldGet(this, _VoteBlockBundle__blocks, "f") && __classPrivateFieldGet(this, _VoteBlockBundle__blocks, "f").length === 0) {
|
|
79743
|
+
throw (new vote_1.default('VOTE_STAPLE_INVALID_CONSTRUCTION', 'Vote Staples must contain at least one block'));
|
|
79744
|
+
}
|
|
79745
|
+
}
|
|
79746
|
+
if (voteOptions.trustedValues?.votes) {
|
|
79747
|
+
__classPrivateFieldSet(this, _VoteBlockBundle__votes, voteOptions.trustedValues.votes, "f");
|
|
79748
|
+
if (__classPrivateFieldGet(this, _VoteBlockBundle__votes, "f") && __classPrivateFieldGet(this, _VoteBlockBundle__votes, "f").length === 0) {
|
|
79749
|
+
throw (new vote_1.default('VOTE_STAPLE_INVALID_CONSTRUCTION', 'Vote Staples must contain at least one vote'));
|
|
79750
|
+
}
|
|
79751
|
+
}
|
|
79752
|
+
if (voteOptions.trustedValues?.touchedAccounts) {
|
|
79753
|
+
__classPrivateFieldSet(this, _VoteBlockBundle__touchedAccounts, voteOptions.trustedValues.touchedAccounts, "f");
|
|
79754
|
+
}
|
|
79755
|
+
__classPrivateFieldSet(this, _VoteBlockBundle_options, voteOptions, "f");
|
|
79348
79756
|
if (typeof votesStapled === 'string') {
|
|
79349
79757
|
votesStapled = Buffer.from(votesStapled, 'base64');
|
|
79350
79758
|
}
|
|
@@ -79376,83 +79784,21 @@ class VoteBlockBundle {
|
|
|
79376
79784
|
__classPrivateFieldSet(this, _VoteBlockBundle_value, votesStapled, "f");
|
|
79377
79785
|
}
|
|
79378
79786
|
/**
|
|
79379
|
-
*
|
|
79787
|
+
* Force evaluation of votes and blocks unless lazy loading is specified
|
|
79380
79788
|
*/
|
|
79381
|
-
|
|
79382
|
-
|
|
79383
|
-
|
|
79384
|
-
|
|
79385
|
-
if (data.length !== 2) {
|
|
79386
|
-
throw (new vote_1.default('VOTE_MALFORMED_STAPLE', 'Vote staple must contain exactly 2 elements (votes, and blocks)'));
|
|
79387
|
-
}
|
|
79388
|
-
const [blocksRaw, votesRaw] = data;
|
|
79389
|
-
if (!Array.isArray(blocksRaw) || !Array.isArray(votesRaw)) {
|
|
79390
|
-
throw (new vote_1.default('VOTE_MALFORMED_STAPLE', 'Vote staple must contain exactly 2 elements (votes, and blocks)'));
|
|
79391
|
-
}
|
|
79392
|
-
if (blocksRaw.length < 1) {
|
|
79393
|
-
throw (new vote_1.default('VOTE_MALFORMED_STAPLE_BLOCKS_AT_LEAST_ONE', 'There must be at least 1 block'));
|
|
79394
|
-
}
|
|
79395
|
-
/**
|
|
79396
|
-
* List of blocks
|
|
79397
|
-
*/
|
|
79398
|
-
const blocksUnsorted = blocksRaw.map(function (blockData) {
|
|
79399
|
-
if (!(Buffer.isBuffer(blockData))) {
|
|
79400
|
-
throw (new vote_1.default('VOTE_MALFORMED_STAPLE_BLOCKS', 'Each block must be an Octet String'));
|
|
79401
|
-
}
|
|
79402
|
-
return (new block_1.Block(blockData));
|
|
79403
|
-
});
|
|
79404
|
-
if (votesRaw.length < 1) {
|
|
79405
|
-
throw (new vote_1.default('VOTE_MALFORMED_STAPLE_VOTES_AT_LEAST_ONE', 'There must be at least one vote'));
|
|
79406
|
-
}
|
|
79407
|
-
/**
|
|
79408
|
-
* Get a list of every block hash
|
|
79409
|
-
*/
|
|
79410
|
-
const blockHashes = {};
|
|
79411
|
-
for (const block of blocksUnsorted) {
|
|
79412
|
-
blockHashes[block.hash.toString()] = block;
|
|
79413
|
-
}
|
|
79414
|
-
/*
|
|
79415
|
-
* Ensure blocks are sorted the same way as the vote
|
|
79416
|
-
*/
|
|
79417
|
-
this.votes = votesRaw.map(function (voteData) {
|
|
79418
|
-
if (!(Buffer.isBuffer(voteData))) {
|
|
79419
|
-
throw (new vote_1.default('VOTE_MALFORMED_STAPLE_VOTES', 'Each vote must be an Octet String'));
|
|
79420
|
-
}
|
|
79421
|
-
const vote = new Vote(voteData, voteOptions);
|
|
79422
|
-
if (vote.blocks.length !== blocksUnsorted.length) {
|
|
79423
|
-
throw (new vote_1.default('VOTE_STAPLE_ALL_VOTES_MUST_HAVE_SAME_BLOCKS_COUNT', `Each vote must vote on the exact set of blocks being stapled (same number) (vote: ${vote.blocks.length}; blocks: ${blocksUnsorted.length})`));
|
|
79424
|
-
}
|
|
79425
|
-
for (const voteBlockHash of vote.blocks) {
|
|
79426
|
-
const voteBlockHashCheck = blockHashes[voteBlockHash.toString()];
|
|
79427
|
-
if (voteBlockHashCheck === undefined) {
|
|
79428
|
-
throw (new vote_1.default('VOTE_STAPLE_ALL_VOTES_MUST_HAVE_SAME_BLOCKS_MISSING', `Each vote must be on the exact set of blocks being stapled (missing ${voteBlockHash.toString()})`));
|
|
79429
|
-
}
|
|
79430
|
-
}
|
|
79431
|
-
return (vote);
|
|
79432
|
-
});
|
|
79433
|
-
/**
|
|
79434
|
-
* Order blocks by the vote ordering
|
|
79435
|
-
*/
|
|
79436
|
-
this.blocks = this.votes[0].blocks.map(function (blockHash) {
|
|
79437
|
-
return (blockHashes[blockHash.toString()]);
|
|
79438
|
-
});
|
|
79439
|
-
/**
|
|
79440
|
-
* Ensure every vote has the block hashes in the same order
|
|
79441
|
-
*/
|
|
79442
|
-
for (const vote of this.votes) {
|
|
79443
|
-
for (let blockHashIndex = 0; blockHashIndex < vote.blocks.length; blockHashIndex++) {
|
|
79444
|
-
const voteBlockHash = vote.blocks[blockHashIndex];
|
|
79445
|
-
const stapleBlockHash = this.blocks[blockHashIndex];
|
|
79446
|
-
if (voteBlockHash.toString() !== stapleBlockHash.hash.toString()) {
|
|
79447
|
-
throw (new vote_1.default('VOTE_STAPLE_ALL_VOTES_MUST_HAVE_SAME_BLOCKS_ORDER', 'All votes must list blocks in the same order'));
|
|
79448
|
-
}
|
|
79449
|
-
}
|
|
79789
|
+
if (voteOptions.lazy !== true) {
|
|
79790
|
+
void this.votes;
|
|
79791
|
+
void this.blocks;
|
|
79792
|
+
void __classPrivateFieldGet(this, _VoteBlockBundle_instances, "a", _VoteBlockBundle__blocksAndVotesRaw_get);
|
|
79450
79793
|
}
|
|
79451
79794
|
}
|
|
79452
79795
|
/**
|
|
79453
79796
|
* Get the serialized version
|
|
79454
79797
|
*/
|
|
79455
79798
|
toBytes(uncompressed) {
|
|
79799
|
+
if (!__classPrivateFieldGet(this, _VoteBlockBundle__asn1Validated, "f")) {
|
|
79800
|
+
void __classPrivateFieldGet(this, _VoteBlockBundle_instances, "a", _VoteBlockBundle__blocksAndVotesRaw_get);
|
|
79801
|
+
}
|
|
79456
79802
|
if (uncompressed) {
|
|
79457
79803
|
return (__classPrivateFieldGet(this, _VoteBlockBundle_value, "f"));
|
|
79458
79804
|
}
|
|
@@ -79471,7 +79817,7 @@ class VoteBlockBundle {
|
|
|
79471
79817
|
*/
|
|
79472
79818
|
get hash() {
|
|
79473
79819
|
if (!__classPrivateFieldGet(this, _VoteBlockBundle__hash, "f")) {
|
|
79474
|
-
const canonicalVoteStaple = VoteBlockBundle.fromVotesAndBlocks(this.votes, this.blocks);
|
|
79820
|
+
const canonicalVoteStaple = VoteBlockBundle.fromVotesAndBlocks(this.votes, this.blocks, { lazy: true });
|
|
79475
79821
|
const hash = (0, hash_1.Hash)(Buffer.from(canonicalVoteStaple.toBytes(true)));
|
|
79476
79822
|
__classPrivateFieldSet(this, _VoteBlockBundle__hash, new VoteStapleHash(hash), "f");
|
|
79477
79823
|
}
|
|
@@ -79536,21 +79882,163 @@ class VoteBlockBundle {
|
|
|
79536
79882
|
...additionalFields
|
|
79537
79883
|
});
|
|
79538
79884
|
}
|
|
79885
|
+
get votes() {
|
|
79886
|
+
if (__classPrivateFieldGet(this, _VoteBlockBundle__votes, "f") !== undefined && this._votesValidated) {
|
|
79887
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle__votes, "f"));
|
|
79888
|
+
}
|
|
79889
|
+
const voteOptions = __classPrivateFieldGet(this, _VoteBlockBundle_options, "f");
|
|
79890
|
+
const blocksUnsorted = Object.values(__classPrivateFieldGet(this, _VoteBlockBundle_instances, "a", _VoteBlockBundle_blockHashes_get));
|
|
79891
|
+
/*
|
|
79892
|
+
* If votes are already known, use them otherwise parse from raw data
|
|
79893
|
+
*/
|
|
79894
|
+
const newVotes = __classPrivateFieldGet(this, _VoteBlockBundle__votes, "f") ?? __classPrivateFieldGet(this, _VoteBlockBundle_instances, "a", _VoteBlockBundle__votesRaw_get).map((voteData) => {
|
|
79895
|
+
if (!(Buffer.isBuffer(voteData))) {
|
|
79896
|
+
throw (new vote_1.default('VOTE_MALFORMED_STAPLE_VOTES', 'Each vote must be an Octet String'));
|
|
79897
|
+
}
|
|
79898
|
+
const vote = new Vote(voteData, voteOptions);
|
|
79899
|
+
return (vote);
|
|
79900
|
+
});
|
|
79901
|
+
/**
|
|
79902
|
+
* Validate each vote and ensure they all vote on the same block hashes in order
|
|
79903
|
+
*/
|
|
79904
|
+
let stapleBlockHashes;
|
|
79905
|
+
for (const vote of newVotes) {
|
|
79906
|
+
if (vote.blocks.length !== blocksUnsorted.length) {
|
|
79907
|
+
throw (new vote_1.default('VOTE_STAPLE_ALL_VOTES_MUST_HAVE_SAME_BLOCKS_COUNT', `Each vote must vote on the exact set of blocks being stapled (same number) (vote: ${vote.blocks.length}; blocks: ${blocksUnsorted.length})`));
|
|
79908
|
+
}
|
|
79909
|
+
for (const voteBlockHash of vote.blocks) {
|
|
79910
|
+
const voteBlockHashCheck = __classPrivateFieldGet(this, _VoteBlockBundle_instances, "a", _VoteBlockBundle_blockHashes_get)[voteBlockHash.toString()];
|
|
79911
|
+
if (voteBlockHashCheck === undefined) {
|
|
79912
|
+
throw (new vote_1.default('VOTE_STAPLE_ALL_VOTES_MUST_HAVE_SAME_BLOCKS_MISSING', `Each vote must be on the exact set of blocks being stapled (missing ${voteBlockHash.toString()})`));
|
|
79913
|
+
}
|
|
79914
|
+
}
|
|
79915
|
+
if (stapleBlockHashes === undefined) {
|
|
79916
|
+
stapleBlockHashes = vote.blocks;
|
|
79917
|
+
continue;
|
|
79918
|
+
}
|
|
79919
|
+
for (let blockHashIndex = 0; blockHashIndex < vote.blocks.length; blockHashIndex++) {
|
|
79920
|
+
const voteBlocksHash = vote.blocks[blockHashIndex];
|
|
79921
|
+
const stapleBlockHash = stapleBlockHashes[blockHashIndex];
|
|
79922
|
+
if (voteBlocksHash.toString() !== stapleBlockHash.toString()) {
|
|
79923
|
+
throw (new vote_1.default('VOTE_STAPLE_ALL_VOTES_MUST_HAVE_SAME_BLOCKS_ORDER', 'All votes must list blocks in the same order'));
|
|
79924
|
+
}
|
|
79925
|
+
}
|
|
79926
|
+
}
|
|
79927
|
+
__classPrivateFieldSet(this, _VoteBlockBundle__votes, newVotes, "f");
|
|
79928
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle__votes, "f"));
|
|
79929
|
+
}
|
|
79930
|
+
get blocks() {
|
|
79931
|
+
if (__classPrivateFieldGet(this, _VoteBlockBundle__blocks, "f") !== undefined && this._votesValidated) {
|
|
79932
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle__blocks, "f"));
|
|
79933
|
+
}
|
|
79934
|
+
/**
|
|
79935
|
+
* Order blocks by the vote ordering
|
|
79936
|
+
*/
|
|
79937
|
+
__classPrivateFieldSet(this, _VoteBlockBundle__blocks, this.votes[0].blocks.map((blockHash) => {
|
|
79938
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle_instances, "a", _VoteBlockBundle_blockHashes_get)[blockHash.toString()]);
|
|
79939
|
+
}), "f");
|
|
79940
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle__blocks, "f"));
|
|
79941
|
+
}
|
|
79942
|
+
get touchedAccounts() {
|
|
79943
|
+
if (__classPrivateFieldGet(this, _VoteBlockBundle__touchedAccounts, "f") !== undefined) {
|
|
79944
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle__touchedAccounts, "f"));
|
|
79945
|
+
}
|
|
79946
|
+
const { touched } = (0, effects_1.computeEffectOfBlocks)(this.blocks);
|
|
79947
|
+
__classPrivateFieldSet(this, _VoteBlockBundle__touchedAccounts, touched, "f");
|
|
79948
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle__touchedAccounts, "f"));
|
|
79949
|
+
}
|
|
79539
79950
|
}
|
|
79540
79951
|
exports.VoteBlockBundle = VoteBlockBundle;
|
|
79541
|
-
_VoteBlockBundle_value = new WeakMap(), _VoteBlockBundle_valueCompressed = new WeakMap(), _VoteBlockBundle__hash = new WeakMap(), _VoteBlockBundle__blocksHash = new WeakMap()
|
|
79952
|
+
_VoteBlockBundle_value = new WeakMap(), _VoteBlockBundle_valueCompressed = new WeakMap(), _VoteBlockBundle__hash = new WeakMap(), _VoteBlockBundle__blocksHash = new WeakMap(), _VoteBlockBundle__blockHashes = new WeakMap(), _VoteBlockBundle__votes = new WeakMap(), _VoteBlockBundle__blocks = new WeakMap(), _VoteBlockBundle__touchedAccounts = new WeakMap(), _VoteBlockBundle_votesRaw = new WeakMap(), _VoteBlockBundle_blocksRaw = new WeakMap(), _VoteBlockBundle_options = new WeakMap(), _VoteBlockBundle__asn1Validated = new WeakMap(), _VoteBlockBundle_instances = new WeakSet(), _VoteBlockBundle__blocksAndVotesRaw_get = function _VoteBlockBundle__blocksAndVotesRaw_get() {
|
|
79953
|
+
/**
|
|
79954
|
+
* Parse BER encoded data into objects
|
|
79955
|
+
*/
|
|
79956
|
+
const data = (0, asn1_1.ASN1toJS)(__classPrivateFieldGet(this, _VoteBlockBundle_value, "f"));
|
|
79957
|
+
if (!Array.isArray(data)) {
|
|
79958
|
+
throw (new vote_1.default('VOTE_MALFORMED_STAPLE', 'Vote staple must be a Sequence'));
|
|
79959
|
+
}
|
|
79960
|
+
if (data.length !== 2) {
|
|
79961
|
+
throw (new vote_1.default('VOTE_MALFORMED_STAPLE', 'Vote staple must contain exactly 2 elements (votes, and blocks)'));
|
|
79962
|
+
}
|
|
79963
|
+
const [blocksRaw, votesRaw] = data;
|
|
79964
|
+
if (!Array.isArray(blocksRaw) || !Array.isArray(votesRaw)) {
|
|
79965
|
+
throw (new vote_1.default('VOTE_MALFORMED_STAPLE', 'Vote staple must contain exactly 2 elements (votes, and blocks)'));
|
|
79966
|
+
}
|
|
79967
|
+
if (blocksRaw.length < 1) {
|
|
79968
|
+
throw (new vote_1.default('VOTE_MALFORMED_STAPLE_BLOCKS_AT_LEAST_ONE', 'There must be at least 1 block'));
|
|
79969
|
+
}
|
|
79970
|
+
if (votesRaw.length < 1) {
|
|
79971
|
+
throw (new vote_1.default('VOTE_MALFORMED_STAPLE_VOTES_AT_LEAST_ONE', 'There must be at least one vote'));
|
|
79972
|
+
}
|
|
79973
|
+
__classPrivateFieldSet(this, _VoteBlockBundle_votesRaw, votesRaw, "f");
|
|
79974
|
+
__classPrivateFieldSet(this, _VoteBlockBundle_blocksRaw, blocksRaw, "f");
|
|
79975
|
+
__classPrivateFieldSet(this, _VoteBlockBundle__asn1Validated, true, "f");
|
|
79976
|
+
return ({
|
|
79977
|
+
blocksRaw: __classPrivateFieldGet(this, _VoteBlockBundle_blocksRaw, "f"),
|
|
79978
|
+
votesRaw: __classPrivateFieldGet(this, _VoteBlockBundle_votesRaw, "f")
|
|
79979
|
+
});
|
|
79980
|
+
}, _VoteBlockBundle__blocksRaw_get = function _VoteBlockBundle__blocksRaw_get() {
|
|
79981
|
+
if (__classPrivateFieldGet(this, _VoteBlockBundle_blocksRaw, "f") !== undefined) {
|
|
79982
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle_blocksRaw, "f"));
|
|
79983
|
+
}
|
|
79984
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle_instances, "a", _VoteBlockBundle__blocksAndVotesRaw_get).blocksRaw);
|
|
79985
|
+
}, _VoteBlockBundle__votesRaw_get = function _VoteBlockBundle__votesRaw_get() {
|
|
79986
|
+
if (__classPrivateFieldGet(this, _VoteBlockBundle_votesRaw, "f") !== undefined) {
|
|
79987
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle_votesRaw, "f"));
|
|
79988
|
+
}
|
|
79989
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle_instances, "a", _VoteBlockBundle__blocksAndVotesRaw_get).votesRaw);
|
|
79990
|
+
}, _VoteBlockBundle_blockHashes_get = function _VoteBlockBundle_blockHashes_get() {
|
|
79991
|
+
if (__classPrivateFieldGet(this, _VoteBlockBundle__blockHashes, "f") !== undefined) {
|
|
79992
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle__blockHashes, "f"));
|
|
79993
|
+
}
|
|
79994
|
+
/**
|
|
79995
|
+
* List of blocks
|
|
79996
|
+
* If blocks are already known, use them otherwise parse from raw data
|
|
79997
|
+
*/
|
|
79998
|
+
let blocksUnsorted = [];
|
|
79999
|
+
if (__classPrivateFieldGet(this, _VoteBlockBundle__blocks, "f") !== undefined) {
|
|
80000
|
+
blocksUnsorted = __classPrivateFieldGet(this, _VoteBlockBundle__blocks, "f");
|
|
80001
|
+
}
|
|
80002
|
+
else {
|
|
80003
|
+
blocksUnsorted = __classPrivateFieldGet(this, _VoteBlockBundle_instances, "a", _VoteBlockBundle__blocksRaw_get).map(function (blockData) {
|
|
80004
|
+
if (!(Buffer.isBuffer(blockData))) {
|
|
80005
|
+
throw (new vote_1.default('VOTE_MALFORMED_STAPLE_BLOCKS', 'Each block must be an Octet String'));
|
|
80006
|
+
}
|
|
80007
|
+
return (new block_1.Block(blockData));
|
|
80008
|
+
});
|
|
80009
|
+
}
|
|
80010
|
+
/**
|
|
80011
|
+
* Get a list of every block hash
|
|
80012
|
+
*/
|
|
80013
|
+
const blockHashes = {};
|
|
80014
|
+
for (const block of blocksUnsorted) {
|
|
80015
|
+
blockHashes[block.hash.toString()] = block;
|
|
80016
|
+
}
|
|
80017
|
+
__classPrivateFieldSet(this, _VoteBlockBundle__blockHashes, blockHashes, "f");
|
|
80018
|
+
return (__classPrivateFieldGet(this, _VoteBlockBundle__blockHashes, "f"));
|
|
80019
|
+
};
|
|
79542
80020
|
VoteBlockBundle.VoteBlockHash = VoteBlockHash;
|
|
79543
80021
|
VoteBlockBundle.isInstance = (0, helper_1.checkableGenerator)(VoteBlockBundle);
|
|
79544
80022
|
class VoteStaple extends VoteBlockBundle {
|
|
79545
80023
|
constructor(votesStapled, voteOptions = {}) {
|
|
79546
80024
|
super(votesStapled, voteOptions);
|
|
80025
|
+
if (voteOptions.lazy !== true) {
|
|
80026
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
80027
|
+
this.votes;
|
|
80028
|
+
}
|
|
80029
|
+
}
|
|
80030
|
+
get votes() {
|
|
80031
|
+
const votes = super.votes;
|
|
80032
|
+
if (this._votesValidated) {
|
|
80033
|
+
return (votes);
|
|
80034
|
+
}
|
|
79547
80035
|
/**
|
|
79548
80036
|
* Ensure no representative has more than 1 vote in the bundle
|
|
79549
80037
|
* and that every vote has the same level of permanence
|
|
79550
80038
|
*/
|
|
79551
80039
|
const seenReps = new account_1.default.Set();
|
|
79552
80040
|
let votesPermanence = undefined;
|
|
79553
|
-
for (const vote of
|
|
80041
|
+
for (const vote of votes) {
|
|
79554
80042
|
if (seenReps.has(vote.issuer)) {
|
|
79555
80043
|
throw (new vote_1.default('VOTE_STAPLE_DUPLICATE_VOTE_ISSUER', `Unable to parse vote information since account ${vote.issuer.publicKeyString.get()} has voted more than once`));
|
|
79556
80044
|
}
|
|
@@ -79562,6 +80050,8 @@ class VoteStaple extends VoteBlockBundle {
|
|
|
79562
80050
|
throw (new vote_1.default('VOTE_STAPLE_PERMANENCE_MISMATCH', `Only votes with permanent set to ${votesPermanence} are permissible in a bundle, however we found a vote that expires on ${vote.validityTo.toISOString()}`));
|
|
79563
80051
|
}
|
|
79564
80052
|
}
|
|
80053
|
+
this._votesValidated = true;
|
|
80054
|
+
return (votes);
|
|
79565
80055
|
}
|
|
79566
80056
|
}
|
|
79567
80057
|
exports.VoteStaple = VoteStaple;
|
|
@@ -79882,7 +80372,7 @@ exports.Testing = { findRDN, blockHashesFromVote, feeFromVote };
|
|
|
79882
80372
|
|
|
79883
80373
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
79884
80374
|
exports.version = void 0;
|
|
79885
|
-
exports.version = '0.
|
|
80375
|
+
exports.version = '0.16.0+g906ddd004c65d7e5d33559183bed9119e681c5ae';
|
|
79886
80376
|
exports["default"] = exports.version;
|
|
79887
80377
|
|
|
79888
80378
|
|