Skip to content

Commit

Permalink
Merge pull request #114 from IABTechLab/ans-UID2-4449-helper-for-euid…
Browse files Browse the repository at this point in the history
…-hashing-tool

UID2 Helper for Hashing generalized for EUID
  • Loading branch information
ashleysmithTTD authored Nov 26, 2024
2 parents e1182a5 + bd95942 commit 3c224a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/euidSdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventType, CallbackHandler } from './callbackManager';
import { CallbackContainer, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase';
import { CallbackContainer, UIDHelper, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase';
import { ProductDetails } from './product';
import { UidSecureSignalProviderType } from './secureSignal_types';
import { loadConfig } from './configManager';
Expand Down Expand Up @@ -55,6 +55,7 @@ export class EUID extends SdkBase {
declare global {
interface Window {
__euid: EUID | SDKSetup | undefined;
__euidHelper: UIDHelper | undefined;
__euidSecureSignalProvider?: UidSecureSignalProviderType;
}
}
Expand All @@ -80,6 +81,7 @@ export function __euidInternalHandleScriptLoad() {
const callbacks = window?.__euid?.callbacks || [];
const callbackContainer: CallbackContainer = {};
window.__euid = new EUID(callbacks, callbackContainer);
window.__euidHelper = new UIDHelper();
if (callbackContainer.callback) callbackContainer.callback();
bootstrapInit();
}
Expand Down
20 changes: 19 additions & 1 deletion src/sdkBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isNormalizedPhone, normalizeEmail } from './diiNormalization';
import { isBase64Hash } from './hashedDii';
import { PromiseHandler } from './promiseHandler';
import { StorageManager } from './storageManager';
import { hashAndEncodeIdentifier } from './encoding/hash';
import { hashAndEncodeIdentifier, hashIdentifier } from './encoding/hash';
import { ProductDetails, ProductName } from './product';
import { storeConfig, updateConfig } from './configManager';
import { loadIdentityFromCookieNoLegacy } from './cookieManager';
Expand All @@ -27,6 +27,24 @@ export type SDKSetup = {
};
export type CallbackContainer = { callback?: () => void };

export class UIDHelper {
public normalizeEmail(email: string) {
return normalizeEmail(email);
}

public hashIdentifier(normalizedEmail: string) {
return hashIdentifier(normalizedEmail);
}

public async hashAndEncodeIdentifier(normalizedEmail: string) {
return await hashAndEncodeIdentifier(normalizedEmail);
}

public isNormalizedPhone(phone: string) {
return isNormalizedPhone(phone);
}
}

export abstract class SdkBase {
static get VERSION() {
return version;
Expand Down
26 changes: 3 additions & 23 deletions src/uid2Sdk.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
import { EventType, CallbackHandler } from './callbackManager';
import { isNormalizedPhone, normalizeEmail } from './diiNormalization';
import { hashAndEncodeIdentifier, hashIdentifier } from './encoding/hash';
import { CallbackContainer, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase';
import { CallbackContainer, UIDHelper, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase';
import { ProductDetails } from './product';
import { loadConfig } from './configManager';
import { UidSecureSignalProviderType } from './secureSignal_types';

export * from './exports';

export class UID2Helper {
public normalizeEmail(email: string) {
return normalizeEmail(email);
}

public hashIdentifier(normalizedEmail: string) {
return hashIdentifier(normalizedEmail);
}

public async hashAndEncodeIdentifier(normalizedEmail: string) {
return await hashAndEncodeIdentifier(normalizedEmail);
}

public isNormalizedPhone(phone: string) {
return isNormalizedPhone(phone);
}
}

const productDetails: ProductDetails = {
name: 'UID2',
defaultBaseUrl: 'https://prod.uidapi.com',
Expand Down Expand Up @@ -75,7 +55,7 @@ export class UID2 extends SdkBase {
declare global {
interface Window {
__uid2: UID2 | SDKSetup | undefined;
__uid2Helper: UID2Helper | undefined;
__uid2Helper: UIDHelper | undefined;
__uid2SecureSignalProvider?: UidSecureSignalProviderType;
}
}
Expand All @@ -102,7 +82,7 @@ export function __uid2InternalHandleScriptLoad() {
const callbacks = window?.__uid2?.callbacks || [];
const callbackContainer: CallbackContainer = {};
window.__uid2 = new UID2(callbacks, callbackContainer);
window.__uid2Helper = new UID2Helper();
window.__uid2Helper = new UIDHelper();
if (callbackContainer.callback) callbackContainer.callback();
bootstrapInit();
}
Expand Down

0 comments on commit 3c224a8

Please sign in to comment.