Skip to content

Commit cad605f

Browse files
sakshamg1304rohitesh-wingify
authored andcommitted
fix: add identifiable lib for uuid v5
1 parent 715b4a3 commit cad605f

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.7.0] - 2025-03-27
9+
10+
### Added
11+
- Added identifiable library to import uuid v5 methods instead of implementing in code
12+
-
13+
814
## [1.6.0] - 2025-03-12
915

1016
### Added

VWOFmeSdk.NetStandard2.0/VWOFmeSdk.NetStandard2.0.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<AssemblyName>VWOFmeSdk</AssemblyName>
77
<TargetFramework>net8.0</TargetFramework>
88
<PackageId>VWO.FME.Sdk</PackageId>
9-
<Version>1.6.0</Version>
9+
<Version>1.7.0</Version>
1010
<Authors>VWO devs</Authors>
1111
<Company>Wingify</Company>
1212
<Product>VWO</Product>

VWOFmeSdk/Utils/UUIDUtils.cs

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,14 @@
1717
#pragma warning restore 1587
1818

1919
using System;
20-
using System.Linq;
20+
using Identifiable;
2121

2222
namespace VWOFmeSdk.Utils
2323
{
2424
public static class UUIDUtils
2525
{
26-
/// <summary>
27-
/// This method generates a random UUID.
28-
/// </summary>
29-
/// <param name="apiKey"></param>
30-
/// <returns></returns>
31-
public static string GetRandomUUID(string apiKey)
32-
{
33-
var namespaceUUID = new Guid("00000000-0000-0000-0000-000000000000");
34-
var randomUUID = Guid.NewGuid();
35-
return new Guid(namespaceUUID.ToByteArray()).ToString();
36-
}
26+
private static readonly Guid UrlNamespace = new Guid("6ba7b811-9dad-11d1-80b4-00c04fd430c8"); // The namespace for URLs
27+
private static readonly string VWO_NAMESPACE_URL = "https://vwo.com";
3728

3829
/// <summary>
3930
/// This method generates a UUID for a given userId and accountId.
@@ -43,31 +34,27 @@ public static string GetRandomUUID(string apiKey)
4334
/// <returns></returns>
4435
public static string GetUUID(string userId, string accountId)
4536
{
46-
var vwoNamespace = Guid.Parse("00000000-0000-0000-0000-000000000000");
47-
var userIdNamespace = GenerateUUID(accountId, vwoNamespace.ToString());
48-
var uuidForUserIdAccountId = GenerateUUID(userId, userIdNamespace.ToString());
49-
return uuidForUserIdAccountId.ToString().Replace("-", "").ToUpper();
37+
var accountIdAsString = accountId.ToString();
38+
39+
// Compute the UUID using NamedGuid.Compute from the Identifiable library
40+
var vwoNamespaceGuid = NamedGuid.Compute(NamedGuidAlgorithm.SHA1, UrlNamespace, VWO_NAMESPACE_URL);
41+
var accountIdGuid = NamedGuid.Compute(NamedGuidAlgorithm.SHA1, vwoNamespaceGuid, accountIdAsString);
42+
var userIdGuid = NamedGuid.Compute(NamedGuidAlgorithm.SHA1, accountIdGuid, userId);
43+
44+
var uuid = userIdGuid.ToString("N").ToUpper(); // Format as a UUID string (no hyphens)
45+
return uuid;
5046
}
5147

5248
/// <summary>
53-
/// This method generates a UUID for a given name and namespaceId.
49+
/// This method generates a random UUID.
5450
/// </summary>
55-
/// <param name="name"></param>
56-
/// <param name="namespaceId"></param>
51+
/// <param name="apiKey"></param>
5752
/// <returns></returns>
58-
private static Guid GenerateUUID(string name, string namespaceId)
53+
public static string GetRandomUUID(string apiKey)
5954
{
60-
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(namespaceId))
61-
{
62-
return default;
63-
}
64-
65-
var namespaceBytes = new Guid(namespaceId).ToByteArray();
66-
var nameBytes = System.Text.Encoding.UTF8.GetBytes(name);
67-
var hash = System.Security.Cryptography.SHA1.Create().ComputeHash(namespaceBytes.Concat(nameBytes).ToArray());
68-
hash[6] = (byte)(0x50 | (hash[6] & 0xf));
69-
hash[8] = (byte)(0x80 | (hash[8] & 0x3f));
70-
return new Guid(hash.Take(16).ToArray());
55+
var namespaceUUID = new Guid("00000000-0000-0000-0000-000000000000");
56+
var randomUUID = Guid.NewGuid();
57+
return new Guid(namespaceUUID.ToByteArray()).ToString();
7158
}
7259
}
7360
}

0 commit comments

Comments
 (0)