@keetanetwork/keetanet-client 0.14.11 → 0.14.13
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.d.ts +35 -3
- package/client/index-browser.js +751 -34
- package/client/index.d.ts +35 -3
- package/client/index.js +688 -56
- package/docs/assets/hierarchy.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.Block.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockHash.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.CertificateHash.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 +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 +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.VoteBlockHash.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.AcceptSwapRequest.html +7 -2
- 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.CreateSwapRequest.html +3 -2
- 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.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.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/types/KeetaNetSDK.Referenced.AcceptSwapRequestExpectedDeprecated.html +4 -0
- 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.allFullErrorCodes.html +1 -1
- package/lib/block/index.d.ts +1 -1
- package/lib/error/block.d.ts +2 -2
- package/lib/error/client.d.ts +2 -2
- package/lib/error/index.d.ts +1 -1
- package/lib/kv/kv_redis.d.ts +3 -3
- package/lib/log/common.d.ts +4 -0
- package/lib/log/index.d.ts +4 -0
- 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/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/version.d.ts +1 -1
package/client/index-browser.js
CHANGED
|
@@ -113844,7 +113844,8 @@ var client_schema = /*#__PURE__*/new WeakMap();
|
|
|
113844
113844
|
* - {@link ValidateASN1.IsNull}
|
|
113845
113845
|
*
|
|
113846
113846
|
* More complex types are defined as:
|
|
113847
|
-
* - 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)
|
|
113848
113849
|
* - Sequence of: `{ sequenceOf: schema }`
|
|
113849
113850
|
* - Optional: `{ optional: schema }`
|
|
113850
113851
|
* - Context Tag: `{ type: 'context'; kind: 'implicit' | 'explicit'; contains: schema; value: number }`
|
|
@@ -114197,6 +114198,7 @@ class client_ValidateASN1 {
|
|
|
114197
114198
|
{
|
|
114198
114199
|
const outputStruct = {
|
|
114199
114200
|
type: 'struct',
|
|
114201
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114200
114202
|
fieldNames: schema.fieldNames,
|
|
114201
114203
|
contains: {}
|
|
114202
114204
|
};
|
|
@@ -114228,6 +114230,49 @@ class client_ValidateASN1 {
|
|
|
114228
114230
|
client_assertNever(schema);
|
|
114229
114231
|
}
|
|
114230
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)
|
|
114231
114276
|
if (client_isASN1ContextTag(input)) {
|
|
114232
114277
|
const inputAsChoice = input;
|
|
114233
114278
|
const matchingSchema = schema.choice.find(function (choice) {
|
|
@@ -114249,7 +114294,6 @@ class client_ValidateASN1 {
|
|
|
114249
114294
|
}
|
|
114250
114295
|
for (const choice of schema.choice) {
|
|
114251
114296
|
try {
|
|
114252
|
-
// @ts-ignore
|
|
114253
114297
|
return client_ValidateASN1.againstSchema(input, choice);
|
|
114254
114298
|
} catch (_ignored_checkError) {
|
|
114255
114299
|
/* Ignored error */
|
|
@@ -114339,6 +114383,578 @@ class client_ValidateASN1 {
|
|
|
114339
114383
|
validate(input) {
|
|
114340
114384
|
return client_ValidateASN1.againstSchema(input, client_asn1_classPrivateFieldGet(client_schema, this));
|
|
114341
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
|
+
}
|
|
114342
114958
|
}
|
|
114343
114959
|
|
|
114344
114960
|
/**
|
|
@@ -115397,7 +116013,7 @@ function client_block_toPrimitive(t, r) { if ("object" != typeof t || !t) return
|
|
|
115397
116013
|
|
|
115398
116014
|
|
|
115399
116015
|
const client_BlockErrorType = 'BLOCK';
|
|
115400
|
-
const client_BlockErrorCodes = ['
|
|
116016
|
+
const client_BlockErrorCodes = ['AMOUNT_BELOW_ZERO', 'CANNOT_FORWARD_TO_SELF', 'CANNOT_SEND_NON_TOKEN', 'CERTIFICATE_SUBJECT_MISMATCH', 'EXACT_TRUE_WHEN_FORWARDING', 'EXTERNAL_INVALID', 'EXTERNAL_MISSING', 'EXTERNAL_TOO_LONG', 'GENERAL_FIELD_INVALID', 'IDENTIFIER_INVALID', 'IDENTIFIER_NEED_DEFAULT_PERMISSIONS', 'INTERMEDIATE_CERTIFICATES_ONLY_ADD', 'INVALID_ACCOUNT_TYPE', 'INVALID_CERTIFICATE_VALUE', 'INVALID_CREATE_IDENTIFIER_ARGS', 'INVALID_IDEMPOTENT_FORMAT', 'INVALID_IDEMPOTENT_LENGTH', 'INVALID_MULTISIG_QUORUM', 'INVALID_MULTISIG_SIGNER_COUNT', 'INVALID_MULTISIG_SIGNER_DEPTH', 'INVALID_MULTISIG_SIGNER_DUPLICATE', 'INVALID_PURPOSE_VALIDATION', 'INVALID_SIGNATURE', 'INVALID_SIGNER', 'INVALID_TYPE', 'INVALID_VERSION', 'NO_ADMIN_ON_TARGET', 'NO_DELEGATE_ADMIN', 'NO_DUPLICATE_CERTIFICATE_OPERATION', 'NO_IDENTIFIER_OP', 'NO_MODIFY_PERMISSION_DUPE', 'NO_MULTIPLE_SET_REP', 'NO_MULTISIG_OP', 'NO_TOKEN_OP', 'ONLY_IDENTIFIER_OP', 'ONLY_TOKEN_OP', 'PERMISSIONS_INVALID_DEFAULT', 'PERMISSIONS_INVALID_ENTITY', 'PERMISSIONS_INVALID_PRINCIPAL', 'PERMISSIONS_INVALID_TARGET', 'PREVIOUS_SELF', 'SUPPLY_INVALID', 'TOKEN_RECEIVE_DIFFERS'];
|
|
115401
116017
|
const client_FullBlockErrorCodes = client_BlockErrorCodes.map(code => `${client_BlockErrorType}_${code}`);
|
|
115402
116018
|
class src_client_KeetaNetBlockError extends src_client_KeetaNetErrorBase {
|
|
115403
116019
|
constructor(code, message) {
|
|
@@ -118007,7 +118623,11 @@ class src_client_BlockOperation {
|
|
|
118007
118623
|
if (amount === undefined || amount === null) {
|
|
118008
118624
|
throw new Error('internal error: "amount" is invalid');
|
|
118009
118625
|
}
|
|
118010
|
-
|
|
118626
|
+
const bigintAmount = BigInt(amount);
|
|
118627
|
+
if (bigintAmount < 0n) {
|
|
118628
|
+
throw new src_client_KeetaNetBlockError('BLOCK_AMOUNT_BELOW_ZERO', 'value cannot be negative');
|
|
118629
|
+
}
|
|
118630
|
+
return bigintAmount;
|
|
118011
118631
|
}
|
|
118012
118632
|
}
|
|
118013
118633
|
client_BlockOperation = src_client_BlockOperation;
|
|
@@ -118226,7 +118846,7 @@ class src_client_BlockOperationTOKEN_ADMIN_MODIFY_BALANCE extends src_client_Blo
|
|
|
118226
118846
|
}
|
|
118227
118847
|
client_operations_classPrivateFieldSet(client_token3, this, client_operations_assertClassBrand(client_BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_brand, this, client_computeToken3).call(this, input.token));
|
|
118228
118848
|
client_operations_classPrivateFieldSet(client_amount3, this, this.computeAmount(input.amount));
|
|
118229
|
-
client_operations_classPrivateFieldSet(client_method, this, input.method);
|
|
118849
|
+
client_operations_classPrivateFieldSet(client_method, this, client_toAdjustMethod(input.method));
|
|
118230
118850
|
}
|
|
118231
118851
|
set token(token) {
|
|
118232
118852
|
client_operations_classPrivateFieldSet(client_token3, this, client_operations_assertClassBrand(client_BlockOperationTOKEN_ADMIN_MODIFY_BALANCE_brand, this, client_computeToken3).call(this, token));
|
|
@@ -118235,7 +118855,7 @@ class src_client_BlockOperationTOKEN_ADMIN_MODIFY_BALANCE extends src_client_Blo
|
|
|
118235
118855
|
return client_operations_classPrivateFieldGet(client_token3, this);
|
|
118236
118856
|
}
|
|
118237
118857
|
set method(newMethod) {
|
|
118238
|
-
client_operations_classPrivateFieldSet(client_method, this, newMethod);
|
|
118858
|
+
client_operations_classPrivateFieldSet(client_method, this, client_toAdjustMethod(newMethod));
|
|
118239
118859
|
}
|
|
118240
118860
|
get method() {
|
|
118241
118861
|
return Number(client_operations_classPrivateFieldGet(client_method, this));
|
|
@@ -118573,7 +119193,7 @@ class src_client_BlockOperationMODIFY_PERMISSIONS extends src_client_BlockOperat
|
|
|
118573
119193
|
}
|
|
118574
119194
|
client_operations_classPrivateFieldSet(client_principal, this, this.computeTo(input.principal));
|
|
118575
119195
|
client_operations_classPrivateFieldSet(client_target, this, client_lib_account.toAccount(input.target));
|
|
118576
|
-
client_operations_classPrivateFieldSet(client_method2, this, input.method);
|
|
119196
|
+
client_operations_classPrivateFieldSet(client_method2, this, client_toAdjustMethod(input.method));
|
|
118577
119197
|
client_operations_classPrivateFieldSet(client_permissions, this, client_operations_assertClassBrand(client_BlockOperationMODIFY_PERMISSIONS_brand, this, client_computePermissions).call(this, input.permissions));
|
|
118578
119198
|
}
|
|
118579
119199
|
set principal(principal) {
|
|
@@ -118595,7 +119215,7 @@ class src_client_BlockOperationMODIFY_PERMISSIONS extends src_client_BlockOperat
|
|
|
118595
119215
|
return client_operations_classPrivateFieldGet(client_target, this);
|
|
118596
119216
|
}
|
|
118597
119217
|
set method(method) {
|
|
118598
|
-
client_operations_classPrivateFieldSet(client_method2, this, method);
|
|
119218
|
+
client_operations_classPrivateFieldSet(client_method2, this, client_toAdjustMethod(method));
|
|
118599
119219
|
}
|
|
118600
119220
|
get method() {
|
|
118601
119221
|
return Number(client_operations_classPrivateFieldGet(client_method2, this));
|
|
@@ -119877,6 +120497,7 @@ class src_client_Block {
|
|
|
119877
120497
|
if (this.account.isMultisig()) {
|
|
119878
120498
|
throw new src_client_KeetaNetBlockError('BLOCK_NO_MULTISIG_OP', 'Cannot create a block for a multisig account');
|
|
119879
120499
|
}
|
|
120500
|
+
client_block_assertClassBrand(client_Block_brand, this, client_validateBytes).call(this);
|
|
119880
120501
|
client_block_assertClassBrand(client_Block_brand, this, client_validateSignerField).call(this);
|
|
119881
120502
|
client_block_assertClassBrand(client_Block_brand, this, client_validateOperationsPurpose).call(this);
|
|
119882
120503
|
client_block_assertClassBrand(client_Block_brand, this, client_validateSignatures).call(this);
|
|
@@ -119886,8 +120507,11 @@ class src_client_Block {
|
|
|
119886
120507
|
}
|
|
119887
120508
|
toBytes() {
|
|
119888
120509
|
let includeSignatures = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
119889
|
-
|
|
119890
|
-
|
|
120510
|
+
let useCached = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
120511
|
+
if (useCached) {
|
|
120512
|
+
if (client_block_classPrivateFieldGet(client_valueBytes, this) !== undefined && includeSignatures) {
|
|
120513
|
+
return client_block_classPrivateFieldGet(client_valueBytes, this);
|
|
120514
|
+
}
|
|
119891
120515
|
}
|
|
119892
120516
|
const sharedBlockValues = {
|
|
119893
120517
|
previous: this.previous,
|
|
@@ -120077,6 +120701,19 @@ function client_getSortedRequiredSigners(input) {
|
|
|
120077
120701
|
}
|
|
120078
120702
|
return out;
|
|
120079
120703
|
}
|
|
120704
|
+
function client_validateBytes() {
|
|
120705
|
+
const existingBytes = client_block_classPrivateFieldGet(client_valueBytes, this);
|
|
120706
|
+
if (existingBytes === undefined) {
|
|
120707
|
+
return;
|
|
120708
|
+
}
|
|
120709
|
+
const recalculatedBytesBuffer = client_block_Buffer.from(this.toBytes(true, false));
|
|
120710
|
+
const existingBytesBuffer = client_block_Buffer.from(existingBytes);
|
|
120711
|
+
if (!recalculatedBytesBuffer.equals(existingBytesBuffer)) {
|
|
120712
|
+
const existingBytesHash = client_block_Buffer.from(client_hash_Hash(existingBytesBuffer)).toString('hex').toUpperCase();
|
|
120713
|
+
const recalculatedBytesHash = client_block_Buffer.from(client_hash_Hash(recalculatedBytesBuffer)).toString('hex').toUpperCase();
|
|
120714
|
+
throw new src_client_KeetaNetBlockError('BLOCK_INVALID_SIGNATURE', `Block signed bytes (${existingBytesHash}) do not match calculated bytes (${recalculatedBytesHash})`);
|
|
120715
|
+
}
|
|
120716
|
+
}
|
|
120080
120717
|
function client_validateOperationsPurpose() {
|
|
120081
120718
|
/**
|
|
120082
120719
|
* Do not allow blocks to contain invalid constructions
|
|
@@ -120134,7 +120771,7 @@ function client_validateSignatures() {
|
|
|
120134
120771
|
const signature = new src_client_BufferStorage(this.signatures[i], 64);
|
|
120135
120772
|
const valid = signers[i].verify(this.hash.get(), signature.get());
|
|
120136
120773
|
if (valid !== true) {
|
|
120137
|
-
throw new
|
|
120774
|
+
throw new src_client_KeetaNetBlockError('BLOCK_INVALID_SIGNATURE', `Unable to validate signature of ${this.hash.toString()} against signature ${this.signatures[i].toString('hex')} for account ${signers[i].publicKeyString.get()}`);
|
|
120138
120775
|
}
|
|
120139
120776
|
}
|
|
120140
120777
|
}
|
|
@@ -124592,6 +125229,10 @@ function client_updateAccountInfoInState(state, account, info) {
|
|
|
124592
125229
|
* Compute the effect of a SEND operation
|
|
124593
125230
|
*/
|
|
124594
125231
|
function client_computeEffectOfOperationSEND(state, block, operation) {
|
|
125232
|
+
if (operation.amount < 0n) {
|
|
125233
|
+
throw new Error('Internal error: SEND operation with negative amount');
|
|
125234
|
+
}
|
|
125235
|
+
|
|
124595
125236
|
// Decrement sender balance
|
|
124596
125237
|
const senderChange = {
|
|
124597
125238
|
state,
|
|
@@ -124621,6 +125262,10 @@ function client_computeEffectOfOperationSEND(state, block, operation) {
|
|
|
124621
125262
|
* Compute the effect of a RECEIVE operation
|
|
124622
125263
|
*/
|
|
124623
125264
|
function client_computeEffectOfOperationRECEIVE(state, block, operation) {
|
|
125265
|
+
if (operation.amount < 0n) {
|
|
125266
|
+
throw new Error('Internal error: RECEIVE operation with negative amount');
|
|
125267
|
+
}
|
|
125268
|
+
|
|
124624
125269
|
// Increment recipient balance
|
|
124625
125270
|
const recipientChange = {
|
|
124626
125271
|
state,
|
|
@@ -124656,6 +125301,9 @@ function client_computeEffectOfOperationRECEIVE(state, block, operation) {
|
|
|
124656
125301
|
}
|
|
124657
125302
|
}
|
|
124658
125303
|
function client_computeEffectOfOperationTOKEN_ADMIN_MODIFY_BALANCE(state, block, operation) {
|
|
125304
|
+
if (operation.amount < 0n) {
|
|
125305
|
+
throw new Error('Internal error: TOKEN_ADMIN_MODIFY_BALANCE operation with negative amount');
|
|
125306
|
+
}
|
|
124659
125307
|
if (operation.method === src_client_Block.AdjustMethod.SET) {
|
|
124660
125308
|
const setChange = {
|
|
124661
125309
|
state,
|
|
@@ -124732,6 +125380,9 @@ function client_computeEffectOfOperationCREATE_IDENTIFIER(state, block, operatio
|
|
|
124732
125380
|
client_updateAccountInfoInState(state, operation.identifier, {
|
|
124733
125381
|
multisigQuorum: operation.createArguments.quorum
|
|
124734
125382
|
});
|
|
125383
|
+
if (operation.createArguments.quorum < 1n || operation.createArguments.quorum > BigInt(operation.createArguments.signers.length)) {
|
|
125384
|
+
throw new Error('Internal error: operation.createArguments.quorum is invalid');
|
|
125385
|
+
}
|
|
124735
125386
|
for (const multisigSigner of operation.createArguments.signers) {
|
|
124736
125387
|
state.possibleNewAccounts.add(multisigSigner);
|
|
124737
125388
|
client_addPermission(state, {
|
|
@@ -124773,6 +125424,9 @@ function client_computeEffectOfOperationMODIFY_PERMISSIONS(state, block, operati
|
|
|
124773
125424
|
}
|
|
124774
125425
|
function client_computeEffectOfOperationTOKEN_ADMIN_SUPPLY(state, block, operation) {
|
|
124775
125426
|
var _state$accounts$token;
|
|
125427
|
+
if (operation.amount < 0n) {
|
|
125428
|
+
throw new Error('Internal error: TOKEN_ADMIN_SUPPLY operation with negative amount');
|
|
125429
|
+
}
|
|
124776
125430
|
const tokenPubKey = block.account.publicKeyString.get();
|
|
124777
125431
|
let value = 0n;
|
|
124778
125432
|
switch (operation.method) {
|
|
@@ -125606,6 +126260,10 @@ class client_Log {
|
|
|
125606
126260
|
* Register a new logging target (sink) to send logs to
|
|
125607
126261
|
*/
|
|
125608
126262
|
registerTarget(target) {
|
|
126263
|
+
if (client_log_classPrivateFieldGet(client_destroyed, this)) {
|
|
126264
|
+
throw new Error('Cannot register target on destroyed Log instance');
|
|
126265
|
+
}
|
|
126266
|
+
|
|
125609
126267
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
125610
126268
|
const id = Symbol('LogTargetID');
|
|
125611
126269
|
client_log_classPrivateFieldGet(client_targets, this).set(id, target);
|
|
@@ -125627,6 +126285,9 @@ class client_Log {
|
|
|
125627
126285
|
* Unregister a logging target (sink) to stop sending logs to
|
|
125628
126286
|
*/
|
|
125629
126287
|
unregisterTarget(id) {
|
|
126288
|
+
if (client_log_classPrivateFieldGet(client_destroyed, this)) {
|
|
126289
|
+
return;
|
|
126290
|
+
}
|
|
125630
126291
|
client_log_classPrivateFieldGet(client_targets, this).delete(id);
|
|
125631
126292
|
}
|
|
125632
126293
|
|
|
@@ -125644,6 +126305,9 @@ class client_Log {
|
|
|
125644
126305
|
*/
|
|
125645
126306
|
startAutoSync() {
|
|
125646
126307
|
let rate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
|
|
126308
|
+
if (client_log_classPrivateFieldGet(client_destroyed, this)) {
|
|
126309
|
+
throw new Error('Cannot start auto sync on destroyed Log instance');
|
|
126310
|
+
}
|
|
125647
126311
|
this.stopAutoSync();
|
|
125648
126312
|
client_log_classPrivateFieldSet(client_autoSyncInterval, this, setInterval(async () => {
|
|
125649
126313
|
try {
|
|
@@ -125721,6 +126385,15 @@ class client_Log {
|
|
|
125721
126385
|
this.destroy();
|
|
125722
126386
|
}
|
|
125723
126387
|
|
|
126388
|
+
/**
|
|
126389
|
+
* Dispose of the logger instance, syncing all logs, and clearing targets
|
|
126390
|
+
*/
|
|
126391
|
+
async [Symbol.asyncDispose]() {
|
|
126392
|
+
client_log_classPrivateFieldSet(client_destroyed, this, true);
|
|
126393
|
+
await this.sync();
|
|
126394
|
+
this.destroy();
|
|
126395
|
+
}
|
|
126396
|
+
|
|
125724
126397
|
/**
|
|
125725
126398
|
* Terminate the logger instance, clearing all logs and targets
|
|
125726
126399
|
*/
|
|
@@ -125735,6 +126408,9 @@ class client_Log {
|
|
|
125735
126408
|
}
|
|
125736
126409
|
}
|
|
125737
126410
|
function client_log_log(level, options, from) {
|
|
126411
|
+
if (client_log_classPrivateFieldGet(client_destroyed, this)) {
|
|
126412
|
+
return;
|
|
126413
|
+
}
|
|
125738
126414
|
for (var _len6 = arguments.length, args = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
|
|
125739
126415
|
args[_key6 - 3] = arguments[_key6];
|
|
125740
126416
|
}
|
|
@@ -125794,7 +126470,6 @@ function client_timing_classPrivateFieldSet(s, a, r) { return s.set(client_timin
|
|
|
125794
126470
|
function client_timing_classPrivateFieldGet(s, a) { return s.get(client_timing_assertClassBrand(s, a)); }
|
|
125795
126471
|
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"); }
|
|
125796
126472
|
|
|
125797
|
-
|
|
125798
126473
|
/**
|
|
125799
126474
|
* Support the old way of doing timing where the callers could call
|
|
125800
126475
|
* startTime/endTime with the same string to terminate a timing section
|
|
@@ -125820,8 +126495,13 @@ class client_RequestTiming {
|
|
|
125820
126495
|
constructor() {
|
|
125821
126496
|
client_timing_classPrivateFieldInitSpec(this, client_timing, new Map());
|
|
125822
126497
|
client_timing_classPrivateFieldInitSpec(this, client_counter, 0);
|
|
125823
|
-
|
|
126498
|
+
if (client_RequestTiming.defaultLogger === '@legacy') {
|
|
126499
|
+
this.log = src_client_log.Legacy();
|
|
126500
|
+
} else {
|
|
126501
|
+
this.log = client_RequestTiming.defaultLogger;
|
|
126502
|
+
}
|
|
125824
126503
|
}
|
|
126504
|
+
|
|
125825
126505
|
/**
|
|
125826
126506
|
* Start timing a section of code
|
|
125827
126507
|
* @param section Name of the section to time -- should be unique within the code base so that it can be identified later
|
|
@@ -125835,12 +126515,17 @@ class client_RequestTiming {
|
|
|
125835
126515
|
start: Date.now()
|
|
125836
126516
|
};
|
|
125837
126517
|
client_timing_classPrivateFieldGet(client_timing, this).set(id, data);
|
|
126518
|
+
let endCalled = false;
|
|
125838
126519
|
return {
|
|
125839
|
-
id,
|
|
126520
|
+
id: id,
|
|
125840
126521
|
end: () => {
|
|
126522
|
+
endCalled = true;
|
|
125841
126523
|
this.endTime(id);
|
|
125842
126524
|
},
|
|
125843
126525
|
[Symbol.dispose]: () => {
|
|
126526
|
+
if (endCalled) {
|
|
126527
|
+
return;
|
|
126528
|
+
}
|
|
125844
126529
|
this.endTime(id);
|
|
125845
126530
|
}
|
|
125846
126531
|
};
|
|
@@ -125859,11 +126544,11 @@ class client_RequestTiming {
|
|
|
125859
126544
|
if (typeof section === 'symbol') {
|
|
125860
126545
|
const timingInfo = client_timing_classPrivateFieldGet(client_timing, this).get(section);
|
|
125861
126546
|
if (timingInfo === undefined) {
|
|
125862
|
-
this.log.error(`Timing section ${String(section)} does not exist but "end" was called on it!`);
|
|
126547
|
+
this.log.error('timing::endTime', `Timing section ${String(section)} does not exist but "end" was called on it!`);
|
|
125863
126548
|
return;
|
|
125864
126549
|
}
|
|
125865
126550
|
if (timingInfo.end !== undefined) {
|
|
125866
|
-
this.log.error(`Timing section ${timingInfo.id} already ended but "end" was called on it again!`);
|
|
126551
|
+
this.log.error('timing::endTime', `Timing section ${timingInfo.id} already ended but "end" was called on it again!`);
|
|
125867
126552
|
return;
|
|
125868
126553
|
}
|
|
125869
126554
|
timingInfo.end = Date.now();
|
|
@@ -125963,7 +126648,7 @@ class client_RequestTiming {
|
|
|
125963
126648
|
return client_timing_classPrivateFieldSet(client_counter, this, (_this$counter = client_timing_classPrivateFieldGet(client_counter, this), _this$counter2 = _this$counter++, _this$counter)), _this$counter2;
|
|
125964
126649
|
}
|
|
125965
126650
|
}
|
|
125966
|
-
client_timing_defineProperty(client_RequestTiming, "defaultLogger",
|
|
126651
|
+
client_timing_defineProperty(client_RequestTiming, "defaultLogger", '@legacy');
|
|
125967
126652
|
/* harmony default export */ const src_client_timing = (client_RequestTiming);
|
|
125968
126653
|
;// ./src/lib/kv/index.ts
|
|
125969
126654
|
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; }
|
|
@@ -128150,7 +128835,7 @@ client_lib_ledger_defineProperty(src_client_Ledger, "isInstance", client_checkab
|
|
|
128150
128835
|
// EXTERNAL MODULE: ws (ignored)
|
|
128151
128836
|
var client_ws_ignored_ = __webpack_require__(4708);
|
|
128152
128837
|
;// ./src/version.ts
|
|
128153
|
-
const client_version = '0.14.
|
|
128838
|
+
const client_version = '0.14.13+g566b8de2c01660608e6eb5257113db271d7fc075';
|
|
128154
128839
|
/* harmony default export */ const client_src_version = ((/* unused pure expression or super */ null && (client_version)));
|
|
128155
128840
|
;// ./src/lib/p2p.ts
|
|
128156
128841
|
/* provided dependency */ var client_p2p_Buffer = __webpack_require__(8287)["Buffer"];
|
|
@@ -130385,7 +131070,7 @@ function client_client_toPrimitive(t, r) { if ("object" != typeof t || !t) retur
|
|
|
130385
131070
|
|
|
130386
131071
|
|
|
130387
131072
|
const client_ClientErrorType = 'CLIENT';
|
|
130388
|
-
const client_ClientErrorCodes = ['BUILDER_AMOUNT_IS_ZERO', 'BUILDER_CANNOT_READ_BEFORE_RENDER', 'BUILDER_REQUIRES_PRIVATE_KEY', 'BUILDER_USER_CLIENT_REQUIRED', 'PUBLISH_AID_NOT_AVAILABLE', 'SIGNER_REQUIRES_PRIVATE_KEY', 'SYNC_PUBLISH_FAILED', 'SWAP_INVALID_ACCOUNT_OPTION', 'SWAP_OPTIONS_INVALID', 'SWAP_MISSING_SEND', 'SWAP_MISSING_RECEIVE', 'SWAP_SEND_RECEIVE_ACCOUNT_MISMATCH', 'SWAP_SEND_ACCOUNT_MISMATCH', 'SWAP_REQUEST_TOKEN_MISMATCH', 'SWAP_REQUEST_AMOUNT_MISMATCH'];
|
|
131073
|
+
const client_ClientErrorCodes = ['BUILDER_AMOUNT_IS_ZERO', 'BUILDER_CANNOT_READ_BEFORE_RENDER', 'BUILDER_REQUIRES_PRIVATE_KEY', 'BUILDER_USER_CLIENT_REQUIRED', 'PUBLISH_AID_NOT_AVAILABLE', 'SIGNER_REQUIRES_PRIVATE_KEY', 'SYNC_PUBLISH_FAILED', 'SWAP_INVALID_ACCOUNT_OPTION', 'SWAP_OPTIONS_INVALID', 'SWAP_MISSING_SEND', 'SWAP_MISSING_RECEIVE', 'SWAP_SEND_RECEIVE_ACCOUNT_MISMATCH', 'SWAP_SEND_ACCOUNT_MISMATCH', 'SWAP_SEND_TOKEN_MISMATCH', 'SWAP_SEND_AMOUNT_TOO_LOW', 'SWAP_SEND_AMOUNT_RECEIVE_EXACT_MISMATCH', 'SWAP_REQUEST_TOKEN_MISMATCH', 'SWAP_REQUEST_AMOUNT_MISMATCH'];
|
|
130389
131074
|
const client_FullClientErrorCodes = client_ClientErrorCodes.map(code => `${client_ClientErrorType}_${code}`);
|
|
130390
131075
|
class src_client_KeetaNetClientError extends src_client_KeetaNetErrorBase {
|
|
130391
131076
|
constructor(code, message) {
|
|
@@ -133686,6 +134371,9 @@ client_src_client_defineProperty(src_client_Client, "Config", client_config_name
|
|
|
133686
134371
|
client_src_client_defineProperty(src_client_Client, "DefaultLogger", console);
|
|
133687
134372
|
client_src_client_defineProperty(src_client_Client, "updateRepsInterval", 5 * 60 * 1000);
|
|
133688
134373
|
client_src_client_defineProperty(src_client_Client, "isInstance", client_checkableGenerator(client_Client));
|
|
134374
|
+
/**
|
|
134375
|
+
* @deprecated Use the new structure with `receive` and `send` fields instead
|
|
134376
|
+
*/
|
|
133689
134377
|
const client_defaultListenerOptions = {
|
|
133690
134378
|
change: {
|
|
133691
134379
|
fallbackFrequency: 60 * 1000
|
|
@@ -133823,6 +134511,7 @@ class src_client_UserClient {
|
|
|
133823
134511
|
* @returns Swap {@link Block}
|
|
133824
134512
|
*/
|
|
133825
134513
|
static async createSwapRequest(request, client, options) {
|
|
134514
|
+
var _request$to$exact;
|
|
133826
134515
|
let userClient;
|
|
133827
134516
|
if (src_client_UserClient.isInstance(client)) {
|
|
133828
134517
|
userClient = client;
|
|
@@ -133844,7 +134533,7 @@ class src_client_UserClient {
|
|
|
133844
134533
|
account: request.from.account
|
|
133845
134534
|
});
|
|
133846
134535
|
builder.send(to.account, from.amount, from.token);
|
|
133847
|
-
builder.receive(to.account, to.amount, to.token,
|
|
134536
|
+
builder.receive(to.account, to.amount, to.token, (_request$to$exact = request.to.exact) !== null && _request$to$exact !== void 0 ? _request$to$exact : false);
|
|
133848
134537
|
const blocks = await builder.computeBlocks();
|
|
133849
134538
|
if (blocks.blocks.length !== 1) {
|
|
133850
134539
|
throw new Error('Compute Swap Request Generated more than 1 block');
|
|
@@ -133861,7 +134550,6 @@ class src_client_UserClient {
|
|
|
133861
134550
|
*/
|
|
133862
134551
|
|
|
133863
134552
|
static async acceptSwapRequest(request, builderOrUserClient, options) {
|
|
133864
|
-
var _request$expected, _request$expected2, _request$expected3, _request$expected4;
|
|
133865
134553
|
let builder;
|
|
133866
134554
|
let account;
|
|
133867
134555
|
if (src_client_UserClientBuilder.isInstance(builderOrUserClient)) {
|
|
@@ -133870,15 +134558,16 @@ class src_client_UserClient {
|
|
|
133870
134558
|
} else {
|
|
133871
134559
|
let userClient;
|
|
133872
134560
|
if (src_client_UserClient.isInstance(builderOrUserClient)) {
|
|
134561
|
+
var _options$account;
|
|
133873
134562
|
userClient = builderOrUserClient;
|
|
133874
|
-
account = builderOrUserClient.account;
|
|
134563
|
+
account = (_options$account = options === null || options === void 0 ? void 0 : options.account) !== null && _options$account !== void 0 ? _options$account : builderOrUserClient.account;
|
|
133875
134564
|
} else try {
|
|
133876
|
-
var _options$
|
|
134565
|
+
var _options$account2;
|
|
133877
134566
|
var _usingCtx = client_client_usingCtx2();
|
|
133878
134567
|
// Use await using so this temporary client gets cleaned up
|
|
133879
134568
|
const temporaryClient = _usingCtx.a(this.fromNetwork(builderOrUserClient.network, builderOrUserClient.signer, options));
|
|
133880
134569
|
userClient = temporaryClient;
|
|
133881
|
-
account = (_options$
|
|
134570
|
+
account = (_options$account2 = options === null || options === void 0 ? void 0 : options.account) !== null && _options$account2 !== void 0 ? _options$account2 : builderOrUserClient.signer;
|
|
133882
134571
|
if (account === null) {
|
|
133883
134572
|
throw new src_client_KeetaNetClientError('CLIENT_SWAP_INVALID_ACCOUNT_OPTION', 'Signer is required for building swap block');
|
|
133884
134573
|
}
|
|
@@ -133916,13 +134605,41 @@ class src_client_UserClient {
|
|
|
133916
134605
|
if (!sendOperation.to.comparePublicKey(account)) {
|
|
133917
134606
|
throw new src_client_KeetaNetClientError('CLIENT_SWAP_SEND_ACCOUNT_MISMATCH', 'Swap Request send account does not match');
|
|
133918
134607
|
}
|
|
133919
|
-
|
|
133920
|
-
|
|
133921
|
-
|
|
133922
|
-
|
|
133923
|
-
|
|
134608
|
+
let sendAmount = receiveOperation.amount;
|
|
134609
|
+
if (request.expected) {
|
|
134610
|
+
let expectedReceive;
|
|
134611
|
+
let expectedSend;
|
|
134612
|
+
if ('receive' in request.expected || 'send' in request.expected) {
|
|
134613
|
+
var _request$expected, _request$expected2;
|
|
134614
|
+
expectedReceive = (_request$expected = request.expected) === null || _request$expected === void 0 ? void 0 : _request$expected.receive;
|
|
134615
|
+
expectedSend = (_request$expected2 = request.expected) === null || _request$expected2 === void 0 ? void 0 : _request$expected2.send;
|
|
134616
|
+
} else if ('token' in request.expected || 'amount' in request.expected) {
|
|
134617
|
+
expectedReceive = request.expected;
|
|
134618
|
+
}
|
|
134619
|
+
if (expectedReceive) {
|
|
134620
|
+
if (expectedReceive.token !== undefined && !sendOperation.token.comparePublicKey(expectedReceive.token)) {
|
|
134621
|
+
throw new src_client_KeetaNetClientError('CLIENT_SWAP_REQUEST_TOKEN_MISMATCH', 'Swap Request send token does not match expected');
|
|
134622
|
+
}
|
|
134623
|
+
if (expectedReceive.amount !== undefined && sendOperation.amount !== expectedReceive.amount) {
|
|
134624
|
+
throw new src_client_KeetaNetClientError('CLIENT_SWAP_REQUEST_AMOUNT_MISMATCH', 'Swap Request send amount does not match expected');
|
|
134625
|
+
}
|
|
134626
|
+
}
|
|
134627
|
+
if (expectedSend) {
|
|
134628
|
+
if (expectedSend.token !== undefined && !expectedSend.token.comparePublicKey(receiveOperation.token)) {
|
|
134629
|
+
throw new src_client_KeetaNetClientError('CLIENT_SWAP_SEND_TOKEN_MISMATCH', 'Swap acceptance send token does not match swap request receive token');
|
|
134630
|
+
}
|
|
134631
|
+
if (expectedSend.amount !== undefined) {
|
|
134632
|
+
if (expectedSend.amount < receiveOperation.amount) {
|
|
134633
|
+
throw new src_client_KeetaNetClientError('CLIENT_SWAP_SEND_AMOUNT_TOO_LOW', 'Send amount must be at least the receive amount specified in the swap request');
|
|
134634
|
+
}
|
|
134635
|
+
if (receiveOperation.exact && receiveOperation.amount !== expectedSend.amount) {
|
|
134636
|
+
throw new src_client_KeetaNetClientError('CLIENT_SWAP_SEND_AMOUNT_RECEIVE_EXACT_MISMATCH', 'Send value is not allowed to differ from expected receive amount for exact receives');
|
|
134637
|
+
}
|
|
134638
|
+
sendAmount = expectedSend.amount;
|
|
134639
|
+
}
|
|
134640
|
+
}
|
|
133924
134641
|
}
|
|
133925
|
-
builder.send(request.block.account,
|
|
134642
|
+
builder.send(request.block.account, sendAmount, receiveOperation.token);
|
|
133926
134643
|
const blocks = await builder.computeBlocks();
|
|
133927
134644
|
return [...blocks.blocks, request.block];
|
|
133928
134645
|
}
|
|
@@ -134304,9 +135021,9 @@ class src_client_UserClient {
|
|
|
134304
135021
|
*/
|
|
134305
135022
|
|
|
134306
135023
|
async getCertificates(certificateHash) {
|
|
134307
|
-
var _options$
|
|
135024
|
+
var _options$account3;
|
|
134308
135025
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
134309
|
-
const account = (_options$
|
|
135026
|
+
const account = (_options$account3 = options.account) !== null && _options$account3 !== void 0 ? _options$account3 : this.account;
|
|
134310
135027
|
if (certificateHash !== undefined) {
|
|
134311
135028
|
return await client_client_classPrivateFieldGet(client_client, this).getCertificateByHash(account, certificateHash);
|
|
134312
135029
|
}
|
|
@@ -134810,9 +135527,9 @@ class src_client_UserClient {
|
|
|
134810
135527
|
/** @hidden */
|
|
134811
135528
|
client_UserClient = src_client_UserClient;
|
|
134812
135529
|
function client_getAccount() {
|
|
134813
|
-
var _ref3, _options$
|
|
135530
|
+
var _ref3, _options$account4;
|
|
134814
135531
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
134815
|
-
const retval = (_ref3 = (_options$
|
|
135532
|
+
const retval = (_ref3 = (_options$account4 = options.account) !== null && _options$account4 !== void 0 ? _options$account4 : client_client_classPrivateFieldGet(client_client_config, this).account) !== null && _ref3 !== void 0 ? _ref3 : this.signer;
|
|
134816
135533
|
if (retval === null) {
|
|
134817
135534
|
throw new Error('No signer available in a read-only UserClient');
|
|
134818
135535
|
}
|