@keetanetwork/keetanet-client 0.14.10 → 0.14.12
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/index-browser.js +695 -20
- package/client/index.js +609 -16
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BaseSet.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BaseVoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperation.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationCREATE_IDENTIFIER.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMANAGE_CERTIFICATE.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMODIFY_PERMISSIONS.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationRECEIVE.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSEND.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_INFO.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_REP.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_MODIFY_BALANCE.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_SUPPLY.html +1 -1
- 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 +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1PublicKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1Signature.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PrivateKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PublicKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1Signature.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519PrivateKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519PublicKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519Signature.html +1 -1
- 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 +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.IdentifierKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.IdentifierKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetError.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetErrorBase.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerError.html +2 -2
- 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 +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.Log.html +6 -4
- package/docs/classes/KeetaNetSDK.Referenced.PermissionSetHolder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.PossiblyExpiredVote.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.RequestTiming.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.SignatureStorage.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.Stats.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.StatsPending.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteBlockBundle.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteLikeBase.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteQuoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteStapleHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.html +32 -4
- package/docs/classes/KeetaNetSDK.Referenced.src_lib_utils_buffer.BufferStorage.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 +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATE.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATESerializable.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMODIFY_PERMISSIONS.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationRECEIVE.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSEND.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_INFO.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_REP.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_MODIFY_BALANCE.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_SUPPLY.html +1 -1
- 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.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.Logger.html +4 -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.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.PublicKeyStorage.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.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_asn1.ValidateASN1.html +1 -1
- package/docs/modules/KeetaNetSDK.Referenced.src_lib_utils_helper.html +1 -1
- package/docs/types/KeetaNetSDK.Referenced.BasicSchemaMapJS.html +14 -0
- package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.Schema.html +1 -1
- package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.SchemaMap.html +1 -1
- package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.SchemaMapJS.html +5 -0
- package/docs/variables/KeetaNetSDK.Referenced.FullLedgerBaseErrorCode.html +1 -1
- package/docs/variables/KeetaNetSDK.Referenced.allFullErrorCodes.html +1 -1
- package/docs/variables/KeetaNetSDK.Referenced.src_lib_utils_helper.crypto.html +1 -1
- package/docs/variables/KeetaNetSDK.Referenced.src_lib_utils_helper.util.html +1 -0
- package/lib/error/index.d.ts +1 -1
- package/lib/error/ledger.d.ts +3 -3
- package/lib/kv/kv_redis.d.ts +3 -3
- package/lib/log/common.d.ts +4 -0
- package/lib/log/index.d.ts +6 -2
- package/lib/log/target_gcp.d.ts +1 -1
- package/lib/log/target_gcp.js +2 -2
- package/lib/node/timing.d.ts +4 -3
- package/lib/utils/asn1.d.ts +139 -5
- package/lib/utils/helper.d.ts +7 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/version.d.ts +1 -1
package/client/index-browser.js
CHANGED
|
@@ -101243,6 +101243,7 @@ __webpack_require__.d(client_helper_namespaceObject, {
|
|
|
101243
101243
|
randomInt: () => (client_randomInt),
|
|
101244
101244
|
randomString: () => (client_randomString),
|
|
101245
101245
|
setGenerator: () => (client_setGenerator),
|
|
101246
|
+
util: () => (client_helper_util),
|
|
101246
101247
|
validateBase64ToBuffer: () => (client_validateBase64ToBuffer),
|
|
101247
101248
|
waitTicks: () => (client_waitTicks)
|
|
101248
101249
|
});
|
|
@@ -105947,7 +105948,13 @@ const client_helper_crypto = {
|
|
|
105947
105948
|
randomUUID: client_helper_randomUUID,
|
|
105948
105949
|
randomBytes: client_helper_randomBytes,
|
|
105949
105950
|
createCipheriv: client_crypto_default().createCipheriv.bind((client_crypto_default())),
|
|
105950
|
-
createDecipheriv: client_crypto_default().createDecipheriv.bind((client_crypto_default()))
|
|
105951
|
+
createDecipheriv: client_crypto_default().createDecipheriv.bind((client_crypto_default())),
|
|
105952
|
+
createHash: client_crypto_default().createHash.bind((client_crypto_default())),
|
|
105953
|
+
createHmac: client_crypto_default().createHmac.bind((client_crypto_default()))
|
|
105954
|
+
};
|
|
105955
|
+
const client_helper_util = {
|
|
105956
|
+
inspect: client_util.inspect,
|
|
105957
|
+
types: client_util.types
|
|
105951
105958
|
};
|
|
105952
105959
|
;// ./node_modules/rfc4648/lib/rfc4648.js
|
|
105953
105960
|
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
|
@@ -113837,7 +113844,8 @@ var client_schema = /*#__PURE__*/new WeakMap();
|
|
|
113837
113844
|
* - {@link ValidateASN1.IsNull}
|
|
113838
113845
|
*
|
|
113839
113846
|
* More complex types are defined as:
|
|
113840
|
-
* - Choice: `{ choice:
|
|
113847
|
+
* - Choice (named): `{ choice: { name1: schema1, name2: schema2, ... } }` - Converts to `{ name1: value }` or `{ name2: value }`
|
|
113848
|
+
* - Choice (legacy array): `{ choice: [ schema1, schema2, ... ] }` - Converts to union type (ambiguous for re-encoding)
|
|
113841
113849
|
* - Sequence of: `{ sequenceOf: schema }`
|
|
113842
113850
|
* - Optional: `{ optional: schema }`
|
|
113843
113851
|
* - Context Tag: `{ type: 'context'; kind: 'implicit' | 'explicit'; contains: schema; value: number }`
|
|
@@ -114190,6 +114198,7 @@ class client_ValidateASN1 {
|
|
|
114190
114198
|
{
|
|
114191
114199
|
const outputStruct = {
|
|
114192
114200
|
type: 'struct',
|
|
114201
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114193
114202
|
fieldNames: schema.fieldNames,
|
|
114194
114203
|
contains: {}
|
|
114195
114204
|
};
|
|
@@ -114221,6 +114230,49 @@ class client_ValidateASN1 {
|
|
|
114221
114230
|
client_assertNever(schema);
|
|
114222
114231
|
}
|
|
114223
114232
|
} else if ('choice' in schema) {
|
|
114233
|
+
// Handle named choices: { choice: { a: schema1, b: schema2 } }
|
|
114234
|
+
if (!Array.isArray(schema.choice)) {
|
|
114235
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114236
|
+
const choiceObj = schema.choice;
|
|
114237
|
+
|
|
114238
|
+
// For context tags, match by value and kind
|
|
114239
|
+
if (client_isASN1ContextTag(input)) {
|
|
114240
|
+
const inputAsChoice = input;
|
|
114241
|
+
for (const choiceName in choiceObj) {
|
|
114242
|
+
const choice = choiceObj[choiceName];
|
|
114243
|
+
if (choice === undefined) {
|
|
114244
|
+
continue;
|
|
114245
|
+
}
|
|
114246
|
+
if (!client_isASN1ContextTag(choice)) {
|
|
114247
|
+
continue;
|
|
114248
|
+
}
|
|
114249
|
+
if (choice.value !== inputAsChoice.value) {
|
|
114250
|
+
continue;
|
|
114251
|
+
}
|
|
114252
|
+
if (choice.kind !== inputAsChoice.kind) {
|
|
114253
|
+
continue;
|
|
114254
|
+
}
|
|
114255
|
+
return client_ValidateASN1.againstSchema(input, choice);
|
|
114256
|
+
}
|
|
114257
|
+
throw new Error('No valid choice found');
|
|
114258
|
+
}
|
|
114259
|
+
|
|
114260
|
+
// Try each choice
|
|
114261
|
+
for (const choiceName in choiceObj) {
|
|
114262
|
+
const choice = choiceObj[choiceName];
|
|
114263
|
+
if (choice === undefined) {
|
|
114264
|
+
continue;
|
|
114265
|
+
}
|
|
114266
|
+
try {
|
|
114267
|
+
return client_ValidateASN1.againstSchema(input, choice);
|
|
114268
|
+
} catch (_ignored_checkError) {
|
|
114269
|
+
/* Ignored error */
|
|
114270
|
+
}
|
|
114271
|
+
}
|
|
114272
|
+
throw new Error('No valid choice found');
|
|
114273
|
+
}
|
|
114274
|
+
|
|
114275
|
+
// Handle array choices (legacy)
|
|
114224
114276
|
if (client_isASN1ContextTag(input)) {
|
|
114225
114277
|
const inputAsChoice = input;
|
|
114226
114278
|
const matchingSchema = schema.choice.find(function (choice) {
|
|
@@ -114242,7 +114294,6 @@ class client_ValidateASN1 {
|
|
|
114242
114294
|
}
|
|
114243
114295
|
for (const choice of schema.choice) {
|
|
114244
114296
|
try {
|
|
114245
|
-
// @ts-ignore
|
|
114246
114297
|
return client_ValidateASN1.againstSchema(input, choice);
|
|
114247
114298
|
} catch (_ignored_checkError) {
|
|
114248
114299
|
/* Ignored error */
|
|
@@ -114332,6 +114383,578 @@ class client_ValidateASN1 {
|
|
|
114332
114383
|
validate(input) {
|
|
114333
114384
|
return client_ValidateASN1.againstSchema(input, client_asn1_classPrivateFieldGet(client_schema, this));
|
|
114334
114385
|
}
|
|
114386
|
+
|
|
114387
|
+
/**
|
|
114388
|
+
* Convert an ASN.1 object to a JavaScript object (including primitives)
|
|
114389
|
+
* based on the schema.
|
|
114390
|
+
*
|
|
114391
|
+
* Converts ASN1 objects to plain JavaScript objects according to the schema:
|
|
114392
|
+
* - Structs are converted to plain objects with field names as keys
|
|
114393
|
+
* - For ambiguous types (IsAnyString, IsAnyDate), returns ASN.1-like objects: { type: 'string', kind: 'utf8', value: 'text' }
|
|
114394
|
+
* - Arrays/sequences are preserved as arrays
|
|
114395
|
+
* - Primitive types (bigint, string, boolean, null, Buffer, Date) are preserved
|
|
114396
|
+
*
|
|
114397
|
+
* Example schema: { type: 'struct', fieldNames: ['name', 'age'], contains: { name: ValidateASN1.IsAnyString, age: ValidateASN1.IsInteger } }
|
|
114398
|
+
* Input: { type: 'struct', fieldNames: ['name', 'age'], contains: { name: { type: 'string', kind: 'utf8', value: 'John Doe' }, age: 30n } }
|
|
114399
|
+
* Output: { name: { type: 'string', kind: 'utf8', value: 'John Doe' }, age: 30n }
|
|
114400
|
+
*/
|
|
114401
|
+
toJavaScriptObject(input) {
|
|
114402
|
+
this.validate(input);
|
|
114403
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114404
|
+
return client_ValidateASN1.toPlainObject(input, client_asn1_classPrivateFieldGet(client_schema, this));
|
|
114405
|
+
}
|
|
114406
|
+
|
|
114407
|
+
/**
|
|
114408
|
+
* Convert a plain JavaScript object back to an ASN.1 object based on the schema.
|
|
114409
|
+
*
|
|
114410
|
+
* Converts plain JavaScript objects back to ASN1 representation according to the schema:
|
|
114411
|
+
* - Plain objects with field names are converted to ASN1Struct
|
|
114412
|
+
* - For ambiguous schemas, recognizes ASN.1-like objects: { type: 'string', kind: 'utf8', value: 'text' }
|
|
114413
|
+
* - Arrays are preserved as sequences
|
|
114414
|
+
* - Primitive types are preserved or wrapped in appropriate ASN1 types
|
|
114415
|
+
*
|
|
114416
|
+
* Example schema: { type: 'struct', fieldNames: ['name', 'age'], contains: { name: ValidateASN1.IsAnyString, age: ValidateASN1.IsInteger } }
|
|
114417
|
+
* Input: { name: { type: 'string', kind: 'utf8', value: 'John Doe' }, age: 30n }
|
|
114418
|
+
* Output: { type: 'struct', fieldNames: ['name', 'age'], contains: { name: { type: 'string', kind: 'utf8', value: 'John Doe' }, age: 30n } }
|
|
114419
|
+
*/
|
|
114420
|
+
fromJavaScriptObject(input) {
|
|
114421
|
+
const retval = client_ValidateASN1.fromPlainObject(input, client_asn1_classPrivateFieldGet(client_schema, this));
|
|
114422
|
+
this.validate(retval);
|
|
114423
|
+
return retval;
|
|
114424
|
+
}
|
|
114425
|
+
|
|
114426
|
+
/**
|
|
114427
|
+
* Convert an ASN.1 object to a plain JavaScript object based on a schema
|
|
114428
|
+
*/
|
|
114429
|
+
static toPlainObject(input, schemaIn) {
|
|
114430
|
+
let schema = schemaIn;
|
|
114431
|
+
if (typeof schema === 'function') {
|
|
114432
|
+
schema = schema();
|
|
114433
|
+
}
|
|
114434
|
+
|
|
114435
|
+
// Handle choice schemas first (before primitive checks)
|
|
114436
|
+
// This ensures named choices wrap their values correctly
|
|
114437
|
+
if (typeof schema === 'object' && schema !== null && 'choice' in schema) {
|
|
114438
|
+
// Handle named choices: { choice: { a: schema1, b: schema2 } }
|
|
114439
|
+
if (!Array.isArray(schema.choice)) {
|
|
114440
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114441
|
+
const choiceObj = schema.choice;
|
|
114442
|
+
for (const choiceName in choiceObj) {
|
|
114443
|
+
const choiceSchema = choiceObj[choiceName];
|
|
114444
|
+
if (choiceSchema === undefined) {
|
|
114445
|
+
continue;
|
|
114446
|
+
}
|
|
114447
|
+
try {
|
|
114448
|
+
// Validate that the input matches this choice schema
|
|
114449
|
+
client_ValidateASN1.againstSchema(input, choiceSchema);
|
|
114450
|
+
// If validation passes, convert and wrap in named object
|
|
114451
|
+
const converted = client_ValidateASN1.toPlainObject(input, choiceSchema);
|
|
114452
|
+
return {
|
|
114453
|
+
[choiceName]: converted
|
|
114454
|
+
};
|
|
114455
|
+
} catch {
|
|
114456
|
+
// Try next choice
|
|
114457
|
+
}
|
|
114458
|
+
}
|
|
114459
|
+
throw new Error('No valid choice found');
|
|
114460
|
+
}
|
|
114461
|
+
|
|
114462
|
+
// Handle array choices (legacy): { choice: [schema1, schema2] }
|
|
114463
|
+
// For choices, recursively convert the selected choice
|
|
114464
|
+
for (const choice of schema.choice) {
|
|
114465
|
+
try {
|
|
114466
|
+
return client_ValidateASN1.toPlainObject(input, choice);
|
|
114467
|
+
} catch {
|
|
114468
|
+
// Try next choice
|
|
114469
|
+
}
|
|
114470
|
+
}
|
|
114471
|
+
throw new Error('No valid choice found');
|
|
114472
|
+
}
|
|
114473
|
+
|
|
114474
|
+
// Handle primitives that don't need conversion
|
|
114475
|
+
if (typeof input === 'bigint' || typeof input === 'boolean' || input === null || client_isBuffer(input) || client_util.types.isDate(input)) {
|
|
114476
|
+
return input;
|
|
114477
|
+
}
|
|
114478
|
+
|
|
114479
|
+
// Handle plain strings
|
|
114480
|
+
if (typeof input === 'string') {
|
|
114481
|
+
return input;
|
|
114482
|
+
}
|
|
114483
|
+
|
|
114484
|
+
// Handle basic schema types
|
|
114485
|
+
if (typeof schema === 'symbol') {
|
|
114486
|
+
switch (schema) {
|
|
114487
|
+
case client_ValidateASN1.IsInteger:
|
|
114488
|
+
case client_ValidateASN1.IsBoolean:
|
|
114489
|
+
case client_ValidateASN1.IsNull:
|
|
114490
|
+
case client_ValidateASN1.IsOctetString:
|
|
114491
|
+
case client_ValidateASN1.IsString:
|
|
114492
|
+
case client_ValidateASN1.IsDate:
|
|
114493
|
+
return input;
|
|
114494
|
+
case client_ValidateASN1.IsAnyString:
|
|
114495
|
+
if (client_isASN1String(input)) {
|
|
114496
|
+
// For ambiguous schemas, return ASN.1-like object
|
|
114497
|
+
return {
|
|
114498
|
+
type: 'string',
|
|
114499
|
+
kind: input.kind,
|
|
114500
|
+
value: input.value
|
|
114501
|
+
};
|
|
114502
|
+
}
|
|
114503
|
+
return input;
|
|
114504
|
+
case client_ValidateASN1.IsAnyDate:
|
|
114505
|
+
if (client_isASN1Date(input)) {
|
|
114506
|
+
// For ambiguous schemas, return ASN.1-like object
|
|
114507
|
+
return {
|
|
114508
|
+
type: 'date',
|
|
114509
|
+
kind: input.kind,
|
|
114510
|
+
value: input.date
|
|
114511
|
+
};
|
|
114512
|
+
}
|
|
114513
|
+
return input;
|
|
114514
|
+
case client_ValidateASN1.IsBitString:
|
|
114515
|
+
if (client_isASN1BitString(input)) {
|
|
114516
|
+
// Use expanded form to preserve unusedBits information
|
|
114517
|
+
// This distinguishes between bit strings like 111 and 0111
|
|
114518
|
+
return {
|
|
114519
|
+
type: 'bitstring',
|
|
114520
|
+
value: input.value,
|
|
114521
|
+
unusedBits: input.unusedBits
|
|
114522
|
+
};
|
|
114523
|
+
}
|
|
114524
|
+
return input;
|
|
114525
|
+
case client_ValidateASN1.IsOID:
|
|
114526
|
+
if (client_isASN1OID(input)) {
|
|
114527
|
+
return input.oid;
|
|
114528
|
+
}
|
|
114529
|
+
return input;
|
|
114530
|
+
case client_ValidateASN1.IsSet:
|
|
114531
|
+
return input;
|
|
114532
|
+
case client_ValidateASN1.IsAny:
|
|
114533
|
+
case client_ValidateASN1.IsUnknown:
|
|
114534
|
+
return input;
|
|
114535
|
+
}
|
|
114536
|
+
}
|
|
114537
|
+
|
|
114538
|
+
// Handle bigint schema (fixed value)
|
|
114539
|
+
if (typeof schema === 'bigint') {
|
|
114540
|
+
return input;
|
|
114541
|
+
}
|
|
114542
|
+
|
|
114543
|
+
// Handle object schemas
|
|
114544
|
+
if (typeof schema === 'object' && schema !== null) {
|
|
114545
|
+
if ('type' in schema) {
|
|
114546
|
+
switch (schema.type) {
|
|
114547
|
+
case 'struct':
|
|
114548
|
+
{
|
|
114549
|
+
if (!client_isASN1Struct(input)) {
|
|
114550
|
+
throw new Error('Expected ASN1Struct');
|
|
114551
|
+
}
|
|
114552
|
+
const result = {};
|
|
114553
|
+
for (const fieldName of schema.fieldNames) {
|
|
114554
|
+
const fieldValue = input.contains[fieldName];
|
|
114555
|
+
if (fieldValue === undefined) {
|
|
114556
|
+
continue;
|
|
114557
|
+
}
|
|
114558
|
+
const fieldSchema = schema.contains[fieldName];
|
|
114559
|
+
if (client_isASN1ContextTag(fieldValue)) {
|
|
114560
|
+
// Context tags are metadata like optional - unwrap them completely
|
|
114561
|
+
// Need to unwrap optional and get the context tag schema
|
|
114562
|
+
let contextSchema = fieldSchema;
|
|
114563
|
+
if (typeof contextSchema === 'object' && contextSchema !== null && 'optional' in contextSchema) {
|
|
114564
|
+
contextSchema = contextSchema.optional;
|
|
114565
|
+
}
|
|
114566
|
+
|
|
114567
|
+
// For implicit context tags with ArrayBuffer, can't convert further
|
|
114568
|
+
if (fieldValue.kind === 'implicit' && client_util.types.isArrayBuffer(fieldValue.contains)) {
|
|
114569
|
+
result[fieldName] = fieldValue.contains;
|
|
114570
|
+
} else if (typeof contextSchema === 'object' && contextSchema !== null && 'type' in contextSchema && contextSchema.type === 'context' && 'contains' in contextSchema) {
|
|
114571
|
+
// Unwrap the context tag - just convert the inner value
|
|
114572
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114573
|
+
result[fieldName] = client_ValidateASN1.toPlainObject(fieldValue.contains, contextSchema.contains);
|
|
114574
|
+
} else {
|
|
114575
|
+
// Fallback: convert the inner value with full field schema
|
|
114576
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114577
|
+
result[fieldName] = client_ValidateASN1.toPlainObject(fieldValue.contains, fieldSchema);
|
|
114578
|
+
}
|
|
114579
|
+
} else {
|
|
114580
|
+
// For all other types (including strings and dates), recursively convert
|
|
114581
|
+
const plainValue = client_ValidateASN1.toPlainObject(fieldValue, fieldSchema);
|
|
114582
|
+
result[fieldName] = plainValue;
|
|
114583
|
+
}
|
|
114584
|
+
}
|
|
114585
|
+
return result;
|
|
114586
|
+
}
|
|
114587
|
+
case 'string':
|
|
114588
|
+
if (client_isASN1String(input)) {
|
|
114589
|
+
return input.value;
|
|
114590
|
+
}
|
|
114591
|
+
return input;
|
|
114592
|
+
case 'date':
|
|
114593
|
+
if (client_isASN1Date(input)) {
|
|
114594
|
+
return input.date;
|
|
114595
|
+
}
|
|
114596
|
+
return input;
|
|
114597
|
+
case 'oid':
|
|
114598
|
+
if (client_isASN1OID(input)) {
|
|
114599
|
+
return input.oid;
|
|
114600
|
+
}
|
|
114601
|
+
return input;
|
|
114602
|
+
case 'context':
|
|
114603
|
+
if (client_isASN1ContextTag(input)) {
|
|
114604
|
+
// For implicit context tags with ArrayBuffer, we can't convert further
|
|
114605
|
+
if (input.kind === 'implicit' && client_util.types.isArrayBuffer(input.contains)) {
|
|
114606
|
+
return input.contains;
|
|
114607
|
+
}
|
|
114608
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114609
|
+
return client_ValidateASN1.toPlainObject(input.contains, schema.contains);
|
|
114610
|
+
}
|
|
114611
|
+
return input;
|
|
114612
|
+
}
|
|
114613
|
+
}
|
|
114614
|
+
if ('sequenceOf' in schema) {
|
|
114615
|
+
if (!Array.isArray(input)) {
|
|
114616
|
+
throw new Error('Expected array for sequenceOf');
|
|
114617
|
+
}
|
|
114618
|
+
return input.map(item => client_ValidateASN1.toPlainObject(item, schema.sequenceOf));
|
|
114619
|
+
}
|
|
114620
|
+
if ('optional' in schema) {
|
|
114621
|
+
if (input === undefined) {
|
|
114622
|
+
return undefined;
|
|
114623
|
+
}
|
|
114624
|
+
return client_ValidateASN1.toPlainObject(input, schema.optional);
|
|
114625
|
+
}
|
|
114626
|
+
if (Array.isArray(schema)) {
|
|
114627
|
+
if (!Array.isArray(input)) {
|
|
114628
|
+
throw new Error('Expected array');
|
|
114629
|
+
}
|
|
114630
|
+
const result = [];
|
|
114631
|
+
for (let i = 0; i < Math.min(input.length, schema.length); i++) {
|
|
114632
|
+
const item = input[i];
|
|
114633
|
+
if (item === undefined) {
|
|
114634
|
+
result.push(undefined);
|
|
114635
|
+
} else {
|
|
114636
|
+
result.push(client_ValidateASN1.toPlainObject(item, schema[i]));
|
|
114637
|
+
}
|
|
114638
|
+
}
|
|
114639
|
+
return result;
|
|
114640
|
+
}
|
|
114641
|
+
}
|
|
114642
|
+
return input;
|
|
114643
|
+
}
|
|
114644
|
+
|
|
114645
|
+
/**
|
|
114646
|
+
* Convert a plain JavaScript object to an ASN.1 object based on a schema
|
|
114647
|
+
*/
|
|
114648
|
+
static fromPlainObject(input, schemaIn) {
|
|
114649
|
+
let schema = schemaIn;
|
|
114650
|
+
if (typeof schema === 'function') {
|
|
114651
|
+
schema = schema();
|
|
114652
|
+
}
|
|
114653
|
+
|
|
114654
|
+
// Handle null/undefined
|
|
114655
|
+
if (input === null || input === undefined) {
|
|
114656
|
+
/* Verify that the schema for this is actually is nullable */
|
|
114657
|
+
let nullable = false;
|
|
114658
|
+
if (schema === client_ValidateASN1.IsNull) {
|
|
114659
|
+
nullable = true;
|
|
114660
|
+
} else if (typeof schema === 'object' && schema !== null) {
|
|
114661
|
+
if ('optional' in schema) {
|
|
114662
|
+
nullable = true;
|
|
114663
|
+
}
|
|
114664
|
+
}
|
|
114665
|
+
if (!nullable) {
|
|
114666
|
+
throw new Error(`Expected non-null value, got ${input}`);
|
|
114667
|
+
}
|
|
114668
|
+
|
|
114669
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114670
|
+
return input;
|
|
114671
|
+
}
|
|
114672
|
+
|
|
114673
|
+
// For ambiguous schemas (IsAnyString, IsAnyDate), check if input is already in ASN.1-like format
|
|
114674
|
+
// These are objects like { type: 'string', kind: 'utf8', value: 'text' } or { type: 'date', kind: 'general', value: Date }
|
|
114675
|
+
// Also handle expanded bitstring format: { type: 'bitstring', value: Buffer, unusedBits: number }
|
|
114676
|
+
if (typeof input === 'object' && input !== null && !client_isBuffer(input) && !client_util.types.isDate(input) && !Array.isArray(input)) {
|
|
114677
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114678
|
+
const inputObj = input;
|
|
114679
|
+
|
|
114680
|
+
// Check for string-like format: { type: 'string', kind, value }
|
|
114681
|
+
if (inputObj.type === 'string' && typeof inputObj.kind === 'string' && 'value' in inputObj) {
|
|
114682
|
+
const kind = inputObj.kind;
|
|
114683
|
+
if (kind === 'printable' || kind === 'ia5' || kind === 'utf8') {
|
|
114684
|
+
if (typeof inputObj.value === 'string') {
|
|
114685
|
+
return {
|
|
114686
|
+
type: 'string',
|
|
114687
|
+
kind,
|
|
114688
|
+
value: inputObj.value
|
|
114689
|
+
};
|
|
114690
|
+
}
|
|
114691
|
+
}
|
|
114692
|
+
}
|
|
114693
|
+
|
|
114694
|
+
// Check for date-like format: { type: 'date', kind, value }
|
|
114695
|
+
if (inputObj.type === 'date' && typeof inputObj.kind === 'string' && 'value' in inputObj) {
|
|
114696
|
+
const kind = inputObj.kind;
|
|
114697
|
+
if (kind === 'utc' || kind === 'general') {
|
|
114698
|
+
if (client_util.types.isDate(inputObj.value)) {
|
|
114699
|
+
return {
|
|
114700
|
+
type: 'date',
|
|
114701
|
+
kind,
|
|
114702
|
+
date: inputObj.value
|
|
114703
|
+
};
|
|
114704
|
+
}
|
|
114705
|
+
}
|
|
114706
|
+
}
|
|
114707
|
+
|
|
114708
|
+
// Check for bitstring format: { type: 'bitstring', value, unusedBits }
|
|
114709
|
+
if (inputObj.type === 'bitstring' && 'value' in inputObj && 'unusedBits' in inputObj) {
|
|
114710
|
+
if (client_isBuffer(inputObj.value) && typeof inputObj.unusedBits === 'number') {
|
|
114711
|
+
return {
|
|
114712
|
+
type: 'bitstring',
|
|
114713
|
+
value: inputObj.value,
|
|
114714
|
+
unusedBits: inputObj.unusedBits
|
|
114715
|
+
};
|
|
114716
|
+
}
|
|
114717
|
+
}
|
|
114718
|
+
}
|
|
114719
|
+
|
|
114720
|
+
// Check schema FIRST before doing any primitive handling
|
|
114721
|
+
// This is important for context tags and other wrappers
|
|
114722
|
+
|
|
114723
|
+
// Handle object schemas
|
|
114724
|
+
if (typeof schema === 'object' && schema !== null) {
|
|
114725
|
+
if ('type' in schema) {
|
|
114726
|
+
switch (schema.type) {
|
|
114727
|
+
case 'context':
|
|
114728
|
+
{
|
|
114729
|
+
// Context tags: reconstruct from schema definition (metadata like optional)
|
|
114730
|
+
// Schema has the kind and value, input is the plain value
|
|
114731
|
+
// At this point we know schema.type === 'context', so it must have kind, value, contains
|
|
114732
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114733
|
+
const contextTagSchema = schema;
|
|
114734
|
+
return {
|
|
114735
|
+
type: 'context',
|
|
114736
|
+
kind: contextTagSchema.kind,
|
|
114737
|
+
value: contextTagSchema.value,
|
|
114738
|
+
contains: client_ValidateASN1.fromPlainObject(input, contextTagSchema.contains)
|
|
114739
|
+
};
|
|
114740
|
+
}
|
|
114741
|
+
case 'struct':
|
|
114742
|
+
{
|
|
114743
|
+
if (typeof input !== 'object' || input === null) {
|
|
114744
|
+
throw new Error('Expected object for struct');
|
|
114745
|
+
}
|
|
114746
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114747
|
+
const inputObj = input;
|
|
114748
|
+
const result = {
|
|
114749
|
+
type: 'struct',
|
|
114750
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114751
|
+
fieldNames: schema.fieldNames,
|
|
114752
|
+
contains: {}
|
|
114753
|
+
};
|
|
114754
|
+
for (const fieldName of schema.fieldNames) {
|
|
114755
|
+
const fieldValue = inputObj[fieldName];
|
|
114756
|
+
if (fieldValue === undefined) {
|
|
114757
|
+
continue;
|
|
114758
|
+
}
|
|
114759
|
+
const fieldSchema = schema.contains[fieldName];
|
|
114760
|
+
result.contains[fieldName] = client_ValidateASN1.fromPlainObject(fieldValue, fieldSchema);
|
|
114761
|
+
}
|
|
114762
|
+
return result;
|
|
114763
|
+
}
|
|
114764
|
+
case 'string':
|
|
114765
|
+
if (typeof input === 'string') {
|
|
114766
|
+
return {
|
|
114767
|
+
type: 'string',
|
|
114768
|
+
kind: schema.kind,
|
|
114769
|
+
value: input
|
|
114770
|
+
};
|
|
114771
|
+
}
|
|
114772
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114773
|
+
return input;
|
|
114774
|
+
case 'date':
|
|
114775
|
+
if (client_util.types.isDate(input)) {
|
|
114776
|
+
return {
|
|
114777
|
+
type: 'date',
|
|
114778
|
+
kind: schema.kind,
|
|
114779
|
+
date: input
|
|
114780
|
+
};
|
|
114781
|
+
}
|
|
114782
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114783
|
+
return input;
|
|
114784
|
+
case 'oid':
|
|
114785
|
+
if (typeof input === 'string') {
|
|
114786
|
+
return {
|
|
114787
|
+
type: 'oid',
|
|
114788
|
+
oid: input
|
|
114789
|
+
};
|
|
114790
|
+
}
|
|
114791
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114792
|
+
return input;
|
|
114793
|
+
}
|
|
114794
|
+
}
|
|
114795
|
+
if ('choice' in schema) {
|
|
114796
|
+
// Handle named choices: { choice: { a: schema1, b: schema2 } }
|
|
114797
|
+
if (!Array.isArray(schema.choice)) {
|
|
114798
|
+
if (typeof input === 'object' && input !== null && !client_isBuffer(input) && !client_util.types.isDate(input)) {
|
|
114799
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114800
|
+
const inputObj = input;
|
|
114801
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114802
|
+
const choiceObj = schema.choice;
|
|
114803
|
+
|
|
114804
|
+
// Find which choice name is present in the input
|
|
114805
|
+
for (const choiceName in choiceObj) {
|
|
114806
|
+
if (choiceName in inputObj) {
|
|
114807
|
+
const choiceSchema = choiceObj[choiceName];
|
|
114808
|
+
if (choiceSchema === undefined) {
|
|
114809
|
+
continue;
|
|
114810
|
+
}
|
|
114811
|
+
const choiceValue = inputObj[choiceName];
|
|
114812
|
+
return client_ValidateASN1.fromPlainObject(choiceValue, choiceSchema);
|
|
114813
|
+
}
|
|
114814
|
+
}
|
|
114815
|
+
}
|
|
114816
|
+
throw new Error('No valid choice found for input - expected object with one of: ' + Object.keys(schema.choice).join(', '));
|
|
114817
|
+
}
|
|
114818
|
+
|
|
114819
|
+
// Handle array choices (legacy): { choice: [schema1, schema2] }
|
|
114820
|
+
// For choices, try to convert with each choice schema
|
|
114821
|
+
for (const choice of schema.choice) {
|
|
114822
|
+
try {
|
|
114823
|
+
return client_ValidateASN1.fromPlainObject(input, choice);
|
|
114824
|
+
} catch {
|
|
114825
|
+
// Try next choice
|
|
114826
|
+
}
|
|
114827
|
+
}
|
|
114828
|
+
throw new Error('No valid choice found for input');
|
|
114829
|
+
}
|
|
114830
|
+
if ('sequenceOf' in schema) {
|
|
114831
|
+
if (!Array.isArray(input)) {
|
|
114832
|
+
throw new Error('Expected array for sequenceOf');
|
|
114833
|
+
}
|
|
114834
|
+
return input.map(item => client_ValidateASN1.fromPlainObject(item, schema.sequenceOf));
|
|
114835
|
+
}
|
|
114836
|
+
if ('optional' in schema) {
|
|
114837
|
+
return client_ValidateASN1.fromPlainObject(input, schema.optional);
|
|
114838
|
+
}
|
|
114839
|
+
if (Array.isArray(schema)) {
|
|
114840
|
+
if (!Array.isArray(input)) {
|
|
114841
|
+
throw new Error('Expected array');
|
|
114842
|
+
}
|
|
114843
|
+
const result = [];
|
|
114844
|
+
for (let i = 0; i < schema.length; i++) {
|
|
114845
|
+
if (i < input.length && input[i] !== undefined) {
|
|
114846
|
+
result.push(client_ValidateASN1.fromPlainObject(input[i], schema[i]));
|
|
114847
|
+
} else if (client_isASN1ModifierOptional(schema[i])) {
|
|
114848
|
+
result.push(undefined);
|
|
114849
|
+
} else {
|
|
114850
|
+
throw new Error(`Missing required field at index ${i}`);
|
|
114851
|
+
}
|
|
114852
|
+
}
|
|
114853
|
+
return result;
|
|
114854
|
+
}
|
|
114855
|
+
}
|
|
114856
|
+
|
|
114857
|
+
// Handle symbol schemas (basic types)
|
|
114858
|
+
if (typeof schema === 'symbol') {
|
|
114859
|
+
switch (schema) {
|
|
114860
|
+
case client_ValidateASN1.IsInteger:
|
|
114861
|
+
case client_ValidateASN1.IsBoolean:
|
|
114862
|
+
case client_ValidateASN1.IsNull:
|
|
114863
|
+
case client_ValidateASN1.IsDate:
|
|
114864
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114865
|
+
return input;
|
|
114866
|
+
case client_ValidateASN1.IsOctetString:
|
|
114867
|
+
// OctetString can accept a Buffer directly
|
|
114868
|
+
if (client_isBuffer(input)) {
|
|
114869
|
+
return input;
|
|
114870
|
+
}
|
|
114871
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114872
|
+
return input;
|
|
114873
|
+
case client_ValidateASN1.IsString:
|
|
114874
|
+
if (typeof input === 'string') {
|
|
114875
|
+
return input;
|
|
114876
|
+
}
|
|
114877
|
+
throw new Error('Expected string');
|
|
114878
|
+
case client_ValidateASN1.IsAnyString:
|
|
114879
|
+
if (typeof input === 'string') {
|
|
114880
|
+
// Determine appropriate string kind
|
|
114881
|
+
if (client_isStringValidForKind(input, 'printable')) {
|
|
114882
|
+
return {
|
|
114883
|
+
type: 'string',
|
|
114884
|
+
kind: 'printable',
|
|
114885
|
+
value: input
|
|
114886
|
+
};
|
|
114887
|
+
} else if (client_isStringValidForKind(input, 'ia5')) {
|
|
114888
|
+
return {
|
|
114889
|
+
type: 'string',
|
|
114890
|
+
kind: 'ia5',
|
|
114891
|
+
value: input
|
|
114892
|
+
};
|
|
114893
|
+
} else {
|
|
114894
|
+
return {
|
|
114895
|
+
type: 'string',
|
|
114896
|
+
kind: 'utf8',
|
|
114897
|
+
value: input
|
|
114898
|
+
};
|
|
114899
|
+
}
|
|
114900
|
+
}
|
|
114901
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114902
|
+
return input;
|
|
114903
|
+
case client_ValidateASN1.IsAnyDate:
|
|
114904
|
+
if (client_util.types.isDate(input)) {
|
|
114905
|
+
if (input.getUTCFullYear() < 2050) {
|
|
114906
|
+
return {
|
|
114907
|
+
type: 'date',
|
|
114908
|
+
kind: 'utc',
|
|
114909
|
+
date: input
|
|
114910
|
+
};
|
|
114911
|
+
} else {
|
|
114912
|
+
return {
|
|
114913
|
+
type: 'date',
|
|
114914
|
+
kind: 'general',
|
|
114915
|
+
date: input
|
|
114916
|
+
};
|
|
114917
|
+
}
|
|
114918
|
+
}
|
|
114919
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114920
|
+
return input;
|
|
114921
|
+
case client_ValidateASN1.IsBitString:
|
|
114922
|
+
if (client_isBuffer(input)) {
|
|
114923
|
+
return {
|
|
114924
|
+
type: 'bitstring',
|
|
114925
|
+
value: input,
|
|
114926
|
+
unusedBits: 0
|
|
114927
|
+
};
|
|
114928
|
+
}
|
|
114929
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114930
|
+
return input;
|
|
114931
|
+
case client_ValidateASN1.IsOID:
|
|
114932
|
+
if (typeof input === 'string') {
|
|
114933
|
+
return {
|
|
114934
|
+
type: 'oid',
|
|
114935
|
+
oid: input
|
|
114936
|
+
};
|
|
114937
|
+
}
|
|
114938
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114939
|
+
return input;
|
|
114940
|
+
case client_ValidateASN1.IsSet:
|
|
114941
|
+
case client_ValidateASN1.IsAny:
|
|
114942
|
+
case client_ValidateASN1.IsUnknown:
|
|
114943
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114944
|
+
return input;
|
|
114945
|
+
}
|
|
114946
|
+
}
|
|
114947
|
+
|
|
114948
|
+
// Handle bigint schema (fixed value)
|
|
114949
|
+
if (typeof schema === 'bigint') {
|
|
114950
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114951
|
+
return input;
|
|
114952
|
+
}
|
|
114953
|
+
|
|
114954
|
+
// Default: return input as-is
|
|
114955
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114956
|
+
return input;
|
|
114957
|
+
}
|
|
114335
114958
|
}
|
|
114336
114959
|
|
|
114337
114960
|
/**
|
|
@@ -116914,7 +117537,7 @@ function client_ledger_toPrimitive(t, r) { if ("object" != typeof t || !t) retur
|
|
|
116914
117537
|
const client_LedgerErrorType = 'LEDGER';
|
|
116915
117538
|
const client_LedgerBaseErrorCodes = ['BLOCK_ALREADY_EXISTS', 'BLOCK_EXPIRED', 'TRANSACTION_ABORTED', 'INVALID_CHAIN', 'INVALID_NETWORK', 'INVALID_SUBNET', 'INVALID_PERMISSIONS', 'INVALID_OWNER_COUNT', 'INVALID_BALANCE', 'INVALID_SET_REP', 'OPERATION_NOT_SUPPORTED', 'NOT_EMPTY', 'PREVIOUS_ALREADY_USED', 'PREVIOUS_NOT_SEEN', 'SUCCESSOR_VOTE_EXISTS', 'INSUFFICIENT_VOTING_WEIGHT', 'INVALID_ACCOUNT_INFO_KEY', 'RECEIVE_NOT_MET', 'DUPLICATE_VOTE_FOUND', 'CANNOT_EXCHANGE_PERM_VOTE', 'TEMP_VOTE_INCLUDES_SELF', 'BLOCKS_DIFFER_FROM_VOTED_ON', 'NO_PERM_WITHOUT_SELF_TEMP', 'DUPLICATE_VOTE_ISSUER_FOUND', 'OTHER', 'MISSING_BLOCKS',
|
|
116916
117539
|
// Fee Errors
|
|
116917
|
-
'FEE_AMOUNT_MISMATCH', 'FEE_TOKEN_MISMATCH', 'FEE_MISSING', 'MISSING_REQUIRED_FEE_BLOCK', 'VOTE_WITH_QUOTE', 'QUOTE_MISMATCH', 'REQUIRED_FEE_MISMATCH'];
|
|
117540
|
+
'FEE_AMOUNT_MISMATCH', 'FEE_TOKEN_MISMATCH', 'FEE_MISSING', 'MISSING_REQUIRED_FEE_BLOCK', 'MULTIPLE_FEE_BLOCK', 'VOTE_WITH_QUOTE', 'QUOTE_MISMATCH', 'REQUIRED_FEE_MISMATCH'];
|
|
116918
117541
|
|
|
116919
117542
|
// Errors that can trigger rep sync
|
|
116920
117543
|
const client_LedgerVoteErrorCodes = ['NOT_SUCCESSOR', 'NOT_OPENING'];
|
|
@@ -125599,6 +126222,10 @@ class client_Log {
|
|
|
125599
126222
|
* Register a new logging target (sink) to send logs to
|
|
125600
126223
|
*/
|
|
125601
126224
|
registerTarget(target) {
|
|
126225
|
+
if (client_log_classPrivateFieldGet(client_destroyed, this)) {
|
|
126226
|
+
throw new Error('Cannot register target on destroyed Log instance');
|
|
126227
|
+
}
|
|
126228
|
+
|
|
125602
126229
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
125603
126230
|
const id = Symbol('LogTargetID');
|
|
125604
126231
|
client_log_classPrivateFieldGet(client_targets, this).set(id, target);
|
|
@@ -125620,6 +126247,9 @@ class client_Log {
|
|
|
125620
126247
|
* Unregister a logging target (sink) to stop sending logs to
|
|
125621
126248
|
*/
|
|
125622
126249
|
unregisterTarget(id) {
|
|
126250
|
+
if (client_log_classPrivateFieldGet(client_destroyed, this)) {
|
|
126251
|
+
return;
|
|
126252
|
+
}
|
|
125623
126253
|
client_log_classPrivateFieldGet(client_targets, this).delete(id);
|
|
125624
126254
|
}
|
|
125625
126255
|
|
|
@@ -125637,6 +126267,9 @@ class client_Log {
|
|
|
125637
126267
|
*/
|
|
125638
126268
|
startAutoSync() {
|
|
125639
126269
|
let rate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
|
|
126270
|
+
if (client_log_classPrivateFieldGet(client_destroyed, this)) {
|
|
126271
|
+
throw new Error('Cannot start auto sync on destroyed Log instance');
|
|
126272
|
+
}
|
|
125640
126273
|
this.stopAutoSync();
|
|
125641
126274
|
client_log_classPrivateFieldSet(client_autoSyncInterval, this, setInterval(async () => {
|
|
125642
126275
|
try {
|
|
@@ -125714,6 +126347,15 @@ class client_Log {
|
|
|
125714
126347
|
this.destroy();
|
|
125715
126348
|
}
|
|
125716
126349
|
|
|
126350
|
+
/**
|
|
126351
|
+
* Dispose of the logger instance, syncing all logs, and clearing targets
|
|
126352
|
+
*/
|
|
126353
|
+
async [Symbol.asyncDispose]() {
|
|
126354
|
+
client_log_classPrivateFieldSet(client_destroyed, this, true);
|
|
126355
|
+
await this.sync();
|
|
126356
|
+
this.destroy();
|
|
126357
|
+
}
|
|
126358
|
+
|
|
125717
126359
|
/**
|
|
125718
126360
|
* Terminate the logger instance, clearing all logs and targets
|
|
125719
126361
|
*/
|
|
@@ -125728,6 +126370,9 @@ class client_Log {
|
|
|
125728
126370
|
}
|
|
125729
126371
|
}
|
|
125730
126372
|
function client_log_log(level, options, from) {
|
|
126373
|
+
if (client_log_classPrivateFieldGet(client_destroyed, this)) {
|
|
126374
|
+
return;
|
|
126375
|
+
}
|
|
125731
126376
|
for (var _len6 = arguments.length, args = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
|
|
125732
126377
|
args[_key6 - 3] = arguments[_key6];
|
|
125733
126378
|
}
|
|
@@ -125787,7 +126432,6 @@ function client_timing_classPrivateFieldSet(s, a, r) { return s.set(client_timin
|
|
|
125787
126432
|
function client_timing_classPrivateFieldGet(s, a) { return s.get(client_timing_assertClassBrand(s, a)); }
|
|
125788
126433
|
function client_timing_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
125789
126434
|
|
|
125790
|
-
|
|
125791
126435
|
/**
|
|
125792
126436
|
* Support the old way of doing timing where the callers could call
|
|
125793
126437
|
* startTime/endTime with the same string to terminate a timing section
|
|
@@ -125813,8 +126457,13 @@ class client_RequestTiming {
|
|
|
125813
126457
|
constructor() {
|
|
125814
126458
|
client_timing_classPrivateFieldInitSpec(this, client_timing, new Map());
|
|
125815
126459
|
client_timing_classPrivateFieldInitSpec(this, client_counter, 0);
|
|
125816
|
-
|
|
126460
|
+
if (client_RequestTiming.defaultLogger === '@legacy') {
|
|
126461
|
+
this.log = src_client_log.Legacy();
|
|
126462
|
+
} else {
|
|
126463
|
+
this.log = client_RequestTiming.defaultLogger;
|
|
126464
|
+
}
|
|
125817
126465
|
}
|
|
126466
|
+
|
|
125818
126467
|
/**
|
|
125819
126468
|
* Start timing a section of code
|
|
125820
126469
|
* @param section Name of the section to time -- should be unique within the code base so that it can be identified later
|
|
@@ -125828,12 +126477,17 @@ class client_RequestTiming {
|
|
|
125828
126477
|
start: Date.now()
|
|
125829
126478
|
};
|
|
125830
126479
|
client_timing_classPrivateFieldGet(client_timing, this).set(id, data);
|
|
126480
|
+
let endCalled = false;
|
|
125831
126481
|
return {
|
|
125832
|
-
id,
|
|
126482
|
+
id: id,
|
|
125833
126483
|
end: () => {
|
|
126484
|
+
endCalled = true;
|
|
125834
126485
|
this.endTime(id);
|
|
125835
126486
|
},
|
|
125836
126487
|
[Symbol.dispose]: () => {
|
|
126488
|
+
if (endCalled) {
|
|
126489
|
+
return;
|
|
126490
|
+
}
|
|
125837
126491
|
this.endTime(id);
|
|
125838
126492
|
}
|
|
125839
126493
|
};
|
|
@@ -125852,11 +126506,11 @@ class client_RequestTiming {
|
|
|
125852
126506
|
if (typeof section === 'symbol') {
|
|
125853
126507
|
const timingInfo = client_timing_classPrivateFieldGet(client_timing, this).get(section);
|
|
125854
126508
|
if (timingInfo === undefined) {
|
|
125855
|
-
this.log.error(`Timing section ${String(section)} does not exist but "end" was called on it!`);
|
|
126509
|
+
this.log.error('timing::endTime', `Timing section ${String(section)} does not exist but "end" was called on it!`);
|
|
125856
126510
|
return;
|
|
125857
126511
|
}
|
|
125858
126512
|
if (timingInfo.end !== undefined) {
|
|
125859
|
-
this.log.error(`Timing section ${timingInfo.id} already ended but "end" was called on it again!`);
|
|
126513
|
+
this.log.error('timing::endTime', `Timing section ${timingInfo.id} already ended but "end" was called on it again!`);
|
|
125860
126514
|
return;
|
|
125861
126515
|
}
|
|
125862
126516
|
timingInfo.end = Date.now();
|
|
@@ -125956,7 +126610,7 @@ class client_RequestTiming {
|
|
|
125956
126610
|
return client_timing_classPrivateFieldSet(client_counter, this, (_this$counter = client_timing_classPrivateFieldGet(client_counter, this), _this$counter2 = _this$counter++, _this$counter)), _this$counter2;
|
|
125957
126611
|
}
|
|
125958
126612
|
}
|
|
125959
|
-
client_timing_defineProperty(client_RequestTiming, "defaultLogger",
|
|
126613
|
+
client_timing_defineProperty(client_RequestTiming, "defaultLogger", '@legacy');
|
|
125960
126614
|
/* harmony default export */ const src_client_timing = (client_RequestTiming);
|
|
125961
126615
|
;// ./src/lib/kv/index.ts
|
|
125962
126616
|
function client_kv_defineProperty(e, r, t) { return (r = client_kv_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -126564,6 +127218,9 @@ class client_LedgerAtomicInterface {
|
|
|
126564
127218
|
if (blocks.length === 0) {
|
|
126565
127219
|
throw new client_ledger_KeetaNetLedgerError('LEDGER_MISSING_BLOCKS', 'At least one block is required to issue a vote');
|
|
126566
127220
|
}
|
|
127221
|
+
if (blocks[0].purpose === src_client_Block.Purpose.FEE) {
|
|
127222
|
+
throw new client_ledger_KeetaNetLedgerError('LEDGER_MISSING_BLOCKS', 'First block cannot be a fee block');
|
|
127223
|
+
}
|
|
126567
127224
|
if (!client_ledger_classPrivateFieldGet(client_ledger_privateKey, this)) {
|
|
126568
127225
|
throw new Error('Cannot vote on block, no private key loaded');
|
|
126569
127226
|
}
|
|
@@ -126622,7 +127279,16 @@ class client_LedgerAtomicInterface {
|
|
|
126622
127279
|
const possibleFeeBlock = blocks.at(-1);
|
|
126623
127280
|
if ((possibleFeeBlock === null || possibleFeeBlock === void 0 ? void 0 : possibleFeeBlock.purpose) === client_BlockPurpose.FEE) {
|
|
126624
127281
|
hasFeeBlock = true;
|
|
126625
|
-
|
|
127282
|
+
/**
|
|
127283
|
+
* If permanent votes were provided then all votes should include the fee block
|
|
127284
|
+
* So only decrement block count if otherVotes are all temporary votes
|
|
127285
|
+
*/
|
|
127286
|
+
const otherVotesAllTemporary = !otherVotes.some(function (checkVote) {
|
|
127287
|
+
return checkVote.$permanent;
|
|
127288
|
+
});
|
|
127289
|
+
if (otherVotesAllTemporary) {
|
|
127290
|
+
blockCount--;
|
|
127291
|
+
}
|
|
126626
127292
|
}
|
|
126627
127293
|
const requiredFees = new Map();
|
|
126628
127294
|
for (const checkVote of otherVotes) {
|
|
@@ -126649,13 +127315,9 @@ class client_LedgerAtomicInterface {
|
|
|
126649
127315
|
throw new client_ledger_KeetaNetLedgerError('LEDGER_CANNOT_EXCHANGE_PERM_VOTE', 'Asked to exchange a permanent vote from us for a permanent vote from us');
|
|
126650
127316
|
}
|
|
126651
127317
|
}
|
|
126652
|
-
|
|
126653
|
-
/* XXX:TODO: Need to account for fee blocks if the input is a permanent vote */
|
|
126654
127318
|
let blocksDifferFromVoteBlocks = checkVote.blocks.length !== blockCount;
|
|
126655
|
-
|
|
126656
127319
|
/* If they do not differ from length alone, compare block hashes */
|
|
126657
127320
|
if (!blocksDifferFromVoteBlocks) {
|
|
126658
|
-
/* XXX:TODO: Need to account for fee blocks if the input is a permanent vote */
|
|
126659
127321
|
for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
|
|
126660
127322
|
if (!blocks[blockIndex].hash.compareHexString(checkVote.blocks[blockIndex])) {
|
|
126661
127323
|
blocksDifferFromVoteBlocks = true;
|
|
@@ -127584,7 +128246,15 @@ async function client_validateBlocksForVote(blocks) {
|
|
|
127584
128246
|
const allLedgerHeads = new Map();
|
|
127585
128247
|
const allLedgerIdempotentKeys = new Map();
|
|
127586
128248
|
const allLedgerIdempotentKeysReverse = new Map();
|
|
128249
|
+
let foundFeeBlock = false;
|
|
127587
128250
|
for (const block of blocks) {
|
|
128251
|
+
if (block.purpose === src_client_Block.Purpose.FEE) {
|
|
128252
|
+
if (foundFeeBlock) {
|
|
128253
|
+
throw new client_ledger_KeetaNetLedgerError('LEDGER_MULTIPLE_FEE_BLOCK', 'Should only contain 1 fee block');
|
|
128254
|
+
} else {
|
|
128255
|
+
foundFeeBlock = true;
|
|
128256
|
+
}
|
|
128257
|
+
}
|
|
127588
128258
|
const prevBlockHash = block.previous;
|
|
127589
128259
|
seenBlockHashes.add(block.hash);
|
|
127590
128260
|
if (block.network !== client_ledger_classPrivateFieldGet(client_network, this)) {
|
|
@@ -127641,7 +128311,7 @@ async function client_validateBlocksForVote(blocks) {
|
|
|
127641
128311
|
};
|
|
127642
128312
|
}
|
|
127643
128313
|
async function client_voteOrQuoteWithFees(blocks, type, quote, options) {
|
|
127644
|
-
var _options$requireBlock
|
|
128314
|
+
var _options$requireBlock;
|
|
127645
128315
|
if (client_ledger_classPrivateFieldGet(client_ledger, this).ledgerWriteMode !== 'read-write') {
|
|
127646
128316
|
throw new Error(`May not issue votes in read-only mode, in ${client_ledger_classPrivateFieldGet(client_ledger, this).ledgerWriteMode} mode`);
|
|
127647
128317
|
}
|
|
@@ -127691,10 +128361,15 @@ async function client_voteOrQuoteWithFees(blocks, type, quote, options) {
|
|
|
127691
128361
|
|
|
127692
128362
|
/**
|
|
127693
128363
|
* If a quote was provided use it as the fee, otherwise generate new fee
|
|
128364
|
+
* If we are creating a vote with permanent `otherVotes` then do not include the fee.
|
|
128365
|
+
* TODO - considering changing how fees are handled when recovering
|
|
127694
128366
|
*/
|
|
127695
|
-
|
|
127696
|
-
|
|
127697
|
-
|
|
128367
|
+
if (requireBlockTimestampCheck) {
|
|
128368
|
+
var _quote$fee;
|
|
128369
|
+
const fee = (_quote$fee = quote === null || quote === void 0 ? void 0 : quote.fee) !== null && _quote$fee !== void 0 ? _quote$fee : await this.getFee(blocks, effects);
|
|
128370
|
+
if (fee !== null) {
|
|
128371
|
+
builder.addFee(fee);
|
|
128372
|
+
}
|
|
127698
128373
|
}
|
|
127699
128374
|
const voteOrQuote = await builder.seal(serial, pendingVoteExpiry);
|
|
127700
128375
|
return voteOrQuote;
|
|
@@ -128122,7 +128797,7 @@ client_lib_ledger_defineProperty(src_client_Ledger, "isInstance", client_checkab
|
|
|
128122
128797
|
// EXTERNAL MODULE: ws (ignored)
|
|
128123
128798
|
var client_ws_ignored_ = __webpack_require__(4708);
|
|
128124
128799
|
;// ./src/version.ts
|
|
128125
|
-
const client_version = '0.14.
|
|
128800
|
+
const client_version = '0.14.12+g091eeeea12610658c71c9ee6a7c5e2eac6aabdde';
|
|
128126
128801
|
/* harmony default export */ const client_src_version = ((/* unused pure expression or super */ null && (client_version)));
|
|
128127
128802
|
;// ./src/lib/p2p.ts
|
|
128128
128803
|
/* provided dependency */ var client_p2p_Buffer = __webpack_require__(8287)["Buffer"];
|