@digitaldefiance/ecies-lib 4.12.8 → 4.13.1
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/README.md +60 -12
- package/package.json +3 -3
- package/src/builders/ecies-builder.d.ts +24 -1
- package/src/builders/ecies-builder.d.ts.map +1 -1
- package/src/builders/ecies-builder.js +24 -1
- package/src/builders/ecies-builder.js.map +1 -1
- package/src/builders/member-builder.d.ts +57 -1
- package/src/builders/member-builder.d.ts.map +1 -1
- package/src/builders/member-builder.js +57 -1
- package/src/builders/member-builder.js.map +1 -1
- package/src/constants.d.ts +99 -10
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +162 -20
- package/src/constants.js.map +1 -1
- package/src/core/errors/crypto-error.d.ts +28 -1
- package/src/core/errors/crypto-error.d.ts.map +1 -1
- package/src/core/errors/crypto-error.js +28 -1
- package/src/core/errors/crypto-error.js.map +1 -1
- package/src/core/types/result.d.ts +21 -1
- package/src/core/types/result.d.ts.map +1 -1
- package/src/core/types/result.js +17 -1
- package/src/core/types/result.js.map +1 -1
- package/src/enumerations/ecies-cipher-suite.d.ts +11 -0
- package/src/enumerations/ecies-cipher-suite.d.ts.map +1 -1
- package/src/enumerations/ecies-cipher-suite.js +11 -1
- package/src/enumerations/ecies-cipher-suite.js.map +1 -1
- package/src/enumerations/ecies-encryption-type.d.ts +26 -3
- package/src/enumerations/ecies-encryption-type.d.ts.map +1 -1
- package/src/enumerations/ecies-encryption-type.js +29 -10
- package/src/enumerations/ecies-encryption-type.js.map +1 -1
- package/src/enumerations/ecies-error-type.d.ts +48 -3
- package/src/enumerations/ecies-error-type.d.ts.map +1 -1
- package/src/enumerations/ecies-error-type.js +45 -0
- package/src/enumerations/ecies-error-type.js.map +1 -1
- package/src/enumerations/ecies-string-key.d.ts +4 -0
- package/src/enumerations/ecies-string-key.d.ts.map +1 -1
- package/src/enumerations/ecies-string-key.js +4 -0
- package/src/enumerations/ecies-string-key.js.map +1 -1
- package/src/enumerations/ecies-version.d.ts +5 -0
- package/src/enumerations/ecies-version.d.ts.map +1 -1
- package/src/enumerations/ecies-version.js +5 -0
- package/src/enumerations/ecies-version.js.map +1 -1
- package/src/enumerations/guid-brand-type.d.ts +13 -8
- package/src/enumerations/guid-brand-type.d.ts.map +1 -1
- package/src/enumerations/guid-brand-type.js +13 -8
- package/src/enumerations/guid-brand-type.js.map +1 -1
- package/src/enumerations/guid-error-type.d.ts +8 -0
- package/src/enumerations/guid-error-type.d.ts.map +1 -1
- package/src/enumerations/guid-error-type.js +8 -0
- package/src/enumerations/guid-error-type.js.map +1 -1
- package/src/enumerations/index.d.ts +4 -0
- package/src/enumerations/index.d.ts.map +1 -1
- package/src/enumerations/index.js +4 -0
- package/src/enumerations/index.js.map +1 -1
- package/src/enumerations/invalid-email-type.d.ts +7 -0
- package/src/enumerations/invalid-email-type.d.ts.map +1 -1
- package/src/enumerations/invalid-email-type.js +7 -0
- package/src/enumerations/invalid-email-type.js.map +1 -1
- package/src/enumerations/length-encoding-type.d.ts +8 -0
- package/src/enumerations/length-encoding-type.d.ts.map +1 -1
- package/src/enumerations/length-encoding-type.js +8 -0
- package/src/enumerations/length-encoding-type.js.map +1 -1
- package/src/enumerations/length-error-type.d.ts +7 -0
- package/src/enumerations/length-error-type.d.ts.map +1 -1
- package/src/enumerations/length-error-type.js +7 -0
- package/src/enumerations/length-error-type.js.map +1 -1
- package/src/enumerations/password-login-error-type.d.ts +6 -0
- package/src/enumerations/password-login-error-type.d.ts.map +1 -1
- package/src/enumerations/password-login-error-type.js +6 -0
- package/src/enumerations/password-login-error-type.js.map +1 -1
- package/src/enumerations/pbkdf2-error-type.d.ts +7 -0
- package/src/enumerations/pbkdf2-error-type.d.ts.map +1 -1
- package/src/enumerations/pbkdf2-error-type.js +7 -0
- package/src/enumerations/pbkdf2-error-type.js.map +1 -1
- package/src/enumerations/pbkdf2-profile.d.ts +7 -0
- package/src/enumerations/pbkdf2-profile.d.ts.map +1 -1
- package/src/enumerations/pbkdf2-profile.js +7 -0
- package/src/enumerations/pbkdf2-profile.js.map +1 -1
- package/src/enumerations/secure-storage-error-type.d.ts +7 -0
- package/src/enumerations/secure-storage-error-type.d.ts.map +1 -1
- package/src/enumerations/secure-storage-error-type.js +7 -0
- package/src/enumerations/secure-storage-error-type.js.map +1 -1
- package/src/errors/index.d.ts +5 -0
- package/src/errors/index.d.ts.map +1 -1
- package/src/errors/index.js +5 -0
- package/src/errors/index.js.map +1 -1
- package/src/errors/invalid-email.d.ts +4 -0
- package/src/errors/invalid-email.d.ts.map +1 -1
- package/src/errors/invalid-email.js +4 -0
- package/src/errors/invalid-email.js.map +1 -1
- package/src/errors/length.d.ts +4 -0
- package/src/errors/length.d.ts.map +1 -1
- package/src/errors/length.js +4 -0
- package/src/errors/length.js.map +1 -1
- package/src/errors/member.d.ts +4 -0
- package/src/errors/member.d.ts.map +1 -1
- package/src/errors/member.js +4 -0
- package/src/errors/member.js.map +1 -1
- package/src/errors/pbkdf2.d.ts +4 -0
- package/src/errors/pbkdf2.d.ts.map +1 -1
- package/src/errors/pbkdf2.js +4 -0
- package/src/errors/pbkdf2.js.map +1 -1
- package/src/errors/secure-storage.d.ts +4 -0
- package/src/errors/secure-storage.d.ts.map +1 -1
- package/src/errors/secure-storage.js +4 -0
- package/src/errors/secure-storage.js.map +1 -1
- package/src/errors/simple-ecies.d.ts +4 -0
- package/src/errors/simple-ecies.d.ts.map +1 -1
- package/src/errors/simple-ecies.js +4 -0
- package/src/errors/simple-ecies.js.map +1 -1
- package/src/errors/simple-test-error.d.ts +3 -0
- package/src/errors/simple-test-error.d.ts.map +1 -1
- package/src/errors/simple-test-error.js +3 -0
- package/src/errors/simple-test-error.js.map +1 -1
- package/src/errors/translatable.d.ts +8 -0
- package/src/errors/translatable.d.ts.map +1 -0
- package/src/errors/translatable.js +20 -0
- package/src/errors/translatable.js.map +1 -0
- package/src/interfaces/checksum-config.d.ts +3 -0
- package/src/interfaces/checksum-config.d.ts.map +1 -1
- package/src/interfaces/checksum-consts.d.ts +4 -0
- package/src/interfaces/checksum-consts.d.ts.map +1 -1
- package/src/interfaces/constants.d.ts +21 -6
- package/src/interfaces/constants.d.ts.map +1 -1
- package/src/interfaces/constants.js +5 -0
- package/src/interfaces/constants.js.map +1 -1
- package/src/interfaces/ecies-config.d.ts +3 -0
- package/src/interfaces/ecies-config.d.ts.map +1 -1
- package/src/interfaces/ecies-consts.d.ts +42 -7
- package/src/interfaces/ecies-consts.d.ts.map +1 -1
- package/src/interfaces/ecies-file-service.d.ts +3 -0
- package/src/interfaces/ecies-file-service.d.ts.map +1 -1
- package/src/interfaces/guid.d.ts +4 -0
- package/src/interfaces/guid.d.ts.map +1 -1
- package/src/interfaces/index.d.ts +4 -0
- package/src/interfaces/index.d.ts.map +1 -1
- package/src/interfaces/index.js +4 -0
- package/src/interfaces/index.js.map +1 -1
- package/src/interfaces/pbkdf2-config.d.ts +8 -0
- package/src/interfaces/pbkdf2-config.d.ts.map +1 -1
- package/src/interfaces/pbkdf2-consts.d.ts +7 -3
- package/src/interfaces/pbkdf2-consts.d.ts.map +1 -1
- package/src/interfaces/pbkdf2-result.d.ts +7 -0
- package/src/interfaces/pbkdf2-result.d.ts.map +1 -1
- package/src/interfaces/platform-id.d.ts +10 -2
- package/src/interfaces/platform-id.d.ts.map +1 -1
- package/src/interfaces/platform-id.js +8 -0
- package/src/interfaces/platform-id.js.map +1 -1
- package/src/interfaces/voting-service.d.ts +5 -6
- package/src/interfaces/voting-service.d.ts.map +1 -1
- package/src/lib/configuration-provenance-utils.d.ts +5 -1
- package/src/lib/configuration-provenance-utils.d.ts.map +1 -1
- package/src/lib/configuration-provenance-utils.js +5 -1
- package/src/lib/configuration-provenance-utils.js.map +1 -1
- package/src/lib/guid.d.ts +47 -29
- package/src/lib/guid.d.ts.map +1 -1
- package/src/lib/guid.js +127 -104
- package/src/lib/guid.js.map +1 -1
- package/src/lib/id-providers/guidv4-provider.d.ts +8 -8
- package/src/lib/id-providers/guidv4-provider.d.ts.map +1 -1
- package/src/lib/id-providers/guidv4-provider.js +10 -10
- package/src/lib/id-providers/guidv4-provider.js.map +1 -1
- package/src/lib/invariants/index.d.ts +3 -0
- package/src/lib/invariants/index.d.ts.map +1 -1
- package/src/lib/invariants/index.js +3 -0
- package/src/lib/invariants/index.js.map +1 -1
- package/src/lib/voting/enumerations/audit-event-type.d.ts +3 -0
- package/src/lib/voting/enumerations/audit-event-type.d.ts.map +1 -1
- package/src/lib/voting/enumerations/audit-event-type.js +3 -0
- package/src/lib/voting/enumerations/audit-event-type.js.map +1 -1
- package/src/lib/voting/enumerations/event-type.d.ts +3 -0
- package/src/lib/voting/enumerations/event-type.d.ts.map +1 -1
- package/src/lib/voting/enumerations/event-type.js +3 -0
- package/src/lib/voting/enumerations/event-type.js.map +1 -1
- package/src/lib/voting/enumerations/index.d.ts +3 -0
- package/src/lib/voting/enumerations/index.d.ts.map +1 -1
- package/src/lib/voting/enumerations/index.js +3 -0
- package/src/lib/voting/enumerations/index.js.map +1 -1
- package/src/lib/voting/enumerations/jurisdictional-level.d.ts +3 -0
- package/src/lib/voting/enumerations/jurisdictional-level.d.ts.map +1 -1
- package/src/lib/voting/enumerations/jurisdictional-level.js +3 -0
- package/src/lib/voting/enumerations/jurisdictional-level.js.map +1 -1
- package/src/lib/voting/enumerations/security-level.d.ts +3 -0
- package/src/lib/voting/enumerations/security-level.d.ts.map +1 -1
- package/src/lib/voting/enumerations/security-level.js +3 -0
- package/src/lib/voting/enumerations/security-level.js.map +1 -1
- package/src/lib/voting/interfaces/aggregated-tally.d.ts +3 -0
- package/src/lib/voting/interfaces/aggregated-tally.d.ts.map +1 -1
- package/src/lib/voting/interfaces/audit-entry.d.ts +3 -0
- package/src/lib/voting/interfaces/audit-entry.d.ts.map +1 -1
- package/src/lib/voting/interfaces/audit-log.d.ts +3 -0
- package/src/lib/voting/interfaces/audit-log.d.ts.map +1 -1
- package/src/lib/voting/interfaces/bulletin-board-entry.d.ts +3 -0
- package/src/lib/voting/interfaces/bulletin-board-entry.d.ts.map +1 -1
- package/src/lib/voting/interfaces/bulletin-board.d.ts +3 -0
- package/src/lib/voting/interfaces/bulletin-board.d.ts.map +1 -1
- package/src/lib/voting/interfaces/checkpoint-manager.d.ts +3 -0
- package/src/lib/voting/interfaces/checkpoint-manager.d.ts.map +1 -1
- package/src/lib/voting/interfaces/checkpoint-metadata.d.ts +3 -0
- package/src/lib/voting/interfaces/checkpoint-metadata.d.ts.map +1 -1
- package/src/lib/voting/interfaces/event-log-entry.d.ts +3 -0
- package/src/lib/voting/interfaces/event-log-entry.d.ts.map +1 -1
- package/src/lib/voting/interfaces/event-logger.d.ts +3 -0
- package/src/lib/voting/interfaces/event-logger.d.ts.map +1 -1
- package/src/lib/voting/interfaces/index.d.ts +3 -0
- package/src/lib/voting/interfaces/index.d.ts.map +1 -1
- package/src/lib/voting/interfaces/index.js.map +1 -1
- package/src/lib/voting/interfaces/jurisdiction-config.d.ts +3 -0
- package/src/lib/voting/interfaces/jurisdiction-config.d.ts.map +1 -1
- package/src/lib/voting/interfaces/poll-configuration.d.ts +3 -0
- package/src/lib/voting/interfaces/poll-configuration.d.ts.map +1 -1
- package/src/lib/voting/interfaces/state-snapshot.d.ts +3 -0
- package/src/lib/voting/interfaces/state-snapshot.d.ts.map +1 -1
- package/src/lib/voting/interfaces/tally-proof.d.ts +3 -0
- package/src/lib/voting/interfaces/tally-proof.d.ts.map +1 -1
- package/src/lib/voting/interfaces/vote-logger.d.ts +3 -0
- package/src/lib/voting/interfaces/vote-logger.d.ts.map +1 -1
- package/src/lib/voting/test-voter-pool.d.ts.map +1 -1
- package/src/lib/voting/test-voter-pool.js +4 -0
- package/src/lib/voting/test-voter-pool.js.map +1 -1
- package/src/member.d.ts +198 -9
- package/src/member.d.ts.map +1 -1
- package/src/member.js +198 -15
- package/src/member.js.map +1 -1
- package/src/pbkdf2-profiles.d.ts +4 -0
- package/src/pbkdf2-profiles.d.ts.map +1 -1
- package/src/phone-number.d.ts +12 -0
- package/src/phone-number.d.ts.map +1 -1
- package/src/phone-number.js +12 -0
- package/src/phone-number.js.map +1 -1
- package/src/regexes.d.ts +15 -1
- package/src/regexes.d.ts.map +1 -1
- package/src/regexes.js +16 -2
- package/src/regexes.js.map +1 -1
- package/src/secure-buffer.d.ts +119 -8
- package/src/secure-buffer.d.ts.map +1 -1
- package/src/secure-buffer.js +119 -8
- package/src/secure-buffer.js.map +1 -1
- package/src/secure-string.d.ts +118 -1
- package/src/secure-string.d.ts.map +1 -1
- package/src/secure-string.js +118 -1
- package/src/secure-string.js.map +1 -1
- package/src/services/aes-gcm.d.ts.map +1 -1
- package/src/services/aes-gcm.js.map +1 -1
- package/src/services/chunk-processor.d.ts.map +1 -1
- package/src/services/chunk-processor.js +2 -2
- package/src/services/chunk-processor.js.map +1 -1
- package/src/services/crc.d.ts +80 -2
- package/src/services/crc.d.ts.map +1 -1
- package/src/services/crc.js +80 -2
- package/src/services/crc.js.map +1 -1
- package/src/services/ecies/crypto-core.d.ts +2 -1
- package/src/services/ecies/crypto-core.d.ts.map +1 -1
- package/src/services/ecies/crypto-core.js +4 -1
- package/src/services/ecies/crypto-core.js.map +1 -1
- package/src/services/ecies/example.d.ts.map +1 -1
- package/src/services/ecies/example.js +4 -4
- package/src/services/ecies/example.js.map +1 -1
- package/src/services/ecies/file.d.ts +4 -0
- package/src/services/ecies/file.d.ts.map +1 -1
- package/src/services/ecies/file.js +6 -6
- package/src/services/ecies/file.js.map +1 -1
- package/src/services/ecies/index.d.ts +4 -2
- package/src/services/ecies/index.d.ts.map +1 -1
- package/src/services/ecies/index.js +4 -2
- package/src/services/ecies/index.js.map +1 -1
- package/src/services/ecies/integration.d.ts.map +1 -1
- package/src/services/ecies/integration.js +10 -4
- package/src/services/ecies/integration.js.map +1 -1
- package/src/services/ecies/interfaces/decryption-result.d.ts +3 -0
- package/src/services/ecies/interfaces/decryption-result.d.ts.map +1 -1
- package/src/services/ecies/interfaces/encryption-result.d.ts +3 -0
- package/src/services/ecies/interfaces/encryption-result.d.ts.map +1 -1
- package/src/services/ecies/interfaces/index.d.ts +3 -0
- package/src/services/ecies/interfaces/index.d.ts.map +1 -1
- package/src/services/ecies/interfaces/multi-encrypted-message.d.ts +3 -0
- package/src/services/ecies/interfaces/multi-encrypted-message.d.ts.map +1 -1
- package/src/services/ecies/interfaces/multi-encrypted-parsed-header.d.ts +3 -0
- package/src/services/ecies/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -1
- package/src/services/ecies/interfaces/multi-recipient.d.ts +3 -0
- package/src/services/ecies/interfaces/multi-recipient.d.ts.map +1 -1
- package/src/services/ecies/interfaces/simple-keypair.d.ts +3 -0
- package/src/services/ecies/interfaces/simple-keypair.d.ts.map +1 -1
- package/src/services/ecies/interfaces/single-encrypted-parsed-header.d.ts +3 -0
- package/src/services/ecies/interfaces/single-encrypted-parsed-header.d.ts.map +1 -1
- package/src/services/ecies/interfaces/wallet-seed.d.ts +3 -0
- package/src/services/ecies/interfaces/wallet-seed.d.ts.map +1 -1
- package/src/services/ecies/manual-test.d.ts.map +1 -1
- package/src/services/ecies/manual-test.js +7 -7
- package/src/services/ecies/manual-test.js.map +1 -1
- package/src/services/ecies/multi-recipient.d.ts +1 -1
- package/src/services/ecies/multi-recipient.d.ts.map +1 -1
- package/src/services/ecies/multi-recipient.js +1 -1
- package/src/services/ecies/multi-recipient.js.map +1 -1
- package/src/services/ecies/service.d.ts +21 -5
- package/src/services/ecies/service.d.ts.map +1 -1
- package/src/services/ecies/service.js +34 -18
- package/src/services/ecies/service.js.map +1 -1
- package/src/services/ecies/single-recipient.d.ts +2 -2
- package/src/services/ecies/single-recipient.d.ts.map +1 -1
- package/src/services/ecies/single-recipient.js +28 -33
- package/src/services/ecies/single-recipient.js.map +1 -1
- package/src/services/encryption-stream.d.ts.map +1 -1
- package/src/services/encryption-stream.js +1 -1
- package/src/services/encryption-stream.js.map +1 -1
- package/src/services/index.d.ts +4 -0
- package/src/services/index.d.ts.map +1 -1
- package/src/services/index.js +4 -0
- package/src/services/index.js.map +1 -1
- package/src/services/multi-recipient-processor.d.ts +15 -9
- package/src/services/multi-recipient-processor.d.ts.map +1 -1
- package/src/services/multi-recipient-processor.js +51 -39
- package/src/services/multi-recipient-processor.js.map +1 -1
- package/src/services/password-login.d.ts +41 -5
- package/src/services/password-login.d.ts.map +1 -1
- package/src/services/password-login.js +43 -7
- package/src/services/password-login.js.map +1 -1
- package/src/services/resumable-encryption.d.ts.map +1 -1
- package/src/services/resumable-encryption.js +5 -1
- package/src/services/resumable-encryption.js.map +1 -1
- package/src/test-mocks/index.d.ts +4 -0
- package/src/test-mocks/index.d.ts.map +1 -1
- package/src/test-mocks/index.js +4 -0
- package/src/test-mocks/index.js.map +1 -1
- package/src/test-mocks/mock-frontend-member.d.ts +91 -0
- package/src/test-mocks/mock-frontend-member.d.ts.map +1 -1
- package/src/test-mocks/mock-frontend-member.js +91 -0
- package/src/test-mocks/mock-frontend-member.js.map +1 -1
- package/src/testing.d.ts +4 -0
- package/src/testing.d.ts.map +1 -1
- package/src/testing.js +4 -1
- package/src/testing.js.map +1 -1
- package/src/transforms/checksumTransform.d.ts +17 -0
- package/src/transforms/checksumTransform.d.ts.map +1 -1
- package/src/transforms/checksumTransform.js +17 -0
- package/src/transforms/checksumTransform.js.map +1 -1
- package/src/transforms/eciesDecryptTransform.d.ts +19 -0
- package/src/transforms/eciesDecryptTransform.d.ts.map +1 -1
- package/src/transforms/eciesDecryptTransform.js +21 -2
- package/src/transforms/eciesDecryptTransform.js.map +1 -1
- package/src/transforms/eciesEncryptTransform.d.ts +20 -0
- package/src/transforms/eciesEncryptTransform.d.ts.map +1 -1
- package/src/transforms/eciesEncryptTransform.js +23 -3
- package/src/transforms/eciesEncryptTransform.js.map +1 -1
- package/src/transforms/index.d.ts +4 -0
- package/src/transforms/index.d.ts.map +1 -1
- package/src/transforms/index.js +4 -0
- package/src/transforms/index.js.map +1 -1
- package/src/transforms/xorMultipleTransform.d.ts +21 -0
- package/src/transforms/xorMultipleTransform.d.ts.map +1 -1
- package/src/transforms/xorMultipleTransform.js +21 -0
- package/src/transforms/xorMultipleTransform.js.map +1 -1
- package/src/transforms/xorTransform.d.ts +13 -0
- package/src/transforms/xorTransform.d.ts.map +1 -1
- package/src/transforms/xorTransform.js +13 -0
- package/src/transforms/xorTransform.js.map +1 -1
- package/src/translations/de.d.ts +3 -0
- package/src/translations/de.d.ts.map +1 -1
- package/src/translations/de.js +3 -0
- package/src/translations/de.js.map +1 -1
- package/src/translations/en-US.d.ts +3 -0
- package/src/translations/en-US.d.ts.map +1 -1
- package/src/translations/en-US.js +3 -0
- package/src/translations/en-US.js.map +1 -1
- package/src/translations/es.d.ts +3 -0
- package/src/translations/es.d.ts.map +1 -1
- package/src/translations/es.js +3 -0
- package/src/translations/es.js.map +1 -1
- package/src/translations/fr.d.ts +3 -0
- package/src/translations/fr.d.ts.map +1 -1
- package/src/translations/fr.js +3 -0
- package/src/translations/fr.js.map +1 -1
- package/src/translations/ja.d.ts +3 -0
- package/src/translations/ja.d.ts.map +1 -1
- package/src/translations/ja.js +3 -0
- package/src/translations/ja.js.map +1 -1
- package/src/translations/uk.d.ts +3 -0
- package/src/translations/uk.d.ts.map +1 -1
- package/src/translations/uk.js +3 -0
- package/src/translations/uk.js.map +1 -1
- package/src/translations/zh-cn.d.ts +3 -0
- package/src/translations/zh-cn.d.ts.map +1 -1
- package/src/translations/zh-cn.js +3 -0
- package/src/translations/zh-cn.js.map +1 -1
- package/src/typed-configuration.d.ts +2 -2
- package/src/typed-configuration.d.ts.map +1 -1
- package/src/typed-configuration.js.map +1 -1
- package/src/types/deep-partial.d.ts +16 -0
- package/src/types/deep-partial.d.ts.map +1 -1
- package/src/types/guid-versions.d.ts +5 -9
- package/src/types/guid-versions.d.ts.map +1 -1
- package/src/types.d.ts +30 -1
- package/src/types.d.ts.map +1 -1
- package/src/types.js +4 -0
- package/src/types.js.map +1 -1
- package/src/utils.d.ts +69 -18
- package/src/utils.d.ts.map +1 -1
- package/src/utils.js +70 -19
- package/src/utils.js.map +1 -1
package/src/lib/guid.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GuidUint8Array = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const uuid = tslib_1.__importStar(require("uuid"));
|
|
6
6
|
const guid_brand_type_1 = require("../enumerations/guid-brand-type");
|
|
@@ -17,7 +17,7 @@ const guid_1 = require("../errors/guid");
|
|
|
17
17
|
* - RawGuidUint8Array: A 16-byte Uint8Array representation of the GUID
|
|
18
18
|
* Guid instances can be converted to any of these representations using the appropriate method.
|
|
19
19
|
*/
|
|
20
|
-
class
|
|
20
|
+
class GuidUint8Array {
|
|
21
21
|
/**
|
|
22
22
|
* GUID is stored internally as a raw 16-byte Uint8Array.
|
|
23
23
|
*/
|
|
@@ -47,6 +47,10 @@ class Guid {
|
|
|
47
47
|
* Cached base64 representation for performance
|
|
48
48
|
*/
|
|
49
49
|
_cachedBase64;
|
|
50
|
+
/**
|
|
51
|
+
* The RFC 4122 version of this GUID (1, 3, 4, 5, or undefined for boundary/invalid)
|
|
52
|
+
*/
|
|
53
|
+
__version;
|
|
50
54
|
/**
|
|
51
55
|
* Regex for validating hex strings (case insensitive)
|
|
52
56
|
*/
|
|
@@ -69,13 +73,13 @@ class Guid {
|
|
|
69
73
|
* Empty/nil GUID constant (all zeros)
|
|
70
74
|
*/
|
|
71
75
|
static get Empty() {
|
|
72
|
-
if (!
|
|
73
|
-
|
|
76
|
+
if (!GuidUint8Array._empty) {
|
|
77
|
+
GuidUint8Array._empty = Object.freeze(new GuidUint8Array('00000000-0000-0000-0000-000000000000'));
|
|
74
78
|
}
|
|
75
|
-
return
|
|
79
|
+
return GuidUint8Array._empty;
|
|
76
80
|
}
|
|
77
81
|
constructor(value) {
|
|
78
|
-
const array =
|
|
82
|
+
const array = GuidUint8Array.validateAndConvert(value);
|
|
79
83
|
// Note: We cannot freeze a Buffer as it's an ArrayBuffer view
|
|
80
84
|
// Instead, we ensure the array is never directly modified after construction
|
|
81
85
|
this._value = array;
|
|
@@ -83,6 +87,7 @@ class Guid {
|
|
|
83
87
|
this._cachedFullHex = undefined;
|
|
84
88
|
this._cachedShortHex = undefined;
|
|
85
89
|
this._cachedBase64 = undefined;
|
|
90
|
+
this.__version = undefined;
|
|
86
91
|
// Seal the instance to prevent property addition/deletion
|
|
87
92
|
// Cache properties can still be set once since they were initialized
|
|
88
93
|
Object.seal(this);
|
|
@@ -113,32 +118,32 @@ class Guid {
|
|
|
113
118
|
if (typeof value === 'string') {
|
|
114
119
|
const isFullHex = value.length === 36 && value.includes('-');
|
|
115
120
|
const isShortHex = value.length === 32 && !value.includes('-');
|
|
116
|
-
if (isFullHex && !
|
|
121
|
+
if (isFullHex && !GuidUint8Array.FULL_HEX_PATTERN.test(value)) {
|
|
117
122
|
const array = new TextEncoder().encode(value);
|
|
118
123
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuidWithDetails, guid_brand_type_1.GuidBrandType.FullHexGuid, value.length, array);
|
|
119
124
|
}
|
|
120
|
-
else if (isShortHex && !
|
|
125
|
+
else if (isShortHex && !GuidUint8Array.HEX_PATTERN.test(value)) {
|
|
121
126
|
const array = new TextEncoder().encode(value);
|
|
122
127
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuidWithDetails, guid_brand_type_1.GuidBrandType.ShortHexGuid, value.length, array);
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
// Determine and verify the brand/type
|
|
126
|
-
const expectedBrand =
|
|
127
|
-
const verifiedBrand =
|
|
131
|
+
const expectedBrand = GuidUint8Array.whichBrand(value);
|
|
132
|
+
const verifiedBrand = GuidUint8Array.verifyGuid(expectedBrand, value);
|
|
128
133
|
if (!verifiedBrand) {
|
|
129
|
-
const valueBuffer =
|
|
134
|
+
const valueBuffer = GuidUint8Array.isUint8Array(value)
|
|
130
135
|
? value
|
|
131
136
|
: new TextEncoder().encode(strValue);
|
|
132
137
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuidWithDetails, expectedBrand, undefined, valueBuffer);
|
|
133
138
|
}
|
|
134
139
|
// Convert to raw array
|
|
135
|
-
const array =
|
|
140
|
+
const array = GuidUint8Array.toRawGuidPlatformBuffer(value);
|
|
136
141
|
// Validate against UUID standard (skip for boundary values)
|
|
137
142
|
const hexString = Array.from(array)
|
|
138
143
|
.map((b) => b.toString(16).padStart(2, '0'))
|
|
139
144
|
.join('');
|
|
140
|
-
const fullHex =
|
|
141
|
-
const isBoundary =
|
|
145
|
+
const fullHex = GuidUint8Array.toFullHexGuid(hexString);
|
|
146
|
+
const isBoundary = GuidUint8Array.isBoundaryValue(fullHex);
|
|
142
147
|
if (!isBoundary && !uuid.validate(fullHex)) {
|
|
143
148
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid, expectedBrand, undefined, array);
|
|
144
149
|
}
|
|
@@ -153,7 +158,7 @@ class Guid {
|
|
|
153
158
|
if (typeof value === 'bigint') {
|
|
154
159
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
155
160
|
}
|
|
156
|
-
const length =
|
|
161
|
+
const length = GuidUint8Array.isUint8Array(value)
|
|
157
162
|
? value.length
|
|
158
163
|
: String(value).length;
|
|
159
164
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuidUnknownLength, undefined, length);
|
|
@@ -166,7 +171,7 @@ class Guid {
|
|
|
166
171
|
return this.asBase64Guid;
|
|
167
172
|
}
|
|
168
173
|
static hydrate(value) {
|
|
169
|
-
return new
|
|
174
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(value));
|
|
170
175
|
}
|
|
171
176
|
static LengthMap = {
|
|
172
177
|
[guid_brand_type_1.GuidBrandType.Unknown]: -1,
|
|
@@ -209,6 +214,16 @@ class Guid {
|
|
|
209
214
|
get asRawGuidPlatformBufferUnsafe() {
|
|
210
215
|
return this._value;
|
|
211
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Attaches the RFC 4122 version to a GuidUint8Array instance.
|
|
219
|
+
* @param guid The GuidUint8Array instance to attach version to
|
|
220
|
+
* @returns The same instance with __version property set
|
|
221
|
+
*/
|
|
222
|
+
static withVersion(guid) {
|
|
223
|
+
const version = guid.getVersion();
|
|
224
|
+
guid.__version = version;
|
|
225
|
+
return guid;
|
|
226
|
+
}
|
|
212
227
|
/**
|
|
213
228
|
* Generates a new random v4 GUID.
|
|
214
229
|
* @returns A new Guid instance with a randomly generated value
|
|
@@ -219,7 +234,7 @@ class Guid {
|
|
|
219
234
|
if (!uuidStr) {
|
|
220
235
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
221
236
|
}
|
|
222
|
-
return new
|
|
237
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(uuidStr));
|
|
223
238
|
}
|
|
224
239
|
catch (error) {
|
|
225
240
|
if (error instanceof guid_1.GuidError) {
|
|
@@ -233,34 +248,34 @@ class Guid {
|
|
|
233
248
|
* @returns A new Guid instance with a randomly generated v4 value
|
|
234
249
|
*/
|
|
235
250
|
static v4() {
|
|
236
|
-
return
|
|
251
|
+
return GuidUint8Array.generate();
|
|
237
252
|
}
|
|
238
253
|
/**
|
|
239
254
|
* Alias for generate() for backward compatibility.
|
|
240
255
|
* @deprecated Use generate() instead for clearer intent
|
|
241
256
|
*/
|
|
242
257
|
static new() {
|
|
243
|
-
return
|
|
258
|
+
return GuidUint8Array.generate();
|
|
244
259
|
}
|
|
245
260
|
/**
|
|
246
261
|
* Parses a GUID from any valid format, throwing on invalid input.
|
|
247
262
|
* This is the primary parsing method for when you expect valid input.
|
|
248
263
|
* @param value The value to parse
|
|
249
|
-
* @returns A new Guid instance
|
|
264
|
+
* @returns A new Guid instance with __version attached
|
|
250
265
|
* @throws {GuidError} If the value is not a valid GUID
|
|
251
266
|
*/
|
|
252
267
|
static parse(value) {
|
|
253
|
-
return new
|
|
268
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(value));
|
|
254
269
|
}
|
|
255
270
|
/**
|
|
256
271
|
* Attempts to parse a GUID, returning null on failure instead of throwing.
|
|
257
272
|
* Use this when you're uncertain if the input is valid.
|
|
258
273
|
* @param value The value to parse
|
|
259
|
-
* @returns A new Guid instance or null if parsing fails
|
|
274
|
+
* @returns A new Guid instance with __version attached, or null if parsing fails
|
|
260
275
|
*/
|
|
261
276
|
static tryParse(value) {
|
|
262
277
|
try {
|
|
263
|
-
return new
|
|
278
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(value));
|
|
264
279
|
}
|
|
265
280
|
catch {
|
|
266
281
|
return null;
|
|
@@ -276,7 +291,7 @@ class Guid {
|
|
|
276
291
|
if (!value)
|
|
277
292
|
return false;
|
|
278
293
|
try {
|
|
279
|
-
const guid = new
|
|
294
|
+
const guid = new GuidUint8Array(value);
|
|
280
295
|
return guid.isValidV4();
|
|
281
296
|
}
|
|
282
297
|
catch {
|
|
@@ -286,51 +301,51 @@ class Guid {
|
|
|
286
301
|
/**
|
|
287
302
|
* Factory method to create a GUID from a full hex string.
|
|
288
303
|
* @param fullHex The full hex string (with dashes)
|
|
289
|
-
* @returns A new Guid instance
|
|
304
|
+
* @returns A new Guid instance with __version attached
|
|
290
305
|
*/
|
|
291
306
|
static fromFullHex(fullHex) {
|
|
292
|
-
return new
|
|
307
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(fullHex));
|
|
293
308
|
}
|
|
294
309
|
/**
|
|
295
310
|
* Factory method to create a GUID from a short hex string.
|
|
296
311
|
* @param shortHex The short hex string (without dashes)
|
|
297
|
-
* @returns A new Guid instance
|
|
312
|
+
* @returns A new Guid instance with __version attached
|
|
298
313
|
*/
|
|
299
314
|
static fromShortHex(shortHex) {
|
|
300
|
-
return new
|
|
315
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(shortHex));
|
|
301
316
|
}
|
|
302
317
|
/**
|
|
303
318
|
* Factory method to create a GUID from a base64 string.
|
|
304
319
|
* @param base64 The base64 encoded string
|
|
305
|
-
* @returns A new Guid instance
|
|
320
|
+
* @returns A new Guid instance with __version attached
|
|
306
321
|
*/
|
|
307
322
|
static fromBase64(base64) {
|
|
308
|
-
return new
|
|
323
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(base64));
|
|
309
324
|
}
|
|
310
325
|
/**
|
|
311
326
|
* Factory method to create a GUID from a bigint.
|
|
312
327
|
* @param bigint The bigint value
|
|
313
|
-
* @returns A new Guid instance
|
|
328
|
+
* @returns A new Guid instance with __version attached
|
|
314
329
|
*/
|
|
315
330
|
static fromBigInt(bigint) {
|
|
316
|
-
return new
|
|
331
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(bigint));
|
|
317
332
|
}
|
|
318
333
|
/**
|
|
319
334
|
* Factory method to create a GUID from a raw Uint8Array.
|
|
320
335
|
* This is an explicit alias for fromBuffer(), provided for clarity when working
|
|
321
336
|
* with browser environments where Uint8Array is the native binary type.
|
|
322
337
|
* @param bytes The raw 16-byte Uint8Array
|
|
323
|
-
* @returns A new Guid instance
|
|
338
|
+
* @returns A new Guid instance with __version attached
|
|
324
339
|
*/
|
|
325
340
|
static fromPlatformBuffer(bytes) {
|
|
326
|
-
return new
|
|
341
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(bytes));
|
|
327
342
|
}
|
|
328
343
|
/**
|
|
329
344
|
* Creates a namespace-based v3 GUID (MD5 hash).
|
|
330
345
|
* Use this for deterministic GUIDs based on a namespace and name.
|
|
331
346
|
* @param name The name to hash within the namespace
|
|
332
347
|
* @param namespace The namespace GUID (e.g., Guid.Namespaces.DNS)
|
|
333
|
-
* @returns A new Guid instance containing the v3 GUID
|
|
348
|
+
* @returns A new Guid instance containing the v3 GUID with __version attached
|
|
334
349
|
* @example
|
|
335
350
|
* const guid = Guid.v3('example.com', Guid.Namespaces.DNS);
|
|
336
351
|
*/
|
|
@@ -338,9 +353,9 @@ class Guid {
|
|
|
338
353
|
try {
|
|
339
354
|
const namespaceStr = typeof namespace === 'string'
|
|
340
355
|
? namespace
|
|
341
|
-
:
|
|
356
|
+
: GuidUint8Array.toFullHexGuid(namespace);
|
|
342
357
|
const v3Guid = uuid.v3(name, namespaceStr);
|
|
343
|
-
return new
|
|
358
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(v3Guid));
|
|
344
359
|
}
|
|
345
360
|
catch (error) {
|
|
346
361
|
if (error instanceof guid_1.GuidError) {
|
|
@@ -355,7 +370,7 @@ class Guid {
|
|
|
355
370
|
* Preferred over v3 as SHA-1 is stronger than MD5.
|
|
356
371
|
* @param name The name to hash within the namespace
|
|
357
372
|
* @param namespace The namespace GUID (e.g., Guid.Namespaces.DNS)
|
|
358
|
-
* @returns A new Guid instance containing the v5 GUID
|
|
373
|
+
* @returns A new Guid instance containing the v5 GUID with __version attached
|
|
359
374
|
* @example
|
|
360
375
|
* const guid = Guid.v5('example.com', Guid.Namespaces.DNS);
|
|
361
376
|
*/
|
|
@@ -363,9 +378,9 @@ class Guid {
|
|
|
363
378
|
try {
|
|
364
379
|
const namespaceStr = typeof namespace === 'string'
|
|
365
380
|
? namespace
|
|
366
|
-
:
|
|
381
|
+
: GuidUint8Array.toFullHexGuid(namespace);
|
|
367
382
|
const v5Guid = uuid.v5(name, namespaceStr);
|
|
368
|
-
return new
|
|
383
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(v5Guid));
|
|
369
384
|
}
|
|
370
385
|
catch (error) {
|
|
371
386
|
if (error instanceof guid_1.GuidError) {
|
|
@@ -394,7 +409,7 @@ class Guid {
|
|
|
394
409
|
const hexString = Array.from(this._value)
|
|
395
410
|
.map((b) => b.toString(16).padStart(2, '0'))
|
|
396
411
|
.join('');
|
|
397
|
-
this._cachedFullHex =
|
|
412
|
+
this._cachedFullHex = GuidUint8Array.toFullHexGuid(hexString);
|
|
398
413
|
}
|
|
399
414
|
return this._cachedFullHex;
|
|
400
415
|
}
|
|
@@ -410,7 +425,7 @@ class Guid {
|
|
|
410
425
|
*/
|
|
411
426
|
get asShortHexGuid() {
|
|
412
427
|
if (!this._cachedShortHex) {
|
|
413
|
-
this._cachedShortHex =
|
|
428
|
+
this._cachedShortHex = GuidUint8Array.toShortHexGuid(this.asFullHexGuid);
|
|
414
429
|
}
|
|
415
430
|
return this._cachedShortHex;
|
|
416
431
|
}
|
|
@@ -452,10 +467,10 @@ class Guid {
|
|
|
452
467
|
* @returns True if the value is a boundary value.
|
|
453
468
|
*/
|
|
454
469
|
static isBoundaryValue(value) {
|
|
455
|
-
return (value ===
|
|
456
|
-
value ===
|
|
457
|
-
value ===
|
|
458
|
-
value ===
|
|
470
|
+
return (value === GuidUint8Array.BOUNDARY_VALUES.ALL_ZEROS_FULL ||
|
|
471
|
+
value === GuidUint8Array.BOUNDARY_VALUES.ALL_ZEROS_SHORT ||
|
|
472
|
+
value === GuidUint8Array.BOUNDARY_VALUES.ALL_FS_FULL ||
|
|
473
|
+
value === GuidUint8Array.BOUNDARY_VALUES.ALL_FS_SHORT);
|
|
459
474
|
}
|
|
460
475
|
/**
|
|
461
476
|
* Verifies if a given GUID is valid for the given brand.
|
|
@@ -468,7 +483,7 @@ class Guid {
|
|
|
468
483
|
return false;
|
|
469
484
|
}
|
|
470
485
|
try {
|
|
471
|
-
const verifyFunc =
|
|
486
|
+
const verifyFunc = GuidUint8Array.VerifyFunctions[guidBrand];
|
|
472
487
|
return verifyFunc(guid);
|
|
473
488
|
}
|
|
474
489
|
catch {
|
|
@@ -481,7 +496,7 @@ class Guid {
|
|
|
481
496
|
* @returns The length of the GUID for the given brand.
|
|
482
497
|
*/
|
|
483
498
|
static guidBrandToLength(guidBrand) {
|
|
484
|
-
const length =
|
|
499
|
+
const length = GuidUint8Array.LengthMap[guidBrand];
|
|
485
500
|
if (length <= 0) {
|
|
486
501
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuidUnknownBrand, guidBrand);
|
|
487
502
|
}
|
|
@@ -497,7 +512,7 @@ class Guid {
|
|
|
497
512
|
if (length <= 0) {
|
|
498
513
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuidUnknownLength, undefined, length);
|
|
499
514
|
}
|
|
500
|
-
const brand =
|
|
515
|
+
const brand = GuidUint8Array.ReverseLengthMap[length];
|
|
501
516
|
if (!brand || brand === guid_brand_type_1.GuidBrandType.Unknown) {
|
|
502
517
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuidUnknownLength, undefined, length);
|
|
503
518
|
}
|
|
@@ -518,16 +533,16 @@ class Guid {
|
|
|
518
533
|
if (fullHexGuidValue === null || fullHexGuidValue === undefined) {
|
|
519
534
|
return false;
|
|
520
535
|
}
|
|
521
|
-
const expectedLength =
|
|
536
|
+
const expectedLength = GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.FullHexGuid);
|
|
522
537
|
const strValue = String(fullHexGuidValue);
|
|
523
538
|
if (strValue.length !== expectedLength) {
|
|
524
539
|
return false;
|
|
525
540
|
}
|
|
526
541
|
// Boundary values are always valid
|
|
527
|
-
if (
|
|
542
|
+
if (GuidUint8Array.isBoundaryValue(strValue)) {
|
|
528
543
|
return true;
|
|
529
544
|
}
|
|
530
|
-
return
|
|
545
|
+
return GuidUint8Array.validateUuid(strValue);
|
|
531
546
|
}
|
|
532
547
|
catch {
|
|
533
548
|
return false;
|
|
@@ -543,15 +558,15 @@ class Guid {
|
|
|
543
558
|
if (shortHexGuidValue === null || shortHexGuidValue === undefined) {
|
|
544
559
|
return false;
|
|
545
560
|
}
|
|
546
|
-
const expectedLength =
|
|
561
|
+
const expectedLength = GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.ShortHexGuid);
|
|
547
562
|
const strValue = String(shortHexGuidValue);
|
|
548
563
|
if (strValue.length !== expectedLength) {
|
|
549
564
|
return false;
|
|
550
565
|
}
|
|
551
566
|
try {
|
|
552
|
-
const fullHexGuid =
|
|
567
|
+
const fullHexGuid = GuidUint8Array.toFullHexGuid(strValue);
|
|
553
568
|
// Boundary values are always valid
|
|
554
|
-
if (
|
|
569
|
+
if (GuidUint8Array.isBoundaryValue(fullHexGuid)) {
|
|
555
570
|
return true;
|
|
556
571
|
}
|
|
557
572
|
return uuid.validate(fullHexGuid);
|
|
@@ -578,22 +593,23 @@ class Guid {
|
|
|
578
593
|
if (typeof value === 'bigint') {
|
|
579
594
|
valueLength = value.toString(16).length;
|
|
580
595
|
}
|
|
581
|
-
else if (
|
|
596
|
+
else if (GuidUint8Array.isUint8Array(value)) {
|
|
582
597
|
valueLength = value.length;
|
|
583
598
|
}
|
|
584
599
|
else {
|
|
585
600
|
valueLength = String(value).length;
|
|
586
601
|
}
|
|
587
|
-
const result = valueLength ===
|
|
602
|
+
const result = valueLength ===
|
|
603
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.Base64Guid);
|
|
588
604
|
if (result) {
|
|
589
605
|
try {
|
|
590
|
-
const fromBase64 =
|
|
606
|
+
const fromBase64 = GuidUint8Array.toRawGuidPlatformBuffer(value);
|
|
591
607
|
const hexString = Array.from(fromBase64)
|
|
592
608
|
.map((b) => b.toString(16).padStart(2, '0'))
|
|
593
609
|
.join('');
|
|
594
|
-
const fullHexGuid =
|
|
610
|
+
const fullHexGuid = GuidUint8Array.toFullHexGuid(hexString);
|
|
595
611
|
// Boundary values are always valid
|
|
596
|
-
if (
|
|
612
|
+
if (GuidUint8Array.isBoundaryValue(fullHexGuid)) {
|
|
597
613
|
return true;
|
|
598
614
|
}
|
|
599
615
|
return uuid.validate(fullHexGuid);
|
|
@@ -618,12 +634,12 @@ class Guid {
|
|
|
618
634
|
if (value === null || value === undefined) {
|
|
619
635
|
return false;
|
|
620
636
|
}
|
|
621
|
-
const expectedLength =
|
|
637
|
+
const expectedLength = GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.RawGuidPlatformBuffer);
|
|
622
638
|
let valueLength;
|
|
623
639
|
if (typeof value === 'bigint') {
|
|
624
640
|
valueLength = value.toString(16).length;
|
|
625
641
|
}
|
|
626
|
-
else if (
|
|
642
|
+
else if (GuidUint8Array.isUint8Array(value)) {
|
|
627
643
|
valueLength = value.length;
|
|
628
644
|
}
|
|
629
645
|
else {
|
|
@@ -633,18 +649,18 @@ class Guid {
|
|
|
633
649
|
return false;
|
|
634
650
|
}
|
|
635
651
|
try {
|
|
636
|
-
if (!
|
|
652
|
+
if (!GuidUint8Array.isUint8Array(value)) {
|
|
637
653
|
return false;
|
|
638
654
|
}
|
|
639
655
|
const hexString = Array.from(value)
|
|
640
656
|
.map((b) => b.toString(16).padStart(2, '0'))
|
|
641
657
|
.join('');
|
|
642
|
-
const fullHexGuid =
|
|
658
|
+
const fullHexGuid = GuidUint8Array.toFullHexGuid(hexString);
|
|
643
659
|
// Boundary values are always valid
|
|
644
|
-
if (
|
|
660
|
+
if (GuidUint8Array.isBoundaryValue(fullHexGuid)) {
|
|
645
661
|
return true;
|
|
646
662
|
}
|
|
647
|
-
return
|
|
663
|
+
return GuidUint8Array.validateUuid(fullHexGuid);
|
|
648
664
|
}
|
|
649
665
|
catch {
|
|
650
666
|
return false;
|
|
@@ -667,13 +683,13 @@ class Guid {
|
|
|
667
683
|
if (typeof value !== 'bigint') {
|
|
668
684
|
return false;
|
|
669
685
|
}
|
|
670
|
-
if (value < 0n || value >
|
|
686
|
+
if (value < 0n || value > GuidUint8Array.MAX_BIGINT_VALUE) {
|
|
671
687
|
return false;
|
|
672
688
|
}
|
|
673
689
|
try {
|
|
674
|
-
const fromBigInt =
|
|
690
|
+
const fromBigInt = GuidUint8Array.toFullHexFromBigInt(value);
|
|
675
691
|
// Boundary values are always valid
|
|
676
|
-
if (
|
|
692
|
+
if (GuidUint8Array.isBoundaryValue(fromBigInt)) {
|
|
677
693
|
return true;
|
|
678
694
|
}
|
|
679
695
|
return uuid.validate(fromBigInt);
|
|
@@ -698,11 +714,11 @@ class Guid {
|
|
|
698
714
|
if (typeof value === 'bigint') {
|
|
699
715
|
return guid_brand_type_1.GuidBrandType.BigIntGuid;
|
|
700
716
|
}
|
|
701
|
-
const isBuffer =
|
|
717
|
+
const isBuffer = GuidUint8Array.isUint8Array(value);
|
|
702
718
|
const expectedLength = isBuffer
|
|
703
719
|
? value.length
|
|
704
720
|
: String(value).length;
|
|
705
|
-
return
|
|
721
|
+
return GuidUint8Array.lengthToGuidBrand(expectedLength, isBuffer);
|
|
706
722
|
}
|
|
707
723
|
/**
|
|
708
724
|
* Converts a given short hex GUID to a full hex GUID.
|
|
@@ -724,31 +740,34 @@ class Guid {
|
|
|
724
740
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
725
741
|
}
|
|
726
742
|
if (typeof guid === 'bigint') {
|
|
727
|
-
return
|
|
743
|
+
return GuidUint8Array.toFullHexFromBigInt(guid);
|
|
728
744
|
}
|
|
729
|
-
else if (
|
|
745
|
+
else if (GuidUint8Array.isUint8Array(guid) &&
|
|
730
746
|
guid.length ===
|
|
731
|
-
|
|
747
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.RawGuidPlatformBuffer)) {
|
|
732
748
|
const hexString = Array.from(guid)
|
|
733
749
|
.map((b) => b.toString(16).padStart(2, '0'))
|
|
734
750
|
.join('');
|
|
735
751
|
const shortHex = hexString;
|
|
736
|
-
return
|
|
752
|
+
return GuidUint8Array.shortGuidToFullGuid(shortHex);
|
|
737
753
|
}
|
|
738
|
-
else if (
|
|
754
|
+
else if (GuidUint8Array.isUint8Array(guid)) {
|
|
739
755
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
740
756
|
}
|
|
741
757
|
// all remaining cases are string types
|
|
742
758
|
const strValue = String(guid);
|
|
743
|
-
if (strValue.length ===
|
|
759
|
+
if (strValue.length ===
|
|
760
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.ShortHexGuid)) {
|
|
744
761
|
// short hex guid
|
|
745
|
-
return
|
|
762
|
+
return GuidUint8Array.shortGuidToFullGuid(strValue);
|
|
746
763
|
}
|
|
747
|
-
else if (strValue.length ===
|
|
764
|
+
else if (strValue.length ===
|
|
765
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.FullHexGuid)) {
|
|
748
766
|
// already a full hex guid
|
|
749
767
|
return strValue;
|
|
750
768
|
}
|
|
751
|
-
else if (strValue.length ===
|
|
769
|
+
else if (strValue.length ===
|
|
770
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.Base64Guid)) {
|
|
752
771
|
// base64 guid
|
|
753
772
|
// base64 guid
|
|
754
773
|
const binary = atob(strValue);
|
|
@@ -759,7 +778,7 @@ class Guid {
|
|
|
759
778
|
const shortGuid = Array.from(bytes)
|
|
760
779
|
.map((b) => b.toString(16).padStart(2, '0'))
|
|
761
780
|
.join('');
|
|
762
|
-
return
|
|
781
|
+
return GuidUint8Array.shortGuidToFullGuid(shortGuid);
|
|
763
782
|
}
|
|
764
783
|
else {
|
|
765
784
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
@@ -770,30 +789,33 @@ class Guid {
|
|
|
770
789
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
771
790
|
}
|
|
772
791
|
if (typeof guid === 'bigint') {
|
|
773
|
-
const fullHex =
|
|
792
|
+
const fullHex = GuidUint8Array.toFullHexFromBigInt(guid);
|
|
774
793
|
return fullHex.replace(/-/g, '');
|
|
775
794
|
}
|
|
776
|
-
else if (
|
|
795
|
+
else if (GuidUint8Array.isUint8Array(guid) &&
|
|
777
796
|
guid.length ===
|
|
778
|
-
|
|
797
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.RawGuidPlatformBuffer)) {
|
|
779
798
|
return Array.from(guid)
|
|
780
799
|
.map((b) => b.toString(16).padStart(2, '0'))
|
|
781
800
|
.join('');
|
|
782
801
|
}
|
|
783
|
-
else if (
|
|
802
|
+
else if (GuidUint8Array.isUint8Array(guid)) {
|
|
784
803
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
785
804
|
}
|
|
786
805
|
// all remaining cases are string types
|
|
787
806
|
const strValue = String(guid);
|
|
788
|
-
if (strValue.length ===
|
|
807
|
+
if (strValue.length ===
|
|
808
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.ShortHexGuid)) {
|
|
789
809
|
// already a short hex guid
|
|
790
810
|
return strValue;
|
|
791
811
|
}
|
|
792
|
-
else if (strValue.length ===
|
|
812
|
+
else if (strValue.length ===
|
|
813
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.FullHexGuid)) {
|
|
793
814
|
// full hex guid
|
|
794
815
|
return strValue.replace(/-/g, '');
|
|
795
816
|
}
|
|
796
|
-
else if (strValue.length ===
|
|
817
|
+
else if (strValue.length ===
|
|
818
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.Base64Guid)) {
|
|
797
819
|
// base64 guid
|
|
798
820
|
const binary = atob(strValue);
|
|
799
821
|
const bytes = new Uint8Array(binary.length);
|
|
@@ -814,7 +836,7 @@ class Guid {
|
|
|
814
836
|
* @returns The bigint as a full hex GUID.
|
|
815
837
|
*/
|
|
816
838
|
static toFullHexFromBigInt(bigInt) {
|
|
817
|
-
if (bigInt < 0n || bigInt >
|
|
839
|
+
if (bigInt < 0n || bigInt > GuidUint8Array.MAX_BIGINT_VALUE) {
|
|
818
840
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
819
841
|
}
|
|
820
842
|
const uuidBigInt = bigInt.toString(16).padStart(32, '0');
|
|
@@ -839,11 +861,11 @@ class Guid {
|
|
|
839
861
|
* @returns The GUID value as a raw GUID array.
|
|
840
862
|
*/
|
|
841
863
|
static toRawGuidPlatformBuffer(value) {
|
|
842
|
-
const expectedBrand =
|
|
864
|
+
const expectedBrand = GuidUint8Array.whichBrand(value);
|
|
843
865
|
let rawGuidBufferResult = new Uint8Array(0);
|
|
844
866
|
switch (expectedBrand) {
|
|
845
867
|
case guid_brand_type_1.GuidBrandType.FullHexGuid: {
|
|
846
|
-
const hex1 =
|
|
868
|
+
const hex1 = GuidUint8Array.toShortHexGuid(value);
|
|
847
869
|
rawGuidBufferResult = new Uint8Array(hex1.length / 2);
|
|
848
870
|
for (let i = 0; i < hex1.length; i += 2) {
|
|
849
871
|
rawGuidBufferResult[i / 2] = parseInt(hex1.slice(i, i + 2), 16);
|
|
@@ -851,7 +873,7 @@ class Guid {
|
|
|
851
873
|
break;
|
|
852
874
|
}
|
|
853
875
|
case guid_brand_type_1.GuidBrandType.ShortHexGuid: {
|
|
854
|
-
const hex2 =
|
|
876
|
+
const hex2 = GuidUint8Array.toShortHexGuid(value);
|
|
855
877
|
rawGuidBufferResult = new Uint8Array(hex2.length / 2);
|
|
856
878
|
for (let i = 0; i < hex2.length; i += 2) {
|
|
857
879
|
rawGuidBufferResult[i / 2] = parseInt(hex2.slice(i, i + 2), 16);
|
|
@@ -859,7 +881,7 @@ class Guid {
|
|
|
859
881
|
break;
|
|
860
882
|
}
|
|
861
883
|
case guid_brand_type_1.GuidBrandType.Base64Guid:
|
|
862
|
-
if (typeof value === 'string' ||
|
|
884
|
+
if (typeof value === 'string' || GuidUint8Array.isUint8Array(value)) {
|
|
863
885
|
const b64 = value.toString();
|
|
864
886
|
const binary = atob(b64);
|
|
865
887
|
rawGuidBufferResult = new Uint8Array(binary.length);
|
|
@@ -875,7 +897,7 @@ class Guid {
|
|
|
875
897
|
rawGuidBufferResult = value;
|
|
876
898
|
break;
|
|
877
899
|
case guid_brand_type_1.GuidBrandType.BigIntGuid: {
|
|
878
|
-
const hex3 =
|
|
900
|
+
const hex3 = GuidUint8Array.toShortHexGuid(GuidUint8Array.toFullHexFromBigInt(value));
|
|
879
901
|
rawGuidBufferResult = new Uint8Array(hex3.length / 2);
|
|
880
902
|
for (let i = 0; i < hex3.length; i += 2) {
|
|
881
903
|
rawGuidBufferResult[i / 2] = parseInt(hex3.slice(i, i + 2), 16);
|
|
@@ -886,7 +908,7 @@ class Guid {
|
|
|
886
908
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuidUnknownBrand);
|
|
887
909
|
}
|
|
888
910
|
if (rawGuidBufferResult.length !==
|
|
889
|
-
|
|
911
|
+
GuidUint8Array.guidBrandToLength(guid_brand_type_1.GuidBrandType.RawGuidPlatformBuffer)) {
|
|
890
912
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuidUnknownLength, undefined, rawGuidBufferResult.length);
|
|
891
913
|
}
|
|
892
914
|
return rawGuidBufferResult;
|
|
@@ -937,14 +959,14 @@ class Guid {
|
|
|
937
959
|
* @returns True if the GUID is null, undefined, or empty
|
|
938
960
|
*/
|
|
939
961
|
static isNilOrEmpty(guid) {
|
|
940
|
-
return !guid || (guid instanceof
|
|
962
|
+
return !guid || (guid instanceof GuidUint8Array && guid.isEmpty());
|
|
941
963
|
}
|
|
942
964
|
/**
|
|
943
965
|
* Creates a new Guid instance with the same value as this one.
|
|
944
|
-
* @returns A new Guid instance with identical value
|
|
966
|
+
* @returns A new Guid instance with identical value and __version attached
|
|
945
967
|
*/
|
|
946
968
|
clone() {
|
|
947
|
-
return new
|
|
969
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(Uint8Array.from(this._value)));
|
|
948
970
|
}
|
|
949
971
|
/**
|
|
950
972
|
* Returns the hash code for this GUID based on its array content.
|
|
@@ -966,7 +988,7 @@ class Guid {
|
|
|
966
988
|
*/
|
|
967
989
|
getVersion() {
|
|
968
990
|
// Skip boundary values
|
|
969
|
-
if (
|
|
991
|
+
if (GuidUint8Array.isBoundaryValue(this.asFullHexGuid)) {
|
|
970
992
|
return undefined;
|
|
971
993
|
}
|
|
972
994
|
// Version is in bits 48-51 (byte 6, high nibble)
|
|
@@ -989,7 +1011,7 @@ class Guid {
|
|
|
989
1011
|
*/
|
|
990
1012
|
isValidV4() {
|
|
991
1013
|
// Boundary values are considered valid
|
|
992
|
-
if (
|
|
1014
|
+
if (GuidUint8Array.isBoundaryValue(this.asFullHexGuid)) {
|
|
993
1015
|
return true;
|
|
994
1016
|
}
|
|
995
1017
|
const version = this.getVersion();
|
|
@@ -1060,12 +1082,12 @@ class Guid {
|
|
|
1060
1082
|
}
|
|
1061
1083
|
/**
|
|
1062
1084
|
* Creates a v1 GUID (time-based).
|
|
1063
|
-
* @returns A new Guid instance containing a v1 GUID
|
|
1085
|
+
* @returns A new Guid instance containing a v1 GUID with __version attached
|
|
1064
1086
|
*/
|
|
1065
1087
|
static v1() {
|
|
1066
1088
|
try {
|
|
1067
1089
|
const v1Guid = uuid.v1();
|
|
1068
|
-
return new
|
|
1090
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(v1Guid));
|
|
1069
1091
|
}
|
|
1070
1092
|
catch (error) {
|
|
1071
1093
|
if (error instanceof guid_1.GuidError)
|
|
@@ -1089,14 +1111,15 @@ class Guid {
|
|
|
1089
1111
|
}
|
|
1090
1112
|
/**
|
|
1091
1113
|
* Creates a GUID from URL-safe base64.
|
|
1114
|
+
* @returns A new Guid instance with __version attached
|
|
1092
1115
|
*/
|
|
1093
1116
|
static fromUrlSafeBase64(urlSafe) {
|
|
1094
1117
|
const base64 = urlSafe
|
|
1095
1118
|
.replace(/-/g, '+')
|
|
1096
1119
|
.replace(/_/g, '/')
|
|
1097
1120
|
.padEnd(24, '=');
|
|
1098
|
-
return new
|
|
1121
|
+
return GuidUint8Array.withVersion(new GuidUint8Array(base64));
|
|
1099
1122
|
}
|
|
1100
1123
|
}
|
|
1101
|
-
exports.
|
|
1124
|
+
exports.GuidUint8Array = GuidUint8Array;
|
|
1102
1125
|
//# sourceMappingURL=guid.js.map
|