@digitaldefiance/ecies-lib 4.4.2 → 4.4.3
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/LICENSE +21 -0
- package/package.json +9 -6
- package/src/builders/ecies-builder.ts +39 -0
- package/src/builders/{index.js → index.ts} +1 -1
- package/src/builders/member-builder.ts +155 -0
- package/src/constants.ts +609 -0
- package/src/core/errors/crypto-error.ts +78 -0
- package/src/core/{index.js → index.ts} +1 -1
- package/src/core/types/result.ts +19 -0
- package/src/email-string.ts +82 -0
- package/src/enumerations/disposed-error-type.ts +11 -0
- package/src/enumerations/ecies-cipher-suite.ts +4 -0
- package/src/enumerations/ecies-encryption-type.ts +41 -0
- package/src/enumerations/ecies-error-type.ts +43 -0
- package/src/enumerations/ecies-string-key.ts +205 -0
- package/src/enumerations/ecies-version.ts +3 -0
- package/src/enumerations/guid-brand-type.ts +26 -0
- package/src/enumerations/guid-error-type.ts +6 -0
- package/src/enumerations/id-provider-error-type.ts +50 -0
- package/src/enumerations/{index.js → index.ts} +0 -1
- package/src/enumerations/invalid-email-type.ts +5 -0
- package/src/enumerations/length-encoding-type.ts +6 -0
- package/src/enumerations/length-error-type.ts +5 -0
- package/src/enumerations/member-error-type.ts +106 -0
- package/src/enumerations/{member-type.d.ts → member-type.ts} +7 -6
- package/src/enumerations/password-login-error-type.ts +4 -0
- package/src/enumerations/pbkdf2-error-type.ts +5 -0
- package/src/enumerations/pbkdf2-profile.ts +5 -0
- package/src/enumerations/secure-storage-error-type.ts +5 -0
- package/src/errors/disposed.ts +36 -0
- package/src/errors/ecies.ts +153 -0
- package/src/errors/guid.ts +130 -0
- package/src/errors/id-provider.ts +40 -0
- package/src/errors/{index.d.ts → index.ts} +0 -1
- package/src/errors/invalid-email.ts +23 -0
- package/src/errors/length.ts +19 -0
- package/src/errors/member.ts +20 -0
- package/src/errors/pbkdf2.ts +20 -0
- package/src/errors/secure-storage.ts +17 -0
- package/src/errors/simple-ecies.ts +21 -0
- package/src/errors/simple-test-error.ts +6 -0
- package/src/i18n-setup.ts +130 -0
- package/src/{index.js → index.ts} +64 -7
- package/src/interfaces/checksum-config.ts +4 -0
- package/src/interfaces/checksum-consts.ts +13 -0
- package/src/interfaces/configuration-provenance.ts +54 -0
- package/src/interfaces/constants.ts +75 -0
- package/src/interfaces/ecies-config.ts +8 -0
- package/src/interfaces/ecies-consts.ts +74 -0
- package/src/interfaces/ecies-file-service.ts +6 -0
- package/src/interfaces/encrypted-chunk.ts +64 -0
- package/src/interfaces/encryption-state.ts +19 -0
- package/src/interfaces/frontend-member-operational.ts +77 -0
- package/src/interfaces/guid.ts +86 -0
- package/src/interfaces/id-provider.ts +152 -0
- package/src/interfaces/{index.d.ts → index.ts} +0 -1
- package/src/interfaces/invariant.ts +60 -0
- package/src/interfaces/library-error.ts +23 -0
- package/src/interfaces/{member-storage.d.ts → member-storage.ts} +11 -10
- package/src/interfaces/{member-with-mnemonic.d.ts → member-with-mnemonic.ts} +3 -3
- package/src/interfaces/member.ts +84 -0
- package/src/interfaces/multi-recipient-chunk.ts +61 -0
- package/src/interfaces/pbkdf2-config.ts +6 -0
- package/src/interfaces/pbkdf2-consts.ts +10 -0
- package/src/interfaces/pbkdf2-result.ts +5 -0
- package/src/interfaces/stream-config.ts +17 -0
- package/src/interfaces/stream-header.ts +34 -0
- package/src/interfaces/stream-progress.ts +31 -0
- package/src/lib/configuration-provenance-utils.ts +26 -0
- package/src/lib/crypto-container.ts +64 -0
- package/src/lib/guid.ts +1097 -0
- package/src/lib/id-providers/custom-provider.ts +109 -0
- package/src/lib/id-providers/guidv4-provider.ts +141 -0
- package/src/lib/id-providers/{index.d.ts → index.ts} +6 -5
- package/src/lib/id-providers/objectid-provider.ts +125 -0
- package/src/lib/id-providers/uuid-provider.ts +133 -0
- package/src/lib/{index.js → index.ts} +2 -2
- package/src/lib/invariant-validator.ts +133 -0
- package/src/lib/invariants/encryption-algorithm-consistency.ts +73 -0
- package/src/lib/invariants/{index.js → index.ts} +0 -1
- package/src/lib/invariants/pbkdf2-profiles-validity.ts +78 -0
- package/src/lib/invariants/recipient-id-consistency.ts +46 -0
- package/src/lib/multi-recipient-chunk-utils.ts +63 -0
- package/src/member.ts +495 -0
- package/src/{pbkdf2-profiles.d.ts → pbkdf2-profiles.ts} +2 -2
- package/src/phone-number.ts +18 -0
- package/src/regexes.ts +10 -0
- package/src/secure-buffer.ts +226 -0
- package/src/secure-string.ts +244 -0
- package/src/services/aes-gcm.ts +220 -0
- package/src/services/chunk-processor.ts +188 -0
- package/src/services/ecies/README.md +147 -0
- package/src/services/ecies/crypto-core.ts +292 -0
- package/src/services/ecies/example.ts +185 -0
- package/src/services/ecies/file.ts +167 -0
- package/src/services/ecies/{index.js → index.ts} +2 -1
- package/src/services/ecies/integration.ts +241 -0
- package/src/services/ecies/interfaces.ts +62 -0
- package/src/services/ecies/manual-test.ts +219 -0
- package/src/services/ecies/multi-recipient.ts +545 -0
- package/src/services/ecies/service.ts +370 -0
- package/src/services/ecies/signature.ts +93 -0
- package/src/services/ecies/single-recipient.ts +476 -0
- package/src/services/encryption-stream.ts +435 -0
- package/src/services/{index.js → index.ts} +0 -1
- package/src/services/multi-recipient-processor.ts +377 -0
- package/src/services/password-login.ts +226 -0
- package/src/services/pbkdf2.ts +169 -0
- package/src/services/progress-tracker.ts +128 -0
- package/src/services/resumable-encryption.ts +135 -0
- package/src/services/xor.ts +65 -0
- package/src/test-mocks/index.ts +1 -0
- package/src/test-mocks/mock-frontend-member.ts +276 -0
- package/src/{testing.js → testing.ts} +0 -1
- package/src/translations/{de.js → de.ts} +112 -56
- package/src/translations/{en-US.js → en-US.ts} +116 -58
- package/src/translations/{es.js → es.ts} +134 -67
- package/src/translations/{fr.js → fr.ts} +129 -64
- package/src/translations/{ja.js → ja.ts} +111 -55
- package/src/translations/{uk.js → uk.ts} +132 -67
- package/src/translations/{zh-cn.js → zh-cn.ts} +60 -29
- package/src/types/deep-partial.ts +11 -0
- package/src/{types.d.ts → types.ts} +15 -7
- package/src/utils/encryption-type-utils.ts +76 -0
- package/src/utils.ts +329 -0
- package/src/builders/ecies-builder.d.ts +0 -18
- package/src/builders/ecies-builder.d.ts.map +0 -1
- package/src/builders/ecies-builder.js +0 -30
- package/src/builders/ecies-builder.js.map +0 -1
- package/src/builders/index.d.ts +0 -6
- package/src/builders/index.d.ts.map +0 -1
- package/src/builders/index.js.map +0 -1
- package/src/builders/member-builder.d.ts +0 -51
- package/src/builders/member-builder.d.ts.map +0 -1
- package/src/builders/member-builder.js +0 -97
- package/src/builders/member-builder.js.map +0 -1
- package/src/constants.d.ts +0 -60
- package/src/constants.d.ts.map +0 -1
- package/src/constants.js +0 -446
- package/src/constants.js.map +0 -1
- package/src/core/errors/crypto-error.d.ts +0 -34
- package/src/core/errors/crypto-error.d.ts.map +0 -1
- package/src/core/errors/crypto-error.js +0 -56
- package/src/core/errors/crypto-error.js.map +0 -1
- package/src/core/index.d.ts +0 -6
- package/src/core/index.d.ts.map +0 -1
- package/src/core/index.js.map +0 -1
- package/src/core/types/result.d.ts +0 -16
- package/src/core/types/result.d.ts.map +0 -1
- package/src/core/types/result.js +0 -12
- package/src/core/types/result.js.map +0 -1
- package/src/email-string.d.ts +0 -42
- package/src/email-string.d.ts.map +0 -1
- package/src/email-string.js +0 -67
- package/src/email-string.js.map +0 -1
- package/src/enumerations/disposed-error-type.d.ts +0 -12
- package/src/enumerations/disposed-error-type.d.ts.map +0 -1
- package/src/enumerations/disposed-error-type.js +0 -13
- package/src/enumerations/disposed-error-type.js.map +0 -1
- package/src/enumerations/ecies-cipher-suite.d.ts +0 -4
- package/src/enumerations/ecies-cipher-suite.d.ts.map +0 -1
- package/src/enumerations/ecies-cipher-suite.js +0 -6
- package/src/enumerations/ecies-cipher-suite.js.map +0 -1
- package/src/enumerations/ecies-encryption-type.d.ts +0 -11
- package/src/enumerations/ecies-encryption-type.d.ts.map +0 -1
- package/src/enumerations/ecies-encryption-type.js +0 -27
- package/src/enumerations/ecies-encryption-type.js.map +0 -1
- package/src/enumerations/ecies-error-type.d.ts +0 -44
- package/src/enumerations/ecies-error-type.d.ts.map +0 -1
- package/src/enumerations/ecies-error-type.js +0 -45
- package/src/enumerations/ecies-error-type.js.map +0 -1
- package/src/enumerations/ecies-string-key.d.ts +0 -192
- package/src/enumerations/ecies-string-key.d.ts.map +0 -1
- package/src/enumerations/ecies-string-key.js +0 -199
- package/src/enumerations/ecies-string-key.js.map +0 -1
- package/src/enumerations/ecies-version.d.ts +0 -4
- package/src/enumerations/ecies-version.d.ts.map +0 -1
- package/src/enumerations/ecies-version.js +0 -5
- package/src/enumerations/ecies-version.js.map +0 -1
- package/src/enumerations/guid-brand-type.d.ts +0 -27
- package/src/enumerations/guid-brand-type.d.ts.map +0 -1
- package/src/enumerations/guid-brand-type.js +0 -28
- package/src/enumerations/guid-brand-type.js.map +0 -1
- package/src/enumerations/guid-error-type.d.ts +0 -7
- package/src/enumerations/guid-error-type.d.ts.map +0 -1
- package/src/enumerations/guid-error-type.js +0 -8
- package/src/enumerations/guid-error-type.js.map +0 -1
- package/src/enumerations/id-provider-error-type.d.ts +0 -43
- package/src/enumerations/id-provider-error-type.d.ts.map +0 -1
- package/src/enumerations/id-provider-error-type.js +0 -44
- package/src/enumerations/id-provider-error-type.js.map +0 -1
- package/src/enumerations/index.d.ts +0 -18
- package/src/enumerations/index.d.ts.map +0 -1
- package/src/enumerations/index.js.map +0 -1
- package/src/enumerations/invalid-email-type.d.ts +0 -6
- package/src/enumerations/invalid-email-type.d.ts.map +0 -1
- package/src/enumerations/invalid-email-type.js +0 -7
- package/src/enumerations/invalid-email-type.js.map +0 -1
- package/src/enumerations/length-encoding-type.d.ts +0 -7
- package/src/enumerations/length-encoding-type.d.ts.map +0 -1
- package/src/enumerations/length-encoding-type.js +0 -8
- package/src/enumerations/length-encoding-type.js.map +0 -1
- package/src/enumerations/length-error-type.d.ts +0 -6
- package/src/enumerations/length-error-type.d.ts.map +0 -1
- package/src/enumerations/length-error-type.js +0 -7
- package/src/enumerations/length-error-type.js.map +0 -1
- package/src/enumerations/member-error-type.d.ts +0 -87
- package/src/enumerations/member-error-type.d.ts.map +0 -1
- package/src/enumerations/member-error-type.js +0 -88
- package/src/enumerations/member-error-type.js.map +0 -1
- package/src/enumerations/member-type.d.ts.map +0 -1
- package/src/enumerations/member-type.js +0 -16
- package/src/enumerations/member-type.js.map +0 -1
- package/src/enumerations/password-login-error-type.d.ts +0 -5
- package/src/enumerations/password-login-error-type.d.ts.map +0 -1
- package/src/enumerations/password-login-error-type.js +0 -6
- package/src/enumerations/password-login-error-type.js.map +0 -1
- package/src/enumerations/pbkdf2-error-type.d.ts +0 -6
- package/src/enumerations/pbkdf2-error-type.d.ts.map +0 -1
- package/src/enumerations/pbkdf2-error-type.js +0 -7
- package/src/enumerations/pbkdf2-error-type.js.map +0 -1
- package/src/enumerations/pbkdf2-profile.d.ts +0 -6
- package/src/enumerations/pbkdf2-profile.d.ts.map +0 -1
- package/src/enumerations/pbkdf2-profile.js +0 -7
- package/src/enumerations/pbkdf2-profile.js.map +0 -1
- package/src/enumerations/secure-storage-error-type.d.ts +0 -6
- package/src/enumerations/secure-storage-error-type.d.ts.map +0 -1
- package/src/enumerations/secure-storage-error-type.js +0 -7
- package/src/enumerations/secure-storage-error-type.js.map +0 -1
- package/src/errors/disposed.d.ts +0 -22
- package/src/errors/disposed.d.ts.map +0 -1
- package/src/errors/disposed.js +0 -28
- package/src/errors/disposed.js.map +0 -1
- package/src/errors/ecies.d.ts +0 -52
- package/src/errors/ecies.d.ts.map +0 -1
- package/src/errors/ecies.js +0 -78
- package/src/errors/ecies.js.map +0 -1
- package/src/errors/guid.d.ts +0 -49
- package/src/errors/guid.d.ts.map +0 -1
- package/src/errors/guid.js +0 -96
- package/src/errors/guid.js.map +0 -1
- package/src/errors/id-provider.d.ts +0 -23
- package/src/errors/id-provider.d.ts.map +0 -1
- package/src/errors/id-provider.js +0 -29
- package/src/errors/id-provider.js.map +0 -1
- package/src/errors/index.d.ts.map +0 -1
- package/src/errors/index.js +0 -10
- package/src/errors/index.js.map +0 -1
- package/src/errors/invalid-email.d.ts +0 -8
- package/src/errors/invalid-email.d.ts.map +0 -1
- package/src/errors/invalid-email.js +0 -15
- package/src/errors/invalid-email.js.map +0 -1
- package/src/errors/length.d.ts +0 -7
- package/src/errors/length.d.ts.map +0 -1
- package/src/errors/length.js +0 -11
- package/src/errors/length.js.map +0 -1
- package/src/errors/member.d.ts +0 -7
- package/src/errors/member.d.ts.map +0 -1
- package/src/errors/member.js +0 -11
- package/src/errors/member.js.map +0 -1
- package/src/errors/pbkdf2.d.ts +0 -7
- package/src/errors/pbkdf2.d.ts.map +0 -1
- package/src/errors/pbkdf2.js +0 -11
- package/src/errors/pbkdf2.js.map +0 -1
- package/src/errors/secure-storage.d.ts +0 -7
- package/src/errors/secure-storage.d.ts.map +0 -1
- package/src/errors/secure-storage.js +0 -12
- package/src/errors/secure-storage.js.map +0 -1
- package/src/errors/simple-ecies.d.ts +0 -6
- package/src/errors/simple-ecies.d.ts.map +0 -1
- package/src/errors/simple-ecies.js +0 -12
- package/src/errors/simple-ecies.js.map +0 -1
- package/src/errors/simple-test-error.d.ts +0 -4
- package/src/errors/simple-test-error.d.ts.map +0 -1
- package/src/errors/simple-test-error.js +0 -7
- package/src/errors/simple-test-error.js.map +0 -1
- package/src/i18n-setup.d.ts +0 -32
- package/src/i18n-setup.d.ts.map +0 -1
- package/src/i18n-setup.js +0 -101
- package/src/i18n-setup.js.map +0 -1
- package/src/index.d.ts +0 -80
- package/src/index.d.ts.map +0 -1
- package/src/index.js.map +0 -1
- package/src/interfaces/checksum-config.d.ts +0 -5
- package/src/interfaces/checksum-config.d.ts.map +0 -1
- package/src/interfaces/checksum-config.js +0 -2
- package/src/interfaces/checksum-config.js.map +0 -1
- package/src/interfaces/checksum-consts.d.ts +0 -11
- package/src/interfaces/checksum-consts.d.ts.map +0 -1
- package/src/interfaces/checksum-consts.js +0 -2
- package/src/interfaces/checksum-consts.js.map +0 -1
- package/src/interfaces/configuration-provenance.d.ts +0 -43
- package/src/interfaces/configuration-provenance.d.ts.map +0 -1
- package/src/interfaces/configuration-provenance.js +0 -3
- package/src/interfaces/configuration-provenance.js.map +0 -1
- package/src/interfaces/constants.d.ts +0 -70
- package/src/interfaces/constants.d.ts.map +0 -1
- package/src/interfaces/constants.js +0 -2
- package/src/interfaces/constants.js.map +0 -1
- package/src/interfaces/ecies-config.d.ts +0 -9
- package/src/interfaces/ecies-config.d.ts.map +0 -1
- package/src/interfaces/ecies-config.js +0 -2
- package/src/interfaces/ecies-config.js.map +0 -1
- package/src/interfaces/ecies-consts.d.ts +0 -61
- package/src/interfaces/ecies-consts.d.ts.map +0 -1
- package/src/interfaces/ecies-consts.js +0 -2
- package/src/interfaces/ecies-consts.js.map +0 -1
- package/src/interfaces/ecies-file-service.d.ts +0 -7
- package/src/interfaces/ecies-file-service.d.ts.map +0 -1
- package/src/interfaces/ecies-file-service.js +0 -2
- package/src/interfaces/ecies-file-service.js.map +0 -1
- package/src/interfaces/encrypted-chunk.d.ts +0 -55
- package/src/interfaces/encrypted-chunk.d.ts.map +0 -1
- package/src/interfaces/encrypted-chunk.js +0 -12
- package/src/interfaces/encrypted-chunk.js.map +0 -1
- package/src/interfaces/encryption-state.d.ts +0 -18
- package/src/interfaces/encryption-state.d.ts.map +0 -1
- package/src/interfaces/encryption-state.js +0 -2
- package/src/interfaces/encryption-state.js.map +0 -1
- package/src/interfaces/frontend-member-operational.d.ts +0 -51
- package/src/interfaces/frontend-member-operational.d.ts.map +0 -1
- package/src/interfaces/frontend-member-operational.js +0 -2
- package/src/interfaces/frontend-member-operational.js.map +0 -1
- package/src/interfaces/guid.d.ts +0 -78
- package/src/interfaces/guid.d.ts.map +0 -1
- package/src/interfaces/guid.js +0 -2
- package/src/interfaces/guid.js.map +0 -1
- package/src/interfaces/id-provider.d.ts +0 -107
- package/src/interfaces/id-provider.d.ts.map +0 -1
- package/src/interfaces/id-provider.js +0 -52
- package/src/interfaces/id-provider.js.map +0 -1
- package/src/interfaces/index.d.ts.map +0 -1
- package/src/interfaces/index.js +0 -13
- package/src/interfaces/index.js.map +0 -1
- package/src/interfaces/invariant.d.ts +0 -46
- package/src/interfaces/invariant.d.ts.map +0 -1
- package/src/interfaces/invariant.js +0 -18
- package/src/interfaces/invariant.js.map +0 -1
- package/src/interfaces/library-error.d.ts +0 -23
- package/src/interfaces/library-error.d.ts.map +0 -1
- package/src/interfaces/library-error.js +0 -2
- package/src/interfaces/library-error.js.map +0 -1
- package/src/interfaces/member-storage.d.ts.map +0 -1
- package/src/interfaces/member-storage.js +0 -2
- package/src/interfaces/member-storage.js.map +0 -1
- package/src/interfaces/member-with-mnemonic.d.ts.map +0 -1
- package/src/interfaces/member-with-mnemonic.js +0 -2
- package/src/interfaces/member-with-mnemonic.js.map +0 -1
- package/src/interfaces/member.d.ts +0 -55
- package/src/interfaces/member.d.ts.map +0 -1
- package/src/interfaces/member.js +0 -2
- package/src/interfaces/member.js.map +0 -1
- package/src/interfaces/multi-recipient-chunk.d.ts +0 -54
- package/src/interfaces/multi-recipient-chunk.d.ts.map +0 -1
- package/src/interfaces/multi-recipient-chunk.js +0 -11
- package/src/interfaces/multi-recipient-chunk.js.map +0 -1
- package/src/interfaces/pbkdf2-config.d.ts +0 -7
- package/src/interfaces/pbkdf2-config.d.ts.map +0 -1
- package/src/interfaces/pbkdf2-config.js +0 -2
- package/src/interfaces/pbkdf2-config.js.map +0 -1
- package/src/interfaces/pbkdf2-consts.d.ts +0 -9
- package/src/interfaces/pbkdf2-consts.d.ts.map +0 -1
- package/src/interfaces/pbkdf2-consts.js +0 -2
- package/src/interfaces/pbkdf2-consts.js.map +0 -1
- package/src/interfaces/pbkdf2-result.d.ts +0 -6
- package/src/interfaces/pbkdf2-result.d.ts.map +0 -1
- package/src/interfaces/pbkdf2-result.js +0 -2
- package/src/interfaces/pbkdf2-result.js.map +0 -1
- package/src/interfaces/stream-config.d.ts +0 -14
- package/src/interfaces/stream-config.d.ts.map +0 -1
- package/src/interfaces/stream-config.js +0 -8
- package/src/interfaces/stream-config.js.map +0 -1
- package/src/interfaces/stream-header.d.ts +0 -29
- package/src/interfaces/stream-header.d.ts.map +0 -1
- package/src/interfaces/stream-header.js +0 -9
- package/src/interfaces/stream-header.js.map +0 -1
- package/src/interfaces/stream-progress.d.ts +0 -33
- package/src/interfaces/stream-progress.d.ts.map +0 -1
- package/src/interfaces/stream-progress.js +0 -2
- package/src/interfaces/stream-progress.js.map +0 -1
- package/src/lib/configuration-provenance-utils.d.ts +0 -11
- package/src/lib/configuration-provenance-utils.d.ts.map +0 -1
- package/src/lib/configuration-provenance-utils.js +0 -23
- package/src/lib/configuration-provenance-utils.js.map +0 -1
- package/src/lib/crypto-container.d.ts +0 -25
- package/src/lib/crypto-container.d.ts.map +0 -1
- package/src/lib/crypto-container.js +0 -46
- package/src/lib/crypto-container.js.map +0 -1
- package/src/lib/guid.d.ts +0 -344
- package/src/lib/guid.d.ts.map +0 -1
- package/src/lib/guid.js +0 -914
- package/src/lib/guid.js.map +0 -1
- package/src/lib/id-providers/custom-provider.d.ts +0 -46
- package/src/lib/id-providers/custom-provider.d.ts.map +0 -1
- package/src/lib/id-providers/custom-provider.js +0 -85
- package/src/lib/id-providers/custom-provider.js.map +0 -1
- package/src/lib/id-providers/guidv4-provider.d.ts +0 -56
- package/src/lib/id-providers/guidv4-provider.d.ts.map +0 -1
- package/src/lib/id-providers/guidv4-provider.js +0 -122
- package/src/lib/id-providers/guidv4-provider.js.map +0 -1
- package/src/lib/id-providers/index.d.ts.map +0 -1
- package/src/lib/id-providers/index.js +0 -29
- package/src/lib/id-providers/index.js.map +0 -1
- package/src/lib/id-providers/objectid-provider.d.ts +0 -43
- package/src/lib/id-providers/objectid-provider.d.ts.map +0 -1
- package/src/lib/id-providers/objectid-provider.js +0 -104
- package/src/lib/id-providers/objectid-provider.js.map +0 -1
- package/src/lib/id-providers/uuid-provider.d.ts +0 -52
- package/src/lib/id-providers/uuid-provider.d.ts.map +0 -1
- package/src/lib/id-providers/uuid-provider.js +0 -110
- package/src/lib/id-providers/uuid-provider.js.map +0 -1
- package/src/lib/index.d.ts +0 -6
- package/src/lib/index.d.ts.map +0 -1
- package/src/lib/index.js.map +0 -1
- package/src/lib/invariant-validator.d.ts +0 -59
- package/src/lib/invariant-validator.d.ts.map +0 -1
- package/src/lib/invariant-validator.js +0 -97
- package/src/lib/invariant-validator.js.map +0 -1
- package/src/lib/invariants/encryption-algorithm-consistency.d.ts +0 -17
- package/src/lib/invariants/encryption-algorithm-consistency.d.ts.map +0 -1
- package/src/lib/invariants/encryption-algorithm-consistency.js +0 -49
- package/src/lib/invariants/encryption-algorithm-consistency.js.map +0 -1
- package/src/lib/invariants/index.d.ts +0 -4
- package/src/lib/invariants/index.d.ts.map +0 -1
- package/src/lib/invariants/index.js.map +0 -1
- package/src/lib/invariants/pbkdf2-profiles-validity.d.ts +0 -16
- package/src/lib/invariants/pbkdf2-profiles-validity.d.ts.map +0 -1
- package/src/lib/invariants/pbkdf2-profiles-validity.js +0 -58
- package/src/lib/invariants/pbkdf2-profiles-validity.js.map +0 -1
- package/src/lib/invariants/recipient-id-consistency.d.ts +0 -18
- package/src/lib/invariants/recipient-id-consistency.d.ts.map +0 -1
- package/src/lib/invariants/recipient-id-consistency.js +0 -31
- package/src/lib/invariants/recipient-id-consistency.js.map +0 -1
- package/src/lib/multi-recipient-chunk-utils.d.ts +0 -38
- package/src/lib/multi-recipient-chunk-utils.d.ts.map +0 -1
- package/src/lib/multi-recipient-chunk-utils.js +0 -41
- package/src/lib/multi-recipient-chunk-utils.js.map +0 -1
- package/src/member.d.ts +0 -92
- package/src/member.d.ts.map +0 -1
- package/src/member.js +0 -322
- package/src/member.js.map +0 -1
- package/src/pbkdf2-profiles.d.ts.map +0 -1
- package/src/pbkdf2-profiles.js +0 -2
- package/src/pbkdf2-profiles.js.map +0 -1
- package/src/phone-number.d.ts +0 -6
- package/src/phone-number.d.ts.map +0 -1
- package/src/phone-number.js +0 -18
- package/src/phone-number.js.map +0 -1
- package/src/regexes.d.ts +0 -7
- package/src/regexes.d.ts.map +0 -1
- package/src/regexes.js +0 -7
- package/src/regexes.js.map +0 -1
- package/src/secure-buffer.d.ts +0 -61
- package/src/secure-buffer.d.ts.map +0 -1
- package/src/secure-buffer.js +0 -201
- package/src/secure-buffer.js.map +0 -1
- package/src/secure-string.d.ts +0 -46
- package/src/secure-string.d.ts.map +0 -1
- package/src/secure-string.js +0 -206
- package/src/secure-string.js.map +0 -1
- package/src/services/aes-gcm.d.ts +0 -57
- package/src/services/aes-gcm.d.ts.map +0 -1
- package/src/services/aes-gcm.js +0 -142
- package/src/services/aes-gcm.js.map +0 -1
- package/src/services/chunk-processor.d.ts +0 -31
- package/src/services/chunk-processor.d.ts.map +0 -1
- package/src/services/chunk-processor.js +0 -145
- package/src/services/chunk-processor.js.map +0 -1
- package/src/services/ecies/crypto-core.d.ts +0 -72
- package/src/services/ecies/crypto-core.d.ts.map +0 -1
- package/src/services/ecies/crypto-core.js +0 -205
- package/src/services/ecies/crypto-core.js.map +0 -1
- package/src/services/ecies/example.d.ts +0 -25
- package/src/services/ecies/example.d.ts.map +0 -1
- package/src/services/ecies/example.js +0 -121
- package/src/services/ecies/example.js.map +0 -1
- package/src/services/ecies/file.d.ts +0 -18
- package/src/services/ecies/file.d.ts.map +0 -1
- package/src/services/ecies/file.js +0 -106
- package/src/services/ecies/file.js.map +0 -1
- package/src/services/ecies/index.d.ts +0 -38
- package/src/services/ecies/index.d.ts.map +0 -1
- package/src/services/ecies/index.js.map +0 -1
- package/src/services/ecies/integration.d.ts +0 -59
- package/src/services/ecies/integration.d.ts.map +0 -1
- package/src/services/ecies/integration.js +0 -167
- package/src/services/ecies/integration.js.map +0 -1
- package/src/services/ecies/interfaces.d.ts +0 -54
- package/src/services/ecies/interfaces.d.ts.map +0 -1
- package/src/services/ecies/interfaces.js +0 -5
- package/src/services/ecies/interfaces.js.map +0 -1
- package/src/services/ecies/manual-test.d.ts +0 -29
- package/src/services/ecies/manual-test.d.ts.map +0 -1
- package/src/services/ecies/manual-test.js +0 -163
- package/src/services/ecies/manual-test.js.map +0 -1
- package/src/services/ecies/multi-recipient.d.ts +0 -56
- package/src/services/ecies/multi-recipient.d.ts.map +0 -1
- package/src/services/ecies/multi-recipient.js +0 -344
- package/src/services/ecies/multi-recipient.js.map +0 -1
- package/src/services/ecies/service.d.ts +0 -120
- package/src/services/ecies/service.d.ts.map +0 -1
- package/src/services/ecies/service.js +0 -210
- package/src/services/ecies/service.js.map +0 -1
- package/src/services/ecies/signature.d.ts +0 -27
- package/src/services/ecies/signature.d.ts.map +0 -1
- package/src/services/ecies/signature.js +0 -72
- package/src/services/ecies/signature.js.map +0 -1
- package/src/services/ecies/single-recipient.d.ts +0 -46
- package/src/services/ecies/single-recipient.d.ts.map +0 -1
- package/src/services/ecies/single-recipient.js +0 -322
- package/src/services/ecies/single-recipient.js.map +0 -1
- package/src/services/encryption-stream.d.ts +0 -71
- package/src/services/encryption-stream.d.ts.map +0 -1
- package/src/services/encryption-stream.js +0 -295
- package/src/services/encryption-stream.js.map +0 -1
- package/src/services/index.d.ts +0 -11
- package/src/services/index.d.ts.map +0 -1
- package/src/services/index.js.map +0 -1
- package/src/services/multi-recipient-processor.d.ts +0 -35
- package/src/services/multi-recipient-processor.d.ts.map +0 -1
- package/src/services/multi-recipient-processor.js +0 -289
- package/src/services/multi-recipient-processor.js.map +0 -1
- package/src/services/password-login.d.ts +0 -47
- package/src/services/password-login.d.ts.map +0 -1
- package/src/services/password-login.js +0 -115
- package/src/services/password-login.js.map +0 -1
- package/src/services/pbkdf2.d.ts +0 -54
- package/src/services/pbkdf2.d.ts.map +0 -1
- package/src/services/pbkdf2.js +0 -108
- package/src/services/pbkdf2.js.map +0 -1
- package/src/services/progress-tracker.d.ts +0 -23
- package/src/services/progress-tracker.d.ts.map +0 -1
- package/src/services/progress-tracker.js +0 -103
- package/src/services/progress-tracker.js.map +0 -1
- package/src/services/resumable-encryption.d.ts +0 -19
- package/src/services/resumable-encryption.d.ts.map +0 -1
- package/src/services/resumable-encryption.js +0 -105
- package/src/services/resumable-encryption.js.map +0 -1
- package/src/services/xor.d.ts +0 -37
- package/src/services/xor.d.ts.map +0 -1
- package/src/services/xor.js +0 -63
- package/src/services/xor.js.map +0 -1
- package/src/test-mocks/index.d.ts +0 -2
- package/src/test-mocks/index.d.ts.map +0 -1
- package/src/test-mocks/index.js +0 -2
- package/src/test-mocks/index.js.map +0 -1
- package/src/test-mocks/mock-frontend-member.d.ts +0 -85
- package/src/test-mocks/mock-frontend-member.d.ts.map +0 -1
- package/src/test-mocks/mock-frontend-member.js +0 -190
- package/src/test-mocks/mock-frontend-member.js.map +0 -1
- package/src/testing.d.ts +0 -2
- package/src/testing.d.ts.map +0 -1
- package/src/testing.js.map +0 -1
- package/src/translations/de.d.ts +0 -4
- package/src/translations/de.d.ts.map +0 -1
- package/src/translations/de.js.map +0 -1
- package/src/translations/en-US.d.ts +0 -4
- package/src/translations/en-US.d.ts.map +0 -1
- package/src/translations/en-US.js.map +0 -1
- package/src/translations/es.d.ts +0 -4
- package/src/translations/es.d.ts.map +0 -1
- package/src/translations/es.js.map +0 -1
- package/src/translations/fr.d.ts +0 -4
- package/src/translations/fr.d.ts.map +0 -1
- package/src/translations/fr.js.map +0 -1
- package/src/translations/ja.d.ts +0 -4
- package/src/translations/ja.d.ts.map +0 -1
- package/src/translations/ja.js.map +0 -1
- package/src/translations/uk.d.ts +0 -4
- package/src/translations/uk.d.ts.map +0 -1
- package/src/translations/uk.js.map +0 -1
- package/src/translations/zh-cn.d.ts +0 -4
- package/src/translations/zh-cn.d.ts.map +0 -1
- package/src/translations/zh-cn.js.map +0 -1
- package/src/types/deep-partial.d.ts +0 -4
- package/src/types/deep-partial.d.ts.map +0 -1
- package/src/types/deep-partial.js +0 -2
- package/src/types/deep-partial.js.map +0 -1
- package/src/types.d.ts.map +0 -1
- package/src/types.js +0 -2
- package/src/types.js.map +0 -1
- package/src/utils/encryption-type-utils.d.ts +0 -29
- package/src/utils/encryption-type-utils.d.ts.map +0 -1
- package/src/utils/encryption-type-utils.js +0 -61
- package/src/utils/encryption-type-utils.js.map +0 -1
- package/src/utils.d.ts +0 -68
- package/src/utils.d.ts.map +0 -1
- package/src/utils.js +0 -273
- package/src/utils.js.map +0 -1
package/src/lib/guid.js
DELETED
|
@@ -1,914 +0,0 @@
|
|
|
1
|
-
import * as uuid from 'uuid';
|
|
2
|
-
import { GuidBrandType } from '../enumerations/guid-brand-type';
|
|
3
|
-
import { GuidErrorType } from '../enumerations/guid-error-type';
|
|
4
|
-
import { GuidError } from '../errors/guid';
|
|
5
|
-
/**
|
|
6
|
-
* GuidV4 represents a GUID (Globally Unique Identifier) that is compliant with the RFC 4122 standard.
|
|
7
|
-
* GuidV4 instances can be created from a variety of input types, including:
|
|
8
|
-
* - FullHexGuid: A 36-character string representation of the GUID, including dashes
|
|
9
|
-
* - ShortHexGuid: A 32-character string representation of the GUID, excluding dashes
|
|
10
|
-
* - Base64Guid: A 24-character base64-encoded string representation of the GUID
|
|
11
|
-
* - BigIntGuid: A bigint representation of the GUID
|
|
12
|
-
* - RawGuidBuffer: A 16-byte Buffer representation of the GUID
|
|
13
|
-
* GuidV4 instances can be converted to any of these representations using the appropriate method.
|
|
14
|
-
*/
|
|
15
|
-
export class GuidV4 {
|
|
16
|
-
/**
|
|
17
|
-
* GUID is stored internally as a raw 16-byte Buffer.
|
|
18
|
-
*/
|
|
19
|
-
_value;
|
|
20
|
-
/**
|
|
21
|
-
* Boundary value constants for special GUID validation
|
|
22
|
-
*/
|
|
23
|
-
static BOUNDARY_VALUES = {
|
|
24
|
-
ALL_ZEROS_FULL: '00000000-0000-0000-0000-000000000000',
|
|
25
|
-
ALL_ZEROS_SHORT: '00000000000000000000000000000000',
|
|
26
|
-
ALL_FS_FULL: 'ffffffff-ffff-ffff-ffff-ffffffffffff',
|
|
27
|
-
ALL_FS_SHORT: 'ffffffffffffffffffffffffffffffff',
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Maximum valid bigint value for a 128-bit GUID
|
|
31
|
-
*/
|
|
32
|
-
static MAX_BIGINT_VALUE = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
|
|
33
|
-
/**
|
|
34
|
-
* Cached full hex representation for performance
|
|
35
|
-
*/
|
|
36
|
-
_cachedFullHex;
|
|
37
|
-
/**
|
|
38
|
-
* Cached short hex representation for performance
|
|
39
|
-
*/
|
|
40
|
-
_cachedShortHex;
|
|
41
|
-
/**
|
|
42
|
-
* Cached base64 representation for performance
|
|
43
|
-
*/
|
|
44
|
-
_cachedBase64;
|
|
45
|
-
/**
|
|
46
|
-
* Regex for validating hex strings (case insensitive)
|
|
47
|
-
*/
|
|
48
|
-
static HEX_PATTERN = /^[0-9a-f]+$/i;
|
|
49
|
-
/**
|
|
50
|
-
* Regex for validating full hex GUID format
|
|
51
|
-
*/
|
|
52
|
-
static FULL_HEX_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
53
|
-
/**
|
|
54
|
-
* Cached empty/nil GUID constant (all zeros)
|
|
55
|
-
*/
|
|
56
|
-
static _empty;
|
|
57
|
-
/**
|
|
58
|
-
* Empty/nil GUID constant (all zeros)
|
|
59
|
-
*/
|
|
60
|
-
static get Empty() {
|
|
61
|
-
if (!GuidV4._empty) {
|
|
62
|
-
GuidV4._empty = Object.freeze(new GuidV4('00000000-0000-0000-0000-000000000000'));
|
|
63
|
-
}
|
|
64
|
-
return GuidV4._empty;
|
|
65
|
-
}
|
|
66
|
-
constructor(value) {
|
|
67
|
-
const buffer = GuidV4.validateAndConvert(value);
|
|
68
|
-
// Note: We cannot freeze a Buffer as it's an ArrayBuffer view
|
|
69
|
-
// Instead, we ensure the buffer is never directly modified after construction
|
|
70
|
-
this._value = buffer;
|
|
71
|
-
// Initialize cache properties so they exist before sealing
|
|
72
|
-
this._cachedFullHex = undefined;
|
|
73
|
-
this._cachedShortHex = undefined;
|
|
74
|
-
this._cachedBase64 = undefined;
|
|
75
|
-
// Seal the instance to prevent property addition/deletion
|
|
76
|
-
// Cache properties can still be set once since they were initialized
|
|
77
|
-
Object.seal(this);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Validates input and converts to raw buffer with comprehensive error handling.
|
|
81
|
-
* This centralizes all validation logic for better maintainability.
|
|
82
|
-
* @param value The input value to validate and convert
|
|
83
|
-
* @returns The validated raw GUID buffer
|
|
84
|
-
* @throws {GuidError} If validation fails
|
|
85
|
-
*/
|
|
86
|
-
static validateAndConvert(value) {
|
|
87
|
-
try {
|
|
88
|
-
// Null/undefined check
|
|
89
|
-
if (value === null || value === undefined) {
|
|
90
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
91
|
-
}
|
|
92
|
-
// Empty string check (but allow 0n bigint)
|
|
93
|
-
const strValue = String(value);
|
|
94
|
-
if (!strValue && value !== 0n) {
|
|
95
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
96
|
-
}
|
|
97
|
-
// Validate bigint is non-negative
|
|
98
|
-
if (typeof value === 'bigint' && value < 0n) {
|
|
99
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
100
|
-
}
|
|
101
|
-
// Validate hex strings contain only valid hex characters
|
|
102
|
-
if (typeof value === 'string') {
|
|
103
|
-
const isFullHex = value.length === 36 && value.includes('-');
|
|
104
|
-
const isShortHex = value.length === 32 && !value.includes('-');
|
|
105
|
-
if (isFullHex && !GuidV4.FULL_HEX_PATTERN.test(value)) {
|
|
106
|
-
const buffer = Buffer.from(value);
|
|
107
|
-
throw new GuidError(GuidErrorType.InvalidGuidWithDetails, GuidBrandType.FullHexGuid, value.length, buffer);
|
|
108
|
-
}
|
|
109
|
-
else if (isShortHex && !GuidV4.HEX_PATTERN.test(value)) {
|
|
110
|
-
const buffer = Buffer.from(value);
|
|
111
|
-
throw new GuidError(GuidErrorType.InvalidGuidWithDetails, GuidBrandType.ShortHexGuid, value.length, buffer);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// Determine and verify the brand/type
|
|
115
|
-
const expectedBrand = GuidV4.whichBrand(value);
|
|
116
|
-
const verifiedBrand = GuidV4.verifyGuid(expectedBrand, value);
|
|
117
|
-
if (!verifiedBrand) {
|
|
118
|
-
const valueBuffer = Buffer.isBuffer(value)
|
|
119
|
-
? value
|
|
120
|
-
: Buffer.from(strValue);
|
|
121
|
-
throw new GuidError(GuidErrorType.InvalidGuidWithDetails, expectedBrand, undefined, valueBuffer);
|
|
122
|
-
}
|
|
123
|
-
// Convert to raw buffer
|
|
124
|
-
const buffer = GuidV4.toRawGuidBuffer(value);
|
|
125
|
-
// Validate against UUID standard (skip for boundary values)
|
|
126
|
-
const fullHex = GuidV4.toFullHexGuid(buffer.toString('hex'));
|
|
127
|
-
const isBoundary = GuidV4.isBoundaryValue(fullHex);
|
|
128
|
-
if (!isBoundary && !uuid.validate(fullHex)) {
|
|
129
|
-
throw new GuidError(GuidErrorType.InvalidGuid, expectedBrand, undefined, buffer);
|
|
130
|
-
}
|
|
131
|
-
return buffer;
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
// Re-throw GuidError as-is
|
|
135
|
-
if (error instanceof GuidError) {
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
// Wrap other errors with context
|
|
139
|
-
if (typeof value === 'bigint') {
|
|
140
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
141
|
-
}
|
|
142
|
-
const length = value instanceof Buffer ? value.length : String(value).length;
|
|
143
|
-
throw new GuidError(GuidErrorType.InvalidGuidUnknownLength, undefined, length);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
static validateUuid(value) {
|
|
147
|
-
return uuid.validate(value);
|
|
148
|
-
}
|
|
149
|
-
serialize() {
|
|
150
|
-
return this.asBase64Guid;
|
|
151
|
-
}
|
|
152
|
-
static hydrate(value) {
|
|
153
|
-
return new GuidV4(value);
|
|
154
|
-
}
|
|
155
|
-
static LengthMap = {
|
|
156
|
-
[GuidBrandType.Unknown]: -1,
|
|
157
|
-
[GuidBrandType.FullHexGuid]: 36,
|
|
158
|
-
[GuidBrandType.ShortHexGuid]: 32,
|
|
159
|
-
[GuidBrandType.Base64Guid]: 24,
|
|
160
|
-
[GuidBrandType.RawGuidBuffer]: 16,
|
|
161
|
-
[GuidBrandType.BigIntGuid]: -1, // Variable length
|
|
162
|
-
};
|
|
163
|
-
static ReverseLengthMap = {
|
|
164
|
-
0: GuidBrandType.Unknown,
|
|
165
|
-
36: GuidBrandType.FullHexGuid,
|
|
166
|
-
32: GuidBrandType.ShortHexGuid,
|
|
167
|
-
24: GuidBrandType.Base64Guid,
|
|
168
|
-
16: GuidBrandType.RawGuidBuffer,
|
|
169
|
-
// BigIntGuid is variable length, so it is not included in the reverse map
|
|
170
|
-
};
|
|
171
|
-
static VerifyFunctions = {
|
|
172
|
-
[GuidBrandType.Unknown]: () => false,
|
|
173
|
-
[GuidBrandType.FullHexGuid]: (guid) => this.isFullHexGuid(guid),
|
|
174
|
-
[GuidBrandType.ShortHexGuid]: (guid) => this.isShortHexGuid(guid),
|
|
175
|
-
[GuidBrandType.Base64Guid]: (guid) => this.isBase64Guid(guid),
|
|
176
|
-
[GuidBrandType.BigIntGuid]: (guid) => this.isBigIntGuid(guid),
|
|
177
|
-
[GuidBrandType.RawGuidBuffer]: (guid) => this.isRawGuidBuffer(guid),
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* Returns the GUID as a raw Buffer.
|
|
181
|
-
* NOTE: Returns a defensive copy to prevent external mutation.
|
|
182
|
-
* Use asRawGuidBufferUnsafe() if you need the internal buffer and guarantee no mutation.
|
|
183
|
-
*/
|
|
184
|
-
get asRawGuidBuffer() {
|
|
185
|
-
return Buffer.from(this._value);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Returns the internal raw Buffer without copying.
|
|
189
|
-
* ⚠️ WARNING: Do NOT mutate the returned buffer! This is for performance-critical paths only.
|
|
190
|
-
* Mutating this buffer will corrupt the GUID instance.
|
|
191
|
-
* @internal
|
|
192
|
-
*/
|
|
193
|
-
get asRawGuidBufferUnsafe() {
|
|
194
|
-
return this._value;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Generates a new random v4 GUID.
|
|
198
|
-
* @returns A new GuidV4 instance with a randomly generated value
|
|
199
|
-
*/
|
|
200
|
-
static generate() {
|
|
201
|
-
try {
|
|
202
|
-
const uuidStr = uuid.v4();
|
|
203
|
-
if (!uuidStr) {
|
|
204
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
205
|
-
}
|
|
206
|
-
return new GuidV4(uuidStr);
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
if (error instanceof GuidError) {
|
|
210
|
-
throw error;
|
|
211
|
-
}
|
|
212
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Alias for generate() for backward compatibility.
|
|
217
|
-
* @deprecated Use generate() instead for clearer intent
|
|
218
|
-
*/
|
|
219
|
-
static new() {
|
|
220
|
-
return GuidV4.generate();
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Parses a GUID from any valid format, throwing on invalid input.
|
|
224
|
-
* This is the primary parsing method for when you expect valid input.
|
|
225
|
-
* @param value The value to parse
|
|
226
|
-
* @returns A new GuidV4 instance
|
|
227
|
-
* @throws {GuidError} If the value is not a valid GUID
|
|
228
|
-
*/
|
|
229
|
-
static parse(value) {
|
|
230
|
-
return new GuidV4(value);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Attempts to parse a GUID, returning null on failure instead of throwing.
|
|
234
|
-
* Use this when you're uncertain if the input is valid.
|
|
235
|
-
* @param value The value to parse
|
|
236
|
-
* @returns A new GuidV4 instance or null if parsing fails
|
|
237
|
-
*/
|
|
238
|
-
static tryParse(value) {
|
|
239
|
-
try {
|
|
240
|
-
return new GuidV4(value);
|
|
241
|
-
}
|
|
242
|
-
catch {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Validates whether a value is a valid GUID without creating an instance.
|
|
248
|
-
* More efficient than tryParse when you only need validation.
|
|
249
|
-
* @param value The value to validate
|
|
250
|
-
* @returns True if valid, false otherwise
|
|
251
|
-
*/
|
|
252
|
-
static isValid(value) {
|
|
253
|
-
if (!value)
|
|
254
|
-
return false;
|
|
255
|
-
try {
|
|
256
|
-
const guid = new GuidV4(value);
|
|
257
|
-
return guid.isValidV4();
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Factory method to create a GUID from a full hex string.
|
|
265
|
-
* @param fullHex The full hex string (with dashes)
|
|
266
|
-
* @returns A new GuidV4 instance
|
|
267
|
-
*/
|
|
268
|
-
static fromFullHex(fullHex) {
|
|
269
|
-
return new GuidV4(fullHex);
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Factory method to create a GUID from a short hex string.
|
|
273
|
-
* @param shortHex The short hex string (without dashes)
|
|
274
|
-
* @returns A new GuidV4 instance
|
|
275
|
-
*/
|
|
276
|
-
static fromShortHex(shortHex) {
|
|
277
|
-
return new GuidV4(shortHex);
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Factory method to create a GUID from a base64 string.
|
|
281
|
-
* @param base64 The base64 encoded string
|
|
282
|
-
* @returns A new GuidV4 instance
|
|
283
|
-
*/
|
|
284
|
-
static fromBase64(base64) {
|
|
285
|
-
return new GuidV4(base64);
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Factory method to create a GUID from a bigint.
|
|
289
|
-
* @param bigint The bigint value
|
|
290
|
-
* @returns A new GuidV4 instance
|
|
291
|
-
*/
|
|
292
|
-
static fromBigInt(bigint) {
|
|
293
|
-
return new GuidV4(bigint);
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Factory method to create a GUID from a raw buffer.
|
|
297
|
-
* @param buffer The raw 16-byte buffer
|
|
298
|
-
* @returns A new GuidV4 instance
|
|
299
|
-
*/
|
|
300
|
-
static fromBuffer(buffer) {
|
|
301
|
-
return new GuidV4(buffer);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Creates a namespace-based v3 GUID (MD5 hash).
|
|
305
|
-
* Use this for deterministic GUIDs based on a namespace and name.
|
|
306
|
-
* @param namespace The namespace GUID (e.g., uuid.v3.DNS)
|
|
307
|
-
* @param name The name to hash within the namespace
|
|
308
|
-
* @returns A new GuidV4 instance containing the v3 GUID
|
|
309
|
-
* @example
|
|
310
|
-
* const guid = GuidV4.v3('example.com', uuid.v3.DNS);
|
|
311
|
-
*/
|
|
312
|
-
static v3(name, namespace) {
|
|
313
|
-
try {
|
|
314
|
-
const namespaceStr = Buffer.isBuffer(namespace)
|
|
315
|
-
? GuidV4.toFullHexGuid(namespace.toString('hex'))
|
|
316
|
-
: namespace;
|
|
317
|
-
const v3Guid = uuid.v3(name, namespaceStr);
|
|
318
|
-
return new GuidV4(v3Guid);
|
|
319
|
-
}
|
|
320
|
-
catch (error) {
|
|
321
|
-
if (error instanceof GuidError) {
|
|
322
|
-
throw error;
|
|
323
|
-
}
|
|
324
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Creates a namespace-based v5 GUID (SHA-1 hash).
|
|
329
|
-
* Use this for deterministic GUIDs based on a namespace and name.
|
|
330
|
-
* Preferred over v3 as SHA-1 is stronger than MD5.
|
|
331
|
-
* @param namespace The namespace GUID (e.g., uuid.v5.DNS)
|
|
332
|
-
* @param name The name to hash within the namespace
|
|
333
|
-
* @returns A new GuidV4 instance containing the v5 GUID
|
|
334
|
-
* @example
|
|
335
|
-
* const guid = GuidV4.v5('example.com', uuid.v5.DNS);
|
|
336
|
-
*/
|
|
337
|
-
static v5(name, namespace) {
|
|
338
|
-
try {
|
|
339
|
-
const namespaceStr = Buffer.isBuffer(namespace)
|
|
340
|
-
? GuidV4.toFullHexGuid(namespace.toString('hex'))
|
|
341
|
-
: namespace;
|
|
342
|
-
const v5Guid = uuid.v5(name, namespaceStr);
|
|
343
|
-
return new GuidV4(v5Guid);
|
|
344
|
-
}
|
|
345
|
-
catch (error) {
|
|
346
|
-
if (error instanceof GuidError) {
|
|
347
|
-
throw error;
|
|
348
|
-
}
|
|
349
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Common namespace constants for use with v3/v5 GUIDs.
|
|
354
|
-
* Re-exported from uuid library for convenience.
|
|
355
|
-
*/
|
|
356
|
-
static Namespaces = {
|
|
357
|
-
DNS: uuid.v5.DNS,
|
|
358
|
-
URL: uuid.v5.URL,
|
|
359
|
-
};
|
|
360
|
-
/**
|
|
361
|
-
* Returns the GUID as a full hex string.
|
|
362
|
-
* Result is cached for performance.
|
|
363
|
-
*/
|
|
364
|
-
get asFullHexGuid() {
|
|
365
|
-
if (!this._cachedFullHex) {
|
|
366
|
-
this._cachedFullHex = GuidV4.toFullHexGuid(this._value.toString('hex'));
|
|
367
|
-
}
|
|
368
|
-
return this._cachedFullHex;
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Returns the GUID as a raw Uint8Array.
|
|
372
|
-
*/
|
|
373
|
-
get asUint8Array() {
|
|
374
|
-
return this._value;
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Returns the GUID as a short hex string.
|
|
378
|
-
* Result is cached for performance.
|
|
379
|
-
*/
|
|
380
|
-
get asShortHexGuid() {
|
|
381
|
-
if (!this._cachedShortHex) {
|
|
382
|
-
this._cachedShortHex = GuidV4.toShortHexGuid(this.asFullHexGuid);
|
|
383
|
-
}
|
|
384
|
-
return this._cachedShortHex;
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Returns the GUID as a base64 string.
|
|
388
|
-
*/
|
|
389
|
-
toString() {
|
|
390
|
-
return this.asBase64Guid;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Returns the GUID as a JSON string.
|
|
394
|
-
* @returns The GUID as a JSON string.
|
|
395
|
-
*/
|
|
396
|
-
toJson() {
|
|
397
|
-
return JSON.stringify(this.asBase64Guid);
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Returns the GUID as a bigint.
|
|
401
|
-
*/
|
|
402
|
-
get asBigIntGuid() {
|
|
403
|
-
return BigInt('0x' + this._value.toString('hex'));
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Returns the GUID as a base64 string.
|
|
407
|
-
* Result is cached for performance.
|
|
408
|
-
*/
|
|
409
|
-
get asBase64Guid() {
|
|
410
|
-
if (!this._cachedBase64) {
|
|
411
|
-
this._cachedBase64 = this._value.toString('base64');
|
|
412
|
-
}
|
|
413
|
-
return this._cachedBase64;
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Checks if a GUID value is a boundary value (all zeros or all Fs).
|
|
417
|
-
* @param value The GUID value to check.
|
|
418
|
-
* @returns True if the value is a boundary value.
|
|
419
|
-
*/
|
|
420
|
-
static isBoundaryValue(value) {
|
|
421
|
-
return (value === GuidV4.BOUNDARY_VALUES.ALL_ZEROS_FULL ||
|
|
422
|
-
value === GuidV4.BOUNDARY_VALUES.ALL_ZEROS_SHORT ||
|
|
423
|
-
value === GuidV4.BOUNDARY_VALUES.ALL_FS_FULL ||
|
|
424
|
-
value === GuidV4.BOUNDARY_VALUES.ALL_FS_SHORT);
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Verifies if a given GUID is valid for the given brand.
|
|
428
|
-
* @param guidBrand The brand of the GUID to verify.
|
|
429
|
-
* @param guid The GUID to verify.
|
|
430
|
-
* @returns True if the GUID is valid for the given brand, false otherwise.
|
|
431
|
-
*/
|
|
432
|
-
static verifyGuid(guidBrand, guid) {
|
|
433
|
-
if (guid === null || guid === undefined) {
|
|
434
|
-
return false;
|
|
435
|
-
}
|
|
436
|
-
try {
|
|
437
|
-
const verifyFunc = GuidV4.VerifyFunctions[guidBrand];
|
|
438
|
-
return verifyFunc(guid);
|
|
439
|
-
}
|
|
440
|
-
catch {
|
|
441
|
-
return false;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Returns the length of the GUID for the given brand.
|
|
446
|
-
* @param guidBrand The brand of the GUID to get the length for.
|
|
447
|
-
* @returns The length of the GUID for the given brand.
|
|
448
|
-
*/
|
|
449
|
-
static guidBrandToLength(guidBrand) {
|
|
450
|
-
const length = GuidV4.LengthMap[guidBrand];
|
|
451
|
-
if (length <= 0) {
|
|
452
|
-
throw new GuidError(GuidErrorType.InvalidGuidUnknownBrand, guidBrand);
|
|
453
|
-
}
|
|
454
|
-
return length;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Returns the brand of the GUID for the given length.
|
|
458
|
-
* @param length The length of the GUID to get the brand for.
|
|
459
|
-
* @param isBuffer Whether the GUID is a Buffer.
|
|
460
|
-
* @returns The brand of the GUID for the given length.
|
|
461
|
-
*/
|
|
462
|
-
static lengthToGuidBrand(length, isBuffer) {
|
|
463
|
-
if (length <= 0) {
|
|
464
|
-
throw new GuidError(GuidErrorType.InvalidGuidUnknownLength, undefined, length);
|
|
465
|
-
}
|
|
466
|
-
const brand = GuidV4.ReverseLengthMap[length];
|
|
467
|
-
if (!brand || brand === GuidBrandType.Unknown) {
|
|
468
|
-
throw new GuidError(GuidErrorType.InvalidGuidUnknownLength, undefined, length);
|
|
469
|
-
}
|
|
470
|
-
// Validate buffer vs string type consistency
|
|
471
|
-
const isBrandBuffer = brand === GuidBrandType.RawGuidBuffer;
|
|
472
|
-
if (isBuffer !== isBrandBuffer) {
|
|
473
|
-
throw new GuidError(GuidErrorType.InvalidGuidUnknownLength, brand, length);
|
|
474
|
-
}
|
|
475
|
-
return brand;
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Verifies if a given GUID is a valid full hex GUID.
|
|
479
|
-
* @param fullHexGuidValue The full hex GUID to verify.
|
|
480
|
-
* @returns True if the GUID is a valid full hex GUID, false otherwise.
|
|
481
|
-
*/
|
|
482
|
-
static isFullHexGuid(fullHexGuidValue) {
|
|
483
|
-
try {
|
|
484
|
-
if (fullHexGuidValue === null || fullHexGuidValue === undefined) {
|
|
485
|
-
return false;
|
|
486
|
-
}
|
|
487
|
-
const expectedLength = GuidV4.guidBrandToLength(GuidBrandType.FullHexGuid);
|
|
488
|
-
const strValue = String(fullHexGuidValue);
|
|
489
|
-
if (strValue.length !== expectedLength) {
|
|
490
|
-
return false;
|
|
491
|
-
}
|
|
492
|
-
// Boundary values are always valid
|
|
493
|
-
if (GuidV4.isBoundaryValue(strValue)) {
|
|
494
|
-
return true;
|
|
495
|
-
}
|
|
496
|
-
return GuidV4.validateUuid(strValue);
|
|
497
|
-
}
|
|
498
|
-
catch {
|
|
499
|
-
return false;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
/**
|
|
503
|
-
* Verifies if a given GUID is a valid short hex GUID.
|
|
504
|
-
* @param shortHexGuidValue The short hex GUID to verify.
|
|
505
|
-
* @returns True if the GUID is a valid short hex GUID, false otherwise.
|
|
506
|
-
*/
|
|
507
|
-
static isShortHexGuid(shortHexGuidValue) {
|
|
508
|
-
try {
|
|
509
|
-
if (shortHexGuidValue === null || shortHexGuidValue === undefined) {
|
|
510
|
-
return false;
|
|
511
|
-
}
|
|
512
|
-
const expectedLength = GuidV4.guidBrandToLength(GuidBrandType.ShortHexGuid);
|
|
513
|
-
const strValue = String(shortHexGuidValue);
|
|
514
|
-
if (strValue.length !== expectedLength) {
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
try {
|
|
518
|
-
const fullHexGuid = GuidV4.toFullHexGuid(strValue);
|
|
519
|
-
// Boundary values are always valid
|
|
520
|
-
if (GuidV4.isBoundaryValue(fullHexGuid)) {
|
|
521
|
-
return true;
|
|
522
|
-
}
|
|
523
|
-
return uuid.validate(fullHexGuid);
|
|
524
|
-
}
|
|
525
|
-
catch {
|
|
526
|
-
return false;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
catch {
|
|
530
|
-
return false;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Verifies if a given GUID is a valid base64 GUID.
|
|
535
|
-
* @param value The base64 GUID to verify.
|
|
536
|
-
* @returns True if the GUID is a valid base64 GUID, false otherwise.
|
|
537
|
-
*/
|
|
538
|
-
static isBase64Guid(value) {
|
|
539
|
-
try {
|
|
540
|
-
if (value === null || value === undefined) {
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
let valueLength;
|
|
544
|
-
if (typeof value === 'bigint') {
|
|
545
|
-
valueLength = value.toString(16).length;
|
|
546
|
-
}
|
|
547
|
-
else if (value instanceof Buffer) {
|
|
548
|
-
valueLength = value.length;
|
|
549
|
-
}
|
|
550
|
-
else {
|
|
551
|
-
valueLength = String(value).length;
|
|
552
|
-
}
|
|
553
|
-
const result = valueLength === GuidV4.guidBrandToLength(GuidBrandType.Base64Guid);
|
|
554
|
-
if (result) {
|
|
555
|
-
try {
|
|
556
|
-
const fromBase64 = GuidV4.toRawGuidBuffer(value);
|
|
557
|
-
const fullHexGuid = GuidV4.toFullHexGuid(fromBase64.toString('hex'));
|
|
558
|
-
// Boundary values are always valid
|
|
559
|
-
if (GuidV4.isBoundaryValue(fullHexGuid)) {
|
|
560
|
-
return true;
|
|
561
|
-
}
|
|
562
|
-
return uuid.validate(fullHexGuid);
|
|
563
|
-
}
|
|
564
|
-
catch {
|
|
565
|
-
return false;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
return result;
|
|
569
|
-
}
|
|
570
|
-
catch {
|
|
571
|
-
return false;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
/**
|
|
575
|
-
* Verifies if a given GUID is a valid raw GUID buffer.
|
|
576
|
-
* @param value The raw GUID buffer to verify.
|
|
577
|
-
* @returns True if the GUID is a valid raw GUID buffer, false otherwise.
|
|
578
|
-
*/
|
|
579
|
-
static isRawGuidBuffer(value) {
|
|
580
|
-
try {
|
|
581
|
-
if (value === null || value === undefined) {
|
|
582
|
-
return false;
|
|
583
|
-
}
|
|
584
|
-
const expectedLength = GuidV4.guidBrandToLength(GuidBrandType.RawGuidBuffer);
|
|
585
|
-
let valueLength;
|
|
586
|
-
if (typeof value === 'bigint') {
|
|
587
|
-
valueLength = value.toString(16).length;
|
|
588
|
-
}
|
|
589
|
-
else if (value instanceof Buffer) {
|
|
590
|
-
valueLength = value.length;
|
|
591
|
-
}
|
|
592
|
-
else {
|
|
593
|
-
valueLength = String(value).length;
|
|
594
|
-
}
|
|
595
|
-
if (valueLength !== expectedLength) {
|
|
596
|
-
return false;
|
|
597
|
-
}
|
|
598
|
-
try {
|
|
599
|
-
if (!(value instanceof Buffer)) {
|
|
600
|
-
return false;
|
|
601
|
-
}
|
|
602
|
-
const fullHexGuid = GuidV4.toFullHexGuid(value.toString('hex'));
|
|
603
|
-
// Boundary values are always valid
|
|
604
|
-
if (GuidV4.isBoundaryValue(fullHexGuid)) {
|
|
605
|
-
return true;
|
|
606
|
-
}
|
|
607
|
-
return GuidV4.validateUuid(fullHexGuid);
|
|
608
|
-
}
|
|
609
|
-
catch {
|
|
610
|
-
return false;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
catch {
|
|
614
|
-
return false;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Verifies if a given GUID is a valid bigint GUID.
|
|
619
|
-
* @param value The bigint GUID to verify.
|
|
620
|
-
* @returns True if the GUID is a valid bigint GUID, false otherwise.
|
|
621
|
-
*/
|
|
622
|
-
static isBigIntGuid(value) {
|
|
623
|
-
try {
|
|
624
|
-
if (value === null || value === undefined) {
|
|
625
|
-
return false;
|
|
626
|
-
}
|
|
627
|
-
if (typeof value !== 'bigint') {
|
|
628
|
-
return false;
|
|
629
|
-
}
|
|
630
|
-
if (value < 0n || value > GuidV4.MAX_BIGINT_VALUE) {
|
|
631
|
-
return false;
|
|
632
|
-
}
|
|
633
|
-
try {
|
|
634
|
-
const fromBigInt = GuidV4.toFullHexFromBigInt(value);
|
|
635
|
-
// Boundary values are always valid
|
|
636
|
-
if (GuidV4.isBoundaryValue(fromBigInt)) {
|
|
637
|
-
return true;
|
|
638
|
-
}
|
|
639
|
-
return uuid.validate(fromBigInt);
|
|
640
|
-
}
|
|
641
|
-
catch {
|
|
642
|
-
return false;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
catch {
|
|
646
|
-
return false;
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Determines the brand of a given GUID value.
|
|
651
|
-
* @param value The GUID value to determine the brand of.
|
|
652
|
-
* @returns The brand of the GUID value.
|
|
653
|
-
*/
|
|
654
|
-
static whichBrand(value) {
|
|
655
|
-
if (value === null || value === undefined) {
|
|
656
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
657
|
-
}
|
|
658
|
-
if (typeof value === 'bigint') {
|
|
659
|
-
return GuidBrandType.BigIntGuid;
|
|
660
|
-
}
|
|
661
|
-
const isBuffer = value instanceof Buffer;
|
|
662
|
-
const expectedLength = isBuffer ? value.length : String(value).length;
|
|
663
|
-
return GuidV4.lengthToGuidBrand(expectedLength, isBuffer);
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Converts a given short hex GUID to a full hex GUID.
|
|
667
|
-
* @param shortGuid The short hex GUID to convert.
|
|
668
|
-
* @returns The short hex GUID as a full hex GUID.
|
|
669
|
-
*/
|
|
670
|
-
static shortGuidToFullGuid(shortGuid) {
|
|
671
|
-
// insert dashes
|
|
672
|
-
const str = shortGuid.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '$1-$2-$3-$4-$5');
|
|
673
|
-
return str;
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Converts a given GUID value to a full hex GUID.
|
|
677
|
-
* @param guid The GUID value to convert.
|
|
678
|
-
* @returns The GUID value as a full hex GUID.
|
|
679
|
-
*/
|
|
680
|
-
static toFullHexGuid(guid) {
|
|
681
|
-
if (guid === null || guid === undefined) {
|
|
682
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
683
|
-
}
|
|
684
|
-
if (typeof guid === 'bigint') {
|
|
685
|
-
return GuidV4.toFullHexFromBigInt(guid);
|
|
686
|
-
}
|
|
687
|
-
else if (Buffer.isBuffer(guid) &&
|
|
688
|
-
guid.length === GuidV4.guidBrandToLength(GuidBrandType.RawGuidBuffer)) {
|
|
689
|
-
const shortHex = guid.toString('hex');
|
|
690
|
-
return GuidV4.shortGuidToFullGuid(shortHex);
|
|
691
|
-
}
|
|
692
|
-
else if (Buffer.isBuffer(guid)) {
|
|
693
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
694
|
-
}
|
|
695
|
-
// all remaining cases are string types
|
|
696
|
-
const strValue = String(guid);
|
|
697
|
-
if (strValue.length === GuidV4.guidBrandToLength(GuidBrandType.ShortHexGuid)) {
|
|
698
|
-
// short hex guid
|
|
699
|
-
return GuidV4.shortGuidToFullGuid(strValue);
|
|
700
|
-
}
|
|
701
|
-
else if (strValue.length === GuidV4.guidBrandToLength(GuidBrandType.FullHexGuid)) {
|
|
702
|
-
// already a full hex guid
|
|
703
|
-
return strValue;
|
|
704
|
-
}
|
|
705
|
-
else if (strValue.length === GuidV4.guidBrandToLength(GuidBrandType.Base64Guid)) {
|
|
706
|
-
// base64 guid
|
|
707
|
-
const shortGuid = Buffer.from(strValue, 'base64').toString('hex');
|
|
708
|
-
return GuidV4.shortGuidToFullGuid(shortGuid);
|
|
709
|
-
}
|
|
710
|
-
else {
|
|
711
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
static toShortHexGuid(guid) {
|
|
715
|
-
if (guid === null || guid === undefined) {
|
|
716
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
717
|
-
}
|
|
718
|
-
if (typeof guid === 'bigint') {
|
|
719
|
-
const fullHex = GuidV4.toFullHexFromBigInt(guid);
|
|
720
|
-
return fullHex.replace(/-/g, '');
|
|
721
|
-
}
|
|
722
|
-
else if (Buffer.isBuffer(guid) &&
|
|
723
|
-
guid.length === GuidV4.guidBrandToLength(GuidBrandType.RawGuidBuffer)) {
|
|
724
|
-
return guid.toString('hex');
|
|
725
|
-
}
|
|
726
|
-
else if (Buffer.isBuffer(guid)) {
|
|
727
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
728
|
-
}
|
|
729
|
-
// all remaining cases are string types
|
|
730
|
-
const strValue = String(guid);
|
|
731
|
-
if (strValue.length === GuidV4.guidBrandToLength(GuidBrandType.ShortHexGuid)) {
|
|
732
|
-
// already a short hex guid
|
|
733
|
-
return strValue;
|
|
734
|
-
}
|
|
735
|
-
else if (strValue.length === GuidV4.guidBrandToLength(GuidBrandType.FullHexGuid)) {
|
|
736
|
-
// full hex guid
|
|
737
|
-
return strValue.replace(/-/g, '');
|
|
738
|
-
}
|
|
739
|
-
else if (strValue.length === GuidV4.guidBrandToLength(GuidBrandType.Base64Guid)) {
|
|
740
|
-
// base64 guid
|
|
741
|
-
return Buffer.from(strValue, 'base64').toString('hex');
|
|
742
|
-
}
|
|
743
|
-
else {
|
|
744
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Converts a given bigint to a full hex GUID.
|
|
749
|
-
* @param bigInt The bigint to convert.
|
|
750
|
-
* @returns The bigint as a full hex GUID.
|
|
751
|
-
*/
|
|
752
|
-
static toFullHexFromBigInt(bigInt) {
|
|
753
|
-
if (bigInt < 0n || bigInt > GuidV4.MAX_BIGINT_VALUE) {
|
|
754
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
755
|
-
}
|
|
756
|
-
const uuidBigInt = bigInt.toString(16).padStart(32, '0');
|
|
757
|
-
// After padding, should always be exactly 32 characters
|
|
758
|
-
if (uuidBigInt.length !== 32) {
|
|
759
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
760
|
-
}
|
|
761
|
-
const rebuiltUuid = uuidBigInt.slice(0, 8) +
|
|
762
|
-
'-' +
|
|
763
|
-
uuidBigInt.slice(8, 12) +
|
|
764
|
-
'-' +
|
|
765
|
-
uuidBigInt.slice(12, 16) +
|
|
766
|
-
'-' +
|
|
767
|
-
uuidBigInt.slice(16, 20) +
|
|
768
|
-
'-' +
|
|
769
|
-
uuidBigInt.slice(20);
|
|
770
|
-
return rebuiltUuid;
|
|
771
|
-
}
|
|
772
|
-
/**
|
|
773
|
-
* Converts a given GUID value to a raw GUID buffer.
|
|
774
|
-
* @param value The GUID value to convert.
|
|
775
|
-
* @returns The GUID value as a raw GUID buffer.
|
|
776
|
-
*/
|
|
777
|
-
static toRawGuidBuffer(value) {
|
|
778
|
-
const expectedBrand = GuidV4.whichBrand(value);
|
|
779
|
-
let rawGuidBufferResult = Buffer.alloc(0);
|
|
780
|
-
switch (expectedBrand) {
|
|
781
|
-
case GuidBrandType.FullHexGuid:
|
|
782
|
-
rawGuidBufferResult = Buffer.from(GuidV4.toShortHexGuid(value), 'hex');
|
|
783
|
-
break;
|
|
784
|
-
case GuidBrandType.ShortHexGuid:
|
|
785
|
-
rawGuidBufferResult = Buffer.from(GuidV4.toShortHexGuid(value), 'hex');
|
|
786
|
-
break;
|
|
787
|
-
case GuidBrandType.Base64Guid:
|
|
788
|
-
// Ensure value is a string before using it with Buffer.from
|
|
789
|
-
if (typeof value === 'string' || value instanceof Buffer) {
|
|
790
|
-
rawGuidBufferResult = Buffer.from(value.toString(), 'base64');
|
|
791
|
-
}
|
|
792
|
-
else {
|
|
793
|
-
throw new GuidError(GuidErrorType.InvalidGuid);
|
|
794
|
-
}
|
|
795
|
-
break;
|
|
796
|
-
case GuidBrandType.RawGuidBuffer:
|
|
797
|
-
rawGuidBufferResult = value;
|
|
798
|
-
break;
|
|
799
|
-
case GuidBrandType.BigIntGuid:
|
|
800
|
-
rawGuidBufferResult = Buffer.from(GuidV4.toShortHexGuid(GuidV4.toFullHexFromBigInt(value)), 'hex');
|
|
801
|
-
break;
|
|
802
|
-
default:
|
|
803
|
-
throw new GuidError(GuidErrorType.InvalidGuidUnknownBrand);
|
|
804
|
-
}
|
|
805
|
-
if (rawGuidBufferResult.length !==
|
|
806
|
-
GuidV4.guidBrandToLength(GuidBrandType.RawGuidBuffer)) {
|
|
807
|
-
throw new GuidError(GuidErrorType.InvalidGuidUnknownLength, undefined, rawGuidBufferResult.length);
|
|
808
|
-
}
|
|
809
|
-
return rawGuidBufferResult;
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Compare two GuidV4 instances for equality.
|
|
813
|
-
* @param other - The other GuidV4 instance to compare (can be null/undefined)
|
|
814
|
-
* @param constantTime - Use constant-time comparison to prevent timing attacks (default: false)
|
|
815
|
-
* @returns True if the two GuidV4 instances are equal, false otherwise
|
|
816
|
-
*/
|
|
817
|
-
equals(other, constantTime = false) {
|
|
818
|
-
if (!other) {
|
|
819
|
-
return false;
|
|
820
|
-
}
|
|
821
|
-
if (constantTime) {
|
|
822
|
-
// Constant-time comparison to prevent timing attacks
|
|
823
|
-
// Always compare all 16 bytes regardless of early mismatches
|
|
824
|
-
const a = this.asRawGuidBufferUnsafe;
|
|
825
|
-
const b = other.asRawGuidBuffer;
|
|
826
|
-
let result = 0;
|
|
827
|
-
for (let i = 0; i < 16; i++) {
|
|
828
|
-
result |= a[i] ^ b[i];
|
|
829
|
-
}
|
|
830
|
-
return result === 0;
|
|
831
|
-
}
|
|
832
|
-
return Buffer.compare(this.asRawGuidBufferUnsafe, other.asRawGuidBuffer) === 0;
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Checks if this GUID is empty (all zeros).
|
|
836
|
-
* @returns True if the GUID is all zeros, false otherwise
|
|
837
|
-
*/
|
|
838
|
-
isEmpty() {
|
|
839
|
-
// Check if all bytes are zero
|
|
840
|
-
for (let i = 0; i < this._value.length; i++) {
|
|
841
|
-
if (this._value[i] !== 0) {
|
|
842
|
-
return false;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
return true;
|
|
846
|
-
}
|
|
847
|
-
/**
|
|
848
|
-
* Static helper to check if a GUID is null, undefined, or empty.
|
|
849
|
-
* @param guid The GUID to check
|
|
850
|
-
* @returns True if the GUID is null, undefined, or empty
|
|
851
|
-
*/
|
|
852
|
-
static isNilOrEmpty(guid) {
|
|
853
|
-
return !guid || (guid instanceof GuidV4 && guid.isEmpty());
|
|
854
|
-
}
|
|
855
|
-
/**
|
|
856
|
-
* Creates a new GuidV4 instance with the same value as this one.
|
|
857
|
-
* @returns A new GuidV4 instance with identical value
|
|
858
|
-
*/
|
|
859
|
-
clone() {
|
|
860
|
-
return new GuidV4(Buffer.from(this._value));
|
|
861
|
-
}
|
|
862
|
-
/**
|
|
863
|
-
* Returns the hash code for this GUID based on its buffer content.
|
|
864
|
-
* Useful for using GUIDs as Map/Set keys.
|
|
865
|
-
* @returns A numeric hash code
|
|
866
|
-
*/
|
|
867
|
-
hashCode() {
|
|
868
|
-
let hash = 0;
|
|
869
|
-
for (let i = 0; i < this._value.length; i++) {
|
|
870
|
-
hash = ((hash << 5) - hash) + this._value[i];
|
|
871
|
-
hash = hash & hash; // Convert to 32-bit integer
|
|
872
|
-
}
|
|
873
|
-
return hash;
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* Extracts the RFC 4122 version from the GUID.
|
|
877
|
-
* Returns undefined for boundary values or invalid GUIDs.
|
|
878
|
-
* @returns The version number (1-5) or undefined
|
|
879
|
-
*/
|
|
880
|
-
getVersion() {
|
|
881
|
-
// Skip boundary values
|
|
882
|
-
if (GuidV4.isBoundaryValue(this.asFullHexGuid)) {
|
|
883
|
-
return undefined;
|
|
884
|
-
}
|
|
885
|
-
// Version is in bits 48-51 (byte 6, high nibble)
|
|
886
|
-
const versionByte = this._value[6];
|
|
887
|
-
const version = (versionByte >> 4) & 0x0F;
|
|
888
|
-
// Valid RFC 4122 versions are 1-5
|
|
889
|
-
return version >= 1 && version <= 5 ? version : undefined;
|
|
890
|
-
}
|
|
891
|
-
/**
|
|
892
|
-
* Validates that this GUID is a proper v4 GUID according to RFC 4122.
|
|
893
|
-
* Boundary values (all zeros/all Fs) return true as they're mathematically valid.
|
|
894
|
-
* @returns True if valid v4 GUID or boundary value, false otherwise
|
|
895
|
-
*/
|
|
896
|
-
isValidV4() {
|
|
897
|
-
// Boundary values are considered valid
|
|
898
|
-
if (GuidV4.isBoundaryValue(this.asFullHexGuid)) {
|
|
899
|
-
return true;
|
|
900
|
-
}
|
|
901
|
-
const version = this.getVersion();
|
|
902
|
-
return version === 4;
|
|
903
|
-
}
|
|
904
|
-
/**
|
|
905
|
-
* Compares two GUIDs for ordering.
|
|
906
|
-
* Useful for sorting GUID arrays.
|
|
907
|
-
* @param other The other GUID to compare to
|
|
908
|
-
* @returns -1 if this < other, 0 if equal, 1 if this > other
|
|
909
|
-
*/
|
|
910
|
-
compareTo(other) {
|
|
911
|
-
return Buffer.compare(this.asRawGuidBufferUnsafe, other.asRawGuidBuffer);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
//# sourceMappingURL=guid.js.map
|