@digitaldefiance/node-ecies-lib 4.12.7 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -18
- package/package.json +5 -4
- package/src/builders/ecies-builder.d.ts +12 -0
- package/src/builders/ecies-builder.d.ts.map +1 -1
- package/src/builders/ecies-builder.js.map +1 -1
- package/src/builders/index.d.ts +3 -0
- package/src/builders/index.d.ts.map +1 -1
- package/src/builders/index.js +3 -0
- package/src/builders/index.js.map +1 -1
- package/src/builders/member-builder.d.ts +16 -0
- package/src/builders/member-builder.d.ts.map +1 -1
- package/src/builders/member-builder.js +16 -0
- package/src/builders/member-builder.js.map +1 -1
- package/src/constants.d.ts +23 -10
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +57 -84
- package/src/constants.js.map +1 -1
- package/src/core/errors/crypto-error.d.ts +4 -0
- package/src/core/errors/crypto-error.d.ts.map +1 -1
- package/src/core/errors/crypto-error.js +4 -0
- package/src/core/errors/crypto-error.js.map +1 -1
- package/src/core/index.d.ts +3 -0
- package/src/core/index.d.ts.map +1 -1
- package/src/core/index.js +3 -0
- package/src/core/index.js.map +1 -1
- package/src/core/types/result.d.ts +4 -0
- package/src/core/types/result.d.ts.map +1 -1
- package/src/enumerations/index.d.ts +3 -0
- package/src/enumerations/index.d.ts.map +1 -1
- package/src/enumerations/index.js +3 -0
- package/src/enumerations/index.js.map +1 -1
- package/src/enumerations/pbkdf2-profile.d.ts +4 -0
- package/src/enumerations/pbkdf2-profile.d.ts.map +1 -1
- package/src/enumerations/pbkdf2-profile.js +4 -0
- package/src/enumerations/pbkdf2-profile.js.map +1 -1
- package/src/errors/index.d.ts +3 -0
- package/src/errors/index.d.ts.map +1 -1
- package/src/errors/index.js +3 -0
- package/src/errors/index.js.map +1 -1
- package/src/errors/translatable.d.ts +9 -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/errors/voting.d.ts +5 -0
- package/src/errors/voting.d.ts.map +1 -1
- package/src/errors/voting.js +5 -0
- package/src/errors/voting.js.map +1 -1
- package/src/examples/typed-configuration-usage.js +3 -3
- package/src/examples/typed-configuration-usage.js.map +1 -1
- package/src/i18n/ecies-i18n-factory.d.ts +1 -1
- package/src/i18n/ecies-i18n-factory.d.ts.map +1 -1
- package/src/i18n/ecies-i18n-factory.js +7 -2
- package/src/i18n/ecies-i18n-factory.js.map +1 -1
- package/src/i18n/index.d.ts +3 -0
- package/src/i18n/index.d.ts.map +1 -1
- package/src/i18n/index.js +3 -0
- package/src/i18n/index.js.map +1 -1
- package/src/i18n/node-ecies-i18n-setup.d.ts +5 -0
- package/src/i18n/node-ecies-i18n-setup.d.ts.map +1 -1
- package/src/i18n/node-ecies-i18n-setup.js +12 -0
- package/src/i18n/node-ecies-i18n-setup.js.map +1 -1
- package/src/i18n/translations/de.d.ts +4 -0
- package/src/i18n/translations/de.d.ts.map +1 -1
- package/src/i18n/translations/de.js +4 -0
- package/src/i18n/translations/de.js.map +1 -1
- package/src/i18n/translations/en-GB.d.ts +4 -0
- package/src/i18n/translations/en-GB.d.ts.map +1 -1
- package/src/i18n/translations/en-GB.js +4 -0
- package/src/i18n/translations/en-GB.js.map +1 -1
- package/src/i18n/translations/en-US.d.ts +5 -0
- package/src/i18n/translations/en-US.d.ts.map +1 -1
- package/src/i18n/translations/en-US.js +5 -0
- package/src/i18n/translations/en-US.js.map +1 -1
- package/src/i18n/translations/es.d.ts +4 -0
- package/src/i18n/translations/es.d.ts.map +1 -1
- package/src/i18n/translations/es.js +4 -0
- package/src/i18n/translations/es.js.map +1 -1
- package/src/i18n/translations/fr.d.ts +4 -0
- package/src/i18n/translations/fr.d.ts.map +1 -1
- package/src/i18n/translations/fr.js +4 -0
- package/src/i18n/translations/fr.js.map +1 -1
- package/src/i18n/translations/index.d.ts +3 -0
- package/src/i18n/translations/index.d.ts.map +1 -1
- package/src/i18n/translations/index.js +3 -0
- package/src/i18n/translations/index.js.map +1 -1
- package/src/i18n/translations/ja.d.ts +4 -0
- package/src/i18n/translations/ja.d.ts.map +1 -1
- package/src/i18n/translations/ja.js +4 -0
- package/src/i18n/translations/ja.js.map +1 -1
- package/src/i18n/translations/uk.d.ts +4 -0
- package/src/i18n/translations/uk.d.ts.map +1 -1
- package/src/i18n/translations/uk.js +4 -0
- package/src/i18n/translations/uk.js.map +1 -1
- package/src/i18n/translations/zh-cn.d.ts +4 -0
- package/src/i18n/translations/zh-cn.d.ts.map +1 -1
- package/src/i18n/translations/zh-cn.js +4 -0
- package/src/i18n/translations/zh-cn.js.map +1 -1
- package/src/index.d.ts +12 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +12 -0
- package/src/index.js.map +1 -1
- package/src/interfaces/authenticated-cipher.d.ts +5 -0
- package/src/interfaces/authenticated-cipher.d.ts.map +1 -1
- package/src/interfaces/authenticated-decipher.d.ts +3 -0
- package/src/interfaces/authenticated-decipher.d.ts.map +1 -1
- 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 +3 -0
- package/src/interfaces/checksum-consts.d.ts.map +1 -1
- package/src/interfaces/configuration-provenance.d.ts +3 -0
- package/src/interfaces/configuration-provenance.d.ts.map +1 -1
- package/src/interfaces/constants.d.ts +5 -1
- package/src/interfaces/constants.d.ts.map +1 -1
- package/src/interfaces/ecies-consts.d.ts +5 -2
- package/src/interfaces/ecies-consts.d.ts.map +1 -1
- package/src/interfaces/encrypted-chunk.d.ts +3 -0
- package/src/interfaces/encrypted-chunk.d.ts.map +1 -1
- package/src/interfaces/encryption-consts.d.ts +3 -0
- package/src/interfaces/encryption-consts.d.ts.map +1 -1
- package/src/interfaces/guid.d.ts +3 -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/keypair-buffer-with-un-encrypted-private-key.d.ts +3 -0
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +1 -1
- package/src/interfaces/keyring-consts.d.ts +3 -0
- package/src/interfaces/keyring-consts.d.ts.map +1 -1
- package/src/interfaces/member-with-mnemonic.d.ts +3 -0
- package/src/interfaces/member-with-mnemonic.d.ts.map +1 -1
- package/src/interfaces/member.d.ts +3 -0
- package/src/interfaces/member.d.ts.map +1 -1
- package/src/interfaces/multi-encrypted-message.d.ts +3 -0
- package/src/interfaces/multi-encrypted-message.d.ts.map +1 -1
- package/src/interfaces/multi-encrypted-parsed-header.d.ts +3 -0
- package/src/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -1
- package/src/interfaces/multi-recipient-chunk.d.ts +3 -0
- package/src/interfaces/multi-recipient-chunk.d.ts.map +1 -1
- package/src/interfaces/multi-recipient-chunk.js.map +1 -1
- package/src/interfaces/pbkdf-profiles.d.ts +3 -0
- package/src/interfaces/pbkdf-profiles.d.ts.map +1 -1
- package/src/interfaces/pbkdf2-result.d.ts +3 -0
- package/src/interfaces/pbkdf2-result.d.ts.map +1 -1
- package/src/interfaces/platform-buffer.d.ts +3 -0
- package/src/interfaces/platform-buffer.d.ts.map +1 -1
- package/src/interfaces/platform-id.d.ts +3 -0
- package/src/interfaces/platform-id.d.ts.map +1 -1
- package/src/interfaces/signing-key-private-key-info.d.ts +3 -0
- package/src/interfaces/signing-key-private-key-info.d.ts.map +1 -1
- package/src/interfaces/simple-keypair-buffer.d.ts +3 -0
- package/src/interfaces/simple-keypair-buffer.d.ts.map +1 -1
- package/src/interfaces/simple-keypair.d.ts +3 -0
- package/src/interfaces/simple-keypair.d.ts.map +1 -1
- package/src/interfaces/simple-public-key-only-buffer.d.ts +3 -0
- package/src/interfaces/simple-public-key-only-buffer.d.ts.map +1 -1
- package/src/interfaces/simple-public-key-only.d.ts +3 -0
- package/src/interfaces/simple-public-key-only.d.ts.map +1 -1
- package/src/interfaces/single-encrypted-parsed-header.d.ts +3 -0
- package/src/interfaces/single-encrypted-parsed-header.d.ts.map +1 -1
- package/src/interfaces/stream-config.d.ts +3 -0
- package/src/interfaces/stream-config.d.ts.map +1 -1
- package/src/interfaces/stream-config.js.map +1 -1
- package/src/interfaces/wallet-seed.d.ts +3 -0
- package/src/interfaces/wallet-seed.d.ts.map +1 -1
- package/src/interfaces/wrapped-key-consts.d.ts +3 -0
- package/src/interfaces/wrapped-key-consts.d.ts.map +1 -1
- package/src/isolated-private.d.ts.map +1 -1
- package/src/isolated-private.js +8 -0
- package/src/isolated-private.js.map +1 -1
- package/src/isolated-public.d.ts.map +1 -1
- package/src/isolated-public.js +8 -0
- package/src/isolated-public.js.map +1 -1
- package/src/lib/crypto-container.d.ts.map +1 -1
- package/src/lib/crypto-container.js +5 -0
- package/src/lib/crypto-container.js.map +1 -1
- package/src/lib/guid.d.ts +57 -33
- package/src/lib/guid.d.ts.map +1 -1
- package/src/lib/guid.js +131 -105
- package/src/lib/guid.js.map +1 -1
- package/src/lib/id-providers/buffer-provider.d.ts.map +1 -1
- package/src/lib/id-providers/buffer-provider.js +5 -0
- package/src/lib/id-providers/buffer-provider.js.map +1 -1
- package/src/lib/id-providers/guidv4-provider.d.ts +62 -0
- package/src/lib/id-providers/guidv4-provider.d.ts.map +1 -0
- package/src/lib/id-providers/guidv4-provider.js +146 -0
- package/src/lib/id-providers/guidv4-provider.js.map +1 -0
- package/src/lib/index.d.ts +4 -0
- package/src/lib/index.d.ts.map +1 -1
- package/src/lib/index.js +4 -0
- package/src/lib/index.js.map +1 -1
- package/src/lib/invariant-validator.d.ts.map +1 -1
- package/src/lib/invariant-validator.js +5 -0
- package/src/lib/invariant-validator.js.map +1 -1
- package/src/lib/invariants/recipient-id-consistency.d.ts.map +1 -1
- package/src/lib/invariants/recipient-id-consistency.js +9 -4
- package/src/lib/invariants/recipient-id-consistency.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-extended.d.ts +3 -0
- package/src/lib/voting/interfaces/checkpoint-manager-extended.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/encrypted-vote.d.ts +3 -0
- package/src/lib/voting/interfaces/encrypted-vote.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/jurisdiction-config.d.ts +3 -0
- package/src/lib/voting/interfaces/jurisdiction-config.d.ts.map +1 -1
- package/src/lib/voting/interfaces/plaintext-vote.d.ts +3 -0
- package/src/lib/voting/interfaces/plaintext-vote.d.ts.map +1 -1
- package/src/lib/voting/interfaces/poll-tallier.d.ts +3 -0
- package/src/lib/voting/interfaces/poll-tallier.d.ts.map +1 -1
- package/src/lib/voting/interfaces/poll.d.ts +3 -0
- package/src/lib/voting/interfaces/poll.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-encoder.d.ts +3 -0
- package/src/lib/voting/interfaces/vote-encoder.d.ts.map +1 -1
- package/src/lib/voting/interfaces/vote-logger-extended.d.ts +3 -0
- package/src/lib/voting/interfaces/vote-logger-extended.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/interfaces/voting-receipt.d.ts +3 -0
- package/src/lib/voting/interfaces/voting-receipt.d.ts.map +1 -1
- package/src/lib/voting/poll.d.ts.map +1 -1
- package/src/lib/voting/poll.js +2 -2
- package/src/lib/voting/poll.js.map +1 -1
- package/src/lib/voting/test-voter-pool.d.ts.map +1 -1
- package/src/lib/voting/test-voter-pool.js +5 -0
- package/src/lib/voting/test-voter-pool.js.map +1 -1
- package/src/member.d.ts +8 -0
- package/src/member.d.ts.map +1 -1
- package/src/member.js +28 -20
- package/src/member.js.map +1 -1
- package/src/secure-buffer.d.ts.map +1 -1
- package/src/secure-buffer.js +5 -0
- package/src/secure-buffer.js.map +1 -1
- package/src/services/aes-gcm.d.ts.map +1 -1
- package/src/services/aes-gcm.js +5 -0
- package/src/services/aes-gcm.js.map +1 -1
- package/src/services/chunk-processor.d.ts +3 -0
- 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 +90 -0
- package/src/services/crc.d.ts.map +1 -0
- package/src/services/crc.js +198 -0
- package/src/services/crc.js.map +1 -0
- package/src/services/ecies/crypto-core.d.ts.map +1 -1
- package/src/services/ecies/crypto-core.js +3 -0
- package/src/services/ecies/crypto-core.js.map +1 -1
- package/src/services/ecies/file.d.ts.map +1 -1
- package/src/services/ecies/file.js +10 -7
- 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/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/multi-recipient.d.ts +5 -5
- package/src/services/ecies/multi-recipient.d.ts.map +1 -1
- package/src/services/ecies/multi-recipient.js +11 -6
- package/src/services/ecies/multi-recipient.js.map +1 -1
- package/src/services/ecies/service.d.ts +18 -5
- package/src/services/ecies/service.d.ts.map +1 -1
- package/src/services/ecies/service.js +29 -21
- package/src/services/ecies/service.js.map +1 -1
- package/src/services/ecies/signature.d.ts +3 -0
- package/src/services/ecies/signature.d.ts.map +1 -1
- package/src/services/ecies/signature.js +3 -0
- package/src/services/ecies/signature.js.map +1 -1
- package/src/services/ecies/single-recipient.d.ts +6 -6
- package/src/services/ecies/single-recipient.d.ts.map +1 -1
- package/src/services/ecies/single-recipient.js +27 -23
- package/src/services/ecies/single-recipient.js.map +1 -1
- package/src/services/ecies/utilities.d.ts +3 -0
- package/src/services/ecies/utilities.d.ts.map +1 -1
- package/src/services/ecies/utilities.js +8 -5
- package/src/services/ecies/utilities.js.map +1 -1
- package/src/services/encryption-stream.d.ts +8 -2
- package/src/services/encryption-stream.d.ts.map +1 -1
- package/src/services/encryption-stream.js +9 -2
- 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 +3 -3
- package/src/services/multi-recipient-processor.d.ts.map +1 -1
- package/src/services/multi-recipient-processor.js +5 -2
- package/src/services/multi-recipient-processor.js.map +1 -1
- package/src/services/pbkdf2.d.ts.map +1 -1
- package/src/services/pbkdf2.js +8 -5
- package/src/services/pbkdf2.js.map +1 -1
- package/src/services/progress-tracker.d.ts +3 -0
- package/src/services/progress-tracker.d.ts.map +1 -1
- package/src/services/progress-tracker.js.map +1 -1
- package/src/test-mocks/index.d.ts +3 -0
- package/src/test-mocks/index.d.ts.map +1 -1
- package/src/test-mocks/index.js +3 -0
- package/src/test-mocks/index.js.map +1 -1
- package/src/test-mocks/mock-backend-member.d.ts.map +1 -1
- package/src/test-mocks/mock-backend-member.js +5 -0
- package/src/test-mocks/mock-backend-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 +5 -0
- package/src/transforms/checksumTransform.d.ts.map +1 -1
- package/src/transforms/checksumTransform.js +5 -0
- package/src/transforms/checksumTransform.js.map +1 -1
- package/src/transforms/eciesDecryptTransform.d.ts +5 -0
- package/src/transforms/eciesDecryptTransform.d.ts.map +1 -1
- package/src/transforms/eciesDecryptTransform.js +7 -4
- package/src/transforms/eciesDecryptTransform.js.map +1 -1
- package/src/transforms/eciesEncryptTransform.d.ts +5 -0
- package/src/transforms/eciesEncryptTransform.d.ts.map +1 -1
- package/src/transforms/eciesEncryptTransform.js +8 -5
- 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 +5 -0
- package/src/transforms/xorMultipleTransform.d.ts.map +1 -1
- package/src/transforms/xorMultipleTransform.js +5 -0
- package/src/transforms/xorMultipleTransform.js.map +1 -1
- package/src/transforms/xorTransform.d.ts +5 -0
- package/src/transforms/xorTransform.d.ts.map +1 -1
- package/src/transforms/xorTransform.js +5 -0
- package/src/transforms/xorTransform.js.map +1 -1
- package/src/typed-configuration.d.ts +1 -1
- package/src/typed-configuration.d.ts.map +1 -1
- package/src/typed-configuration.js +2 -2
- package/src/typed-configuration.js.map +1 -1
- package/src/types/guid-versions.d.ts +6 -6
- package/src/types/guid-versions.d.ts.map +1 -1
- package/src/types/index.d.ts +3 -0
- package/src/types/index.d.ts.map +1 -1
- package/src/types/index.js +3 -0
- package/src/types/index.js.map +1 -1
- package/src/types.d.ts +5 -0
- package/src/types.d.ts.map +1 -1
- package/src/types.js.map +1 -1
- package/src/utils.d.ts.map +1 -1
- package/src/utils.js +6 -1
- package/src/utils.js.map +1 -1
package/src/lib/guid.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GuidBuffer = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* RFC 4122 compliant GUID implementation for Node.js.
|
|
7
|
+
* Provides comprehensive GUID/UUID operations including generation (v1, v3, v4, v5),
|
|
8
|
+
* validation, conversion between formats (hex, base64, bigint, Buffer), and type-safe
|
|
9
|
+
* branded types for compile-time format verification.
|
|
10
|
+
*/
|
|
5
11
|
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
6
12
|
const uuid = tslib_1.__importStar(require("uuid"));
|
|
7
13
|
/**
|
|
@@ -14,7 +20,7 @@ const uuid = tslib_1.__importStar(require("uuid"));
|
|
|
14
20
|
* - RawGuidPlatformBuffer: A 16-byte Buffer representation of the GUID
|
|
15
21
|
* Guid instances can be converted to any of these representations using the appropriate method.
|
|
16
22
|
*/
|
|
17
|
-
class
|
|
23
|
+
class GuidBuffer {
|
|
18
24
|
/**
|
|
19
25
|
* GUID is stored internally as a raw 16-byte Buffer.
|
|
20
26
|
*/
|
|
@@ -44,6 +50,10 @@ class Guid {
|
|
|
44
50
|
* Cached base64 representation for performance
|
|
45
51
|
*/
|
|
46
52
|
_cachedBase64;
|
|
53
|
+
/**
|
|
54
|
+
* The RFC 4122 version of this GUID (1, 3, 4, 5, or undefined for boundary/invalid)
|
|
55
|
+
*/
|
|
56
|
+
__version;
|
|
47
57
|
/**
|
|
48
58
|
* Regex for validating hex strings (case insensitive)
|
|
49
59
|
*/
|
|
@@ -72,13 +82,13 @@ class Guid {
|
|
|
72
82
|
* Empty/nil GUID constant (all zeros)
|
|
73
83
|
*/
|
|
74
84
|
static get Empty() {
|
|
75
|
-
if (!
|
|
76
|
-
|
|
85
|
+
if (!GuidBuffer._empty) {
|
|
86
|
+
GuidBuffer._empty = Object.freeze(new GuidBuffer('00000000-0000-0000-0000-000000000000'));
|
|
77
87
|
}
|
|
78
|
-
return
|
|
88
|
+
return GuidBuffer._empty;
|
|
79
89
|
}
|
|
80
90
|
constructor(value) {
|
|
81
|
-
const buffer =
|
|
91
|
+
const buffer = GuidBuffer.validateAndConvert(value);
|
|
82
92
|
// Note: We cannot freeze a Buffer as it's an ArrayBuffer view
|
|
83
93
|
// Instead, we ensure the buffer is never directly modified after construction
|
|
84
94
|
this._value = buffer;
|
|
@@ -86,6 +96,7 @@ class Guid {
|
|
|
86
96
|
this._cachedFullHex = undefined;
|
|
87
97
|
this._cachedShortHex = undefined;
|
|
88
98
|
this._cachedBase64 = undefined;
|
|
99
|
+
this.__version = undefined;
|
|
89
100
|
// Seal the instance to prevent property addition/deletion
|
|
90
101
|
// Cache properties can still be set once since they were initialized
|
|
91
102
|
Object.seal(this);
|
|
@@ -116,18 +127,18 @@ class Guid {
|
|
|
116
127
|
if (typeof value === 'string') {
|
|
117
128
|
const isFullHex = value.length === 36 && value.includes('-');
|
|
118
129
|
const isShortHex = value.length === 32 && !value.includes('-');
|
|
119
|
-
if (isFullHex && !
|
|
130
|
+
if (isFullHex && !GuidBuffer.FULL_HEX_PATTERN.test(value)) {
|
|
120
131
|
const buffer = Buffer.from(value);
|
|
121
132
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuidWithDetails, ecies_lib_1.GuidBrandType.FullHexGuid, value.length, buffer);
|
|
122
133
|
}
|
|
123
|
-
else if (isShortHex && !
|
|
134
|
+
else if (isShortHex && !GuidBuffer.HEX_PATTERN.test(value)) {
|
|
124
135
|
const buffer = Buffer.from(value);
|
|
125
136
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuidWithDetails, ecies_lib_1.GuidBrandType.ShortHexGuid, value.length, buffer);
|
|
126
137
|
}
|
|
127
138
|
}
|
|
128
139
|
// Determine and verify the brand/type
|
|
129
|
-
const expectedBrand =
|
|
130
|
-
const verifiedBrand =
|
|
140
|
+
const expectedBrand = GuidBuffer.whichBrand(value);
|
|
141
|
+
const verifiedBrand = GuidBuffer.verifyGuid(expectedBrand, value);
|
|
131
142
|
if (!verifiedBrand) {
|
|
132
143
|
const valueBuffer = Buffer.isBuffer(value)
|
|
133
144
|
? value
|
|
@@ -135,11 +146,11 @@ class Guid {
|
|
|
135
146
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuidWithDetails, expectedBrand, undefined, valueBuffer);
|
|
136
147
|
}
|
|
137
148
|
// Convert to raw buffer
|
|
138
|
-
const buffer =
|
|
149
|
+
const buffer = GuidBuffer.toRawGuidPlatformBuffer(value);
|
|
139
150
|
// Validate against UUID standard (skip for boundary values)
|
|
140
151
|
const hexString = buffer.toString('hex');
|
|
141
|
-
const fullHex =
|
|
142
|
-
const isBoundary =
|
|
152
|
+
const fullHex = GuidBuffer.toFullHexGuid(hexString);
|
|
153
|
+
const isBoundary = GuidBuffer.isBoundaryValue(fullHex);
|
|
143
154
|
if (!isBoundary && !uuid.validate(fullHex)) {
|
|
144
155
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuid, expectedBrand, undefined, buffer);
|
|
145
156
|
}
|
|
@@ -167,7 +178,7 @@ class Guid {
|
|
|
167
178
|
return this.asBase64Guid;
|
|
168
179
|
}
|
|
169
180
|
static hydrate(value) {
|
|
170
|
-
return new
|
|
181
|
+
return GuidBuffer.withVersion(new GuidBuffer(value));
|
|
171
182
|
}
|
|
172
183
|
static LengthMap = {
|
|
173
184
|
[ecies_lib_1.GuidBrandType.Unknown]: -1,
|
|
@@ -210,6 +221,16 @@ class Guid {
|
|
|
210
221
|
get asRawGuidPlatformBufferUnsafe() {
|
|
211
222
|
return this._value;
|
|
212
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Attaches the RFC 4122 version to a GuidBuffer instance.
|
|
226
|
+
* @param guid The GuidBuffer instance to attach version to
|
|
227
|
+
* @returns The same instance with __version property set
|
|
228
|
+
*/
|
|
229
|
+
static withVersion(guid) {
|
|
230
|
+
const version = guid.getVersion();
|
|
231
|
+
guid.__version = version;
|
|
232
|
+
return guid;
|
|
233
|
+
}
|
|
213
234
|
/**
|
|
214
235
|
* Generates a new random v4 GUID.
|
|
215
236
|
* @returns A new Guid instance with a randomly generated value
|
|
@@ -220,7 +241,7 @@ class Guid {
|
|
|
220
241
|
if (!uuidStr) {
|
|
221
242
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuid);
|
|
222
243
|
}
|
|
223
|
-
return new
|
|
244
|
+
return GuidBuffer.withVersion(new GuidBuffer(uuidStr));
|
|
224
245
|
}
|
|
225
246
|
catch (error) {
|
|
226
247
|
if (error instanceof ecies_lib_1.GuidError) {
|
|
@@ -234,34 +255,34 @@ class Guid {
|
|
|
234
255
|
* @returns A new Guid instance with a randomly generated v4 value
|
|
235
256
|
*/
|
|
236
257
|
static v4() {
|
|
237
|
-
return
|
|
258
|
+
return GuidBuffer.generate();
|
|
238
259
|
}
|
|
239
260
|
/**
|
|
240
261
|
* Alias for generate() for backward compatibility.
|
|
241
262
|
* @deprecated Use generate() instead for clearer intent
|
|
242
263
|
*/
|
|
243
264
|
static new() {
|
|
244
|
-
return
|
|
265
|
+
return GuidBuffer.generate();
|
|
245
266
|
}
|
|
246
267
|
/**
|
|
247
268
|
* Parses a GUID from any valid format, throwing on invalid input.
|
|
248
269
|
* This is the primary parsing method for when you expect valid input.
|
|
249
270
|
* @param value The value to parse
|
|
250
|
-
* @returns A new Guid instance
|
|
271
|
+
* @returns A new Guid instance with __version attached
|
|
251
272
|
* @throws {GuidError} If the value is not a valid GUID
|
|
252
273
|
*/
|
|
253
274
|
static parse(value) {
|
|
254
|
-
return new
|
|
275
|
+
return GuidBuffer.withVersion(new GuidBuffer(value));
|
|
255
276
|
}
|
|
256
277
|
/**
|
|
257
278
|
* Attempts to parse a GUID, returning null on failure instead of throwing.
|
|
258
279
|
* Use this when you're uncertain if the input is valid.
|
|
259
280
|
* @param value The value to parse
|
|
260
|
-
* @returns A new Guid instance or null if parsing fails
|
|
281
|
+
* @returns A new Guid instance with __version attached, or null if parsing fails
|
|
261
282
|
*/
|
|
262
283
|
static tryParse(value) {
|
|
263
284
|
try {
|
|
264
|
-
return new
|
|
285
|
+
return GuidBuffer.withVersion(new GuidBuffer(value));
|
|
265
286
|
}
|
|
266
287
|
catch {
|
|
267
288
|
return null;
|
|
@@ -277,7 +298,7 @@ class Guid {
|
|
|
277
298
|
if (!value)
|
|
278
299
|
return false;
|
|
279
300
|
try {
|
|
280
|
-
const guid = new
|
|
301
|
+
const guid = new GuidBuffer(value);
|
|
281
302
|
return guid.isValidV4();
|
|
282
303
|
}
|
|
283
304
|
catch {
|
|
@@ -287,68 +308,68 @@ class Guid {
|
|
|
287
308
|
/**
|
|
288
309
|
* Factory method to create a GUID from a full hex string.
|
|
289
310
|
* @param fullHex The full hex string (with dashes)
|
|
290
|
-
* @returns A new Guid instance
|
|
311
|
+
* @returns A new Guid instance with __version attached
|
|
291
312
|
*/
|
|
292
313
|
static fromFullHex(fullHex) {
|
|
293
|
-
return new
|
|
314
|
+
return GuidBuffer.withVersion(new GuidBuffer(fullHex));
|
|
294
315
|
}
|
|
295
316
|
/**
|
|
296
317
|
* Factory method to create a GUID from a short hex string.
|
|
297
318
|
* @param shortHex The short hex string (without dashes)
|
|
298
|
-
* @returns A new Guid instance
|
|
319
|
+
* @returns A new Guid instance with __version attached
|
|
299
320
|
*/
|
|
300
321
|
static fromShortHex(shortHex) {
|
|
301
|
-
return new
|
|
322
|
+
return GuidBuffer.withVersion(new GuidBuffer(shortHex));
|
|
302
323
|
}
|
|
303
324
|
/**
|
|
304
325
|
* Factory method to create a GUID from a base64 string.
|
|
305
326
|
* @param base64 The base64 encoded string
|
|
306
|
-
* @returns A new Guid instance
|
|
327
|
+
* @returns A new Guid instance with __version attached
|
|
307
328
|
*/
|
|
308
329
|
static fromBase64(base64) {
|
|
309
|
-
return new
|
|
330
|
+
return GuidBuffer.withVersion(new GuidBuffer(base64));
|
|
310
331
|
}
|
|
311
332
|
/**
|
|
312
333
|
* Factory method to create a GUID from a bigint.
|
|
313
334
|
* @param bigint The bigint value
|
|
314
|
-
* @returns A new Guid instance
|
|
335
|
+
* @returns A new Guid instance with __version attached
|
|
315
336
|
*/
|
|
316
337
|
static fromBigInt(bigint) {
|
|
317
|
-
return new
|
|
338
|
+
return GuidBuffer.withVersion(new GuidBuffer(bigint));
|
|
318
339
|
}
|
|
319
340
|
/**
|
|
320
341
|
* Factory method to create a GUID from a raw buffer.
|
|
321
342
|
* @param buffer The raw 16-byte buffer
|
|
322
|
-
* @returns A new Guid instance
|
|
343
|
+
* @returns A new Guid instance with __version attached
|
|
323
344
|
*/
|
|
324
345
|
static fromBuffer(buffer) {
|
|
325
|
-
return new
|
|
346
|
+
return GuidBuffer.withVersion(new GuidBuffer(buffer));
|
|
326
347
|
}
|
|
327
348
|
/**
|
|
328
349
|
* Factory method to create a GUID from a raw Uint8Array.
|
|
329
350
|
* This converts the Uint8Array to a Buffer first.
|
|
330
351
|
* @param bytes The raw 16-byte Uint8Array
|
|
331
|
-
* @returns A new Guid instance
|
|
352
|
+
* @returns A new Guid instance with __version attached
|
|
332
353
|
*/
|
|
333
354
|
static fromUint8Array(bytes) {
|
|
334
|
-
return new
|
|
355
|
+
return GuidBuffer.withVersion(new GuidBuffer(Buffer.from(bytes)));
|
|
335
356
|
}
|
|
336
357
|
/**
|
|
337
358
|
* Creates a namespace-based v3 GUID (MD5 hash).
|
|
338
359
|
* Use this for deterministic GUIDs based on a namespace and name.
|
|
339
360
|
* @param namespace The namespace GUID (e.g., uuid.v3.DNS)
|
|
340
361
|
* @param name The name to hash within the namespace
|
|
341
|
-
* @returns A new Guid instance containing the v3 GUID
|
|
362
|
+
* @returns A new Guid instance containing the v3 GUID with __version attached
|
|
342
363
|
* @example
|
|
343
364
|
* const guid = Guid.v3('example.com', uuid.v3.DNS);
|
|
344
365
|
*/
|
|
345
366
|
static v3(name, namespace) {
|
|
346
367
|
try {
|
|
347
368
|
const namespaceStr = Buffer.isBuffer(namespace)
|
|
348
|
-
?
|
|
369
|
+
? GuidBuffer.toFullHexGuid(namespace.toString('hex'))
|
|
349
370
|
: namespace;
|
|
350
371
|
const v3Guid = uuid.v3(name, namespaceStr);
|
|
351
|
-
return new
|
|
372
|
+
return GuidBuffer.withVersion(new GuidBuffer(v3Guid));
|
|
352
373
|
}
|
|
353
374
|
catch (error) {
|
|
354
375
|
if (error instanceof ecies_lib_1.GuidError) {
|
|
@@ -363,17 +384,17 @@ class Guid {
|
|
|
363
384
|
* Preferred over v3 as SHA-1 is stronger than MD5.
|
|
364
385
|
* @param namespace The namespace GUID (e.g., uuid.v5.DNS)
|
|
365
386
|
* @param name The name to hash within the namespace
|
|
366
|
-
* @returns A new Guid instance containing the v5 GUID
|
|
387
|
+
* @returns A new Guid instance containing the v5 GUID with __version attached
|
|
367
388
|
* @example
|
|
368
389
|
* const guid = Guid.v5('example.com', uuid.v5.DNS);
|
|
369
390
|
*/
|
|
370
391
|
static v5(name, namespace) {
|
|
371
392
|
try {
|
|
372
393
|
const namespaceStr = Buffer.isBuffer(namespace)
|
|
373
|
-
?
|
|
394
|
+
? GuidBuffer.toFullHexGuid(namespace.toString('hex'))
|
|
374
395
|
: namespace;
|
|
375
396
|
const v5Guid = uuid.v5(name, namespaceStr);
|
|
376
|
-
return new
|
|
397
|
+
return GuidBuffer.withVersion(new GuidBuffer(v5Guid));
|
|
377
398
|
}
|
|
378
399
|
catch (error) {
|
|
379
400
|
if (error instanceof ecies_lib_1.GuidError) {
|
|
@@ -400,7 +421,7 @@ class Guid {
|
|
|
400
421
|
get asFullHexGuid() {
|
|
401
422
|
if (!this._cachedFullHex) {
|
|
402
423
|
const hexString = this._value.toString('hex');
|
|
403
|
-
this._cachedFullHex =
|
|
424
|
+
this._cachedFullHex = GuidBuffer.toFullHexGuid(hexString);
|
|
404
425
|
}
|
|
405
426
|
return this._cachedFullHex;
|
|
406
427
|
}
|
|
@@ -422,7 +443,7 @@ class Guid {
|
|
|
422
443
|
*/
|
|
423
444
|
get asShortHexGuid() {
|
|
424
445
|
if (!this._cachedShortHex) {
|
|
425
|
-
this._cachedShortHex =
|
|
446
|
+
this._cachedShortHex = GuidBuffer.toShortHexGuid(this.asFullHexGuid);
|
|
426
447
|
}
|
|
427
448
|
return this._cachedShortHex;
|
|
428
449
|
}
|
|
@@ -464,10 +485,10 @@ class Guid {
|
|
|
464
485
|
* @returns True if the value is a boundary value.
|
|
465
486
|
*/
|
|
466
487
|
static isBoundaryValue(value) {
|
|
467
|
-
return (value ===
|
|
468
|
-
value ===
|
|
469
|
-
value ===
|
|
470
|
-
value ===
|
|
488
|
+
return (value === GuidBuffer.BOUNDARY_VALUES.ALL_ZEROS_FULL ||
|
|
489
|
+
value === GuidBuffer.BOUNDARY_VALUES.ALL_ZEROS_SHORT ||
|
|
490
|
+
value === GuidBuffer.BOUNDARY_VALUES.ALL_FS_FULL ||
|
|
491
|
+
value === GuidBuffer.BOUNDARY_VALUES.ALL_FS_SHORT);
|
|
471
492
|
}
|
|
472
493
|
/**
|
|
473
494
|
* Verifies if a given GUID is valid for the given brand.
|
|
@@ -480,7 +501,7 @@ class Guid {
|
|
|
480
501
|
return false;
|
|
481
502
|
}
|
|
482
503
|
try {
|
|
483
|
-
const verifyFunc =
|
|
504
|
+
const verifyFunc = GuidBuffer.VerifyFunctions[guidBrand];
|
|
484
505
|
return verifyFunc(guid);
|
|
485
506
|
}
|
|
486
507
|
catch {
|
|
@@ -493,7 +514,7 @@ class Guid {
|
|
|
493
514
|
* @returns The length of the GUID for the given brand.
|
|
494
515
|
*/
|
|
495
516
|
static guidBrandToLength(guidBrand) {
|
|
496
|
-
const length =
|
|
517
|
+
const length = GuidBuffer.LengthMap[guidBrand];
|
|
497
518
|
if (length <= 0) {
|
|
498
519
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuidUnknownBrand, guidBrand);
|
|
499
520
|
}
|
|
@@ -509,7 +530,7 @@ class Guid {
|
|
|
509
530
|
if (length <= 0) {
|
|
510
531
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuidUnknownLength, undefined, length);
|
|
511
532
|
}
|
|
512
|
-
const brand =
|
|
533
|
+
const brand = GuidBuffer.ReverseLengthMap[length];
|
|
513
534
|
if (!brand || brand === ecies_lib_1.GuidBrandType.Unknown) {
|
|
514
535
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuidUnknownLength, undefined, length);
|
|
515
536
|
}
|
|
@@ -530,16 +551,16 @@ class Guid {
|
|
|
530
551
|
if (fullHexGuidValue === null || fullHexGuidValue === undefined) {
|
|
531
552
|
return false;
|
|
532
553
|
}
|
|
533
|
-
const expectedLength =
|
|
554
|
+
const expectedLength = GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.FullHexGuid);
|
|
534
555
|
const strValue = String(fullHexGuidValue);
|
|
535
556
|
if (strValue.length !== expectedLength) {
|
|
536
557
|
return false;
|
|
537
558
|
}
|
|
538
559
|
// Boundary values are always valid
|
|
539
|
-
if (
|
|
560
|
+
if (GuidBuffer.isBoundaryValue(strValue)) {
|
|
540
561
|
return true;
|
|
541
562
|
}
|
|
542
|
-
return
|
|
563
|
+
return GuidBuffer.validateUuid(strValue);
|
|
543
564
|
}
|
|
544
565
|
catch {
|
|
545
566
|
return false;
|
|
@@ -555,15 +576,15 @@ class Guid {
|
|
|
555
576
|
if (shortHexGuidValue === null || shortHexGuidValue === undefined) {
|
|
556
577
|
return false;
|
|
557
578
|
}
|
|
558
|
-
const expectedLength =
|
|
579
|
+
const expectedLength = GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.ShortHexGuid);
|
|
559
580
|
const strValue = String(shortHexGuidValue);
|
|
560
581
|
if (strValue.length !== expectedLength) {
|
|
561
582
|
return false;
|
|
562
583
|
}
|
|
563
584
|
try {
|
|
564
|
-
const fullHexGuid =
|
|
585
|
+
const fullHexGuid = GuidBuffer.toFullHexGuid(strValue);
|
|
565
586
|
// Boundary values are always valid
|
|
566
|
-
if (
|
|
587
|
+
if (GuidBuffer.isBoundaryValue(fullHexGuid)) {
|
|
567
588
|
return true;
|
|
568
589
|
}
|
|
569
590
|
return uuid.validate(fullHexGuid);
|
|
@@ -590,20 +611,20 @@ class Guid {
|
|
|
590
611
|
if (typeof value === 'bigint') {
|
|
591
612
|
valueLength = value.toString(16).length;
|
|
592
613
|
}
|
|
593
|
-
else if (
|
|
614
|
+
else if (GuidBuffer.isBufferLike(value)) {
|
|
594
615
|
valueLength = value.length;
|
|
595
616
|
}
|
|
596
617
|
else {
|
|
597
618
|
valueLength = String(value).length;
|
|
598
619
|
}
|
|
599
|
-
const result = valueLength ===
|
|
620
|
+
const result = valueLength === GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.Base64Guid);
|
|
600
621
|
if (result) {
|
|
601
622
|
try {
|
|
602
|
-
const fromBase64 =
|
|
623
|
+
const fromBase64 = GuidBuffer.toRawGuidPlatformBuffer(value);
|
|
603
624
|
const hexString = fromBase64.toString('hex');
|
|
604
|
-
const fullHexGuid =
|
|
625
|
+
const fullHexGuid = GuidBuffer.toFullHexGuid(hexString);
|
|
605
626
|
// Boundary values are always valid
|
|
606
|
-
if (
|
|
627
|
+
if (GuidBuffer.isBoundaryValue(fullHexGuid)) {
|
|
607
628
|
return true;
|
|
608
629
|
}
|
|
609
630
|
return uuid.validate(fullHexGuid);
|
|
@@ -628,12 +649,12 @@ class Guid {
|
|
|
628
649
|
if (value === null || value === undefined) {
|
|
629
650
|
return false;
|
|
630
651
|
}
|
|
631
|
-
const expectedLength =
|
|
652
|
+
const expectedLength = GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.RawGuidPlatformBuffer);
|
|
632
653
|
let valueLength;
|
|
633
654
|
if (typeof value === 'bigint') {
|
|
634
655
|
valueLength = value.toString(16).length;
|
|
635
656
|
}
|
|
636
|
-
else if (
|
|
657
|
+
else if (GuidBuffer.isBufferLike(value)) {
|
|
637
658
|
valueLength = value.length;
|
|
638
659
|
}
|
|
639
660
|
else {
|
|
@@ -643,18 +664,18 @@ class Guid {
|
|
|
643
664
|
return false;
|
|
644
665
|
}
|
|
645
666
|
try {
|
|
646
|
-
if (!
|
|
667
|
+
if (!GuidBuffer.isBufferLike(value)) {
|
|
647
668
|
return false;
|
|
648
669
|
}
|
|
649
670
|
// Convert Uint8Array to Buffer if needed
|
|
650
671
|
const buffer = Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
651
672
|
const hexString = buffer.toString('hex');
|
|
652
|
-
const fullHexGuid =
|
|
673
|
+
const fullHexGuid = GuidBuffer.toFullHexGuid(hexString);
|
|
653
674
|
// Boundary values are always valid
|
|
654
|
-
if (
|
|
675
|
+
if (GuidBuffer.isBoundaryValue(fullHexGuid)) {
|
|
655
676
|
return true;
|
|
656
677
|
}
|
|
657
|
-
return
|
|
678
|
+
return GuidBuffer.validateUuid(fullHexGuid);
|
|
658
679
|
}
|
|
659
680
|
catch {
|
|
660
681
|
return false;
|
|
@@ -677,13 +698,13 @@ class Guid {
|
|
|
677
698
|
if (typeof value !== 'bigint') {
|
|
678
699
|
return false;
|
|
679
700
|
}
|
|
680
|
-
if (value < 0n || value >
|
|
701
|
+
if (value < 0n || value > GuidBuffer.MAX_BIGINT_VALUE) {
|
|
681
702
|
return false;
|
|
682
703
|
}
|
|
683
704
|
try {
|
|
684
|
-
const fromBigInt =
|
|
705
|
+
const fromBigInt = GuidBuffer.toFullHexFromBigInt(value);
|
|
685
706
|
// Boundary values are always valid
|
|
686
|
-
if (
|
|
707
|
+
if (GuidBuffer.isBoundaryValue(fromBigInt)) {
|
|
687
708
|
return true;
|
|
688
709
|
}
|
|
689
710
|
return uuid.validate(fromBigInt);
|
|
@@ -708,11 +729,11 @@ class Guid {
|
|
|
708
729
|
if (typeof value === 'bigint') {
|
|
709
730
|
return ecies_lib_1.GuidBrandType.BigIntGuid;
|
|
710
731
|
}
|
|
711
|
-
const isBuffer =
|
|
732
|
+
const isBuffer = GuidBuffer.isBufferLike(value);
|
|
712
733
|
const expectedLength = isBuffer
|
|
713
734
|
? value.length
|
|
714
735
|
: String(value).length;
|
|
715
|
-
return
|
|
736
|
+
return GuidBuffer.lengthToGuidBrand(expectedLength, isBuffer);
|
|
716
737
|
}
|
|
717
738
|
/**
|
|
718
739
|
* Converts a given short hex GUID to a full hex GUID.
|
|
@@ -734,32 +755,34 @@ class Guid {
|
|
|
734
755
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuid);
|
|
735
756
|
}
|
|
736
757
|
if (typeof guid === 'bigint') {
|
|
737
|
-
return
|
|
758
|
+
return GuidBuffer.toFullHexFromBigInt(guid);
|
|
738
759
|
}
|
|
739
|
-
else if (
|
|
760
|
+
else if (GuidBuffer.isBufferLike(guid) &&
|
|
740
761
|
guid.length ===
|
|
741
|
-
|
|
762
|
+
GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.RawGuidPlatformBuffer)) {
|
|
742
763
|
const hexString = guid.toString('hex');
|
|
743
764
|
const shortHex = hexString;
|
|
744
|
-
return
|
|
765
|
+
return GuidBuffer.shortGuidToFullGuid(shortHex);
|
|
745
766
|
}
|
|
746
|
-
else if (
|
|
767
|
+
else if (GuidBuffer.isBufferLike(guid)) {
|
|
747
768
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuid);
|
|
748
769
|
}
|
|
749
770
|
// all remaining cases are string types
|
|
750
771
|
const strValue = String(guid);
|
|
751
|
-
if (strValue.length ===
|
|
772
|
+
if (strValue.length ===
|
|
773
|
+
GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.ShortHexGuid)) {
|
|
752
774
|
// short hex guid
|
|
753
|
-
return
|
|
775
|
+
return GuidBuffer.shortGuidToFullGuid(strValue);
|
|
754
776
|
}
|
|
755
|
-
else if (strValue.length ===
|
|
777
|
+
else if (strValue.length ===
|
|
778
|
+
GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.FullHexGuid)) {
|
|
756
779
|
// already a full hex guid
|
|
757
780
|
return strValue;
|
|
758
781
|
}
|
|
759
|
-
else if (strValue.length ===
|
|
782
|
+
else if (strValue.length === GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.Base64Guid)) {
|
|
760
783
|
// base64 guid
|
|
761
784
|
const shortGuid = Buffer.from(strValue, 'base64').toString('hex');
|
|
762
|
-
return
|
|
785
|
+
return GuidBuffer.shortGuidToFullGuid(shortGuid);
|
|
763
786
|
}
|
|
764
787
|
else {
|
|
765
788
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuid);
|
|
@@ -770,28 +793,30 @@ class Guid {
|
|
|
770
793
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuid);
|
|
771
794
|
}
|
|
772
795
|
if (typeof guid === 'bigint') {
|
|
773
|
-
const fullHex =
|
|
796
|
+
const fullHex = GuidBuffer.toFullHexFromBigInt(guid);
|
|
774
797
|
return fullHex.replace(/-/g, '');
|
|
775
798
|
}
|
|
776
|
-
else if (
|
|
799
|
+
else if (GuidBuffer.isBufferLike(guid) &&
|
|
777
800
|
guid.length ===
|
|
778
|
-
|
|
801
|
+
GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.RawGuidPlatformBuffer)) {
|
|
779
802
|
return guid.toString('hex');
|
|
780
803
|
}
|
|
781
|
-
else if (
|
|
804
|
+
else if (GuidBuffer.isBufferLike(guid)) {
|
|
782
805
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuid);
|
|
783
806
|
}
|
|
784
807
|
// all remaining cases are string types
|
|
785
808
|
const strValue = String(guid);
|
|
786
|
-
if (strValue.length ===
|
|
809
|
+
if (strValue.length ===
|
|
810
|
+
GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.ShortHexGuid)) {
|
|
787
811
|
// already a short hex guid
|
|
788
812
|
return strValue;
|
|
789
813
|
}
|
|
790
|
-
else if (strValue.length ===
|
|
814
|
+
else if (strValue.length ===
|
|
815
|
+
GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.FullHexGuid)) {
|
|
791
816
|
// full hex guid
|
|
792
817
|
return strValue.replace(/-/g, '');
|
|
793
818
|
}
|
|
794
|
-
else if (strValue.length ===
|
|
819
|
+
else if (strValue.length === GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.Base64Guid)) {
|
|
795
820
|
// base64 guid
|
|
796
821
|
return Buffer.from(strValue, 'base64').toString('hex');
|
|
797
822
|
}
|
|
@@ -805,7 +830,7 @@ class Guid {
|
|
|
805
830
|
* @returns The bigint as a full hex GUID.
|
|
806
831
|
*/
|
|
807
832
|
static toFullHexFromBigInt(bigInt) {
|
|
808
|
-
if (bigInt < 0n || bigInt >
|
|
833
|
+
if (bigInt < 0n || bigInt > GuidBuffer.MAX_BIGINT_VALUE) {
|
|
809
834
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuid);
|
|
810
835
|
}
|
|
811
836
|
const uuidBigInt = bigInt.toString(16).padStart(32, '0');
|
|
@@ -830,14 +855,14 @@ class Guid {
|
|
|
830
855
|
* @returns The GUID value as a raw GUID buffer.
|
|
831
856
|
*/
|
|
832
857
|
static toRawGuidPlatformBuffer(value) {
|
|
833
|
-
const expectedBrand =
|
|
858
|
+
const expectedBrand = GuidBuffer.whichBrand(value);
|
|
834
859
|
let rawGuidBufferResult = Buffer.alloc(0);
|
|
835
860
|
switch (expectedBrand) {
|
|
836
861
|
case ecies_lib_1.GuidBrandType.FullHexGuid:
|
|
837
|
-
rawGuidBufferResult = Buffer.from(
|
|
862
|
+
rawGuidBufferResult = Buffer.from(GuidBuffer.toShortHexGuid(value), 'hex');
|
|
838
863
|
break;
|
|
839
864
|
case ecies_lib_1.GuidBrandType.ShortHexGuid:
|
|
840
|
-
rawGuidBufferResult = Buffer.from(
|
|
865
|
+
rawGuidBufferResult = Buffer.from(GuidBuffer.toShortHexGuid(value), 'hex');
|
|
841
866
|
break;
|
|
842
867
|
case ecies_lib_1.GuidBrandType.Base64Guid:
|
|
843
868
|
// Ensure value is a string before using it with Buffer.from
|
|
@@ -861,13 +886,13 @@ class Guid {
|
|
|
861
886
|
}
|
|
862
887
|
break;
|
|
863
888
|
case ecies_lib_1.GuidBrandType.BigIntGuid:
|
|
864
|
-
rawGuidBufferResult = Buffer.from(
|
|
889
|
+
rawGuidBufferResult = Buffer.from(GuidBuffer.toShortHexGuid(GuidBuffer.toFullHexFromBigInt(value)), 'hex');
|
|
865
890
|
break;
|
|
866
891
|
default:
|
|
867
892
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuidUnknownBrand);
|
|
868
893
|
}
|
|
869
894
|
if (rawGuidBufferResult.length !==
|
|
870
|
-
|
|
895
|
+
GuidBuffer.guidBrandToLength(ecies_lib_1.GuidBrandType.RawGuidPlatformBuffer)) {
|
|
871
896
|
throw new ecies_lib_1.GuidError(ecies_lib_1.GuidErrorType.InvalidGuidUnknownLength, undefined, rawGuidBufferResult.length);
|
|
872
897
|
}
|
|
873
898
|
return rawGuidBufferResult;
|
|
@@ -914,14 +939,14 @@ class Guid {
|
|
|
914
939
|
* @returns True if the GUID is null, undefined, or empty
|
|
915
940
|
*/
|
|
916
941
|
static isNilOrEmpty(guid) {
|
|
917
|
-
return !guid || (guid instanceof
|
|
942
|
+
return !guid || (guid instanceof GuidBuffer && guid.isEmpty());
|
|
918
943
|
}
|
|
919
944
|
/**
|
|
920
945
|
* Creates a new Guid instance with the same value as this one.
|
|
921
|
-
* @returns A new Guid instance with identical value
|
|
946
|
+
* @returns A new Guid instance with identical value and __version attached
|
|
922
947
|
*/
|
|
923
948
|
clone() {
|
|
924
|
-
return new
|
|
949
|
+
return GuidBuffer.withVersion(new GuidBuffer(Buffer.from(this._value)));
|
|
925
950
|
}
|
|
926
951
|
/**
|
|
927
952
|
* Returns the hash code for this GUID based on its buffer content.
|
|
@@ -943,7 +968,7 @@ class Guid {
|
|
|
943
968
|
*/
|
|
944
969
|
getVersion() {
|
|
945
970
|
// Skip boundary values
|
|
946
|
-
if (
|
|
971
|
+
if (GuidBuffer.isBoundaryValue(this.asFullHexGuid)) {
|
|
947
972
|
return undefined;
|
|
948
973
|
}
|
|
949
974
|
// Version is in bits 48-51 (byte 6, high nibble)
|
|
@@ -966,7 +991,7 @@ class Guid {
|
|
|
966
991
|
*/
|
|
967
992
|
isValidV4() {
|
|
968
993
|
// Boundary values are considered valid
|
|
969
|
-
if (
|
|
994
|
+
if (GuidBuffer.isBoundaryValue(this.asFullHexGuid)) {
|
|
970
995
|
return true;
|
|
971
996
|
}
|
|
972
997
|
const version = this.getVersion();
|
|
@@ -1029,12 +1054,12 @@ class Guid {
|
|
|
1029
1054
|
}
|
|
1030
1055
|
/**
|
|
1031
1056
|
* Creates a v1 GUID (time-based).
|
|
1032
|
-
* @returns A new Guid instance containing a v1 GUID
|
|
1057
|
+
* @returns A new Guid instance containing a v1 GUID with __version attached
|
|
1033
1058
|
*/
|
|
1034
1059
|
static v1() {
|
|
1035
1060
|
try {
|
|
1036
1061
|
const v1Guid = uuid.v1();
|
|
1037
|
-
return new
|
|
1062
|
+
return GuidBuffer.withVersion(new GuidBuffer(v1Guid));
|
|
1038
1063
|
}
|
|
1039
1064
|
catch (error) {
|
|
1040
1065
|
if (error instanceof ecies_lib_1.GuidError)
|
|
@@ -1061,22 +1086,23 @@ class Guid {
|
|
|
1061
1086
|
}
|
|
1062
1087
|
/**
|
|
1063
1088
|
* Creates a GUID from URL-safe base64.
|
|
1089
|
+
* @returns A new Guid instance with __version attached
|
|
1064
1090
|
*/
|
|
1065
1091
|
static fromUrlSafeBase64(urlSafe) {
|
|
1066
1092
|
const base64 = urlSafe
|
|
1067
1093
|
.replace(/-/g, '+')
|
|
1068
1094
|
.replace(/_/g, '/')
|
|
1069
1095
|
.padEnd(24, '=');
|
|
1070
|
-
return new
|
|
1096
|
+
return GuidBuffer.withVersion(new GuidBuffer(base64));
|
|
1071
1097
|
}
|
|
1072
1098
|
/**
|
|
1073
1099
|
* Alias for isRawGuidPlatformBuffer for backward compatibility
|
|
1074
1100
|
*/
|
|
1075
|
-
static isRawGuidBuffer =
|
|
1101
|
+
static isRawGuidBuffer = GuidBuffer.isRawGuidPlatformBuffer;
|
|
1076
1102
|
/**
|
|
1077
1103
|
* Alias for toRawGuidPlatformBuffer for backward compatibility
|
|
1078
1104
|
*/
|
|
1079
|
-
static toRawGuidBuffer =
|
|
1105
|
+
static toRawGuidBuffer = GuidBuffer.toRawGuidPlatformBuffer;
|
|
1080
1106
|
}
|
|
1081
|
-
exports.
|
|
1107
|
+
exports.GuidBuffer = GuidBuffer;
|
|
1082
1108
|
//# sourceMappingURL=guid.js.map
|